Skip to main content
Version: 0.0.98

ts_shape.features.segment_analysis.time_windowed_features

Classes
NameDescription
TimeWindowedFeatureTableBuild ML-ready feature tables from segmented timeseries data.

TimeWindowedFeatureTable​

classsource

Bases: Base

Build ML-ready feature tables from segmented timeseries data.

Takes the output of SegmentProcessor.apply_ranges and computes statistical metrics per UUID within fixed-size time windows (e.g. every 1 minute).

Methods:

  • compute_long: One row per (time_window, uuid, segment). Long format.
  • compute: One row per time_window with columns {uuid}__{metric}. Wide format.
Functions
NameDescription
compute_longCompute statistical metrics per UUID per time window (long format).
computeCompute a wide-format feature table with one row per time window.

compute_long​

classmethodsource
compute_long(
dataframe: pd.DataFrame,
window: str = "1min",
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
segment_column: str | None = "segment_value",
metrics: list[str] | None = None,
) -> pd.DataFrame

Compute statistical metrics per UUID per time window (long format).

Groups the input data into fixed-size time windows of window and computes numeric statistics for each (time_window, uuid, segment) group.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame (typically output of SegmentProcessor.apply_ranges).required
windowstrPandas frequency string for the time window size (e.g. '1min', '30s', '5min'). freq is the deprecated name.'1min'
time_columnstrColumn containing timestamps.'systime'
uuid_columnstrColumn identifying each timeseries signal.'uuid'
value_columnstrColumn containing numeric values.'value_double'
segment_columnstr | NoneColumn to sub-group by (e.g. 'segment_value'). Set to None to ignore segments entirely.'segment_value'
metricslist[str] | NoneSubset of metric names to compute. None uses all 19.None

Windows are the bins of pd.Grouper(freq=window) (for sub-daily frequencies they start at midnight of the first day; on tz-aware data they are wall-clock windows in the data's zone). A window that spans a segment change gives one row per segment. Groups with fewer than 2 non-missing values are left out.

Returns
TypeDescription
DataFrameDataFrame with columns time_window, uuid, segment_value?,
[DataFramesample_count, metric_1, ..., start, end, duration_seconds], one row
DataFrameper (window, uuid, segment) sorted in that order. time_window
DataFrameis the pandas bin label; start, end) is the window itself.
[DataFrameFor left-labeled windows ('1min', 'D', 'MS' ...) start equals
DataFrametime_window; right-labeled ones ('W', 'ME', 'QE', 'YE' ...)
DataFrameare labeled by their last day, so e.g. the 'ME' window labeled
DataFrame2024-01-31 has start 2024-01-01 and end 2024-02-01.
DataFrameEmpty (with these columns) when no group has 2 values.

compute​

classmethodsource
compute(
dataframe: pd.DataFrame,
window: str = "1min",
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
segment_column: str | None = "segment_value",
metrics: list[str] | None = None,
column_separator: str = "__",
) -> pd.DataFrame

Compute a wide-format feature table with one row per time window.

Each column is named {uuid}{separator}{metric} (e.g. temperature__mean). Windows where a UUID has insufficient data are filled with NaN. Every window between the first and the last sample appears, also one where no UUID has 2 values (all NaN; with a segment_column its segment is NaN too).

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame (typically output of SegmentProcessor.apply_ranges).required
windowstrPandas frequency string for the time window size. freq is the deprecated name.'1min'
time_columnstrColumn containing timestamps.'systime'
uuid_columnstrColumn identifying each timeseries signal.'uuid'
value_columnstrColumn containing numeric values.'value_double'
segment_columnstr | NoneColumn to sub-group by. Set to None to ignore segments.'segment_value'
metricslist[str] | NoneSubset of metric names to compute. None uses all 19.None
column_separatorstrSeparator between uuid and metric in wide column names.'__'
Returns
TypeDescription
DataFrameDataFrame with columns [time_window, segment_value?, {uuid}__{metric}, ...], sorted by time_window; time_window is the pandas bin label (see :meth:compute_long). Empty input gives an empty frame; input with no group of 2 values gives one row per window and only the index columns.