metobs_toolkit.Dataset.coarsen_time_resolution#

Dataset.coarsen_time_resolution(origin=None, origin_tz=None, freq=None, method=None, limit=None)[source]#

Resample the observations to coarser timeresolution.

The assumed dataset resolution (stored in the metadf attribute) will be updated.

Parameters:
  • origin (datetime.datetime, optional) – Define the origin (first timestamp) for the obervations. The origin is timezone naive, and is assumed to have the same timezone as the obervations. If None, the earliest occuring timestamp is used as origin. The default is None.

  • origin_tz (str, optional) – Timezone string of the input observations. Element of pytz.all_timezones. If None, the timezone from the settings is used. The default is None.

  • freq (DateOffset, Timedelta or str, optional) – The offset string or object representing target conversion. Ex: ‘15min’ is 15 minutes, ‘1h’, is one hour. If None, the target time resolution of the dataset.settings is used. The default is None.

  • method ('nearest' or 'bfill', optional) – Method to apply for the resampling. If None, the resample method of the dataset.settings is used. The default is None.

  • limit (int, optional) – Limit of how many values to fill with one original observations. If None, the target limit of the dataset.settings is used. The default is None.

Return type:

None.

Examples

>>> import metobs_toolkit
>>>
>>> # Import data into a Dataset
>>> dataset = metobs_toolkit.Dataset()
>>> dataset.update_settings(
...                         input_data_file=metobs_toolkit.demo_datafile,
...                         input_metadata_file=metobs_toolkit.demo_metadatafile,
...                         template_file=metobs_toolkit.demo_template,
...                         )
>>> dataset.import_data_from_file()
>>> dataset.coarsen_time_resolution(freq='15min') #to 15 minutes resolution
>>> dataset.df[['temp', 'humidity']].head()
                                     temp  humidity
name      datetime
vlinder01 2022-09-01 00:00:00+00:00  18.8      65
          2022-09-01 00:15:00+00:00  18.7      65
          2022-09-01 00:30:00+00:00  18.7      65
          2022-09-01 00:45:00+00:00  18.6      65
          2022-09-01 01:00:00+00:00  18.4      65