Skip to main content
Version: Next

ts_shape.features.segment_analysis.segment_processor

Classes
NameDescription
SegmentProcessorApply extracted time ranges to process data and compute metric profiles.

SegmentProcessor​

classsource

Bases: Base

Apply extracted time ranges to process data and compute metric profiles.

Takes the output of SegmentExtractor.extract_time_ranges and uses it to filter and annotate process parameter data, then computes statistical metrics per UUID per segment.

Methods:

  • apply_ranges: Filter process data by time ranges, annotate with segment info.
  • compute_metric_profiles: Compute statistical metrics per UUID per segment.
Functions
NameDescription
apply_rangesCut process data into the extracted time ranges.
compute_metric_profilesCompute statistical metrics per UUID per segment.

apply_ranges​

classmethodsource
apply_ranges(
dataframe: pd.DataFrame,
time_ranges: pd.DataFrame,
uuid_column: str = "uuid",
time_column: str = "systime",
target_uuids: list[str] | None = None,
) -> pd.DataFrame

Cut process data into the extracted time ranges.

Every row whose timestamp lies in a range gets that range's segment_value and segment_index. Ranges are half-open, segment_start <= t < segment_end, so a sample exactly at a boundary belongs to the range that starts there and contiguous ranges (interval_end="next_change") cut every row exactly once. The row exactly at segment_end belongs to the range only when the range's end_inclusive is True (extract_time_ranges sets it for the last segment, closed at the end of the data, and for every interval_end="last_sample" segment). Without an end_inclusive column, the end is inclusive when no other range starts at that instant. Rows outside every range (before the first range, in gaps such as an empty order number) are dropped; rows without a timestamp are dropped.

Overlapping ranges (only possible with a hand-built time_ranges) are applied one by one, so a row in two ranges appears twice; a warning says how many overlaps there are.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame with process parameter data (all UUIDs).required
time_rangesDataFrameOutput from SegmentExtractor.extract_time_ranges, or any frame with segment_start, segment_end, segment_value and segment_index columns. Naive range bounds are read in the data's time zone and aware bounds are converted to it; aware bounds on naive data raise ValueError.required
uuid_columnstrColumn identifying each timeseries.'uuid'
time_columnstrColumn containing timestamps.'systime'
target_uuidslist[str] | NoneOptional list of UUIDs to include. None keeps all.None
Returns
TypeDescription
DataFrameThe matching rows of dataframe (all columns, time column
DataFrameparsed to datetime), ordered by range and then by input order,
DataFramewith added columns:
DataFrame- segment_value: The active order/part number for each row.
DataFrame- segment_index: The sequential segment index.

compute_metric_profiles​

classmethodsource
compute_metric_profiles(
dataframe: pd.DataFrame,
uuid_column: str = "uuid",
value_column: str = "value_double",
group_column: str = "segment_value",
metrics: list[str] | None = None,
) -> pd.DataFrame

Compute statistical metrics per UUID per segment.

Typically called on the output of apply_ranges. Computes the statistics of NumericStatistics.summary_as_dict per (UUID, segment) pair, for all pairs at once. Missing values are ignored; pairs with fewer than 2 non-missing values are left out.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame (output of apply_ranges or similar).required
uuid_columnstrColumn identifying each timeseries.'uuid'
value_columnstrColumn containing numeric values.'value_double'
group_columnstrColumn to group segments by (e.g. 'segment_value', 'segment_index'). Use 'segment_value' to aggregate all ranges of the same order, or 'segment_index' for individual ranges.'segment_value'
metricslist[str] | NoneSubset of metric names to compute. None uses all 19.None
Returns
TypeDescription
DataFrameDataFrame with columns uuid, <group_column>, sample_count,
[DataFramemetric_1, ...], one row per pair, sorted by uuid and group.
DataFramesample_count is the number of non-missing values. Empty (with
DataFramethese columns) when no pair has 2 values.