ts_shape.features.segment_analysis.segment_processor
| Name | Description |
|---|---|
SegmentProcessor | Apply extracted time ranges to process data and compute metric profiles. |
SegmentProcessor
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.
| Name | Description |
|---|---|
apply_ranges | Cut process data into the extracted time ranges. |
compute_metric_profiles | Compute statistical metrics per UUID per segment. |
apply_ranges
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.
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Input DataFrame with process parameter data (all UUIDs). | required |
time_ranges | DataFrame | Output 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_column | str | Column identifying each timeseries. | 'uuid' |
time_column | str | Column containing timestamps. | 'systime' |
target_uuids | list[str] | None | Optional list of UUIDs to include. None keeps all. | None |
| Type | Description |
|---|---|
DataFrame | The matching rows of dataframe (all columns, time column |
DataFrame | parsed to datetime), ordered by range and then by input order, |
DataFrame | with added columns: |
DataFrame | - segment_value: The active order/part number for each row. |
DataFrame | - segment_index: The sequential segment index. |
compute_metric_profiles
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.
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Input DataFrame (output of apply_ranges or similar). | required |
uuid_column | str | Column identifying each timeseries. | 'uuid' |
value_column | str | Column containing numeric values. | 'value_double' |
group_column | str | Column 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' |
metrics | list[str] | None | Subset of metric names to compute. None uses all 19. | None |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns uuid, <group_column>, sample_count, |
[DataFrame | metric_1, ...], one row per pair, sorted by uuid and group. |
DataFrame | sample_count is the number of non-missing values. Empty (with |
DataFrame | these columns) when no pair has 2 values. |