metobs_toolkit.station.Station.resample#

Station.resample(target_freq: str | Timedelta, obstype: str | None = None, shift_tolerance: str | Timedelta = Timedelta('0 days 00:04:00'), origin: None | Timestamp = None, origin_simplify_tolerance: str | Timedelta = Timedelta('0 days 00:04:00')) None[source]#

Resample observation data to a specified frequency.

Resampling is done by creating target timestamps, aligning them with the present timestamps, and transferring the nearest (in time) value to the target timestamp. There is no interpolation in time.

Alignment restrictions can be specified by setting the shift_tolerance, which indicates the maximum shift (in time) that aligned timestamps can have.

Since the origin (the first timestamp in the current observations) is in general not a suitable candidate to serve as origin for the target frequency, a suitable origin is deduced. This can be done by specifying the origin argument, or if None it is done automatically. This is done by simplifying the current origin by rounding it down, and testing if the shift in the new tolerance is smaller than origin_simplify_tolerance.

Parameters:
  • target_freq (str or pandas.Timedelta) – The target frequency to which the data should be resampled. Can be specified as a pandas frequency string (e.g., ‘5T’ for 5 minutes) or a pandas.Timedelta object.

  • obstype (str or None, optional) – The observation type (sensor) to resample. If None, all sensors will be resampled to the same frequency. Default is None.

  • shift_tolerance (str or pandas.Timedelta, optional) – The maximum allowed time shift tolerance for aligning data during resampling. Default is 4 minutes.

  • origin (pandas.Timestamp, or None, optional) – The origin timestamp (=first timestamp) of the target records. Can be a pandas.Timestamp or None. If a timezone-naive timestamp is given, it is assumed to be in UTC. If None, then a suitable origin is used by simplifying the current origin and making sure that origin_simplify_tolerance is met. Default is None.

  • origin_simplify_tolerance (pandas.Timedelta, optional) – This is only used when origin is None. The tolerance for simplifying the origin alignment during resampling. Default is 4 minutes.

Return type:

None

Notes

  • If obstype is None, all sensors in self.sensordata will be resampled to the same frequency.

  • If obstype is specified, it must be a known observation type.

Warning

Since the gaps depend on the record’s frequency and origin, all gaps are removed and re-located. All progress in gap filling will be lost.

Warning

Cumulative tolerance errors can be introduced when this method is called multiple times.