cdo remapcon adds mysterious unnecessary interpolation when regridding unstructured grids
Added by Toby Marthews over 2 years ago
Dear CDO Users,
I hope someone can help with this. Attached I have a worked example (no need to download any files: the code should just run and produce the error).
For this example I created a very tiny NetCDF file which has elevation data for 6 spatial points (in N. Alaska) called SixPointsOnly.nc .
This SixPointsOnly.nc file is an example of an 'unstructured grid'. I want to regrid it to a structured long/lat grid at 0.25deg resolution (essentially just map the 6 data points to where they should be in a global grid).
It seems I can do this using cdo remapcon (commands all attached) however remapcon doesn't do what I expected it to do: instead of 6 points dropped on to the global grid with everything apart from those 6 points being blank, I get two lines in Alaska with nonzero values.
The format of the output file out.nc is exactly what I want (a global grid at 0.25deg resolution) but the elevation numbers remapcon puts into it for the 6 example points are all (without exception) wrong, as you can see from using these commands:
#Expecting a single cell of elevation 392.0 m asl but actually I get 30 m asl
ncea -OFh -d lat,71.1,71.2 -d lon,"-179.7","-179.6" out.nc out1.nc
ncdump -v elevation out1.nc
#Expecting a single cell of elevation 116.0 m asl but actually I get 72.97211 m asl
ncea -OFh -d lat,70.8,70.9 -d lon,"-161.2","-161.1" out.nc out2.nc
ncdump -v elevation out2.nc
#Expecting a single cell of elevation 42.0 m asl but actually I get 266.677 m asl
ncea -OFh -d lat,68.6,68.7 -d lon,"-152.9","-152.8" out.nc out3.nc
ncdump -v elevation out3.nc
#Expecting a single cell of elevation 30.0 m asl but actually I get 116 m asl
ncea -OFh -d lat,68.6,68.7 -d lon,"-133.7","-133.6" out.nc out4.nc
ncdump -v elevation out4.nc
#Expecting a single cell of elevation 91.0 m asl but actually I get 30 m asl
ncea -OFh -d lat,67.3,67.4 -d lon,"-133.7","-133.6" out.nc out5.nc
ncdump -v elevation out5.nc
#Expecting a single cell of elevation 221.0 m asl but actually I get 116 m asl
ncea -OFh -d lat,66.3,66.4 -d lon,"-127.2","-127.1" out.nc out6.nc
ncdump -v elevation out6.nc
It seems that the cdo command is doing some smoothing (even though it's 'conservative' so I wouldn't expect that). Therefore, I think I may be using the wrong CDO tool, but my understanding of the CDO man pages is that it should be appropriate to use remapcon for a job like this. If not remapcon, the man pages don't suggest to me what the right tool would be.
What please am I doing wrong? I am using Climate Data Operators version 1.6.9.
Any help on this would be VERY much appreciated!
Toby
CDORemapcon_example.txt (7.03 KB) CDORemapcon_example.txt | |||
result in out.nc.png (205 KB) result in out.nc.png | |||
SixPointsOnly.nc (8.29 KB) SixPointsOnly.nc | |||
gridfile.txt (273 Bytes) gridfile.txt | |||
out.nc (3.98 MB) out.nc |
Replies (4)
RE: cdo remapcon adds mysterious unnecessary interpolation when regridding unstructured grids - Added by Estanislao Gavilan over 2 years ago
Hi Toby,
I am a bit confused with the example, so I cannot make a picture in my head. Lets start from the very bottom. The CDO version that you are using is extremly old. You should try to upgrade to 2.0.5. About you problem..Are you trying to interpole a unstructured 2d grid in a regular grid? If that is the case, I have also experimented problems with the interpolation. Sometimes CDO does not interpolate correctly, it usually happens on the border of your unstructure grid.
Kind regards
Estanislao
RE: cdo remapcon adds mysterious unnecessary interpolation when regridding unstructured grids - Added by Toby Marthews over 2 years ago
Hi Estanislao,
Thank you very much for the reply: very much appreciated!
First off: I have asked our IT people to update the version of CDO we're using (they say they are busy but will get around to it). You're absolutely right we're out of date on that, although I suspect that this issue will occur for any version of CDO because I'm using very standard commands.
Essentially I have a model that takes 2D driving input (NetCDF) but economises on runtime by simulating only land points and therefore outputs 1D output (a list of points in a 1D NetCDF file). There's no option to make the model output 2D and it's a long-running difficulty of using this climate model because the output isn't immediately viewable in many packages. I am trying to use CDO to 'convert' from 1D back to the original 2D grid. My actual runs have 100s of thousands of points, but I picked out 6 points as an example file above.
It seems to me that I know the target grid (it's the same as my 2D driving data files) and I know the coordinates of each output point (they are in the 1D output as long/lat coordinates). Therefore I should be able to use cdo remapcon to do this conversion.
Trying this (all the commands are above in the example), it produces an output file on the correct 2D grid, but strangely cdo remapcon doesn't manage to 'drop in' the values of the 6 points in the right places (all 6 are incorrect) and it also adds in a swath of extra nonzero values at points surrounding those 6 points (which looks like some kind of smoothing/kriging calculation).
What I'm trying to work out with this query is whether:
(1) CDO can do the job but I am somehow using it incorrectly (perhaps there is some option I am missing) or
(2) CDO can't do this job (in which case I will devote my time coding up a regridder in Fortran)
Any comments on this would be very helpful!
Best regards,
Toby
RE: cdo remapcon adds mysterious unnecessary interpolation when regridding unstructured grids - Added by Estanislao Gavilan over 2 years ago
Hi Toby,
now I can fully understand what you want to do. I am not sure why cdo fails. As far as I know remapcon takes the gradient to compute the interpolation. So maybe cdo is having problems with the 1d data because the gradient points on the edge belongs to different rows. I am sure Karin or Ralf can give you a better explanation.
Toby, will not it be better to reshape the data, and then cdo can interpolate it ?. Your data is large, but you know the dimensions. You can write a simple program to open and close an specific segment, then you can build your 2d array in a lovely loop.
Kind regards,
Estanis
RE: cdo remapcon adds mysterious unnecessary interpolation when regridding unstructured grids - Added by Estanislao Gavilan over 2 years ago
Hi Toby,
I have just tried to use remapcon with your file. I got the error of invalid cell. I think it does not work because it does not follow the cf convection (at least in the version 2.0.5). Take a look to this post https://code.mpimet.mpg.de/boards/1/topics/12910
Kind regards,
Estanislao