Project

General

Profile

Merge datasets by spatial coordinates with intersecting boundaries?

Added by K A almost 9 years ago

Hello,

I need to merge several NetCDF formatted dataset along the spatial dimension that are adjacent, but have intersecting boundaries. The dataset are identical in terms of variables and time dimensions but they represent different spatial area.

Example:

file1: Latitude: 42N to 46N
Longitude 120W to 110W

file2: Latitude: 42N to 46N
Longitude: 110W to 100W

For the intersecting Longitude 110W:
file1 has values for latitudes 42N to 44N and empty cells (NaN) for 45N to 46N
file2 has values for latitudes 45N to 46N and empty cells (NaN) for 42N to 44N
The CDO support forum suggests the unpublished mergegrid function: RE: Merge datasets sorted by spatial coordinates?

Yet the mergegrid function takes all the values from file2 in this intersecting longitude, overwriting the data from file1. Is there a way to have the function only append values that are not NaN?

I have searched for a way (CDO, NCO, others) to merge files with adjacent and intersecting boundaries without finding a solution that does not erase data.

I wrote a program in c++ using NetCDF functions to read data and write it to an enlarged file encompassing my entire area (In the example 120W to 100W). However, it reads/writes values for one spatial coordinate (lon/lat) and one variable at a time and is too slow to be practical.

Any ideas or other people to contact would be greatly appreciated!

Thank you for your time,

Kristen


Replies (2)

RE: Merge datasets by spatial coordinates with intersecting boundaries? - Added by Uwe Schulzweida almost 9 years ago

The CDO operator mergegrid is published since two years (see: https://code.zmaw.de/projects/cdo/embedded/index.html#x1-790002.2.4). Only the non missing values of ifile2 will be used by this operator. The first input file must encompassing your entire area! Try it with the undocumented operator enlargegrid:

cdo enlargegrid,myentiregrid  file1 tmpfile
cdo mergegrid tmpfile file2 result
The challenge for this task is to define myentiregrid which must contain a description of the exact coordinates of the entire grid.

RE: Merge datasets by spatial coordinates with intersecting boundaries? - Added by K A over 8 years ago

The CDO operator mergegrid works if the spatial boundaries of your smaller files are discrete from each other. If the smaller files you wish to merge into the tmpfile defined by "myentiregrid" overlap (think of Tetris pieces), missing values in successive files are in fact used by the operator and overwrite the data in the areas of overlap.

Example:
*See attached file1.png and file2.png

cdo enlargegrid,myentiregrid file1 tmpfile

*See attached tmpfile.png

cdo mergegrid tmpfile file2 result

*See attached result.png

Thanks,
K

file1.png (5.55 KB) file1.png file1
file2.png (6.58 KB) file2.png file2
tmpfile.png (6.67 KB) tmpfile.png tmpfile
result.png (7.39 KB) result.png result
    (1-2/2)