Project

General

Profile

interpolate question

Added by Joseph S almost 5 years ago

Greetings:

I am new to CDO, and I am enjoying it so far and finding it very useful. I am using it on a Windows 7 64-bit machine with cygwin64. Soon, I will migrate fully to a new Linux machine, but for now, the Windows 64-bit version of CDO is working nicely in cygwin64. :)

Using the ERA5 data, I would like perform a weighted-average interpolation for a set of coordinates based on data from the four surrounding ERA5 gridpoints. For example, if I want to know the average temperature at 30.621°N 15.743°E, and I have the surrounding ERA5 points at 30.60°N 15.70°E, 30.65°N 15.70°E, 30.65°N 15.75°E, and 30.60°N 15.77°E, is there a CDO operator that produces a weighted-average at 30.621°N 15.743°E?

I currently perform this operation in the unidata IDV software, but I would like to learn how to perform the same operation with CDO, if it is possible. To help myself, I looked through the manual at the interpolation and weighted-average functions, but I did not see a specific operator for the function that I described. Perhaps I overlooked it. Thanks for any help you may offer.

Thanks kindly,
Joseph


Replies (5)

RE: interpolate question - Added by Karin Meier-Fleischer almost 5 years ago

Hi Joseph,

if I've understood you right than you are looking at gridboxavg which do a grid box average of the neighboring grid boxes.
See https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-3880002.8.10

-Karin

RE: interpolate question - Added by Joseph S almost 5 years ago

Hi Karin,

Thank you for your response. Is it possible for CDO to perform a weighted-average of the four surrounding grid points (not grid boxes)?

For example, in the attached image, point p is surrounded by four grid points that define the grid box in which point p exists. The weighted-average method (for point p) would assign the highest weight to value of the nearest gridpoint, which is shown as gridpoint 1 in the example image. It would assign the second highest weight to the value of gridpoint 2. It would assign the second lowest weight to the value of gridpoint 3. Finally, it would assign the lowest weight to value of gridpoint 4. The assigned weights would be based on the respective distances between point p and the four surrounding gridpoints.

The operation may look like this:

cdo gridpointavg coordinates infile outfile

gridpointavg is the operator
coordinates is the lat/lon of a point

The CDO would then take the entered coordinates and return the weighted-average of the values of the four surrounding gridpoints (not grid boxes).

Also, a nearest-neighbor cdo operator would be helpful as well. It would return the value of the nearest gridpoint relative to the entered coordinates.

Thanks kindly.

Joseph

RE: interpolate question - Added by Ralf Mueller almost 5 years ago

hi!

this sounds like a distance-weighted interpolation to me: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf, page 154.

so if you have the 4 points of data on a grid in infile, use

cdo -remapdis,lat=30.621_lon=15.743 infile outfile
please compare it with your former results and do some test with artificial data (like using zero for some places or so) if possible

hth
ralf

btw: a report about this would be nice, thx in advance

RE: interpolate question - Added by Joseph S almost 5 years ago

Hi Ralf,

Thank you very much. I was able to successfuly apply the operator that you suggested. When using the remapbil operator with the -b F64 precision switch, the results are nearly identical to the Unidata IDV bilinear output results. The differences are extremely small and inconsequential.

Incidentally, I had to reverse the lat/lon entries in your example to lon/lat, but it seems to work flawlessly based on just a few tests. I'm assuming that the lat/lon order in the cdo command depends on the lat/lon order in the original nc file.

The procedure that worked ideally for me was:

cdo -b F64 -remapbil,lon=270.743_lat=24.621 infile outfile

Then, to dump the results to text:

cdo outputtab,name,date,time,lat,lon,value infile > text.out

Nice work! This is exactly what I was hoping to learn when I originally posted. Now, I can create a handy bash script to extract the bilinear weighted-averages of metocean data near many points along lengthy transoceanic routes. Thanks again for this very useful tool. I look forward to using it on my new Linux machine when I finish building it soon. For now, I'm using it with Cygwin64 in Windows 7 Pro.

Kind regards,
Joseph

RE: interpolate question - Added by Ralf Mueller almost 5 years ago

thx for posting the solution, Joseph!

Since you end up with a value in a file, it might be useful to switch from bash to Python or Ruby. In these languages your results can be used in the data-analysis frameworks available for those languages. I found it very hard to work with real values in plain shell scripts - just an idea.

cheers
ralf

    (1-5/5)