View source: R/udConvertGrid.R
udConvertGrid | R Documentation |
Unit conversion for climate4R objects
udConvertGrid(grid, new.units)
grid |
Input grid (either regular, rotated or station data). |
new.units |
Character string vector indicating a udunits-parseable unit definition. See Details. |
Unit conversion and consistency checks
This function is a wrapper of the ud.convert
function from the UCAR's UDUNITS
R bindings, tailored to the climate4R CDM. The function performs a number of checks in order to ensure that: (i) the
units of the input grid and the new units are recognised by the UDUNITS database and (ii), that
the conversion between input and output units is possible. This is internally achieved by the functions
(i) ud.is.parseable
and (ii) ud.are.convertible
from package udunits2.
Multigrid support
The function supports multigrids as input. Note that in this case, the length of the new.units
vector should match the
number of variables within the multigrid (shape of 'var'
dimension), and preserve its ordering (otherwise failing in
the above-mentioned consistency checks).
Returns (invisibly) a grid similar to the input, but with new units
J Bedia
https://www.unidata.ucar.edu/software/udunits
getGridUnits
, for accessing the "units"
attribute of a grid and
setGridUnits
, to manually modify it.
library(transformeR)
require(climate4R.datasets)
data("NCEP_Iberia_ta850")
# Converting from Kelvin to Celsius:
getGridUnits(NCEP_Iberia_ta850)
range(NCEP_Iberia_ta850$Data, na.rm = TRUE)
ta850_degC <- udConvertGrid(grid = NCEP_Iberia_ta850, new.units = "celsius")
getGridUnits(ta850_degC)
range(ta850_degC$Data, na.rm = TRUE)
# Converting from Pascals to mmHg:
data("NCEP_Iberia_psl")
getGridUnits(NCEP_Iberia_psl)
range(NCEP_Iberia_psl$Data, na.rm = TRUE)
psl_mmHg <- udConvertGrid(NCEP_Iberia_psl, new.units = "mmHg")
getGridUnits(psl_mmHg)
range(psl_mmHg$Data, na.rm = TRUE)
# Dealing with multigrids:
mg <- makeMultiGrid(NCEP_Iberia_psl, NCEP_Iberia_ta850)
getVarNames(mg)
getGridUnits(mg)
# Convert all variables:
mg.conv <- udConvertGrid(mg, new.units = c("mmHg", "celsius"))
getGridUnits(mg.conv)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.