Make a daily cut loop with NCO for 365 files?

636 views Asked by At


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.

1

There are 1 answers

1
ClimateUnboxed On

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