-1


I use nco linux-command line for cuting my '.nc' files. Normally use lat and lon of my specific area like below:

ncks -d lat,17.52,30.98 -d lon,-98.52,-78.02 img.nc -O cut.nc 

I need to make a loop for a daily cut of 365 files (all year). I am going to do it with Python, but I really want to know if anyone knows a way to do it with the nco package.

Thanks.

M. Neish
  • 80
  • 8

1 Answers1

1

NCO solution

just do a loop in bash using wildcards * - e.g. if your files are called img20170101.nc etc then:

for file in `ls img*.nc` ; do 
  ncks -d lat,17.52,30.98 -d lon,-98.52,-78.02 ${file} -O ${file%???}_cut.nc
done

the %??? removes ".nc" from the filename

CDO solution By the way, as an alternative you can also use CDO to cut areas:

cdo sellonlatbox,lon1,lon2,lat1,lat2 in.nc out.nc 

Python solution Finally, I have recently discover a fantastic new python package PYGEODE that allows you to open netcdf files easily, make time or spatial averages (correctly!) and cut out lat-lon boxes and print on maps. find it here:

https://github.com/pygeode/pygeode

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Thanks for the help, Adrian. I made the cut with a python loop but going to try wildcards as you recommend it. BTW, i need to check 'cdo', it looks like a good alternative. Thanks again. – Enrique Pacheco Sep 15 '17 at 16:55