Resample

Interpolate and Resample

indsl.resample.interpolate(data: Series, method: Literal['linear', 'ffill', 'stepwise', 'zero', 'slinear', 'quadratic', 'cubic'] = 'linear', kind: Literal['pointwise', 'average'] = 'pointwise', granularity: str = '1s', bounded: int = 1, outside_fill: str = None) Union[DataFrame, Series]

Interpolation

Interpolates and resamples data with a uniform sampling frequency.

Parameters
  • data – Time series.

  • method

    Method. Specifies the interpolation method. Defaults to “linear”. Possible inputs are :

    • ’linear’: linear interpolation.

    • ’ffill’: forward filling.

    • ’stepwise’: yields same result as ffill.

    • ’zero’, ‘slinear’, ‘quadratic’, ‘cubic’: spline interpolation of zeroth, first, second or third order.

  • kind

    Kind. Specifies the kind of returned data points. Defaults to “pointwise”. Possible inputs are :

    • ’pointwise’: returns the pointwise value of the interpolated function for each timestamp.

    • ’average’: returns the average of the interpolated function within each time period.

  • granularity – Frequency. Sampling frequency or granularity of the output (e.g. ‘1s’ or ‘2h’). ‘min’ refers to minutes and ‘M’ to months. Defaults to “1s”.

  • bounded

    Bounded. - 1: Fill in for requested points outside of the data range. - 0: Ignore said points. Defaults to 1.

    Default behaviour is to raise a UserValueError if the data range is not within start and end and no outside fill method is specified (value 1).

  • outside_fill – Outside fill. Specifies how to fill values outside input data range (‘None’ or ‘extrapolate’). Defaults to None.

Returns

Interpolated time series.

Return type

pandas.Series

Raises
  • UserTypeError – data is not a time series

  • UserTypeError – If specified, outside_fill must be either ‘None’ or ‘extrapolate’.

  • Warning – Empty data time series

  • Warning – All data in timeseries is nan

Resampling: Fourier, Polynomial, Linear, min, max, sum, count

indsl.resample.resample(data: Series, method: Literal['fourier', 'polyphase', 'interpolate', 'min', 'max', 'sum', 'count', 'mean'] = 'fourier', granularity_current: str = None, granularity_next: str = '1s', num: int = None, downsampling_factor: int = None, interpolate_resolution: str = None, ffill_resolution: str = None) Series

Resample

This method offers a robust filling of missing data points and data resampling a given sampling frequency. Multiple data resampling options are available:

  • Fourier

  • Polynomial phase filtering

  • Linear interpolation (for up-sampling)

  • Min, max, sum, count, mean (for down-sampling)

Parameters
  • data – Time series.

  • method

    Method. Resampling method:

    • ”fourier” for Fourier method (default)

    • ”polyphase” for polyphase filtering

    • ”interpolate” for linear interpolation when upsampling

    • ”min”, “max”, “sum”, “count”, “mean” when downsampling

  • granularity_current – Current temporal resolution. Temporal resolution of uniform time series, before resampling. Defaults to None. If not specified, the frequency will be implied, which only works if no data is missing. Follows Pandas DateTime convention.

  • granularity_next – Final temporal resolution. Temporal resolution of uniform time series, after resampling. Defaults to “1s”. Either “Number of Samples” or “Final temporal resolution” must be provided.

  • num – Number of Samples. The number of samples in the resampled signal. If this is set, the time deltas will be inferred. Defaults to None. Either “Number of Samples” or “Final temporal resolution” must be provided.

  • downsampling_factor – Down-sampling factor. The down-sampling factor is required for the polyphase filtering. Defaults to None.

  • interpolate_resolution – Interpolation threshold. Gaps smaller than threshold will be interpolated, larger than this will be filled by noise. Defaults to None.

  • ffill_resolution – Forward fill threshold. Gaps smaller than this threshold will be forward filled. Defaults to None.

Returns

Interpolated time series Uniform, resampled time series with specified number of data points.

Return type

pandas.Series

Raises
  • UserTypeError – data is not a time series

  • UserTypeError – Either num or granularity_next has to be set

  • UserTypeError – If specified, outside_fill must be either ‘None’ or ‘extrapolate’.

  • UserTypeError – Method has to be in ‘fourier’, ‘polyphase’, ‘interpolate’, ‘min’, ‘max’, ‘sum’, ‘count’

  • UserTypeError – Empty data time series

  • UserTypeError – All values in the time series are NaN

  • Warning – Can’t infer time series resolution with missing data. Please provide resolution

Resampling to granularity (default)

indsl.resample.resample_to_granularity(series: Series, granularity: str = '1h', aggregate: AggregateEnum = AggregateEnum.MEAN) Series

Resample to granularity

Resample time series to a given fixed granularity (time delta) and aggregation type (read more about aggregation)

Parameters
  • series – Time series.

  • granularity – Granularity. Granularity defines the time range that each aggregate is calculated from. It consists of a time unit and a size. Valid time units are day or d, hour h, minute or m and second or s. For example, 2h means that each time range should be 2 hours wide, 3m means 3 minutes, and so on.

  • aggregate

    Aggregate. Type of aggregation to use when resampling. Possible options are:

    • mean

    • max

    • min

    • count

    • sum

Returns

Resampled time series.

Return type

pandas.Series

Reindex

indsl.resample.reindex(data1: Series, data2: Series, method: Method = Method.LINEAR, kind: Kind = Kind.POINTWISE, bounded: bool = False) List[Series]

Reindex

This method offers data reindexing onto a common index and fills missing data points. If bounded is false, the common index is the union of the the input time-series indices. If bounded is true, the common index is restricted to the period where the time-series overlap. All not-a-number (NaN) values are removed in the output time series.

Parameters
  • data1 – First time series.

  • data2 – Second time series.

  • method

    Method. Specifies the interpolation method. Defaults to “linear”. Possible inputs are :

    • ’zero_previous’: zero order spline interpolation with forward filling mode, i.e. the previous known value of any point is used.

    • ’zero_next’: zero order spline interpolation with backward filling mode, i.e. the next known value of any point is used.

    • ’linear’: linear order spline interpolation.

    • ’quadratic’: quadratic order spline interpolation.

    • ’cubic’: cubic order spline interpolation.

  • kind

    Kind. Specifies the kind of returned data points. Defaults to “pointwise”. Possible inputs are:

    • ’pointwise’: returns the pointwise value of the interpolated function for each timestamp.

    • ’average’: returns the average of the interpolated function within each time period.

  • bounded

    Bounded. Specifies if the output should be bounded to avoid extrapolation. Defaults to False. Possible inputs are:

    • True: Return the intersection of the timeperiods of the input time series.

    • False: Return the union of the timeperiods of the input time series. Extraplolate points outside of the data range.

Returns

First reindexed time series pandas.Series: Second reindexed time series Reindexed time series with common indices.

Return type

pandas.Series

Raises
  • UserTypeError – data1 or data2 are not a time series

  • UserTypeError – Method has to be of type Method

  • UserTypeError – Kind has to be of type Kind

  • UserTypeError – Bounded has to be of type bool

  • UserValueError – All time series must have at least two values