Is there a way to crop a NETCDF file?

jhc picture jhc · Sep 8, 2014 · Viewed 7.4k times · Source

Imagine that you have a file example.nc, that has wind data defined in 90N, 90S, 180E, 180W region. Is there anyway I could in linux, with a simple nc-type command (without extracting the data in matlab/python to rewrite), crop this file to include a smaller region, subset of the above.

For example, 30N, 10S, 60E and 30W.

Answer

N1B4 picture N1B4 · Sep 9, 2014

Yes, using ncks from the NCO package: http://nco.sourceforge.net/nco.html

If you know the indices corresponding to the lat/lon range you want, let's say they are 30-40 in latitude and 25-50 for longitude for example, then you could crop the netCDF file with

ncks -d lat,30,40 -d lon,25,50 example.nc -O cropped_example.nc

make sure you specify the indices with integer values.

Otherwise you can also directly specify the range of the lat and lon values you want, but in this case you must make sure to use decimal points to pass the range as floats.

 ncks -d lat,30.,-10. -d lon,-30.,60. example.nc -O cropped_example.nc