heiplanet_data.converters module⚓︎
heiplanet_data.converters
⚓︎
Unit and coordinate conversions for climate datasets.
This module holds the elementary, dependency-light transformations applied to raw datasets:
- longitude conversion from the 0-360 range to the -180-180 range
(
convert_360_to_180,adjust_longitude_360_to_180), - temperature conversion from Kelvin to Celsius
(
convert_to_celsius,convert_to_celsius_with_attributes), - precipitation conversion from meters to millimeters
(
convert_m_to_mm,convert_m_to_mm_with_attributes), - renaming of coordinates to unified names across data sources
(
rename_coords).
The *_with_attributes variants operate on a whole dataset and keep the
variable attributes (e.g. GRIB metadata) intact.
Functions:
-
adjust_longitude_360_to_180–Adjust longitude from 0-360 to -180-180.
-
convert_360_to_180–Convert longitude from 0-360 to -180-180.
-
convert_m_to_mm–Convert precipitation from meters to millimeters.
-
convert_m_to_mm_with_attributes–Convert precipitation from meters to millimeters and keep attributes.
-
convert_to_celsius–Convert temperature from Kelvin to Celsius.
-
convert_to_celsius_with_attributes–Convert temperature from Kelvin to Celsius and keep attributes.
-
rename_coords–Rename coordinates in the dataset based on a mapping.
Attributes:
-
T–
adjust_longitude_360_to_180
⚓︎
Adjust longitude from 0-360 to -180-180.
Parameters:
-
dataset(Dataset) –Dataset with longitude in 0-360 range.
-
limited_area(bool, default:False) –Flag indicating if the dataset is a limited area. Default is False.
-
lon_name(str, default:'longitude') –Name of the longitude variable in the dataset. Default is "longitude".
Returns:
-
Dataset–xr.Dataset: Dataset with longitude adjusted to -180-180 range.
convert_360_to_180
⚓︎
convert_m_to_mm
⚓︎
convert_m_to_mm_with_attributes
⚓︎
Convert precipitation from meters to millimeters and keep attributes.
Parameters:
-
dataset(Dataset) –Dataset containing precipitation in meters.
-
inplace(bool, default:True) –If True, modify the original dataset. If False, return a new dataset. Default is True.
-
var_name(str, default:'tp') –Name of the precipitation variable in the dataset. Default is "tp".
Returns:
-
Dataset–xr.Dataset: Dataset with precipitation converted to millimeters.
convert_to_celsius
⚓︎
convert_to_celsius_with_attributes
⚓︎
Convert temperature from Kelvin to Celsius and keep attributes.
Parameters:
-
dataset(Dataset) –Dataset containing temperature in Kelvin.
-
inplace(bool, default:True) –If True, modify the original dataset. If False, return a new dataset. Default is True.
-
var_name(str, default:'t2m') –Name of the temperature variable in the dataset. Default is "t2m".
Returns:
-
Dataset–xr.Dataset: Dataset with temperature converted to Celsius.
rename_coords
⚓︎
Rename coordinates in the dataset based on a mapping.
Parameters:
-
dataset(Dataset) –Dataset with coordinates to rename.
-
coords_mapping(dict) –Mapping of old coordinate names to new names.
Returns:
-
Dataset–xr.Dataset: A new dataset with renamed coordinates.