Learn R Programming

rcdo

rcdo is a wrapper around Climate Data Operators.

Installation

You can install rcdo from CRAN with

install.packages("rcdo")

or the development version of rcdo from GitHub with:

# install.packages("pak")
pak::pak("eliocamp/rcdo")

Most operators are supported and are partially documented. The functions start with cdo_ an the name of the operator (e.g. the selname operator is the cdo_selname() function)

Example

library(rcdo)
cdo_use("packaged")  # use package version of cdo that can be installed with `cdo_install()`. 
#> Using packaged CDO, version 2.5.1.
ncep <- "hgt_ncep.nc"

The ymonmean operator computes monthly annual cycle. The rcdo function is cdo_ymonmean()

ncep |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo  ymonmean [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] {{output}}

The output just prints the command with a place holder output. Use cdo_execute() to actually run the command. If no output file is specified, then the result is saved in a tempfile.

ncep |> 
  cdo_ymonmean() |> 
  cdo_execute()
#> [1] "/tmp/RtmpjoNW20/file27c2a87617d80"
#> attr(,"ephemeral")
#> attr(,"ephemeral")[[1]]
#> File will be deleted when garbage collected
#> 
#> attr(,"mtime")
#> [1] "2025-07-07 11:20:52 AEST"
#> attr(,"size")
#> [1] 8630649

Operators can be chained. Lets select just the Southern Hemisphere first.

ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo  ymonmean [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] {{output}}

Now also select the 500 hPa level

ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo  ymonmean [ -sellevel,500 [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] ] {{output}}
ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo  ymonmean [ -sellevel,500 [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] ] {{output}}

Prior art

The ClimateOperators package also wrapps CDO, but it’s approach is different. Instead of wrapping each operator as its own function with parameters as arguments, it provides a generic cdo() function that runs the operators that the user needs to write as strings. Instead of

ncep |> 
  rcdo::cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) 

one would write

ClimateOperators::cdo("sellonlatbox,0,360,-90,0", ncep, output_file)

Copy Link

Version

Install

install.packages('rcdo')

Version

0.3.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Elio Campitelli

Last Published

July 7th, 2025

Functions in rcdo (0.3.0)

cdo

Execute a custom operator
arithdays

Arithmetic with days
apply

Apply operators
arith

Arithmetic on two datasets
arithlat

Arithmetic with latitude
cdo_cache_set

Manages the cache
arithc

Arithmetic with a constant
adisit

Potential temperature to insitu temperature and vice versa
afterburner

ECHAM standard post processor
bitrounding

Bit rounding
cdo_install

Install the supported CDO version
change

Change field header
compc

Comparison of a field with a constant
cdo_use

Chose CDO version to use
cdo_execute

Execute a CDO operation
cdo_set_output

Set output and options
cdo_options_use

Manage CDO options
cmorlite

CMOR lite
comp

Comparison of two fields
collgrid

Collect horizontal grid
condc

Conditional select a constant
daystat

Daily statistics
daypctl

Daily percentile values
copy

Copy datasets
detrend

Detrend time series
deltat

Difference between timesteps
derivepar

Derived model parameters
cond

Conditional select one field
dayarith

Daily arithmetic
cond2

Conditional select two fields
ecacwd

Consecutive wet days index per time period
ecafd

Frost days index per time period
ecacsu

Consecutive summer days index per time period
consecstat

Consecute timestep periods
ecaetr

Intraperiod extreme temperature range
dminutestat

Multiday by the minute statistics
dhourstat

Multiday hourly statistics
ecacwdi

Cold wave duration index wrt mean of reference period
ecacwfi

Coldspell days index wrt 10th percentile of reference period
ecar90ptot

Precipitation percent due to R90p days
ecacdd

Consecutive dry days index per time period
ecacfd

Consecutive frost days index per time period
ecar90p

Wet days wrt 90th percentile of reference period
ecatg90p

Warm days percent wrt 90th percentile of reference period
ecar99p

Extremely wet days wrt 99th percentile of reference period
duplicate

Duplicates a dataset
ecar99ptot

Precipitation percent due to R99p days
ecatn90p

Warm nights percent wrt 90th percentile of reference period
ecatn10p

Cold nights percent wrt 10th percentile of reference period
ecatr

Tropical nights index per time period
distgrid

Distribute horizontal grid
diff

Compare two datasets field by field
ecagsl

Thermal Growing season length index
ecahd

Heating degree days per time period
ecahwdi

Heat wave duration index wrt mean of reference period
ecahwfi

Warm spell days index wrt 90th percentile of reference period
ecaid

Ice days index per time period
ecar95p

Very wet days wrt 95th percentile of reference period
ensstat2

Statistical values over an ensemble
ecar95ptot

Precipitation percent due to R95p days
ecar75p

Moderate wet days wrt 75th percentile of reference period
ecar75ptot

Precipitation percent due to R75p days
expr

Evaluate expressions
ecarx5day

Highest fiveday precipitation amount per time period
ecasdii

Simple daily intensity index per time period
ecatg10p

Cold days percent wrt 10th percentile of reference period
ecasu

Summer days index per time period
enlarge

Enlarge fields
eofs

Empirical Orthogonal Functions
fldcor

Correlation in grid space
ensval

Ensemble validation tools
getgridcell

Get grid cell index
eofcoeff

Principal coefficients of EOFs
ecapd

