Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
JOSSOUD Olivier
CFA Tools
Commits
0a3c2536
Commit
0a3c2536
authored
Jan 26, 2021
by
JOSSOUD Olivier
Browse files
Flow Processor. Improve datetime_out computation.
parent
445327b7
Pipeline
#101067
passed with stages
in 4 minutes and 51 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
30 deletions
+22
-30
cfatools/processor/flow.py
cfatools/processor/flow.py
+17
-10
cfatools/tests/test_processor/test_flow.py
cfatools/tests/test_processor/test_flow.py
+5
-20
No files found.
cfatools/processor/flow.py
View file @
0a3c2536
...
...
@@ -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
...
...
cfatools/tests/test_processor/test_flow.py
View file @
0a3c2536
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment