Commit 7f2fbf64 authored by amichaut's avatar amichaut
Browse files

added track average of voronoi area

parent a559bf9d
Pipeline #56647 failed with stage
in 14 seconds
......@@ -50,7 +50,7 @@ If **Track Analyzer** is run in command line (see below), the data directory mus
To install **Track Analyzer**, just run:
```sh
pip install track-analyzer`
pip install track-analyzer
```
### with a virtualenv
......
This diff is collapsed.
This diff is collapsed.
......@@ -550,7 +550,7 @@ def compute_Voronoi(df, frame, groups=None, compute_local_area=True, lengthscale
return {'vor': vor, 'areas': areas}
def compute_all_Voronoi(data_dir, df, outdir=None, compute_local_area=True, area_threshold=3):
def compute_all_Voronoi(data_dir, df, outdir=None, compute_local_area=True, area_threshold=3, df_mean=None):
"""
Compute Voronoi tesselation for all frames. Optional: compute Voronoi cell area
:param data_dir: path to data directory
......@@ -563,6 +563,8 @@ def compute_all_Voronoi(data_dir, df, outdir=None, compute_local_area=True, area
:type compute_local_area: bool
:param area_threshold: exclusion threshold, above a multiple of area median
:type area_threshold: float or int
:param df_mean: DataFrame containing mean values for each track
:type df_mean: pandas.DataFrame
:return: dict containing voronoi tesselation for each frame as keys
:rtype: dict
"""
......@@ -585,6 +587,15 @@ def compute_all_Voronoi(data_dir, df, outdir=None, compute_local_area=True, area
pickle_fn = osp.join(outdir, 'voronoi.p')
pickle.dump(data_dict, open(pickle_fn, "wb"))
# calculate track average
if df_mean is not None:
df_mean['area'] = np.nan
groups = df.groupby('track')
for track in df['track'].unique():
traj = groups.get_group(track)
ind = df_mean['track'] == track
df_mean.loc[ind, 'area'] = traj['area'].mean()
return data_dict
......
......@@ -984,11 +984,13 @@ def plot_all_vector_fields(data_dir, df, data, field, plot_on_field=None, dim=3,
map_param=map_param, plot_dir=plot_dir, plot_config=plot_config)
def plot_all_Voronoi(data_dir, df, data, show_local_area=True,
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={'no_bkg': False, 'vlim': None, 'show_axis': False, 'cmap': 'plasma', 'size_factor': 1},
plot_dir=None, plot_config=None, dont_print_count=False):
""""""
"""
Plot Voronoi for all frames and calculate voronoi cell area.
"""
if plot_dir is None:
plot_dir = osp.join(data_dir, 'voronoi')
tpr.safe_mkdir(plot_dir)
......@@ -999,9 +1001,9 @@ def plot_all_Voronoi(data_dir, df, data, show_local_area=True,
# get vlim
if show_local_area:
if 'local_area' in df.columns:
if 'area' in df.columns:
if map_param['vlim'] is None:
vlim = [df['local_area'].min(), df['local_area'].max()]
vlim = [df['area'].min(), df['area'].max()]
if vlim == [np.nan, np.nan]:
show_local_area = False
else:
......
......@@ -153,7 +153,9 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
# Voronoi analysis
if voronoi_config['run']:
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'])
area_threshold=voronoi_config['area_threshold'],df_mean=df_prop)
df_prop.to_csv(mean_fn)
if voronoi_config['plot']:
plot_dir = osp.join(sub_dir, 'voronoi')
tpr.safe_mkdir(plot_dir)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment