Converting longitude range on curvilinear grid
Added by Brendan DeTracey almost 5 years ago
Longitude can be converted from [0,360] to [-180,180] by using the command sellonlatbox,-180,180,-90,90
but this only works on regular grids, not curvilinear. I tried another contortion:
cdo ifthenelse -expr,'longitude > 180' zos_Omon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_2014.nc -expr,'longitude = 360 - longitude' zos_Omon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_2014.nc zos_Omon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_2014.nc test.nc cdo(1) expr: Process started cdo(2) expr: Process started cdo(2) expr (Abort): Variable >longitude< not found!
Is there a way to do this in cdo? I can do it it using nco but I was hoping to only use cdo in my scripts.
If there is no way to do this, I would like to suggest a new command be added. The only problem might be that it could only be applied if the output format is netcdf, not grib.
Thanks!
Replies (3)
RE: Converting longitude range on curvilinear grid - Added by Uwe Schulzweida almost 5 years ago
The longitude coordinates can be accessed in expr by clon( x ) (longitudes of the variable x). Unfortunately all available coordinate variables in expr are read only.
A new data variable can be created with:
cdo expr,"lon = (clon(zos) > 180) ? clon(zos) - 360 : clon(zos)" zos_Omon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_2014.nc result
RE: Converting longitude range on curvilinear grid - Added by Brendan DeTracey almost 5 years ago
Thanks
RE: Converting longitude range on curvilinear grid - Added by Brendan DeTracey almost 5 years ago
Any chance of adding this functionality to cdo?
setlon180
- converts all longitudes and longitude bounds (i.e. variable defined by lon:bounds
attribute) to range [-180, 180)setlon360
- converts all longitudes and longitude bounds (i.e. variable defined by lon:bounds
attribute) to range [0, 360)
The functions would have to emit an error or warning if the target file type is grib.
Depending on how cdo internally unwraps longitude, the functions might need to recalculate longitude bounds to keep them continuous. For example, a point with longitude 179.5 and bounds [178.5, 180.5] would be remain unchanged by setlon180
, a point with 180 and bounds [179, 181] would change to -180 and bounds [-181, -179].