ILAMB.Variable.Variable.convert

Variable.convert(unit, density=998.2, molar_mass=12.0107)[source]

Convert the variable to a given unit.

We use the UDUNITS library via the cf_units python interface to convert the variable’s unit. Additional support is provided for unit conversions in which substance information is required. For example, in quantities such as precipitation it is common to have data in the form of a mass rate per unit area [kg s-1 m-2] yet desire it in a linear rate [m s-1]. This can be accomplished if the density of the substance is known. We assume here that water is the substance, but this can be changed by specifying the density when calling the function.

Parameters
  • unit (str) – the desired converted unit

  • density (float, optional) – the mass density in [kg m-3] to use when converting linear rates to area density rates

  • mol_mass (float, optional) – the molar mass in [kg mol-1], default value assumes substance to be converted is carbon

Returns

self – this object with its unit converted

Return type

ILAMB.Variable.Variable