Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Track Analyzer
track-analyzer
Commits
217e78a7
Commit
217e78a7
authored
Jan 31, 2022
by
amichaut
Browse files
quiet flag replaced quiet count
parent
fba7cfd7
Changes
3
Hide whitespace changes
Inline
Side-by-side
track_analyzer/plotting.py
View file @
217e78a7
...
...
@@ -110,7 +110,7 @@ def plot_cmap(plot_dir, label, cmap, vmin, vmax, plot_config=None, suffix=''):
def
plot_traj
(
df
,
frame
,
data_dir
,
groups
=
None
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
plot_dir
=
None
,
show_plot
=
False
,
dim
=
3
,
plot_config
=
None
,
traj_parameters
=
None
,
quiet
=
False
):
show_plot
=
False
,
dim
=
3
,
plot_config
=
None
,
traj_parameters
=
None
,
quiet
=
0
):
"""
Plot all trajectories of a given frame on an image if traj_parameters['no_bkg'] is False and an image is given.
Plots can be color coded z value, by groups, or with random colors (traj_parameters['color_code']='z' or 'group' or 'random' or 'none')
...
...
@@ -118,7 +118,7 @@ def plot_traj(df, frame, data_dir, groups=None, image={'image_fn': None, 't_dim'
It can be plotted in 3D with plot3D, elevation and angle set the 3D view
"""
if
not
quiet
:
if
quiet
<
1
:
sys
.
stdout
.
write
(
"
\033
[K"
)
# go back to previous line
print
(
'plotting frame {}'
.
format
(
int
(
frame
)),
flush
=
True
,
end
=
'
\r
'
)
...
...
@@ -284,10 +284,10 @@ def plot_traj(df, frame, data_dir, groups=None, image={'image_fn': None, 't_dim'
def
plot_scalar_field
(
data_dir
,
df
,
data
,
field
,
frame
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
{
'no_bkg'
:
False
,
'vlim'
:
None
,
'show_axis'
:
False
,
'cmap'
:
'plasma'
},
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
False
,
dont_save
=
False
):
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
,
dont_save
=
False
):
"""Plot scalar field as colormap. The data needs to be generated before. """
if
not
quiet
:
if
quiet
<
1
:
sys
.
stdout
.
write
(
"
\033
[K"
)
# go back to previous line
print
(
'plotting {} {}'
.
format
(
field
,
int
(
frame
)),
flush
=
True
,
end
=
'
\r
'
)
...
...
@@ -364,10 +364,10 @@ def plot_vector_field(data_dir, df, data, field, frame, plot_on_field=None, dim=
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
{
'no_bkg'
:
False
,
'vlim'
:
None
,
'show_axis'
:
False
,
'cmap'
:
'plasma'
,
'size_factor'
:
1
},
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
False
):
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
):
""" Plot vector field"""
if
not
quiet
:
if
quiet
<
1
:
sys
.
stdout
.
write
(
"
\033
[K"
)
# go back to previous line
print
(
'plotting {} {}'
.
format
(
field
,
int
(
frame
)),
flush
=
True
,
end
=
'
\r
'
)
...
...
@@ -455,7 +455,7 @@ def plot_vector_field(data_dir, df, data, field, frame, plot_on_field=None, dim=
def
plot_Voronoi
(
data_dir
,
df
,
frame
,
data
,
show_local_area
=
True
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
{
'no_bkg'
:
False
,
'vlim'
:
None
,
'show_axis'
:
False
,
'cmap'
:
'plasma'
,
'size_factor'
:
1
,
'line_width'
:
1.
},
plot_dir
=
None
,
plot_config
=
None
,
dont_print_count
=
False
,
quiet
=
False
):
plot_dir
=
None
,
plot_config
=
None
,
dont_print_count
=
False
,
quiet
=
0
):
"""
Plot Voronoi tesselation and local area in 2D only.
:param data_dir:
...
...
@@ -471,7 +471,7 @@ def plot_Voronoi(data_dir, df, frame, data, show_local_area=True,
:return:
"""
if
not
quiet
:
if
quiet
<
1
:
sys
.
stdout
.
write
(
"
\033
[K"
)
# go back to previous line
print
(
'plotting {} {}'
.
format
(
'voronoi'
,
int
(
frame
)),
flush
=
True
,
end
=
'
\r
'
)
...
...
@@ -920,7 +920,7 @@ def view_traj(df, image=None, z_step=1):
def
plot_all_traj
(
data_dir
,
df
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
parallelize
=
False
,
dim
=
3
,
plot_dir
=
None
,
traj_parameters
=
None
,
plot_config
=
None
,
quiet
=
False
):
plot_dir
=
None
,
traj_parameters
=
None
,
plot_config
=
None
,
quiet
=
0
):
"""Plot traj for all frames"""
# plotting directory
...
...
@@ -1021,7 +1021,7 @@ def plot_all_traj(data_dir, df, image={'image_fn': None, 't_dim': None, 'z_dim':
def
plot_all_scalar_fields
(
data_dir
,
df
,
data
,
field
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
{
'no_bkg'
:
False
,
'vlim'
:
None
,
'show_axis'
:
False
,
'cmap'
:
'plasma'
},
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
False
):
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
):
"""Plot scalar fields as colormap for all frames."""
# plotting directory
...
...
@@ -1073,7 +1073,7 @@ def plot_all_vector_fields(data_dir, df, data, field, plot_on_field=None, dim=3,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
{
'no_bkg'
:
False
,
'vlim'
:
None
,
'show_axis'
:
False
,
'cmap'
:
'plasma'
,
'size_factor'
:
1
},
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
False
):
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
):
"""Plot vector fields for all frames."""
# plotting directory
...
...
@@ -1122,7 +1122,7 @@ def plot_all_vector_fields(data_dir, df, data, field, plot_on_field=None, dim=3,
def
plot_all_Voronoi
(
data_dir
,
df
,
data
,
show_local_area
=
True
,
df_mean
=
None
,
image
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
},
map_param
=
None
,
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
False
):
map_param
=
None
,
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
):
"""
Plot Voronoi for all frames and calculate voronoi cell area.
"""
...
...
track_analyzer/scripts/analyze_maps.py
View file @
217e78a7
...
...
@@ -35,7 +35,7 @@ from track_analyzer import calculate as tca
def
map_analysis
(
data_dir
,
data
=
None
,
image
=
None
,
refresh
=
False
,
parallelize
=
False
,
filters
=
None
,
plot_config
=
None
,
map_config
=
None
,
data_config
=
None
,
quiet
=
False
):
plot_config
=
None
,
map_config
=
None
,
data_config
=
None
,
quiet
=
0
):
"""Container method to plot a series of maps given by field_values. Manual vlim to colormap can be passed."""
map_dir
=
osp
.
join
(
data_dir
,
'map_analysis'
)
...
...
@@ -140,7 +140,8 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
dir_name
=
'_'
+
subset_name
if
subset_name
!=
''
else
''
dir_name_
=
'{}{}'
.
format
(
len
(
tpr
.
listdir_nohidden
(
map_dir
))
+
1
,
dir_name
)
print
(
r
"Analyzing subset {} "
.
format
(
i
+
1
,
dir_name_
))
if
quiet
<
2
:
print
(
r
"Analyzing subset {} "
.
format
(
i
+
1
,
dir_name_
))
sub_dir
=
osp
.
join
(
map_dir
,
dir_name_
)
sub_dir
=
sub_dir
+
'_1'
if
osp
.
exists
(
sub_dir
)
else
sub_dir
# dont overwrite existing dir
tpr
.
safe_mkdir
(
sub_dir
)
...
...
@@ -202,7 +203,7 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
# plot data
scalar_fields_
=
{
**
scalar_fields
,
**
vector_mean
}
# merge scalar data in one single dict
for
field
in
scalar_fields_
.
keys
():
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting scalar fields..."
)
if
plot_config
[
'save_as_stack'
]:
plot_dir
=
sub_dir
...
...
@@ -215,7 +216,7 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
tpl
.
plot_all_scalar_fields
(
data_dir
,
df
,
field_data
,
field
,
image
=
image
,
map_param
=
map_param_
,
plot_dir
=
plot_dir
,
plot_config
=
plot_config
,
quiet
=
quiet
)
for
field
in
vector_fields
.
keys
():
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting vector fields..."
)
if
plot_config
[
'save_as_stack'
]:
plot_dir
=
sub_dir
...
...
@@ -258,9 +259,10 @@ def parse_args(args=None):
help
=
argparse
.
SUPPRESS
)
parser
.
add_argument
(
'-q'
,
'--quiet'
,
action
=
"
store_true
"
,
action
=
"
count
"
,
default
=
False
,
help
=
'do not display main log output'
)
help
=
"""decrease verbosity level. There are 3 levels:
display detailed log (default), display simple log (-q), display only warning and errors (-qq)"""
)
parsed_args
=
parser
.
parse_args
(
args
)
...
...
track_analyzer/scripts/analyze_tracks.py
View file @
217e78a7
...
...
@@ -35,7 +35,7 @@ from track_analyzer import calculate as tca
def
traj_analysis
(
data_dir
,
data
=
None
,
image
=
None
,
refresh
=
False
,
parallelize
=
False
,
filters
=
None
,
plot_config
=
None
,
traj_config
=
None
,
data_config
=
None
,
quiet
=
False
):
traj_config
=
None
,
data_config
=
None
,
quiet
=
0
):
"""Container method to run analysis related to cell trajectories."""
traj_dir
=
osp
.
join
(
data_dir
,
'traj_analysis'
)
...
...
@@ -126,7 +126,8 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
dir_name
=
'_'
+
subset_name
if
subset_name
!=
''
else
''
dir_name_
=
'{}{}'
.
format
(
len
(
tpr
.
listdir_nohidden
(
traj_dir
))
+
1
,
dir_name
)
print
(
r
"Analyzing subset #{}, named: {}"
.
format
(
i
+
1
,
dir_name_
))
if
quiet
<
2
:
print
(
r
"Analyzing subset #{}, named: {}"
.
format
(
i
+
1
,
dir_name_
))
sub_dir
=
osp
.
join
(
traj_dir
,
dir_name_
)
sub_dir
=
sub_dir
+
'_1'
if
osp
.
exists
(
sub_dir
)
else
sub_dir
# dont overwrite existing dir
tpr
.
safe_mkdir
(
sub_dir
)
...
...
@@ -158,20 +159,20 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
# plot trajectories
if
traj_config_
[
'run'
]:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting trajectories..."
)
tpl
.
plot_all_traj
(
data_dir
,
df
,
image
=
image
,
traj_parameters
=
traj_config_
,
parallelize
=
parallelize
,
dim
=
dim
,
plot_dir
=
sub_dir
,
plot_config
=
plot_config
,
quiet
=
quiet
)
if
total_traj_config
[
'run'
]:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting total trajectories"
)
tpl
.
plot_total_traj
(
data_dir
,
df
,
dim
=
dim
,
plot_dir
=
sub_dir
,
plot_config
=
plot_config
,
specific_config
=
total_traj_config
)
# MSD analysis
if
MSD_config
[
'run'
]:
if
not
quiet
:
if
quiet
<
2
:
print
(
"MSD analysis..."
)
df_prop
=
tpl
.
plot_all_MSD
(
data_dir
,
df
,
df_out
=
df_prop
,
fit_model
=
MSD_config
[
'MSD_model'
],
MSD_parameters
=
MSD_config
,
plot_config
=
plot_config
,
plot_dir
=
sub_dir
,
hue
=
hue
,
...
...
@@ -180,7 +181,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
# Voronoi analysis
if
voronoi_config
[
'run'
]:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Voronoi analysis..."
)
vor_data
=
tca
.
compute_all_Voronoi
(
data_dir
,
df
,
outdir
=
sub_dir
,
compute_local_area
=
voronoi_config
[
'compute_local_area'
],
area_threshold
=
voronoi_config
[
'area_threshold'
],
df_mean
=
df_prop
)
...
...
@@ -205,7 +206,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
if
'var_list'
in
hist_config
.
keys
():
if
len
(
hist_config
[
'var_list'
])
>
0
:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting parameters histograms..."
)
for
p
in
hist_config
[
'var_list'
]:
tpl
.
plot_param_hist
(
data_dir
,
p
,
df
,
plot_config
=
plot_config
,
plot_dir
=
sub_dir
,
hue
=
hue
,
...
...
@@ -213,7 +214,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
if
'mean_var_list'
in
hist_config
.
keys
():
if
len
(
hist_config
[
'mean_var_list'
])
>
0
:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting whole-track histograms..."
)
for
p
in
hist_config
[
'mean_var_list'
]:
tpl
.
plot_param_hist
(
data_dir
,
p
,
df_prop
,
plot_config
=
plot_config
,
plot_dir
=
sub_dir
,
prefix
=
'track_'
,
...
...
@@ -225,7 +226,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
if
'couple_list'
in
scatter_config
.
keys
():
if
len
(
scatter_config
[
'couple_list'
])
>
0
:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting couples of parameters..."
)
for
param_vs_param
in
scatter_config
[
'couple_list'
]:
x_param
,
y_param
=
param_vs_param
...
...
@@ -234,7 +235,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
if
'mean_couple_list'
in
scatter_config
.
keys
():
if
len
(
scatter_config
[
'mean_couple_list'
])
>
0
:
if
not
quiet
:
if
quiet
<
2
:
print
(
"Plotting couples of whole-track parameters..."
)
for
param_vs_param
in
scatter_config
[
'mean_couple_list'
]:
x_param
,
y_param
=
param_vs_param
...
...
@@ -271,9 +272,10 @@ def parse_args(args=None):
help
=
argparse
.
SUPPRESS
)
parser
.
add_argument
(
'-q'
,
'--quiet'
,
action
=
"
store_true
"
,
action
=
"
count
"
,
default
=
False
,
help
=
'do not display main log output'
)
help
=
"""decrease verbosity level. There are 3 levels:
display detailed log (default), display simple log (-q), display only warning and errors (-qq)"""
)
parsed_args
=
parser
.
parse_args
(
args
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment