Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...