Precipitation days index per time period
ecarr1

Wet days index per time period
fldcovar

Covariance in grid space
fdns

Frost days where no snow index per time period
histogram

Histogram
healpix

Change healpix resolution
ensstat

Statistical values over an ensemble
info

Information and simple statistics
fldstat

Statistical values over a field
ecatx10p

Very cold days percent wrt 10th percentile of reference period
ecarx1day

Highest one day precipitation amount per time period
fourier

Fourier transformation
input

Formatted input
inttime

Time interpolation
intyear

Year interpolation
gridboxstat

Statistical values over grid boxes
gridcell

Grid cell quantities
intlevel3d

Linear level interpolation from/to 3D vertical coordinates
maskregion

Mask regions
maskbox

Mask a box
intlevel

Linear level interpolation
gradsdes

GrADS data descriptor file
filter

Time series filtering
filedes

Dataset description
ecatx90p

Very warm days percent wrt 90th percentile of reference period
invert

Invert latitudes
importamsr

Import AMSR binary files
invertlev

Invert levels
mrotuvb

Backward rotation of MPIOM data
hurr

Hurricane days index per time period
merge

Merge datasets
merstat

Meridional statistics
maggraph

Line graph plot
magplot

Lat/Lon plot
importbinary

Import binary data sets
ncl_wind

Wind transformation
importcmsaf

Import CMSAF HDF5 files
pack

Pack data
remap

Grid remapping
regres

Regression
monpctl

Monthly percentile values
mergegrid

Merge grid
outputgmt

GMT output
monstat

Monthly statistics
hourpctl

Hourly percentile values
hourstat

Hourly statistics
pressure

Pressure on model levels
monarith

Monthly arithmetic
outputtab

Table output
rhopot

Calculates potential density
replace

Replace variables
replacevalues

Replace variable values
ninfo

Print the number of parameters, levels or times
mastrfu

Mass stream function
magvector

Lat/Lon vector plot
rotuvb

Rotation
mapreduce

Reduce fields to userdefined mask
remapbic

Bicubic interpolation
output

Formatted output
remapnn

Nearest neighbor remapping
remapbil

Bilinear interpolation
math

Mathematical functions
runpctl

Running percentile values
runstat

Running statistics
remapcon

First order conservative remapping
selregion

Select horizontal regions
remapdis

Distance weighted average remapping
selmulti

Select multiple fields via GRIB1 parameters
select

Select fields
set

Set field info
selyearidx

Select year by index
setbox

Set a box to constant
setattribute

Set attributes
remaplaf

Largest area fraction remapping
remapeta

Remap vertical hybrid level
remapstat

Remaps source points to target cells
seaspctl

Seasonal percentile values
samplegrid

Resample grid
setmiss

Set missing value
setgridcell

Set the value of a grid cell
setpartab

Set parameter table
sethalo

Set the bounds of a field
settime

Set time
strbre

Strong breeze days index per time period
splittime

Split timesteps of a dataset
setzaxis

Set zaxis information
splitdate

Splits a file into dates
splitsel

Split selected timesteps
selsurface

Extract surface
seltime

Select timesteps
selbox

Select a box
seasstat

Seasonal statistics
timstat

Statistical values over all timesteps
strgal

Strong gale days index per time period
timsort

Timsort
strwin

Strong wind days index per time period
tee

Duplicate a data stream and write it to file
sinfo

Short information
seltimeidx

Select timestep by index
selgridcell

Select grid cells
vargen

Generate a field
unpack

Unpack data
selvar

Select fields
showinfo

Show variables, levels or times
smooth

Smooth grid points
timcor

Correlation over time
timfillmiss

Temporal filling of missing values
vertfillmiss

Vertical filling of missing values
ydaystat

Multiyear daily statistics
timpctl

Percentile values over all timesteps
trend

Trend of time series
timcovar

Covariance over time
vertintgh

Vertical height interpolation
trendarith

Add or subtract a trend
ydaypctl

Multiyear daily percentile values
vertintap

Vertical pressure interpolation
specconv

Spectral conversion
timcumsum

Cumulative sum over all timesteps
vertintml

Vertical interpolation
xsinfo

Extra short information
wind

Wind transformation
ymoncomp

Multiyear monthly comparison
ymonarith

Multiyear monthly arithmetic
yhourarith

Multiyear hourly arithmetic
wind2

D and V to velocity potential and stream function
yhourstat

Multiyear hourly statistics
setgrid

Set grid information
setfilter

Set NetCDF4 filter
shiftxy

Shift field
varsstat

Statistical values over all variables
timselpctl

Time range percentile values
split

Split a dataset
timselstat

Time range statistics
showattribute

Show attributes
spectral

Spectral transformation
ydayarith

Multiyear daily arithmetic
yearstat

Yearly statistics
yearpctl

Yearly percentile values
verifygrid

Verify grid coordinates
vertstat

Vertical statistics
wct

Windchill temperature
ymonpctl

Multiyear monthly percentile values
yseasarith

Multiyear seasonal arithmetic
yseaspctl

Multiyear seasonal percentile values
ymonstat

Multiyear monthly statistics
ydrunpctl

Multiyear daily running percentile values
yeararith

Yearly arithmetic
yearmonstat

Yearly mean from monthly data
ydrunstat

Multiyear daily running statistics
yseasstat

Multiyear seasonal statistics
zonstat

Zonal statistics