Skip to content

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), optionally filling annual data up to the end date with the last available year,
  • 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_precipitation(dataset, var_name='tp', time_coord='time')

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_time(dataset, offset=-1, time_unit='D', var_name='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_by_time(dataset, start_date, end_date=None, var_name='time', fill_to_end=False)

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".

  • fill_to_end (bool, default: False ) –

    If True and the data end before the end date, repeat the last time step once per year up to the end date, e.g. to use the latest annual population data for later years. Default is False.

Returns:

  • Dataset –

    xr.Dataset: Dataset truncated from the specified start date.