1

I have multiple satellite orbit paths that cover different latitudes/longitudes, but are all bounded by the same overall lat/lon grid (below). I am trying to split the data from each orbit path into the corresponding 0.5x0.5o lat/lon cell of the large grid.

For example, I'm looking at individual satellite orbits that cross the Beaufort Sea, total lat/lon boundary below:

lat = [82:-0.5:68];   
lon = [-118:-0.5:-160];   

I have 88 orbit files that cover different tracks over the Beaufort Sea. The latitude, longitude, and data from each orbit track is stored in separate cells. Example from one orbit path:

lat{16,1} = [68.751 68.749 68.746 68.743 68.740 68.738 68.735 68.732 68.729 68.726];  
lon{16,1} = [-118.002 -118.006 -118.009 -118.013 -118.016 -118.020 -118.023  
 -118.027 -118.030 -118.034];
data{16,1} = [0 0 0 0 0 1 0 0 0 0; 0 0 0 0 1 1 1 1 1 0; 0 0 0 1 1 1 0 0 0 0];  
% data is stored in height x location  
% each 1 is a cloud, each 0 is clear air  

Each data array is a different length because each orbit path crossed a different number of locations, but has the same number of heights. What I would like is to split the columns of each data array according to their corresponding lat/lon and put each data column into the correct 0.5x0.5o grid cell over the Beaufort Sea. Then I'd divide number of 'clouds' by total number of counts at each location and average to find cloud fraction within each grid cell, but I can figure that out after everything is properly gridded.

So if a grid cell were bounded by 68.75-68.73oN and 118.01-118.03oW, for example, then data columns 4-8 would end up in that grid cell because their lat/lon fall within the grid boundary.

Any help or hints would be greatly appreciated!

Thanks, Aaron

rinzler12
  • 29
  • 4
  • Can you add what the resulting data should look like? I'm having trouble following. – FullStack Aug 31 '15 at 10:24
  • I added a more complete worded description of what I'm looking for, though it doesn't include code as an output so I hope it's still helpful. – rinzler12 Sep 01 '15 at 15:34

1 Answers1

1

Assuming you want to have averages per grid cell, check out this thread on MathCentral.

The outline is as follows: round the coordinates in your data to some positive integer, e.g. round(x/edgelenth-min(X))+1. The round makes sure it's an integer, edgelength is some variable you can set if you want for instance half a degree cells instead of 1 degree, min(X) shifts the origin to 0 and the +1 makes it end up at 1, since MATLAB cannot work with zero index. You can use the same for y, or LAT,LON.

These rounded values you can then group using sparse(lat,lon,z), where z is the data (I'm assuming heights here). Alternatively, if you want to extract more information, use accumarray, for e.g. standard deviations:

datastd = accumarray([LAT LON],z,[],@std,[],issparse);

I'm using this technique on data sets containing some 800M LAT/LON combinations in approximately 5 minutes on a grid with 0.5m edgelength and 1x1km total size.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • I think this is very close to what I'm looking for, thanks. But all my data arrays are different sizes and I'm running into problems with vectors being different lengths when using `sparse`. I'll keep playing around with it. Would you mind posting an example of the code you're using with your lat/lon combinations? – rinzler12 Aug 31 '15 at 18:49
  • Different array sizes shouldn't matter, as long as there's the same amount of LAT,LON,Height combinations. You can find the (partial) code I'm using here: http://stackoverflow.com/questions/32182551/letting-accumarray-ouput-a-table – Adriaan Sep 01 '15 at 08:05