integrated voronoi and tested
This diff is collapsed.
This diff is collapsed.
... | ... | @@ -48,9 +48,9 @@ def make_traj_config(data_dir=None, export_config=True): |
'no_bkg': False, # don't show background image if an image is passed | ||
'size_factor': 1., # to multiply the default size of markers and lines | ||
'show_axis': False, # to show the plot axes (by default just image) | ||
'plot3D': False, # plot in 3D | ||
'elevation': None, # 3D paramater | ||
'angle': None, # 3D paramater | ||
'plot3D': False, # plot in 3D !! Not supportes anymore !! | ||
'elevation': None, # 3D paramater !! Not supportes anymore !! | ||
'angle': None, # 3D paramater !! Not supportes anymore !! | ||
'subset_order': None, # if color code is ROI, order of ROI in color cycle | ||
} | ||
... | ... | @@ -87,15 +87,30 @@ def make_traj_config(data_dir=None, export_config=True): |
'equal_axis': True, # set x and y axes' scaling equal | ||
'color_code': 'random', # color code: 'z', 'ROI', 'random', 'none' | ||
'cmap': 'plasma', # colormap to be used if color_code is 'z' | ||
'z_lim': None # z limits to be used if color_code is 'z' | ||
'cmap_lim': None, # pass custom colormap limits | ||
'subset_order': None, # if color code is ROI, order of ROI in color cycle | ||
} | ||
# config of voronoi plot | ||
voronoi = {'run': True, # run analysis | ||
'plot': True, # plot diagram | ||
'vlim': None, # value limits to display on the color map | ||
'cmap': "plasma", # color map | ||
'compute_local_area': True, # compute voronoi cell area | ||
'show_local_area': True, # show voronoi cell area | ||
'area_threshold': 3, # exclude areas above this multiple of area median | ||
'no_bkg': False, # don't show background image if an image is passed | ||
'size_factor': 1., # to multiply the default size of lines !! Not implemented yet !! | ||
'show_axis': False, # to show the plot axes (by default just image) | ||
} | ||
# package all in a dict | ||
config = {'traj_config_': traj_config_, | ||
'MSD_config': MSD_config, | ||
'scatter_config': scatter_config, | ||
'hist_config': hist_config, | ||
'total_traj_config': total_traj_config | ||
'total_traj_config': total_traj_config, | ||
'voronoi_config': voronoi, | ||
} | ||
if export_config: | ||
... | ... | @@ -119,8 +134,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
traj_dir = osp.join(data_dir, 'traj_analysis') | ||
tpr.safe_mkdir(traj_dir) | ||
### Get data | ||
# Get data | ||
data = tpr.get_data(data_dir, refresh=refresh) if data is None else data | ||
image = tpr.get_image(data_dir) if image is None else image | ||
... | ... | @@ -128,15 +142,14 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
dim = data['dim'] | ||
dimensions = data['dimensions'] | ||
### Get config | ||
# Get config | ||
plot_config = tpl.make_plot_config() if plot_config is None else plot_config | ||
traj_config_default = make_traj_config(data_dir=data_dir, export_config=False) | ||
traj_config = traj_config_default if traj_config is None else traj_config | ||
# check that all configs are in traj_confign, if not load default | ||
for key in ["traj_config_", "MSD_config", "scatter_config", "hist_config", "total_traj_config"]: | ||
for key in ["traj_config_", "MSD_config", "scatter_config", "hist_config", "total_traj_config", "voronoi_config"]: | ||
if key not in traj_config.keys(): | ||
traj_config[key] = traj_config_default[key] | ||
... | ... | @@ -145,8 +158,9 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
scatter_config = traj_config["scatter_config"] | ||
hist_config = traj_config["hist_config"] | ||
total_traj_config = traj_config["total_traj_config"] | ||
voronoi_config = traj_config["voronoi_config"] | ||
### Filter data | ||
# Filter data | ||
filters = tpr.init_filters(data_dir=data_dir, export_to_config=True) if filters is None else filters | ||
subset_analysis = filters['subset'] # how to deal with subsets | ||
filters_ = filters['filters_list'] | ||
... | ... | @@ -159,7 +173,7 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
elif subset_analysis == 'separately': | ||
df_list = [df[df['subset'] == sub] for sub in df['subset'].unique()] # a list of df filtered by subset | ||
### Run analysis | ||
# Run analysis | ||
for i, df in enumerate(df_list): | ||
# name subset directory | ||
dir_name = '' | ||
... | ... | @@ -174,7 +188,6 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
tpr.safe_mkdir(sub_dir) | ||
# export data | ||
# export filtered positions | ||
csv_fn = osp.join(sub_dir, 'all_data.csv') | ||
df.to_csv(csv_fn) | ||
... | ... | @@ -201,15 +214,24 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
if subset_analysis == 'together': | ||
hue = 'subset' | ||
hue_order = df['subset'].unique() if filters['subset_order'] is None else filters['subset_order'] | ||
traj_config_['subset_order'] = hue_order | ||
else: | ||
hue = None | ||
hue_order = None | ||
# plot trajectories | ||
if traj_config_['run']: | ||
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) | ||
if total_traj_config['run']: | ||
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']: | ||
print("MSD analysis...") | ||
MSD_dir = tpr.safe_mkdir(osp.join(sub_dir, 'MSD')) | ||
... | ... | @@ -218,6 +240,16 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa |
hue_order=hue_order) | ||
df_prop.to_csv(mean_fn) | ||
# 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']) | ||
if voronoi_config['plot']: | ||
plot_dir = osp.join(sub_dir, 'voronoi') | ||
tpr.safe_mkdir(plot_dir) | ||
tpl.plot_all_Voronoi(data_dir, df, vor_data, show_local_area=voronoi_config['show_local_area'], image=image, | ||
map_param=voronoi_config, plot_dir=plot_dir, plot_config=plot_config, dont_print_count=False) | ||
if hist_config['run']: | ||
if len(hist_config['var_list']) > 0: | ||
< |