Commit 0940962c authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Encoder. Better detection of end of moveup event. Smooth unblocking events.

parent d31b0362
Pipeline #172379 failed with stage
in 1 minute and 18 seconds
......@@ -86,14 +86,22 @@ def get_moveup_events(encoder_df: pd.DataFrame,
end_datetime = None
end_position = None
# Compute the time difference to the 5th next speed-in-range, to make sure it is not just a few isolate
# value which are in range.
in_range_df = in_range_df.copy()
in_range_df["diff_time"] = in_range_df.index.to_series().diff(periods=5).shift(-5)
end_df = in_range_df[in_range_df["diff_time"] < pd.Timedelta(seconds=5)].head(1)
end_datetime = end_df.index[0]
end_position = end_df["position"][0]
# Search for the datetime and position of the end of the event.
# The event ends when the melting speed in within `normal_speed_range` for at least 5 seconds. The actual
# end datetime is at the first sample of the new "normal melting" phase.
end_datetime = None
for line_datetime, after_line in after_df.iterrows():
if (after_line["speed"] >= min(normal_speed_range)) & (after_line["speed"] <= max(normal_speed_range)): # Speed in range
if end_datetime is not None: # Previous in-range already found
if line_datetime > end_datetime + pd.Timedelta(seconds=5): # The in-range phase lasted at least 5 sec
break # end datetime and position found.
continue # Within melting range since a while, continue until reaching the 5sec.
else: # First occurrence of in-range melting after out-of-range melting.
end_datetime = line_datetime
end_position = after_line["position"]
else: # Out-of-range melting
end_datetime = None
if end_position > (start_position + 25): # New iceblocks added
event_type = "stacking"
......@@ -110,4 +118,31 @@ def get_moveup_events(encoder_df: pd.DataFrame,
return events_df
def smooth_unblocking_events(unblocking_events_df: pd.DataFrame, arrival_df: pd.DataFrame) -> pd.DataFrame:
"""Replace upwards-downwards unblocking event by a linear interpolation.
unblocking_events_df: pd.DataFrame
Output of :func:`get_moveup_events` function, filtered to keep only event of type `unblocking`.
arrival_df: pd.DataFrame
Same as `arrival_df`, with the column `position` smoothed when they were unblocking events.
for index, event in unblocking_events_df.iterrows():
event_ts_df = arrival_df.loc[event["start_datetime"]:event["end_datetime"]] # Arrival_df related to the event
nb_samples = len(event_ts_df.index) # Number of measurement line in the event
step_mm = (event["start_position"] - event["end_position"]) / (nb_samples - 1) # mm/sample melted during the event
# Linear interpolation
positions = list()
for i in range(nb_samples):
positions.append(event["start_position"] - i * step_mm)
# Reset the positions, during the event
arrival_df.loc[event["start_datetime"]:event["end_datetime"]]["position"] = positions
return arrival_df
......@@ -437,6 +437,8 @@ def add_melted_height(arrival_df: pd.DataFrame, encoder_df: pd.DataFrame, iceblo
Same as input `arrival_df`, with melted block height.
moveup_events_df = encoder.get_moveup_events(encoder_df, normal_speed_range)
arrival_df = encoder.smooth_unblocking_events(moveup_events_df[moveup_events_df["event_type"] == "unblocking"],
stacked_iceblock_df = iceblock.get_total_stacked_height(iceblock_df)
arrival_df = get_absolute_melted_height_interp(arrival_df, stacked_iceblock_df, moveup_events_df,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment