Is there a way to crop a NETCDF file?

Imagine you have an example.nc file that has wind data defined in the 90N, 90S, 180E, 180W areas. In any case, I could use linux with a simple nc-type command (without extracting data in matlab / python for rewriting), trim this file to include a smaller area, a subset of the above.

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

+6
source share
2 answers

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

If you know the indexes corresponding to the desired range of latitude and longitude, let's say they are 30-40 in latitude and 25-50 in longitude, for example, you can trim the netCDF file with

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

make sure you specify indices with integer values.

Otherwise, you can also directly specify the range of lat and lon values ​​that you want, but in this case, you should definitely use decimal points to transmit the range as floating point numbers.

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

NCO works fine, but just to list an alternative, you can also do this with cdo (climate data operators), which I think is easier to remember. You can directly specify longitude and latitude values ​​as follows:

 cdo sellonlatbox,lon1,lon2,lat1,lat2 infile.nc outfile.nc 

where lon1, lon2, lat1, lat2 define the boundaries of the area you need. If it is not already installed, you can get it in Ubuntu with

 sudo apt-get install cdo 

Cdo has many other functions for processing, combining and splitting files, and excellent online documentation.

Please note that for CDO to work, you need to determine the coordinate variables (latitude / longitude) in accordance with the CDF conventions, so the NCO solution is more reliable (see comments).

+4
source

Source: https://habr.com/ru/post/1202098/


All Articles