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
d6536dca
Commit
d6536dca
authored
Feb 03, 2022
by
amichaut
Browse files
bugfix after Pandas update: ensure df dtype is changed to numeric
parent
217e78a7
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
run_TA.ipynb
View file @
d6536dca
This diff is collapsed.
Click to expand it.
track_analyzer/plotting.py
View file @
d6536dca
...
...
@@ -406,7 +406,7 @@ def plot_vector_field(data_dir, df, data, field, frame, plot_on_field=None, dim=
dim
=
2
# to ensure that arrows are plotted in black and the z data is not use
fig
=
plot_scalar_field
(
data_dir
,
df
,
data
,
plot_on_field
[
'plot_on'
],
frame
,
image
=
image
,
map_param
=
map_param_
,
plot_dir
=
plot_dir
,
plot_config
=
None
,
dont_print_count
=
True
,
dont_save
=
True
)
quiet
=
2
,
dont_save
=
True
)
ax
=
fig
.
gca
()
invert_yaxis
=
False
# to ensure it's not inverted a second time
else
:
...
...
@@ -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
=
0
):
plot_dir
=
None
,
plot_config
=
None
,
quiet
=
0
):
"""
Plot Voronoi tesselation and local area in 2D only.
:param data_dir:
...
...
@@ -467,7 +467,6 @@ def plot_Voronoi(data_dir, df, frame, data, show_local_area=True,
:param map_param:
:param plot_dir:
:param plot_config:
:param dont_print_count:
:return:
"""
...
...
@@ -696,7 +695,8 @@ def plot_param_vs_param(data_dir, x_param, y_param, df=None, hue=None, hue_order
if
plot_config
[
'despine'
]:
sns
.
despine
(
fig
)
ax
.
legend
(
frameon
=
False
)
if
hue
is
not
None
:
ax
.
legend
(
frameon
=
False
)
filename
=
osp
.
join
(
plot_dir
,
prefix
+
'{}_vs_{}{}{}'
.
format
(
y_param
,
x_param
,
suffix
,
plot_config
[
'format'
]))
fig
.
savefig
(
filename
,
dpi
=
plot_config
[
'dpi'
],
bbox_inches
=
'tight'
)
...
...
@@ -742,7 +742,8 @@ def plot_param_hist(data_dir, param, df=None, hue=None, hue_order=None, hist=Tru
kind
=
"hist"
if
hist
else
"kde"
g
=
sns
.
displot
(
data
=
df
,
x
=
param
,
hue
=
hue
,
kind
=
kind
,
kde
=
kde
,
facet_kws
=
{
'legend_out'
:
False
,
'despine'
:
plot_config
[
'despine'
]})
sns
.
move_legend
(
g
,
"upper right"
,
frameon
=
False
,
bbox_to_anchor
=
[
0.95
,
0.95
],
title
=
None
)
if
hue
is
not
None
:
sns
.
move_legend
(
g
,
"upper right"
,
frameon
=
False
,
bbox_to_anchor
=
[
0.95
,
0.95
],
title
=
None
)
fig
=
g
.
figure
ax
=
g
.
ax
fig
.
set_size_inches
(
figsize
[
0
],
figsize
[
1
])
...
...
track_analyzer/prepare.py
View file @
d6536dca
...
...
@@ -63,7 +63,7 @@ def get_cmap_color(value, colormap='plasma', vmin=None, vmax=None):
"""
Get color corresponding to a value from a colormap. Optionally, give boundaries to colormap with vmin, vmax.
:param value: value to be converted to color
:type value: float
:type value: float
or list or numpy.array
:param colormap: Matplotlib colormap name
:type colormap: str
:param vmin: if not None, minimum value of colormap
...
...
@@ -73,6 +73,7 @@ def get_cmap_color(value, colormap='plasma', vmin=None, vmax=None):
:return: color
:rtype: tuple
"""
colormap
=
plt
.
get_cmap
(
colormap
)
norm
=
plt
.
Normalize
(
vmin
,
vmax
)
return
colormap
(
norm
(
value
))
...
...
@@ -580,7 +581,8 @@ def get_info(data_dir):
info
[
k
]
=
float
(
info
[
k
])
else
:
raise
Exception
(
"ERROR: info.txt doesn't exist or is not at the main data folder"
)
print
(
"WARNING: info.txt doesn't exist or is not at the main data folder"
)
return
None
mandatory_info
=
[
'timescale'
,
'lengthscale'
]
for
mand_info
in
mandatory_info
:
...
...
@@ -639,6 +641,7 @@ def get_data(data_dir, df=None, refresh=False, split_traj=False, set_origin_=Fal
df
=
pd
.
read_csv
(
data_file
,
sep
=
sep
)
# columns must be ['x','y','z','frame','track']
# check data type
df
=
df
.
apply
(
pd
.
to_numeric
,
errors
=
'coerce'
)
dimensions
=
[
'x'
,
'y'
,
'z'
]
if
'z'
in
df
.
columns
else
[
'x'
,
'y'
]
dim
=
len
(
dimensions
)
df
[
'frame'
]
=
df
[
'frame'
].
astype
(
np
.
int
)
...
...
@@ -672,6 +675,11 @@ def get_data(data_dir, df=None, refresh=False, split_traj=False, set_origin_=Fal
else
:
data
=
pickle
.
load
(
open
(
pickle_fn
,
"rb"
))
# extra check that df is numerci (in case of old pickle)
df
=
data
[
'df'
]
df
=
df
.
apply
(
pd
.
to_numeric
,
errors
=
'coerce'
)
data
[
'df'
]
=
df
return
data
...
...
@@ -1176,12 +1184,17 @@ def get_image(data_dir, filename=None, verbose=False):
else
:
# get image size
info
=
get_info
(
data_dir
)
if
'image_width'
in
info
.
keys
()
and
'image_height'
in
info
.
keys
():
if
info
[
'image_width'
]
is
not
None
and
info
[
'image_height'
]
is
not
None
:
image_size
=
(
info
[
'image_height'
],
info
[
'image_width'
])
else
:
if
info
is
None
:
print
(
"WARNING: no info.txt file so image size will be inferred"
)
image_size
=
None
print
(
"WARNING: no image in directory, and image size is not defined in info.txt"
)
else
:
if
'image_width'
in
info
.
keys
()
and
'image_height'
in
info
.
keys
():
if
info
[
'image_width'
]
is
not
None
and
info
[
'image_height'
]
is
not
None
:
image_size
=
(
info
[
'image_height'
],
info
[
'image_width'
])
else
:
image_size
=
None
print
(
"WARNING: no image in directory, and image size is not defined in info.txt"
)
image_dict
=
{
'image_fn'
:
None
,
't_dim'
:
None
,
'z_dim'
:
None
,
'image_size'
:
image_size
}
...
...
track_analyzer/scripts/analyze_maps.py
View file @
d6536dca
...
...
@@ -201,10 +201,10 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
export_field
=
map_param
[
'export_field'
],
outdir
=
sub_dir
)
# plot data
if
quiet
<
2
:
print
(
"Plotting scalar fields..."
)
scalar_fields_
=
{
**
scalar_fields
,
**
vector_mean
}
# merge scalar data in one single dict
for
field
in
scalar_fields_
.
keys
():
if
quiet
<
2
:
print
(
"Plotting scalar fields..."
)
if
plot_config
[
'save_as_stack'
]:
plot_dir
=
sub_dir
else
:
# save series of images in a separate directory
...
...
@@ -215,9 +215,10 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
map_param_
[
'cmap'
]
=
scalar_fields_
[
field
][
'cmap'
]
if
'cmap'
in
scalar_fields_
[
field
].
keys
()
else
'plasma'
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
)
if
quiet
<
2
:
print
(
"Plotting vector fields..."
)
for
field
in
vector_fields
.
keys
():
if
quiet
<
2
:
print
(
"Plotting vector fields..."
)
if
plot_config
[
'save_as_stack'
]:
plot_dir
=
sub_dir
else
:
# save series of images in a separate directory
...
...
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