Getting monthly averages from individual nc files of a selected area?
Added by Ikmal Rosli over 2 years ago
Hello, everyone!
I am new to bash scripting and CDO.
#!/bin/bash infile=/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/daily/*.nc outfile=/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/19970904_monthly_mean.nc cdo -f nc monmean -sellonlatbox,98,122,-15,15 -cat $infile $outfile
The output:
cdo(1) sellonlatbox: Process started
cdo(2) cat: Process started
Does this mean that CDO executes the sellonlatbox
and cat
operator first, before averaging it to monthly?
Thank you.
Replies (5)
RE: Getting monthly averages from individual nc files of a selected area? - Added by Karin Meier-Fleischer over 2 years ago
Hi Ikmal,
CDO executes the operator steps from right to left.
That means it executes
- '-cat $infile' then it pipes the result to
- '-sellonlatbox,98,122,-15,15' and then it pipes the result to
- '-monmean'
RE: Getting monthly averages from individual nc files of a selected area? - Added by Ikmal Rosli over 2 years ago
Hi Karin,
It's taking quite some time to execute those two lines of code. I tried reversing the order of the operators like so:
#!/bin/bash infile=/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/daily/*.nc outfile=/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/19970904_monthly_mean.nc cdo -f nc -monmean -cat -sellonlatbox,98,122,-15,15 $infile $outfile
But this error showed up:
cdo(1) cat: Process started cdo(2) sellonlatbox: Process started cdo(1) cat: 0%cdf_create : ncid=-1 mode=512 chunksizehint=0 file=/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/daily_98125-1515/ Error (cdf_create): /Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/daily_98125-1515/: No such file or directory
I guess the size is not compatible, when sellonlatbox
is called first. Is there any other way to speed up the process?
Thank you.
RE: Getting monthly averages from individual nc files of a selected area? - Added by Ikmal Rosli over 2 years ago
Hi again, Karin.
Wrong output! Here's the output:
cdo(1) cat: Process started cdo(2) sellonlatbox: Process started cdo(1) cat: 0%cdo(2) sellonlatbox: Processed 74649600 values from 2 variables over 1 timestep. cdo(1) cat (Abort): Grid size of the input parameter CHL do not match! [bt] Execution path: [bt] 0 cdo 0x00000001007fcccc show_stackframe + 52 [bt] 1 cdo 0x00000001007fb960 reshGetElem + 348 [bt] 2 cdo 0x00000001007fb7f8 reshGetValue + 12 [bt] 3 cdo 0x000000010082c508 vlistInqTaxis + 68 [bt] 4 cdo 0x0000000100838000 streamClose + 688 [bt] 5 cdo 0x00000001007fb1f0 reshListDestruct + 172 [bt] 6 cdo 0x00000001007fa830 namespaceDelete + 88 [bt] 7 cdo 0x00000001007fcb40 listDestroy + 88 [bt] 8 libsystem_c.dylib 0x00000001bfaa1dd4 __cxa_finalize_ranges + 480 [bt] 9 libsystem_c.dylib 0x00000001bfaa1b68 exit + 44 [bt] 10 cdo 0x000000010056fed4 _Z15define_varnamesPKc + 0 [bt] 11 cdo 0x0000000100613b94 _Z9cdo_abortIJA256_cEEvRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEDpRKT_ + 212 [bt] 12 cdo 0x000000010071dd04 _Z13vlist_compareiii + 476 [bt] 13 cdo 0x00000001005a0ec4 _Z3CatPv + 396 [bt] 14 libsystem_pthread.dylib 0x00000001bfbb626c _pthread_start + 148 [bt] 15 libsystem_pthread.dylib 0x00000001bfbb108c thread_start + 8 ERROR, reshGetElem, resource_handle.c, line 415, called from vlist_to_pointer errorString: "Error while trying to resolve the ID "vlistID" in `vlist_to_pointer()`: list element not found. The failed ID is 24"
Thank you.
RE: Getting monthly averages from individual nc files of a selected area? - Added by Karin Meier-Fleischer over 2 years ago
You can't use cat in front of another operator, it needs one or more files (see documentation https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#subsection.2.2.2)
The order of the operators from your first try was ok. How fast CDO is depends on the number of files and operations you want to perform. If you only need one variable you can select it first and do the operations on only that variable.
For example do the operations only on the variable precip:
cdo -monmean \ -sellonlatbox,98,122,-15,15 \ -selname,precip \ -cat '/Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/daily/*.nc' \ /Volumes/malrosie/data/satellite/chlor_a/cmems/mapped/4km/19970904_monthly_mean.nc
RE: Getting monthly averages from individual nc files of a selected area? - Added by Ikmal Rosli over 2 years ago
Alright, I will do that. Thank you so much for the help.