| name | regrid |
| description | Regrid NetCDF/climate data using CDO (default), NCO (ncremap), or ncatted. |
| user-invocable | true |
Help the user regrid climate/satellite NetCDF data. Default to CDO unless the user specifies NCO/ncremap.
Installation
CDO (default — via conda)
conda install -c conda-forge cdo
NCO (via conda)
conda install -c conda-forge nco
Other options
sudo apt install cdo nco
brew install cdo nco
Regridding Methods (CDO)
Nearest neighbor (fastest; good for masks/categorical data)
cdo remapnn,TARGET_GRID input.nc output.nc
Bilinear interpolation (smooth continuous fields; default for coarse → fine)
cdo remapbil,TARGET_GRID input.nc output.nc
Conservative (flux-preserving; default for fine → coarse)
cdo remapcon,TARGET_GRID input.nc output.nc
With precomputed weights (fast repeated regridding to same grid)
cdo gencon,TARGET_GRID input.nc weights.nc
cdo remap,TARGET_GRID,weights.nc input.nc output.nc
Defining a Target Grid
Pass a grid description file or an existing NetCDF file as TARGET_GRID.
Grid description file (lonlat example)
gridtype = lonlat
xsize = 1440
ysize = 721
xfirst = -179.875
xinc = 0.25
yfirst = -90.0
yinc = 0.25
Extract grid from an existing file
cdo griddes reference.nc > target_grid.txt
cdo remapbil,target_grid.txt input.nc output.nc
Useful CDO Flags
-O — overwrite output
-R — reset time counter
-P N — parallel processing (N threads)
-setmisstoc,VALUE — replace missing values with VALUE
-selname,VAR — select variable before regridding
-mergetime — merge multiple time-step files
Common Workflows
Single file
cdo -O remapnn,target_grid.txt input.nc output.nc
Batch regrid (shell loop with parallelism)
for f in input_*.nc; do
cdo -O -P 8 remapbil,target_grid.txt "${f}" "${f%.nc}.regrid.nc"
done
Merge time steps then regrid
cdo -O mergetime input_*.nc merged.nc
cdo -O remapcon,target_grid.txt merged.nc output.nc
Fix missing coordinate attributes before regridding (ncatted)
ncatted -a units,lon,c,c,"degrees_east" \
-a units,lat,c,c,"degrees_north" \
input.nc input_fixed.nc
cdo remapnn,target_grid.txt input_fixed.nc output.nc
NCO / ncremap (ESMF-based alternative)
ncremap -i input.nc -m weights.nc -o output.nc
ncremap -i input.nc -m weights.nc -o output.nc -P mpas --mss_val=-9999
Requires the E3SM Unified environment or nco with ESMF support.
Python / Dask Distributed Regridding
For large batches, wrap CDO with Dask:
import subprocess
from dask.distributed import LocalCluster, Client
cluster = LocalCluster(n_workers=8)
client = Client(cluster)
def regrid_file(fn):
out = fn.replace('.nc', '_regrid.nc')
cmd = f"cdo -O remap,{GRID},{WEIGHTS} -setmisstoc,-99999 {fn} {out}"
subprocess.run(cmd, shell=True, check=True)
futures = client.map(regrid_file, file_list)
client.gather(futures)
Alternatively use xesmf for pure-Python regridding:
import xesmf as xe
import xarray as xr
ds_in = xr.open_dataset("input.nc")
ds_out = xr.Dataset({"lat": (["lat"], lats), "lon": (["lon"], lons)})
regridder = xe.Regridder(ds_in, ds_out, "bilinear")
ds_regridded = regridder(ds_in)