1

I have a file I downloaded from http://ngdc.noaa.gov/mgg/global/global.html where I extracted a custom grid to my problem in oceanography. However, this grid has a higher resolution (1 min OR 1/60. degree) than I need to run my experiment. Thus, I was wondering if I wanted to have a 10 min grid resolution, how could I "resize" it using for loops? I know how to make it in MATLAB (code pasted below) but since I want to become a python user I don't have any idea how to do it.

MATLAB code:

 ii=0;
 for i=1:10:1681;
     ii=ii+1;
     jj=0;
     for j=1:10:4561;
         jj=jj+1;
         n=j+((i-1)*4561);
         long2(ii,jj)=lon(n);
         latie2(ii,jj)=lat(n);
         c2(ii,jj)=depth(n);
     end
 end

The depth file has the following structure and its array size is 1621x4561:

array([[  200,   191,   192, ...,  1344,  1345,  1343],
       [  191,   178,   192, ...,  1330,  1332,  1337],
       [  178,   176,   177, ...,  1297,  1303,  1314],
       ..., 
       [-1806, -1853, -1897, ...,   295,   296,   295],
       [-1803, -1845, -1887, ...,   294,   295,   295],
       [-1806, -1844, -1881, ...,   294,   294,   295]], dtype=int16)

THanks in advance

moehbon
  • 41
  • 7
  • `for` loops are the easy solution, not the fastest. See [this](http://stackoverflow.com/questions/32302889/matlab-splitting-small-arrays-by-latitude-longitude-into-individual-grid-cells/32310430#32310430) answer for a faster way to do this. – Adriaan Sep 12 '15 at 07:27

1 Answers1

1

You could try hyperslabbing every tenth lon and lat with ncks

ncks -d lat,,,10 -d lon,,,10 in.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19