Combining Data at the Antimeridian

Submitted by pwadmin on Wed, 03/06/2019 - 13:22

Example provided by Dale Robinson, Coast Watch West Coast Node

This example shows how to merge two NetCDF files that span the antimeridian into one NetCDF file. Here we will demonstrate downloading ice concentration from ERDDAP in two sections and then piece them together into one file. This is accomplished with the easy to use NetCDF Operator Tools which are command line programs for working with NetCDF files. Learn more about NCO and download the package at:

Download the two data files in NetCDF format

Western Pacific File Download
Eastern Pacific File Download

Change record dimension from "time" to "longitude"

Temporarily change the record dimension from "time" to "longitude" in the two files. The resulting files are named with a "_L" ending to make it easier to follow the work flow.

ncpdq -O -a longitude,time
ncks -O --mk_rec_dmn longitude
ncpdq -O -a longitude,time
ncks -O --mk_rec_dmn longitude

Remove references to Longitude Extent

Remove the valid_min and valid_max from the longitude variable in both files

ncatted -O -a valid_min,longitude,d,f,
ncatted -O -a valid_max,longitude,d,f,
ncatted -O -a valid_min,longitude,d,f,
ncatted -O -a valid_max,longitude,d,f,

Shift Longitude Range

Use ncap2 to shift the eastern pacific (western hemisphere) longitudes into the range 180 - 360

ncap2 -s "longitude= longitude+360.0f"

Combine the Files

Concatenate Western and Eastern Pacific files along new (longitude) record dimension, naming the resulting file ""


Update Dimensions

Change record dimension back to "time" in the file

ncpdq -O -a time,longitude
ncks -O --mk_rec_dmn time

Set Max and Min Ranges

Restore the valid min and max attributes of the longitude variable, making them 0 and 360, respectively (optional) and delete the old "actual_range" (optional)

ncatted -O -a valid_min,longitude,c,f,0.0
ncatted -O -a valid_max,longitude,c,f,360.0
ncatted -O -a actual_range,longitude,d,,

Clean up (optional)