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

Flow. Rewrite add_iceblock_info() function.

parent 40b2b0dc
Pipeline #149539 passed with stages
in 47 seconds
......@@ -5,7 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$/cfatools" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (cfatools)" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">
......
......@@ -13,6 +13,7 @@ if os.name != "nt":
from cfatools.logreader.dataset import DatasetReader
from cfatools.processor import iceblock
from cfatools.processor import pump
from cfatools.processor import encoder
import matplotlib.pyplot as plt
......@@ -375,7 +376,8 @@ def get_arrival_df(encoder_df: pd.DataFrame,
return arrival_df
def add_iceblock_info(arrival_df: pd.DataFrame, encoder_df: pd.DataFrame, iceblock_df: pd.DataFrame) -> pd.DataFrame:
def add_iceblock_info(arrival_df: pd.DataFrame, encoder_df: pd.DataFrame, iceblock_df: pd.DataFrame,
normal_speed_range: typing.Tuple[float, float] = (-3.0, -0.01)) -> pd.DataFrame:
"""Add iceblock information: melted block height and iceblock code & name.
Parameters
......@@ -386,21 +388,28 @@ def add_iceblock_info(arrival_df: pd.DataFrame, encoder_df: pd.DataFrame, iceblo
Encoder's timestamped data, as obtained with :func:`get_datasets_data` function.
iceblock_df: pd.DataFrame
Iceblock's timestamped data, as obtained with :func:`get_datasets_data` function.
normal_speed_range: typing.Tuple[float, float]
Min and max encoder speed for "normal melting". Negative speed means encoder is going down. Speed unit: mm/s
Returns
-------
pd.DataFrame
Same as input `arrival_df`, with melted block height and iceblock code & name.
"""
# Add encoder speed to arrival_df
arrival_df = pd.merge(arrival_df, encoder_df, left_index=True, right_index=True)
# Add iceblock code and name to arrival_df
iceblock_df = iceblock_df.drop(columns="icbk_datetime")
arrival_df = pd.merge_asof(arrival_df, iceblock_df, left_index=True, right_index=True)
# Compute melted block height for each iceblock, for each encoder step
arrival_df = arrival_df.groupby("icbk_code").apply(__compute_mm__)
moveup_events_df = encoder.get_moveup_events(encoder_df, normal_speed_range)
stacked_iceblock_df = iceblock.get_total_stacked_height(iceblock_df)
encoder_df = get_absolute_melted_height(encoder_df, stacked_iceblock_df, moveup_events_df,
starting_on_plexi=True)
arrival_df = pd.merge(arrival_df, encoder_df[["melted_height"]], left_index=True, right_index=True)
arrival_df = pd.merge_asof(arrival_df,
iceblock_df[["id", "name", "datetime_start"]],
left_index=True,
right_on="datetime_start")
arrival_df = arrival_df.set_index("melt", drop=False)
arrival_df = arrival_df.drop(columns="datetime_start")
arrival_df = arrival_df.rename(columns={'id': 'icbk_code', 'name': 'icbk_name'})
return arrival_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