Commit c6b67c93 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Encoder. Function to manually shift stacking events.

parent 180fec18
Pipeline #172769 failed with stage
in 1 minute and 14 seconds
......@@ -146,3 +146,51 @@ def smooth_unblocking_events(unblocking_events_df: pd.DataFrame, arrival_df: pd.
# Reset the positions, during the event
arrival_df.loc[event["start_datetime"]:event["end_datetime"], "position"] = positions
return arrival_df
def shift_stacking_event(encoder_df: pd.DataFrame,
old_peak_start: pd.Timestamp, old_peak_end: pd.Timestamp, shift: pd.Timedelta) -> pd.DataFrame:
"""Time-shift a "stacking" move-up event
This function should be used wisely, as it modifies the base data. Only for specific human-verified hacks to fix
clearly identified problems.
encoder_df: pd.DataFrame
Encoder dataframe
old_peak_start: pd.Timestamp
Beginning of the stacking event to be shifted (index of the last value *before* the upwards movement).
old_peak_end: pd.Timestamp
End of the stacking event to be shifted (index of the first value *after* the downwards movement).
shift: pd.Timedelta
Duration of the shift.
Same as input's `encoder_df`, with a stacking move-up event shifted.
# Determine the boundaries of the new peak's position
new_peak_start = encoder_df.iloc[encoder_df.index.get_loc(old_peak_start + shift, method='nearest')].name
new_peak_end = encoder_df.iloc[encoder_df.index.get_loc(old_peak_end + shift, method='nearest')].name
# Determine the average slope of the curve, after the original peak
step_mm_per_sec = (encoder_df.loc[old_peak_end, "position"] - encoder_df.loc[new_peak_end, "position"]) / (
old_peak_end - new_peak_end).total_seconds()
# Replace data between old-peak-start and new-peak-start with a linear interpolation based on the slope found above.
prev_position = encoder_df.loc[old_peak_start, "position"]
prev_datetime = old_peak_start
for index, line in encoder_df[old_peak_start:new_peak_start].iterrows():
position = prev_position + step_mm_per_sec * (index - prev_datetime).total_seconds()
encoder_df.loc[index, "position"] = position
encoder_df.loc[index, "speed"] = step_mm_per_sec
# Create a new peak
encoder_df.loc[new_peak_start:new_peak_end, "position"] = 1310.000
encoder_df.loc[new_peak_start:new_peak_end, "speed"] = 0.0
return encoder_df
\ No newline at end of file
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