Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Bacteria Drug UV analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DISCO Beamline
Bacteria Drug UV analysis
Commits
6e095af1
Commit
6e095af1
authored
Jul 1, 2022
by
Hugo chauvet
Browse files
Options
Downloads
Patches
Plain Diff
improve perf of the viewver and correct bug in xls export
parent
ca410fb8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
requirements.txt
+4
-1
4 additions, 1 deletion
requirements.txt
src/bactos_viewver.py
+53
-30
53 additions, 30 deletions
src/bactos_viewver.py
src/lib_bactos_hdf.py
+19
-0
19 additions, 0 deletions
src/lib_bactos_hdf.py
with
76 additions
and
31 deletions
requirements.txt
+
4
−
1
View file @
6e095af1
scikit-image
scikit-image
h5py
h5py
tifffile
tifffile
numpy
numpy
<1.20
scipy
scipy
pandas
pandas
xlsxwriter
ipywidgets
ipympl
This diff is collapsed.
Click to expand it.
src/bactos_viewver.py
+
53
−
30
View file @
6e095af1
...
@@ -95,7 +95,7 @@ def compute_control_ratio(selected_file, ctrl_exp):
...
@@ -95,7 +95,7 @@ def compute_control_ratio(selected_file, ctrl_exp):
The name of the control experiment (i.e. a hdf group name)
The name of the control experiment (i.e. a hdf group name)
"""
"""
positions
=
[
p
for
p
in
range
(
load_imag
e
(
selected_file
,
ctrl_exp
)
.
shape
[
1
])]
positions
=
[
p
for
p
in
range
(
get_stack_shap
e
(
selected_file
,
ctrl_exp
)[
1
])]
IF1c
,
IF2c
=
get_all_pos_fluo
(
selected_file
,
ctrl_exp
,
positions
=
positions
)
IF1c
,
IF2c
=
get_all_pos_fluo
(
selected_file
,
ctrl_exp
,
positions
=
positions
)
IF2c
=
np
.
hstack
(
IF2c
)
IF2c
=
np
.
hstack
(
IF2c
)
...
@@ -447,6 +447,10 @@ class BactosViewver():
...
@@ -447,6 +447,10 @@ class BactosViewver():
self
.
update_intensity_tables
()
self
.
update_intensity_tables
()
self
.
update_control_ratio_table
()
self
.
update_control_ratio_table
()
# Need to init the first call of main figure to display it
with
self
.
WplotAll
:
plt
.
show
(
self
.
figure
)
def
build_explore_gui
(
self
):
def
build_explore_gui
(
self
):
"""
"""
Build the main UI to explore the bacteria on images.
Build the main UI to explore the bacteria on images.
...
@@ -484,9 +488,9 @@ class BactosViewver():
...
@@ -484,9 +488,9 @@ class BactosViewver():
# Create a slider for experiment time
# Create a slider for experiment time
self
.
t
=
widgets
.
IntSlider
(
min
=
0
,
max
=
max
(
self
.
times
),
step
=
1
,
description
=
'
time:
'
)
self
.
t
=
widgets
.
IntSlider
(
min
=
0
,
max
=
max
(
self
.
times
),
step
=
1
,
description
=
'
time:
'
)
# Sliders for image intensity
# Sliders for image intensity
self
.
F1minmax
=
widgets
.
IntRangeSlider
(
value
=
[
0
,
2
**
16
],
min
=
0
,
max
=
5
000
,
self
.
F1minmax
=
widgets
.
IntRangeSlider
(
value
=
[
0
,
2
000
],
min
=
0
,
max
=
2
000
,
description
=
'
F1:
'
,
orientation
=
'
horizontal
'
)
description
=
'
F1:
'
,
orientation
=
'
horizontal
'
)
self
.
F2minmax
=
widgets
.
IntRangeSlider
(
value
=
[
0
,
2
**
16
],
min
=
0
,
max
=
5000
,
self
.
F2minmax
=
widgets
.
IntRangeSlider
(
value
=
[
0
,
5000
],
min
=
0
,
max
=
5000
,
description
=
'
F2:
'
,
orientation
=
'
horizontal
'
)
description
=
'
F2:
'
,
orientation
=
'
horizontal
'
)
self
.
bactos_size_slider
=
widgets
.
FloatRangeSlider
(
value
=
[
0.5
,
15
],
self
.
bactos_size_slider
=
widgets
.
FloatRangeSlider
(
value
=
[
0.5
,
15
],
...
@@ -503,9 +507,9 @@ class BactosViewver():
...
@@ -503,9 +507,9 @@ class BactosViewver():
BTNfilters
.
on_click
(
self
.
on_filter_bactos
)
BTNfilters
.
on_click
(
self
.
on_filter_bactos
)
layoutfilters
=
widgets
.
VBox
([
self
.
bactos_size_slider
,
self
.
bactos_dist_slider
,
BTNfilters
])
layoutfilters
=
widgets
.
VBox
([
self
.
bactos_size_slider
,
self
.
bactos_dist_slider
,
BTNfilters
])
BTNexport
=
widgets
.
Button
(
description
=
'
Exporter vers Excel
'
,
button_style
=
'
success
'
,
self
.
BTNexport
=
widgets
.
Button
(
description
=
'
Exporter vers Excel
'
,
button_style
=
'
success
'
,
layout
=
widgets
.
Layout
(
width
=
'
98%
'
))
layout
=
widgets
.
Layout
(
width
=
'
98%
'
))
BTNexport
.
on_click
(
self
.
on_export
)
self
.
BTNexport
.
on_click
(
self
.
on_export
)
# Set Callback functions
# Set Callback functions
self
.
ListExp
.
observe
(
self
.
on_expe_changed
,
names
=
'
value
'
)
self
.
ListExp
.
observe
(
self
.
on_expe_changed
,
names
=
'
value
'
)
...
@@ -544,7 +548,7 @@ class BactosViewver():
...
@@ -544,7 +548,7 @@ class BactosViewver():
#layout=widgets.Layout(width="20%")
#layout=widgets.Layout(width="20%")
)
)
else
:
else
:
vcontrol
=
widgets
.
VBox
([
export_data_btn
,
self
.
ListExp
,
self
.
accordion
,
BTNexport
],
vcontrol
=
widgets
.
VBox
([
export_data_btn
,
self
.
ListExp
,
self
.
accordion
,
self
.
BTNexport
],
#layout=widgets.Layout(width="20%")
#layout=widgets.Layout(width="20%")
)
)
...
@@ -606,11 +610,11 @@ class BactosViewver():
...
@@ -606,11 +610,11 @@ class BactosViewver():
plt
.
close
(
'
bactostime
'
)
plt
.
close
(
'
bactostime
'
)
with
self
.
WplotAll
:
with
self
.
WplotAll
:
self
.
WplotAll
.
clear_output
()
self
.
WplotAll
.
clear_output
(
wait
=
True
)
# Prevent autodisplay of mpl figures
# Prevent autodisplay of mpl figures
plt
.
ioff
()
plt
.
ioff
()
self
.
figure
=
plt
.
figure
(
'
bactostime
'
,
figsize
=
(
12
,
8
))
self
.
figure
=
plt
.
figure
(
'
bactostime
'
,
figsize
=
(
12
,
8
))
display
(
self
.
figure
.
canvas
)
#
display(self.figure.canvas)
plt
.
ion
()
plt
.
ion
()
# figure.canvas.layout.height = '800px'
# figure.canvas.layout.height = '800px'
...
@@ -806,7 +810,7 @@ class BactosViewver():
...
@@ -806,7 +810,7 @@ class BactosViewver():
self
.
plimg1
.
set_data
(
self
.
selected_imgs
[
t
,
pos
,
z
,
:,
:,
self
.
drug_filter
])
self
.
plimg1
.
set_data
(
self
.
selected_imgs
[
t
,
pos
,
z
,
:,
:,
self
.
drug_filter
])
self
.
plimg2
.
set_data
(
self
.
selected_imgs
[
t
,
pos
,
z
,
:,
:,
self
.
ctrl_filter
])
self
.
plimg2
.
set_data
(
self
.
selected_imgs
[
t
,
pos
,
z
,
:,
:,
self
.
ctrl_filter
])
self
.
figure
.
canvas
.
draw_idle
()
if
update_minmax
:
if
update_minmax
:
p0min
,
p0max
=
np
.
percentile
(
np
.
ma
.
masked_equal
(
self
.
selected_imgs
[
0
,
0
,
0
,
:,
:,
self
.
drug_filter
],
0
),
p0min
,
p0max
=
np
.
percentile
(
np
.
ma
.
masked_equal
(
self
.
selected_imgs
[
0
,
0
,
0
,
:,
:,
self
.
drug_filter
],
0
),
...
@@ -1001,7 +1005,10 @@ class BactosViewver():
...
@@ -1001,7 +1005,10 @@ class BactosViewver():
else
:
else
:
if
self
.
ListExp
.
value
!=
self
.
ListCtrl
.
value
:
if
self
.
ListExp
.
value
!=
self
.
ListCtrl
.
value
:
plt
.
ioff
()
self
.
figure_all_pos
=
plt
.
figure
(
'
Plot all positions
'
,
figsize
=
(
12
,
10
))
self
.
figure_all_pos
=
plt
.
figure
(
'
Plot all positions
'
,
figsize
=
(
12
,
10
))
plt
.
ion
()
G
=
plt
.
GridSpec
(
3
,
2
,
width_ratios
=
[
1
,
1
/
4
])
G
=
plt
.
GridSpec
(
3
,
2
,
width_ratios
=
[
1
,
1
/
4
])
ax1
=
plt
.
subplot
(
G
[
0
,
1
])
ax1
=
plt
.
subplot
(
G
[
0
,
1
])
ax2
=
plt
.
subplot
(
G
[
0
,
0
])
ax2
=
plt
.
subplot
(
G
[
0
,
0
])
...
@@ -1016,7 +1023,10 @@ class BactosViewver():
...
@@ -1016,7 +1023,10 @@ class BactosViewver():
ax2
.
set_title
(
'
Fluo due à la drogue
'
)
ax2
.
set_title
(
'
Fluo due à la drogue
'
)
else
:
else
:
plt
.
ioff
()
self
.
figure_all_pos
=
plt
.
figure
(
'
Plot all positions
'
,
figsize
=
(
12
,
7
))
self
.
figure_all_pos
=
plt
.
figure
(
'
Plot all positions
'
,
figsize
=
(
12
,
7
))
plt
.
ion
()
G
=
plt
.
GridSpec
(
2
,
1
)
G
=
plt
.
GridSpec
(
2
,
1
)
ax3
=
plt
.
subplot
(
G
[
0
,
0
])
ax3
=
plt
.
subplot
(
G
[
0
,
0
])
ax4
=
plt
.
subplot
(
G
[
1
,
0
],
sharex
=
ax3
)
ax4
=
plt
.
subplot
(
G
[
1
,
0
],
sharex
=
ax3
)
...
@@ -1111,7 +1121,7 @@ class BactosViewver():
...
@@ -1111,7 +1121,7 @@ class BactosViewver():
if
ctrl_exp
is
not
None
and
ctrl_exp
!=
exp
:
if
ctrl_exp
is
not
None
and
ctrl_exp
!=
exp
:
exp_all_drug
=
[]
exp_all_drug
=
[]
positions
=
[
p
for
p
in
range
(
load_imag
e
(
self
.
selected_file
,
exp
)
.
shape
[
1
])]
positions
=
[
p
for
p
in
range
(
get_stack_shap
e
(
self
.
selected_file
,
exp
)[
1
])]
for
pos
in
positions
:
for
pos
in
positions
:
drug
=
load_drug_signal
(
self
.
selected_file
,
exp
,
pos
)
drug
=
load_drug_signal
(
self
.
selected_file
,
exp
,
pos
)
SelectB
=
load_selected_bactos
(
self
.
selected_file
,
exp
,
pos
)
SelectB
=
load_selected_bactos
(
self
.
selected_file
,
exp
,
pos
)
...
@@ -1658,6 +1668,7 @@ class BactosViewver():
...
@@ -1658,6 +1668,7 @@ class BactosViewver():
Export the h5file data to excel.
Export the h5file data to excel.
"""
"""
self
.
BTNexport
.
disabled
=
True
# Output file name (should be the same as the imput source)
# Output file name (should be the same as the imput source)
fout
=
os
.
path
.
abspath
(
self
.
source_file
)
fout
=
os
.
path
.
abspath
(
self
.
source_file
)
fout
=
os
.
path
.
splitext
(
fout
)[
0
]
+
'
.xlsx
'
fout
=
os
.
path
.
splitext
(
fout
)[
0
]
+
'
.xlsx
'
...
@@ -1667,7 +1678,7 @@ class BactosViewver():
...
@@ -1667,7 +1678,7 @@ class BactosViewver():
ctrl_exp
=
load_control_exp
(
self
.
selected_file
,
expe
)
ctrl_exp
=
load_control_exp
(
self
.
selected_file
,
expe
)
row
=
-
1
# init raw at -1 (if no bacteria on position 1 set the
row
=
-
1
# init raw at -1 (if no bacteria on position 1 set the
# position 2 on top of Excel sheet)
# position 2 on top of Excel sheet)
positions
=
[
p
for
p
in
range
(
load_imag
e
(
self
.
selected_file
,
expe
)
.
shape
[
1
])]
positions
=
[
p
for
p
in
range
(
get_stack_shap
e
(
self
.
selected_file
,
expe
)[
1
])]
srow
=
0
srow
=
0
# Test if it's a time or static
# Test if it's a time or static
...
@@ -1676,6 +1687,25 @@ class BactosViewver():
...
@@ -1676,6 +1687,25 @@ class BactosViewver():
else
:
else
:
istime
=
False
istime
=
False
#Crop name if too long >31
if
len
(
expe
)
>
31
:
sname
=
expe
[:
31
]
else
:
sname
=
expe
# Excel sheet need to have unik lower case name
if
sname
.
lower
()
in
prevsname
:
try
:
tmpind
=
int
(
sname
[
0
])
except
:
tmpind
=
1
sname
=
str
(
tmpind
+
1
)
+
'
_
'
+
sname
sname
=
sname
[:
31
]
prevsname
+=
[
sname
.
lower
()]
# print(prevsname)
for
pos
in
positions
:
for
pos
in
positions
:
selectedB
=
load_selected_bactos
(
self
.
selected_file
,
selectedB
=
load_selected_bactos
(
self
.
selected_file
,
expe
,
pos
)
expe
,
pos
)
...
@@ -1697,12 +1727,6 @@ class BactosViewver():
...
@@ -1697,12 +1727,6 @@ class BactosViewver():
row
,
col
=
Area
.
shape
row
,
col
=
Area
.
shape
#Crop name if too long >31
if
len
(
expe
)
>
31
:
sname
=
expe
[:
31
]
else
:
sname
=
expe
Area
.
to_excel
(
writer
,
sheet_name
=
sname
,
Area
.
to_excel
(
writer
,
sheet_name
=
sname
,
header
=
head
,
startrow
=
srow
)
header
=
head
,
startrow
=
srow
)
...
@@ -1715,6 +1739,7 @@ class BactosViewver():
...
@@ -1715,6 +1739,7 @@ class BactosViewver():
if
ctrl_exp
!=
expe
:
if
ctrl_exp
!=
expe
:
Idrug
=
create_idrug_pandas
(
self
.
selected_file
,
Idrug
=
create_idrug_pandas
(
self
.
selected_file
,
expe
,
pos
,
selectedB
)
expe
,
pos
,
selectedB
)
if
Idrug
is
not
None
:
Idrug
.
to_excel
(
writer
,
sheet_name
=
sname
,
Idrug
.
to_excel
(
writer
,
sheet_name
=
sname
,
index
=
False
,
header
=
head
,
index
=
False
,
header
=
head
,
startcol
=
col
+
2
+
(
col2
+
1
)
*
2
,
startcol
=
col
+
2
+
(
col2
+
1
)
*
2
,
...
@@ -1735,6 +1760,7 @@ class BactosViewver():
...
@@ -1735,6 +1760,7 @@ class BactosViewver():
if
selectedB
is
not
None
and
expe
==
ctrl_exp
:
if
selectedB
is
not
None
and
expe
==
ctrl_exp
:
F2F1
=
create_control_ratio_pandas
(
self
.
selected_file
,
F2F1
=
create_control_ratio_pandas
(
self
.
selected_file
,
expe
,
positions
)
expe
,
positions
)
if
F2F1
is
not
None
:
F2F1
.
to_excel
(
writer
,
sheet_name
=
sname
,
F2F1
.
to_excel
(
writer
,
sheet_name
=
sname
,
index
=
True
,
startcol
=
col
+
2
+
(
col2
+
1
)
*
2
)
index
=
True
,
startcol
=
col
+
2
+
(
col2
+
1
)
*
2
)
...
@@ -1763,9 +1789,6 @@ class BactosViewver():
...
@@ -1763,9 +1789,6 @@ class BactosViewver():
worksheet
.
insert_chart
(
line
+
5
,
col
+
2
+
(
col2
+
1
)
*
2
,
chart3
)
worksheet
.
insert_chart
(
line
+
5
,
col
+
2
+
(
col2
+
1
)
*
2
,
chart3
)
else
:
else
:
# If no data for this experiment create an empty sheet
# If no data for this experiment create an empty sheet
if
len
(
expe
)
>
31
:
sname
=
expe
[:
31
]
else
:
sname
=
expe
writer
.
book
.
add_worksheet
(
sname
)
writer
.
book
.
add_worksheet
(
sname
)
self
.
BTNexport
.
disabled
=
False
This diff is collapsed.
Click to expand it.
src/lib_bactos_hdf.py
+
19
−
0
View file @
6e095af1
...
@@ -77,6 +77,25 @@ def load_mask(data_in, expe_name, pos):
...
@@ -77,6 +77,25 @@ def load_mask(data_in, expe_name, pos):
return
output
return
output
def
get_stack_shape
(
data_in
,
expe_name
):
"""
Get the dimensions of the image stack for this
"
expe_name
"
in the data_in HDF file.
Parameters:
-----------
- data_in, str:
the path to the h5file.
- expe_name, str:
the name of the experiment.
Return the shape of the image stack
"""
with
h5py
.
File
(
data_in
,
'
r
'
)
as
f
:
output
=
f
[
expe_name
][
'
images
'
].
shape
return
output
def
load_intensity_profile
(
data_in
,
expe_name
,
channel
,
pos
):
def
load_intensity_profile
(
data_in
,
expe_name
,
channel
,
pos
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment