Return the variable converted to different units using a conversion factor. Args: var (:class:`xarray.DataArray` or :class:`numpy.ndarray`): A variable. vartype (:obj:`str`): The type of variable. Choices are: 'wind', 'pressure', 'temp', or 'height
(var, vartype, var_unit, dest_unit)
| 4 | |
| 5 | |
| 6 | def _apply_conv_fact(var, vartype, var_unit, dest_unit): |
| 7 | """Return the variable converted to different units using a conversion |
| 8 | factor. |
| 9 | |
| 10 | Args: |
| 11 | |
| 12 | var (:class:`xarray.DataArray` or :class:`numpy.ndarray`): A |
| 13 | variable. |
| 14 | |
| 15 | vartype (:obj:`str`): The type of variable. Choices are: 'wind', |
| 16 | 'pressure', 'temp', or 'height'. |
| 17 | |
| 18 | var_unit (:obj:`str`): The variable's current units. |
| 19 | |
| 20 | dest_unit (:obj:`str`): The desired units. |
| 21 | |
| 22 | Returns: |
| 23 | |
| 24 | :class:`xarray.DataArray` or :class:`numpy.ndarray`: The variable in |
| 25 | the desired units. |
| 26 | |
| 27 | """ |
| 28 | if var_unit == dest_unit: |
| 29 | return var |
| 30 | |
| 31 | # Note, case where var_unit and dest_unit are base unit, should be |
| 32 | # handled above |
| 33 | if var_unit == _BASE_UNITS[vartype]: |
| 34 | return var*(_CONV_FACTORS[vartype]["to_dest"][dest_unit]) |
| 35 | else: |
| 36 | if dest_unit == _BASE_UNITS[vartype]: |
| 37 | return var*(_CONV_FACTORS[vartype]["to_base"][var_unit]) |
| 38 | else: |
| 39 | return var*(_CONV_FACTORS[vartype]["to_base"][var_unit] * |
| 40 | _CONV_FACTORS[vartype]["to_dest"][dest_unit]) |
| 41 | |
| 42 | |
| 43 | def _to_kelvin(var, var_unit): |