Commit 1fdbf876 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Flow Processor. get_datetime_out. Now ml/min can be passed as pd.Series

parent 46e9e900
Pipeline #106812 passed with stages
in 2 minutes and 50 seconds
......@@ -232,7 +232,7 @@ def get_bubble_density_from_conduct(dataset: DatasetReader):
return compump_df
def get_datetime_out(datetime_in: pd.Series, mlmin_df: pd.DataFrame, tube_volume_ml: float, parallel: bool = True) -> pd.Series:
def get_datetime_out(datetime_in_series: pd.Series, mlmin_series: pd.Series, tube_volume_ml: float, parallel: bool = True) -> 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
......@@ -241,11 +241,11 @@ def get_datetime_out(datetime_in: pd.Series, mlmin_df: pd.DataFrame, tube_volume
Parameters
----------
datetime_in: pd.Series
datetime_in_series: 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.
mlmin_series: pd.Series
Datetime-indexed series of fluid flow rate, in ml/min. In most case, this comes from pump's flow rate settings
time series.
tube_volume_ml: float
Volume of the tube.
parallel: bool
......@@ -258,24 +258,21 @@ def get_datetime_out(datetime_in: pd.Series, mlmin_df: pd.DataFrame, tube_volume
pd.Series
Date/time when the fluid of interest exists the tube.
"""
# Convert Series to single-column Dataframe (it is easier to merge and apply)
datetime_in_df = pd.DataFrame(datetime_in)
data_colname = datetime_in_df.columns[0]
datetime_in_df = datetime_in_df.set_index(data_colname, drop=False)
# Add events' datetime to pump's mlmin change datetime
mlmin_df = pd.merge(mlmin_df, datetime_in_df, left_index=True, right_index=True, how="outer")
datetime_in_series_temp = pd.Series(datetime_in_series.values, index=datetime_in_series, name=datetime_in_series.name)
mlmin_df = pd.merge(mlmin_series, datetime_in_series_temp, left_index=True, right_index=True, how="outer")
mlmin_df = mlmin_df.rename(columns={mlmin_series.name: "mlmin"})
mlmin_df = mlmin_df[["mlmin"]].ffill()
mlmin_df["ml_cumul"] = pump.add_cumulated_volume(mlmin_df["mlmin"])
# Make sure the earliest datetime_in is after the first available ml_cumul
datetime_in = datetime_in[datetime_in >= mlmin_df["ml_cumul"].dropna().index[0]]
datetime_in_series = datetime_in_series[datetime_in_series >= mlmin_df["ml_cumul"].dropna().index[0]]
if parallel:
pandarallel.initialize()
datetime_out = datetime_in.parallel_apply(__get_single_datetime_out__, args=(mlmin_df, tube_volume_ml))
datetime_out = datetime_in_series.parallel_apply(__get_single_datetime_out__, args=(mlmin_df, tube_volume_ml))
else:
datetime_out = datetime_in.apply(__get_single_datetime_out__, args=(mlmin_df, tube_volume_ml))
datetime_out = datetime_in_series.apply(__get_single_datetime_out__, args=(mlmin_df, tube_volume_ml))
return datetime_out
......
......@@ -46,23 +46,24 @@ class TestFlow(TestCase):
"2021-01-01 00:20:00",
"2021-01-01 00:30:00"])
mlmin = [1, 2, 1, 1]
mlmin_df = pd.DataFrame({'mlmin': mlmin}, index=datetimes)
pump_df = pd.DataFrame({'pic': mlmin}, index=datetimes)
# Build ice core insertion date/time test set
icecore_id = [0, 1, 2, 3]
datetime_in = pd.to_datetime(["2021-01-01 00:05:00",
icecore_id = [0, 1, 2, 3, 4]
datetime_in = pd.to_datetime(["2020-12-31 00:00:00",
"2021-01-01 00:05:00",
"2021-01-01 00:09:00",
"2021-01-01 00:10:00",
"2021-01-01 00:11:00"])
icecore_df = pd.DataFrame({'icecore_id': icecore_id, 'datetime_in': datetime_in})
icecore_df["datetime_out"] = flow.get_datetime_out(icecore_df["datetime_in"], mlmin_df, tube_volume_ml,
icecore_df["datetime_out"] = flow.get_datetime_out(icecore_df["datetime_in"], pump_df["pic"], tube_volume_ml,
parallel=False)
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"))
self.assertEqual(icecore_df.iloc[1]["datetime_out"], pd.to_datetime("2021-01-01 00:25:00"))
self.assertEqual(icecore_df.iloc[2]["datetime_out"], pd.to_datetime("2021-01-01 00:29:00"))
self.assertEqual(icecore_df.iloc[3]["datetime_out"], pd.to_datetime("2021-01-01 00:30:00"))
self.assertEqual(icecore_df.iloc[4]["datetime_out"], pd.to_datetime("2021-01-01 00:32:00"))
def test_get_datetime_out_realdateset(self):
monitor_processing_time = False
......
# Absolute path of the base directory where the data files produced by the CFA are be stored.
base_data_path = /home/dryas/cfa/
base_data_path = /homel/ojossoud/Data/data_cfa/
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