Project

General

Profile

Modify regions by selected date and time (months and lonlatbox)

Added by David Gobbett over 5 years ago

Hi,
I want to create a single 12 month 'mask' file that defines crop growing season months over several areas which have different growing seasons. Different regions can be defined by a lon lat box. I would start with a file where all values for all months are set to zero, then want to select regions by bounding box, and selected months at the same time.

To set values to 1 for months Jan-Mar and Nov-Dec as the growing season for a particular region, ideally I would do something like

cdo -setclonlatbox,1,-10,23,30,37 -setcmons,1,1,2,3,11,12 <infile.nc> <outfile.nc>

where infile.nc is the file of 12 months, all zeros.

The setclonlatbox operator looks good, but the problem is can't see a similar (chainable) operator that allows setting values by month. Can anyone suggest a neat approach to this?

Thanks
David


Replies (2)

RE: Modify regions by selected date and time (months and lonlatbox) - Added by Ralf Mueller over 5 years ago

hi David!

IMO there is no such operator like setcmon. Point is, that you want to be flexible wrt. lon, lat and time. My first guess is the expr operators. It has access to all coordinates of a data variable - with a couple of some lengthy conditional statements it should do what you want.

If you manage to put something together, please post it here - I am curious about that one ;-)

hth
ralf

RE: Modify regions by selected date and time (months and lonlatbox) - Added by David Gobbett over 5 years ago

Hi Ralf,

Thanks for suggestion. I did look at the expr operator but didn't end up using it. Now I see it should be possible to do something like this (not tested)

cdo -expr,'mask=(clon>=-10&&clon<23&&clat>=30&&clat<37&&(cmonth=1||cmonth=2||cmonth=3||cmonth=11||cmonth=12))?1:mask' mask.nc outfile.nc

However, I opted to use a more clunky approach with inverted logic, using CDO and Python
1. Select the monthly timestep into a separate file (using selmon), also adding the new filename to a Python list named monMaskFiles
2. Set the masked area values to 1, for selected areas each month using -setclonlatbox,1,<box coords>
3. Merge the files using cdo.mergetime(input = " ".join(x for x in monMaskFiles), output = GSMonths)

cheers
David

    (1-2/2)