metobs_toolkit.Dataset.add_new_unit#

Dataset.add_new_unit(obstype, new_unit, conversion_expression=[])[source]#

Add a new unit to a known observation type.

Parameters:
  • obstype (str) – The observation type to add the new unit to.

  • new_unit (str) – The new unit name.

  • conversion_expression (list or str, optional) –

    The conversion expression to the standard unit of the observation type. The expression is a (list of) strings with simple algebraic operations, where x represent the value in the new unit, and the result is the value in the standard unit. Two examples for temperature (with a standard unit in Celsius):

    [“x - 273.15”] #if the new_unit is Kelvin [“x-32.0”, “x/1.8”] #if the new unit is Farenheit

    The default is [].

Return type:

None.

Examples

>>> import metobs_toolkit
>>>
>>> #Create your Dataset
>>> dataset = metobs_toolkit.Dataset() #empty Dataset
>>>
>>> #Add new unit to a known obstype
>>> dataset.add_new_unit(obstype = 'temp',
...                           new_unit= 'your_new_unit',
...                           conversion_expression = ['x+3', 'x * 2'])
>>> # The conversion means: 1 [your_new_unit] = (1 + 3) * 2 [°C]
>>> dataset.obstypes['temp'].get_info()
temp observation with:
     * standard unit: Celsius
     * data column as None in None
     * known units and aliases: {'Celsius': ['celsius', '°C', '°c', 'celcius', 'Celcius'], 'Kelvin': ['K', 'kelvin'], 'Farenheit': ['farenheit'], 'your_new_unit': []}
     * description: 2m - temperature
     * conversions to known units: {'Kelvin': ['x - 273.15'], 'Farenheit': ['x-32.0', 'x/1.8'], 'your_new_unit': ['x+3', 'x * 2']}
     * originates from data column: None with None as native unit.