4. Time functions#

Output from PCR-GLOBWB (particularly discharge) is often at the daily resolution.

In case statistics or aggregations in time are needed, those functions could be used:

time_funcs.calc_monthly_climatology(df_in: DataFrame, col_name=None) DataFrame[source]#

Calculates the climatological mean of each month across a timeseries at sub-monthly timestep.

Parameters
  • df_in (pd.DataFrame) – dataframe containing timeseries at sub-monthly timestep.

  • col_name (str, optional) – name of column to be considered only. Defaults to None.

Returns

dataframe containing mean of each month.

Return type

pd.DataFrame

time_funcs.resample_time(df: DataFrame, resampling_period: str) DataFrame[source]#

Resamples a dataframe in time. The resampling duration is set with ‘time’ and needs to follow pandas conventions. Output needs to be combined with a statistic, such as “.mean()”.

Parameters
  • df (pd.DataFrame) – dataframe to be resampled.

  • resampling_period (str) – resampling duration.

Returns

actually returns a pd.core.resample.DatetimeIndexResampler

Return type

pd.DataFrame

time_funcs.resample_to_annual(df: DataFrame, stat_func='mean', suffix=None) DataFrame[source]#

Resamples a timeseries at sub-annual time step to annual values. A range of annual statistics can be chosen. If desired, the column name of the returned dataframe can contain a suffix for better distinguishment. By default, column names are unaltered.

Parameters
  • df (pd.DataFrame) – dataframe containing timeseries. Note, only tested with dataframes containing one column.

  • stat_func (str, optional) – Statistical method to be used. Either ‘mean’, ‘max’, ‘min’ or ‘sum’. Defaults to ‘mean’.

  • suffix (str, optional) – Suffix to be added to column of returned dataframe. Defaults to None.

Returns

dataframe containing resampled timeseries.

Return type

pd.DataFrame

time_funcs.resample_to_month(df: DataFrame, stat_func='mean', suffix=None) DataFrame[source]#

Resamples a timeseries at sub-monthly time step to monthly values. A range of monthly statistics can be chosen. If desired, the column name of the returned dataframe can contain a suffix for better distinguishment. By default, column names are unaltered.

Parameters
  • df (pd.DataFrame) – dataframe containing timeseries. Note, only tested with dataframes containing one column.

  • stat_func (str, optional) – Statistical method to be used. Either ‘mean’, ‘max’, ‘min’ or ‘sum’. Defaults to ‘mean’.

  • suffix (str, optional) – Suffix to be added to column of returned dataframe. Defaults to None.

Returns

dataframe containing resampled timeseries.

Return type

pd.DataFrame