Project

General

Profile

how to expand a lat/lon grid - and set new points as nodata

Added by Etienne Tourigny over 11 years ago

Hi,

I am faced with a multi-level file in a regional grid, that I would like to expand into a global grid, with external pixels set as nodata.

I tried using the remapnn command, but it shifted the grid by 180degrees east (all positive longitude values) and produced some errors

cdo remapnn,r720x360 vegtype000001.nc tmp1.nc

I was wondering if there was another way to do this, with cdo or other software. If not, how would one go about creating a new operator to do this in cdo?

Attaching the file as reference.

thanks
Etienne


Replies (6)

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

try "enlargegrid" (undocumented experimental operator) or "enlarge" operator https://code.zmaw.de/embedded/cdo/1.5.5/cdo.html#x1-2010002.6.12

cheers,
J

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Uwe Schulzweida over 11 years ago

Hi Etienne,

Using predefined grids like r720x360 is not a good idea in this case. Define your own grid which includes exactly all coordinates of you input file. Here is an example for a global half degree grid starting at -180 degree and includes exactly the input area.

cat > mygrid << EOR
gridtype  = lonlat
xsize     = 720
ysize     = 360
xfirst    = -179.75
xinc      = 0.5
yfirst    = -89.75
yinc      = 0.5
EOR
Then you can use nearest neighbor remapping in combination with masklonlatbox:
cdo masklonlatbox,-81,-35,-55,13 -remapnn,mygrid vegtype000001.nc tmp1.nc
The undocumented operator enlargegrid will give the same result:
cdo enlargegrid,mygrid vegtype000001.nc tmp2.nc

Unfortunately we have a bug (#2962) with user defined lonlat grids in the latest CDO release 1.5.8. Therefor the above example will not work correctly with this CDO version.

Best regards,
Uwe

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Etienne Tourigny over 11 years ago

Hi,

thanks for your tips.

Using that grid did with remapnn did resolve the displacement issue. I am using 1.5.4 so no apparent problem with user-defined grids.

remapnn still produces values outside of original extent, which masklonlatbox seems to fix - although it's not ideal. Any idea why this is needed, and perhaps an idea for a fix?

However, enlargegrid did not work as expected, result has values only in the -81 to -90 degrees south.
Also I had to remove nodata values, as it doesn't support them.

Should I file bugs for the 2 issues?

thanks
Etienne

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Etienne Tourigny over 11 years ago

Sorry, I was using the enlarge operator... enlargegrid does work correctly.

thanks

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Etienne Tourigny over 11 years ago

Hmmm it seems that enlargegrid does work but is not documented.

Why is enlarge available in the commandline help, but does not seem to work?

- does not support nodata
- produces wrong result

thanks

RE: how to expand a lat/lon grid - and set new points as nodata - Added by Uwe Schulzweida over 11 years ago

The CDO operator enlarge:

cdo enlarge,targetgrid sourcefile result
expands the size of the source grid to the size of the target grid. The expanded area is simple filled with the last gridpoint of the sourcefile. One useful case for this operator is a source gridsize of 1.

    (1-6/6)