Commit 0a3c2536 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Flow Processor. Improve datetime_out computation.

parent 445327b7
Pipeline #101067 passed with stages
in 4 minutes and 51 seconds
......@@ -39,31 +39,38 @@ def get_flow_timeseries(dataset: DatasetReader):
pass
def add_datetime_out(event_df: pd.DataFrame, mlmin_df: pd.DataFrame, tube_volume_ml: float) -> pd.DataFrame:
"""
def get_datetime_out(datetime_in: pd.Series, mlmin_df: pd.DataFrame, tube_volume_ml: float) -> pd.Series:
"""Get the date/time the fluid reaches the end of the tube.
Considering a tube whose internal volume is ``tube_volume_ml``, in which flows a fluid as variable flow rates
listed and timestamped in ``mlmin_df``, if some "transitions" (e.g. a breaks between 2 ice cores) enters the tube at
``datetime_in``, then this function will return the moments these transitions reach the output of the tube.
Parameters
----------
event_df: pd.DataFrame
datetime_in: pd.Series
Datetime-indexed series of moments the fluids of interest enters the tube.
mlmin_df: pd.DataFrame
Datetime-indexed dataframe containing a Series of fluid flow rate, in ml/min (data column must be named
``mlmin``). In most case, this comes from pump's flow rate settings time series.
tube_volume_ml: float
Returns
-------
pd.DataFrame
"""
pd.Series
Date/time when the fluid of interest exists the tube.
"""
# Add events' datetime to pump's mlmin change datetime
mlmin_df = pd.merge(mlmin_df, event_df, left_index=True, right_index=True, how="outer")
mlmin_df = pd.merge(mlmin_df, datetime_in, left_index=True, right_index=True, how="outer")
mlmin_df = mlmin_df[["mlmin"]].ffill()
mlmin_df["ml_cumul"] = pump.add_cumulated_volume(mlmin_df["mlmin"])
event_df["datetime_out"] = event_df["datetime_in"].apply(get_datetime_out, args=(mlmin_df, tube_volume_ml))
datetime_out = datetime_in.apply(__get_single_datetime_out__, args=(mlmin_df, tube_volume_ml))
return event_df
return datetime_out
def get_datetime_out(datetime_in: pd.Timestamp, mlmin_df: pd.DataFrame, tube_volume_ml: float) -> pd.Timestamp:
def __get_single_datetime_out__(datetime_in: pd.Timestamp, mlmin_df: pd.DataFrame, tube_volume_ml: float) -> pd.Timestamp:
"""Get the date/time the fluid reaches the end of the tube.
Considering a tube whose internal volume is ``tube_volume_ml``, in which flows a fluid as variable flow rates
......
......@@ -28,7 +28,7 @@ class TestFlow(TestCase):
except:
self.fail("Exception raised!")
def test_get_datetime_out(self):
def test_get_datetime_out_artificialdataset(self):
tube_volume_ml = 30
# Build variable flow rate test set
......@@ -49,23 +49,15 @@ class TestFlow(TestCase):
icecore_df.set_index("datetime_in", inplace=True)
icecore_df["datetime_in"] = icecore_df.index
# icecore_df["datetime_out"] = icecore_df["datetime_in"].apply(flow.get_datetime_out,
# args=(mlmin_df, tube_volume_ml))
flow.add_datetime_out(icecore_df, mlmin_df, tube_volume_ml)
# try:
#
# except:
# self.fail("Exception raised!")
icecore_df["datetime_out"] = flow.get_datetime_out(icecore_df["datetime_in"], mlmin_df, tube_volume_ml)
self.assertEqual(icecore_df.iloc[0]["datetime_out"], pd.to_datetime("2021-01-01 00:25:00"))
self.assertEqual(icecore_df.iloc[1]["datetime_out"], pd.to_datetime("2021-01-01 00:29:00"))
self.assertEqual(icecore_df.iloc[2]["datetime_out"], pd.to_datetime("2021-01-01 00:30:00"))
self.assertEqual(icecore_df.iloc[3]["datetime_out"], pd.to_datetime("2021-01-01 00:32:00"))
########################
# Real dataset
def test_add_datetime_out(self):
def test_get_datetime_out_realdateset(self):
tube_volume_ml = 30
dataset_name = "20210122_mock_ice_bronkgas_debub"
......@@ -75,20 +67,13 @@ class TestFlow(TestCase):
encoder_df["datetime_in"] = encoder_df.index
t0 = datetime.datetime.now()
t1 = datetime.datetime.now()
profile = cProfile.Profile()
profile.enable()
encoder_df = flow.add_datetime_out(encoder_df, colpump_df, tube_volume_ml)
encoder_df["datetime_out"] = flow.get_datetime_out(encoder_df["datetime_in"], colpump_df, tube_volume_ml)
profile.disable()
ps = pstats.Stats(profile)
ps.print_stats()
t2 = datetime.datetime.now()
print(t1 - t0)
print(t2 - t1)
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