Commit 97b3777b authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

FlowProcessor. Manage case when no moveup event and/or no stack event.

parent 6e48efe3
......@@ -568,30 +568,37 @@ def get_absolute_melted_height(encoder_df: pd.DataFrame,
pd.DataFrame
Same as ``encoder_df``, with an additional ``melted_height`` column.
"""
stack_events_df = moveup_event_df[moveup_event_df["event_type"] == "stacking"]
# Associate the stack events to the total height of ice blocks stacked at this event
stack_events_df = stack_events_df.copy()
stack_events_df = pd.merge_asof(stack_events_df, stacked_iceblocks_df,
left_on="start_datetime", right_on="datetime_stacked",
direction="forward")
# Compute the height of already-stacked ice which has been melted during the stacking event, while the encoder was
# moving or at its parking position
stack_events_df["melted_while_event"] = \
stack_events_df["tot_stacked_height"] - (stack_events_df["end_position"] - stack_events_df["start_position"])
# Compute the average melting speed of the ice block on the melting surface, during the stacking event.
stack_events_df["avg_melting_speed"] = \
-stack_events_df["melted_while_event"] / (stack_events_df["end_datetime"] - stack_events_df["start_datetime"]).dt.total_seconds()
encoder_df["time_diff"] = encoder_df.index.to_series().diff().dt.total_seconds()
encoder_df["ice_speed"] = encoder_df["position"].diff() / encoder_df["time_diff"]
# Compute speed for each timestep of each event
for index, stack_event in stack_events_df.iterrows():
encoder_df.loc[stack_event["start_datetime"]:stack_event["end_datetime"], "ice_speed"] = \
stack_event["avg_melting_speed"]
if len(moveup_event_df.index) != 0:
stack_events_df = moveup_event_df[moveup_event_df["event_type"] == "stacking"]
if len(stack_events_df.index) != 0:
# Associate the stack events to the total height of ice blocks stacked at this event
stack_events_df = stack_events_df.copy()
stack_events_df = pd.merge_asof(stack_events_df, stacked_iceblocks_df,
left_on="start_datetime", right_on="datetime_stacked",
direction="forward")
# Compute the height of already-stacked ice which has been melted during the stacking event, while the
# encoder was moving or at its parking position
stack_events_df["melted_while_event"] = \
stack_events_df["tot_stacked_height"] - (stack_events_df["end_position"] - stack_events_df["start_position"])
# Compute the average melting speed of the ice block on the melting surface, during the stacking event.
stack_events_df["avg_melting_speed"] = \
-stack_events_df["melted_while_event"] / (stack_events_df["end_datetime"] - stack_events_df["start_datetime"]).dt.total_seconds()
# Compute speed for each timestep of each event
for index, stack_event in stack_events_df.iterrows():
encoder_df.loc[stack_event["start_datetime"]:stack_event["end_datetime"], "ice_speed"] = \
stack_event["avg_melting_speed"]
endofmelting_events_df = moveup_event_df[moveup_event_df["event_type"] == "end_of_melting"].reset_index(drop=True)
if len(endofmelting_events_df.index) == 1: # Keep only the encoder data which occured before the end-of-melting
encoder_df = encoder_df[:endofmelting_events_df.loc[0, "start_datetime"]].copy()
elif len(endofmelting_events_df.index) > 1:
raise ValueError("More than one end-of-melting move-up events!")
encoder_df["melted_height"] = (-encoder_df["ice_speed"] * encoder_df["time_diff"]).cumsum()
......
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