简体   繁体   中英

matlab: splitting small arrays by latitude/longitude into individual grid cells of one large array

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.5 o 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.5 o 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.73 o N and 118.01-118.03 o W, 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

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, eg 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 eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM