Skip to main content
Version: Next

ts_shape.events.production.continuous_process_alignment

Continuous-process alignment: transport-lag compensation for multi-station lines.

Classes
NameDescription
ContinuousProcessAlignmentEventsAlign multi-station readings on a continuous production line.

ContinuousProcessAlignmentEvents​

classsource
ContinuousProcessAlignmentEvents(
dataframe: pd.DataFrame,
speed_uuid: str,
line_config: list[dict],
*,
ref_uuid: str | None = None,
cut_uuid: str | None = None,
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
speed_unit: str = "m/min",
min_speed: float = 0.01
) -> None

Bases: Base

Align multi-station readings on a continuous production line.

Readings are shifted to a common material reference time via speed-based transport lag compensation.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format DataFrame with time_column, uuid_column, and signal value columns. All UUIDs (speed, stations, cut signals) share the same DataFrame.required
speed_uuidstrUUID of the line-speed signal.required
line_configlist[dict]Physical layout description — list of dicts with keys name (str), offset (float, meters from reference), and uuids (list[str]).required
ref_uuidstr | NoneDeprecated; has no effect and will be removed in the next major release (passing it emits a DeprecationWarning). Put a reference-point signal into line_config with offset 0 instead.None
cut_uuidstr | NoneOptional UUID whose values carry the cut piece length in meters. Used by segment_by_cut as the default cut_length_uuid.None
time_columnstrName of the timestamp column (default "systime").'systime'
uuid_columnstrName of the UUID/identifier column (default "uuid").'uuid'
value_columnstrValue column of the speed signal, and the default station value column when no override is supplied to a method (default "value_double").'value_double'
speed_unitstrUnit of the speed signal. One of "m/min", "m/s", "mm/s".'m/min'
min_speedfloatMinimum speed in m/s used to clamp the speed before computing lag, preventing infinite lag at standstill (default 0.01).0.01
Raises
TypeDescription
ValueErrorIf speed_unit is not one of the supported units.
Functions
NameDescription
align_to_referenceShift each station reading backward by its transport lag.
segment_by_cutAdd piece columns to the output of align_to_reference.
lag_profileCompute per-window mean lag for each station.
alignment_qualityCoverage check: sample counts per window for speed and each station.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format frame holding the speed, station and cut signals.required
speed_uuidstrUUID of the line-speed signal.required
line_configlist[dict]The stations along the line, one dict each: {"name": "extruder", "offset": 0.0, "uuids": ["t1", "t2"]}. name labels the station, offset is its distance in metres from the reference point (0) along the material flow, and uuids lists the signals measured there. The offsets are physical: they come from the line drawing, not from the data. An unknown key, a missing key, a non-list uuids or a uuid listed twice raises ValueError.required
ref_uuidstr | NoneDeprecated; has no effect.None
cut_uuidstr | NoneOptional UUID whose values carry the cut piece length.None
time_columnstrName of the timestamp column.'systime'
uuid_columnstrName of the UUID column.'uuid'
value_columnstrValue column of the speed signal and default station value column.'value_double'
speed_unitstrUnit of the speed signal ("m/min", "m/s", ...).'m/min'
min_speedfloatSpeeds below this count as standstill.0.01

align_to_reference​

methodsource
align_to_reference(
station_uuids: list[str] | None = None, *, value_column: str | None = None
) -> pd.DataFrame

Shift each station reading backward by its transport lag.

This produces a common material_ref_time for all stations: systime - offset / speed, with the most recent valid speed reading at each station sample (missing speed values are skipped; samples before the first speed reading use the first one), clamped to at least min_speed.

Parameters
NameTypeDescriptionDefault
station_uuidslist[str] | NoneSubset of UUIDs to process. Defaults to all UUIDs in line_config.None
value_columnstr | NoneValue column to carry through. Defaults to the constructor value_column.None
Returns
TypeDescription
DataFrameDataFrame with columns material_ref_time, systime, uuid, component, position_offset_m, lag_seconds, and <value_column>.

segment_by_cut​

methodsource
segment_by_cut(
aligned_df: pd.DataFrame,
*,
cut_length_uuid: str | None = None,
part_counter_uuid: str | None = None,
value_column_cut: str = "value_double",
handle_resets: bool = True
) -> pd.DataFrame

Add piece columns to the output of align_to_reference.

Adds piece_id, piece_length_m, and piece_cut_ref_time to aligned_df.

Cut-event detection strategies (in priority order):

  1. part_counter_uuid (boolean): each True row = 1 cut.
  2. part_counter_uuid (integer/float): each step where the counter increases by delta counts as delta cuts, all attributed to the same timestamp when the signal resolution is coarser than the cut rate. The first reading is the baseline; missing readings are gaps.
  3. cut_length_uuid only: each row of the length signal = 1 cut.

Each cut time is shifted back to the reference point by the cutter's own transport lag (when the cutter's uuid is in line_config), the same way align_to_reference shifts station readings.

Piece assignment: a cut finishes the piece whose material passed the reference point since the previous cut. Rows with material_ref_time in (previous cut, this cut] get this cut's piece_id; rows up to and including the first cut belong to piece 1; rows after the last cut are not cut yet and get piece_id , piece_length_m NaN and piece_cut_ref_time NaT. Pieces cut at the same instant (a counter step > 1) share one boundary, so the material goes to the first of them and the others have no rows.

Parameters
NameTypeDescriptionDefault
aligned_dfDataFrameOutput of align_to_reference.required
cut_length_uuidstr | NoneUUID carrying the cut piece length value. Defaults to the constructor cut_uuid when None.None
part_counter_uuidstr | NoneUUID of a part-counter signal (boolean or monotonically increasing integer).None
value_column_cutstrColumn holding the length value in cut_length_uuid rows. With a counter, each cut takes the latest length reported at or before it.'value_double'
handle_resetsboolWhen True (default) and a numeric part_counter_uuid is used, a decreasing counter (a reset at a shift/part change or PLC restart) is treated as new production: the post-reset counter value is emitted as that many cut events instead of being skipped. When False, a reset's negative delta is ignored and its post-reset pieces are not counted.True
Returns
TypeDescription
DataFramealigned_df augmented with piece_id (nullable Int64, 1-based, numbered in cut order), piece_length_m (float or NaN), and piece_cut_ref_time (the piece's cut at the reference point, in the data's time zone).
Raises
TypeDescription
ValueErrorIf neither cut_length_uuid (nor the constructor cut_uuid) nor part_counter_uuid is given.

lag_profile​

methodsource
lag_profile(
station_uuids: list[str] | None = None, *, window: str = "1min"
) -> pd.DataFrame

Compute per-window mean lag for each station.

Parameters
NameTypeDescriptionDefault
station_uuidslist[str] | NoneSubset of UUIDs to process. Defaults to all UUIDs in line_config.None
windowstrPandas resample frequency for the speed averaging window (default "1min").'1min'
Returns
TypeDescription
DataFrameDataFrame with columns start, uuid, component, position_offset_m, mean_speed_m_s, and lag_seconds. Windows without speed readings have NaN speed and lag.

alignment_quality​

methodsource
alignment_quality(
station_uuids: list[str] | None = None, *, window: str = "1h"
) -> pd.DataFrame

Coverage check: sample counts per window for speed and each station.

Parameters
NameTypeDescriptionDefault
station_uuidslist[str] | NoneSubset of UUIDs to check. Defaults to all UUIDs in line_config.None
windowstrPandas resample frequency for the counting window (default "1h").'1h'
Returns
TypeDescription
DataFrameDataFrame with columns start, speed_sample_count, has_speed_data, has_full_coverage, and per_uuid_counts.