Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120135905
view_AMP_measurement.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 2, 04:44
Size
4 KB
Mime Type
text/x-python
Expires
Fri, Jul 4, 04:44 (2 d)
Engine
blob
Format
Raw Data
Handle
27145693
Attached To
R13271 Optical_Trapping_ML
view_AMP_measurement.py
View Options
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
Z_HELPERS.DM_communication
import
get_docs_VM
if
__name__
==
'__main__'
:
# First, we must query the correct Mongo DB and collection. The DB is called 'Optical_Trapping_ML_DB'.
# There are 2 collections associated with the ampicillin measurements:
# 1) tseries_AMPexp1_meas
# 2) tseries_AMPexp1_analysis
# The first one contains the raw data and the second one contains meta-information about the analysis of the
# raw data.
# ==================================================================================================================
# Let's see how the raw data looks like. We load the first measurement of run 19 of the 'tseries_AMPexp1_meas'
# collection:
query
=
{
'meas_num'
:
'1'
,
'run'
:
19
}
docs
=
get_docs_VM
(
db_name
=
'Optical_Trapping_ML_DB'
,
coll_name
=
'tseries_AMPexp1_meas'
,
query
=
query
)
# If you want to query all the measurements of a given collection you set "query = {}".
# ==================================================================================================================
# We loop over all the documents printing each key-value pair of the document, and we plot the data
for
doc
in
docs
:
for
k
,
v
in
doc
.
items
():
# We do not show the data completely but rather the keys
if
k
!=
'data'
:
print
(
'Key: {} - Value: {}'
.
format
(
k
,
v
))
else
:
print
(
'Data keys: '
,
v
.
keys
())
transmission
=
doc
.
get
(
'data'
)[
'transmission'
]
# For these measurements the time sequence must be created from the time step
dt
=
doc
.
get
(
'dt'
)
time
=
np
.
arange
(
0
,
len
(
transmission
)
*
dt
,
dt
)
# We plot the raw data in Fig.1
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
7
,
5.8
))
ax
.
plot
(
time
,
transmission
,
'k'
)
ax
.
set_xlabel
(
'Time (sec)'
,
size
=
20
)
ax
.
set_ylabel
(
'Transmission (V)'
,
size
=
20
)
ax
.
yaxis
.
set_ticks_position
(
'both'
)
ax
.
xaxis
.
set_ticks_position
(
'both'
)
ax
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
direction
=
'in'
,
labelsize
=
20
)
ax
.
set_title
(
'Raw data'
,
size
=
20
)
fig
.
tight_layout
()
# Each measurement has been analyzed. Let's get the corresponding analyzed document:
analyzed_doc
=
get_docs_VM
(
db_name
=
'Optical_Trapping_ML_DB'
,
coll_name
=
'tseries_AMPexp1_analysis'
,
query
=
{
'_id'
:
doc
[
'_id'
]})[
0
]
# analyzed_doc = get_docs_VM(db_name='Optical_TrappingDB', coll_name='tseries_AMPexp1_analysis',
# query=query)[0]
print
(
doc
[
'_id'
],
analyzed_doc
[
'_id'
])
# The analysis of the time series amounts in classifying each part of the trace in OFF / ON / TRAPPING segments
classification
=
analyzed_doc
[
'classification'
]
off_idx
=
[
x
[
'indices'
]
for
x
in
classification
if
x
[
'type'
]
==
'OFF'
]
on_idx
=
[
x
[
'indices'
]
for
x
in
classification
if
x
[
'type'
]
==
'ON'
]
trap_idx
=
[
x
[
'indices'
]
for
x
in
classification
if
x
[
'type'
]
==
'trapping'
]
# In Fig.2 we plot the different segments
fig2
,
ax2
=
plt
.
subplots
(
figsize
=
(
7
,
5.8
))
ax2
.
plot
(
time
,
transmission
,
'k'
)
for
k
,
idx
in
enumerate
(
off_idx
):
if
k
==
0
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'r'
,
label
=
'Cavity OFF'
)
else
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'r'
)
for
k
,
idx
in
enumerate
(
on_idx
):
if
k
==
0
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'b'
,
label
=
'Cavity ON'
)
else
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'b'
)
for
k
,
idx
in
enumerate
(
trap_idx
):
if
k
==
0
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'g'
,
label
=
'Trapping'
)
else
:
ax2
.
plot
(
time
[
idx
[
0
]:
idx
[
1
]],
transmission
[
idx
[
0
]:
idx
[
1
]],
'g'
)
ax2
.
set_xlabel
(
'Time (sec)'
,
size
=
20
)
ax2
.
set_ylabel
(
'Transmission (V)'
,
size
=
20
)
ax2
.
yaxis
.
set_ticks_position
(
'both'
)
ax2
.
xaxis
.
set_ticks_position
(
'both'
)
ax2
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
direction
=
'in'
,
labelsize
=
20
)
ax2
.
set_title
(
'Raw data with classification'
,
size
=
20
)
fig2
.
tight_layout
()
# In order to compare many measurements, we must carry out a normalization:
norm_factor
=
np
.
median
(
transmission
[
on_idx
[
0
][
0
]:
on_idx
[
0
][
1
]])
transmission
=
transmission
/
norm_factor
fig3
,
ax3
=
plt
.
subplots
(
figsize
=
(
7
,
5.8
))
ax3
.
plot
(
time
,
transmission
,
'b'
)
ax3
.
set_xlabel
(
'Time (sec)'
,
size
=
20
)
ax3
.
set_ylabel
(
'Normalized transmission'
,
size
=
20
)
ax3
.
yaxis
.
set_ticks_position
(
'both'
)
ax3
.
xaxis
.
set_ticks_position
(
'both'
)
ax3
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
direction
=
'in'
,
labelsize
=
20
)
ax3
.
set_title
(
'Normalized Data'
,
size
=
20
)
fig3
.
tight_layout
()
plt
.
show
()
Event Timeline
Log In to Comment