heiplanet_data.temporal module⚓︎
heiplanet_data.temporal
⚓︎
Time-axis operations: shifting, truncation, and monthly aggregation.
This module manipulates the time coordinate of a dataset:
- shifting all time points by a fixed offset (
shift_time), - truncating a dataset to a date range (
truncate_data_by_time), - converting ERA5-Land monthly mean precipitation to monthly totals by
multiplying with the number of days per month
(
calculate_monthly_precipitation).
Functions:
-
calculate_monthly_precipitation–Calculate monthly total precipitation from data downloaded from ERA5-Land monthly data.
-
shift_time–Shift the time coordinate of a dataset by a specified timedelta.
-
truncate_data_by_time–Truncate data from a specific start date to an end date. Both dates are inclusive.
calculate_monthly_precipitation
⚓︎
Calculate monthly total precipitation from data downloaded from ERA5-Land monthly data. The real precipitation of the month = downloaded value * number of days in the month.
Parameters:
-
dataset(Dataset) –Dataset with total precipitation data.
-
var_name(str, default:'tp') –Name of the precipitation variable in the dataset. Default is "tp".
-
time_coord(str, default:'time') –Name of the time coordinate in the dataset. Default is "time".
Returns:
-
Dataset–xr.Dataset: Dataset with monthly total precipitation values.
shift_time
⚓︎
Shift the time coordinate of a dataset by a specified timedelta. The dataset is overwritten with the shifted time values.
Parameters:
-
dataset(Dataset) –Dataset to shift.
-
offset(int, default:-1) –Amount to shift the time coordinate. Default is -1.
-
time_unit(Literal['W', 'D', 'h', 'm', 's', 'ms', 'ns'], default:'D') –Time unit for the shift. Default is "D".
-
var_name(str, default:'time') –Name of the time variable in the dataset. Default is "time".
truncate_data_by_time
⚓︎
Truncate data from a specific start date to an end date. Both dates are inclusive.
Parameters:
-
dataset(Dataset) –Dataset to truncate.
-
start_date(Union[str, datetime64]) –Start date for truncation. Format as "YYYY-MM-DD" or as a numpy datetime64 object.
-
end_date(Union[str, datetime64, None], default:None) –End date for truncation. Format as "YYYY-MM-DD" or as a numpy datetime64 object. If None, truncate until the last date in the dataset. Default is None.
-
var_name(str, default:'time') –Name of the time variable in the dataset. Default is "time".
Returns:
-
Dataset–xr.Dataset: Dataset truncated from the specified start date.