Commit e5fa5bfd authored by amichaut's avatar amichaut
Browse files

traj_analysis functions support uncomplete config files

parent 3077dc19
This diff is collapsed.
......@@ -120,24 +120,8 @@ def plot_traj(df, frame, data_dir, groups=None, image={'image_fn': None, 't_dim'
# get config parameters
plot_config = make_plot_config() if plot_config is None else plot_config
if traj_parameters is None:
traj_parameters = {'color_code': 'z', # color code: 'z', 'group', 'random', 'none'
'cmap': 'plasma', # colormap to be used if color_code is 'z'
'cmap_lim': None,
# pass custom colormap limits (useful for getting coherent boundaries for all frames)
'show_tail': True, # show trajectory tail
'hide_labels': True, # hide trajectory ID
'lab_size': 6, # label size in points if hide_labels is False
'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 !! Not supportes anymore !!
'elevation': None, # 3D paramater !! Not supportes anymore !!
'angle': None, # 3D paramater !! Not supportes anymore !!
'subset_order': None, # if color-code is group, order of group in color cycle
}
# unpack config
color_list = plot_config['color_list']
show_tail = traj_parameters['show_tail']
color_code = traj_parameters['color_code']
......@@ -905,11 +889,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={'traj': True, 'color_code': 'z', 'hide_labels': True, 'lab_size': 6, 'no_bkg': False,
'size_factor': 1., 'plot3D': False, 'cmap_lim': None, 'show_axis': False,
'elevation': None, 'angle': None, 'cmap': 'plasma'},
plot_config=None):
plot_dir=None,traj_parameters=None,plot_config=None):
"""Plot traj for all frames"""
if plot_dir is None:
......@@ -920,6 +900,22 @@ def plot_all_traj(data_dir, df, image={'image_fn': None, 't_dim': None, 'z_dim':
tpr.safe_mkdir(plot_dir)
info = tpr.get_info(data_dir)
# initialize config if None
traj_config = tpr.make_traj_config(export_config=False)
if traj_parameters is None:
traj_parameters = traj_config["traj_config_"]
# check config and replace by default if missing
for k in traj_config["traj_config_"].keys():
if k not in traj_parameters.keys():
traj_parameters[k] = traj_config["traj_config_"][k]
# save config
config_dir = osp.join(plot_dir, 'config')
tpr.safe_mkdir(config_dir)
fn = osp.join(config_dir, 'traj_config_.csv')
tpr.write_dict(traj_parameters, fn)
plot_config = make_plot_config() if plot_config is None else plot_config
......@@ -1029,8 +1025,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={'no_bkg': False, 'vlim': None, 'show_axis': False, 'cmap': 'plasma', 'size_factor': 1},
plot_dir=None, plot_config=None, dont_print_count=False):
map_param=None,plot_dir=None, plot_config=None, dont_print_count=False):
"""
Plot Voronoi for all frames and calculate voronoi cell area.
"""
......@@ -1040,6 +1035,22 @@ def plot_all_Voronoi(data_dir, df, data, show_local_area=True, df_mean = None,
info = tpr.get_info(data_dir)
# initialize config if None
traj_config = tpr.make_traj_config(export_config=False)
if map_param is None:
map_param = traj_config["voronoi_config"]
# check config and replace by default if missing
for k in traj_config["voronoi_config"].keys():
if k not in map_param.keys():
map_param[k] = traj_config["voronoi_config"][k]
# save config
config_dir = osp.join(plot_dir, 'config')
tpr.safe_mkdir(config_dir)
fn = osp.join(config_dir, 'voronoi_config.csv')
tpr.write_dict(map_param, fn)
plot_config = make_plot_config() if plot_config is None else plot_config
# get vlim
......@@ -1065,10 +1076,7 @@ def plot_all_Voronoi(data_dir, df, data, show_local_area=True, df_mean = None,
def plot_all_MSD(data_dir, df=None, df_out=None, fit_model="biased_diff", msd_all=None, refresh=False, hue=None,
hue_order=None,
MSD_parameters={'dim': 2, 'fitrange': None, 'plot_all_MSD': True, 'plot_single_MSD': False,
'logplot_x': True, 'logplot_y': True},
plot_config=None, plot_dir=None):
hue_order=None, MSD_parameters=None, plot_config=None, plot_dir=None):
"""
Plot all MSD of trajectories given by df (MSD_parameters['plot_all_MSD'] is True).
The MSD can be either computed from df or passed with msd_all. If msd_all is None it is computed from df, or it re-computed if refresh is True
......@@ -1078,6 +1086,16 @@ def plot_all_MSD(data_dir, df=None, df_out=None, fit_model="biased_diff", msd_al
Indivual MSD can be plotted too (but it is advised not to do so for large number of trajectories) if MSD_parameters['plot_single_MSD'] is True.
"""
# initialize config if None
traj_config = tpr.make_traj_config(export_config=False)
if MSD_parameters is None:
MSD_parameters = traj_config["MSD_config"]
# check config and replace by default if missing
for k in traj_config["MSD_config"].keys():
if k not in MSD_parameters.keys():
MSD_parameters[k] = traj_config["MSD_config"][k]
# unpack parameters
dim = MSD_parameters['dim']
fitrange = MSD_parameters['fitrange']
......@@ -1095,6 +1113,12 @@ def plot_all_MSD(data_dir, df=None, df_out=None, fit_model="biased_diff", msd_al
plot_dir = osp.join(data_dir, 'MSD')
tpr.safe_mkdir(plot_dir)
# save config
config_dir = osp.join(plot_dir, 'config')
tpr.safe_mkdir(config_dir)
fn = osp.join(config_dir, 'MSD_config.csv')
tpr.write_dict(MSD_parameters, fn)
# prepare dataframes
if df is None:
data = tpr.get_data(data_dir)
......@@ -1217,18 +1241,15 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
color_list = plot_config['color_list']
invert_yaxis = plot_config['invert_yaxis']
#initialize config if None
# initialize config if None
traj_config = tpr.make_traj_config(export_config=False)
if specific_config is None:
specific_config = {'center_origin': False,
'hide_labels': False,
'set_axis_lim': None,
'equal_axis': True,
'label_size': 6,
'color_code': 'random',
'cmap': 'plasma',
'cmap_lim': None,
'subset_order': None,
}
specific_config = traj_config["total_traj_config"]
# check config and replace by default if missing
for k in traj_config["total_traj_config"].keys():
if k not in specific_config.keys():
specific_config[k] = traj_config["total_traj_config"][k]
# unpack config
center_origin = specific_config['center_origin']
......@@ -1249,6 +1270,12 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
plot_dir = osp.join(data_dir, 'centered_traj')
tpr.safe_mkdir(plot_dir)
# save config
config_dir = osp.join(plot_dir, 'config')
tpr.safe_mkdir(config_dir)
fn = osp.join(config_dir, 'total_traj_config.csv')
tpr.write_dict(specific_config, fn)
# group by tracks
track_groups = df.groupby(['track'])
......
......@@ -117,14 +117,6 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
tpr.safe_mkdir(config_dir)
fn = osp.join(config_dir, 'filters.csv')
tpr.write_dict(filters_[i], fn)
for key in traj_config.keys():
fn = osp.join(config_dir, key + '.csv')
tpr.write_dict(traj_config[key], fn)
# if filters[i]['ROI'] is not None:
# filters[i]['ROI']['coord'] = ROI_list[i]
# params_d = [filters[i], traj_config_, MSD_config, plot_config]
# params_n = ['filters', 'traj parameters', 'MSD parameters', 'plotting parameters']
# tpr.write_dict(params_d, filename, dict_names=params_n)
# compute mean track properties
mean_fn = osp.join(sub_dir, 'track_prop.csv')
......@@ -174,32 +166,42 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
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:
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,
hue_order=hue_order)
if len(hist_config['mean_var_list']) > 0:
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_',
hue=hue, hue_order=hue_order)
if scatter_config['run']:
if len(scatter_config['couple_list']) > 0:
print("Plotting couples of parameters...")
for param_vs_param in scatter_config['couple_list']:
x_param, y_param = param_vs_param
tpl.plot_param_vs_param(data_dir, x_param, y_param, df, plot_dir=sub_dir, plot_config=plot_config,
fn = osp.join(config_dir, 'hist_config.csv')
tpr.write_dict(hist_config, fn)
if 'var_list' in hist_config.keys():
if len(hist_config['var_list']) > 0:
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,
hue_order=hue_order)
if 'mean_var_list' in hist_config.keys():
if len(hist_config['mean_var_list']) > 0:
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_',
hue=hue, hue_order=hue_order)
if len(scatter_config['mean_couple_list']) > 0:
print("Plotting couples of whole-track parameters...")
for param_vs_param in scatter_config['mean_couple_list']:
x_param, y_param = param_vs_param
tpl.plot_param_vs_param(data_dir, x_param, y_param, df_prop, plot_dir=sub_dir, plot_config=plot_config,
prefix='track_', hue=hue, hue_order=hue_order)
if scatter_config['run']:
fn = osp.join(config_dir, 'scatter_config.csv')
tpr.write_dict(scatter_config, fn)
if 'couple_list' in scatter_config.keys():
if len(scatter_config['couple_list']) > 0:
print("Plotting couples of parameters...")
for param_vs_param in scatter_config['couple_list']:
x_param, y_param = param_vs_param
tpl.plot_param_vs_param(data_dir, x_param, y_param, df, plot_dir=sub_dir, plot_config=plot_config,
hue=hue, hue_order=hue_order)
if 'mean_couple_list' in scatter_config.keys():
if len(scatter_config['mean_couple_list']) > 0:
print("Plotting couples of whole-track parameters...")
for param_vs_param in scatter_config['mean_couple_list']:
x_param, y_param = param_vs_param
tpl.plot_param_vs_param(data_dir, x_param, y_param, df_prop, plot_dir=sub_dir, plot_config=plot_config,
prefix='track_', hue=hue, hue_order=hue_order)
return df_list
......
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