Commit d45981d6 authored by amichaut's avatar amichaut
Browse files

bugfix: default filters parameters are loaded if missing

parent 807f1227
...@@ -1337,8 +1337,8 @@ def make_data_config(data_dir=None, export_config=True): ...@@ -1337,8 +1337,8 @@ def make_data_config(data_dir=None, export_config=True):
Initialize parameters used by get_data Initialize parameters used by get_data
:param data_dir: path to data directory :param data_dir: path to data directory
:type data_dir: str or None :type data_dir: str or None
:param export_to_config: to export to config file :param export_config: to export to config file
:type export_to_config: bool :type export_config: bool
:return: filters used by select_sub_data() :return: filters used by select_sub_data()
:rtype: dict :rtype: dict
""" """
...@@ -1361,13 +1361,13 @@ def make_data_config(data_dir=None, export_config=True): ...@@ -1361,13 +1361,13 @@ def make_data_config(data_dir=None, export_config=True):
return config return config
def init_filters(data_dir=None, export_to_config=False): def init_filters(data_dir=None, export_config=False):
""" """
Initialize database filters Initialize database filters
:param data_dir: path to data directory :param data_dir: path to data directory
:type data_dir: str or None :type data_dir: str or None
:param export_to_config: to export to config file :param export_config: to export to config file
:type export_to_config: bool :type export_config: bool
:return: filters used by select_sub_data() :return: filters used by select_sub_data()
:rtype: dict :rtype: dict
""" """
...@@ -1388,7 +1388,7 @@ def init_filters(data_dir=None, export_to_config=False): ...@@ -1388,7 +1388,7 @@ def init_filters(data_dir=None, export_to_config=False):
'subset_order': None, # to give a custom order from plotting subset together 'subset_order': None, # to give a custom order from plotting subset together
} }
if export_to_config: if export_config:
if data_dir is None: if data_dir is None:
raise Exception("ERROR: no data_dir given") raise Exception("ERROR: no data_dir given")
else: else:
...@@ -1406,7 +1406,7 @@ def make_all_config(data_dir=None, export_config=True): ...@@ -1406,7 +1406,7 @@ def make_all_config(data_dir=None, export_config=True):
""" """
data_config = make_data_config(data_dir=data_dir, export_config=export_config) data_config = make_data_config(data_dir=data_dir, export_config=export_config)
filters = init_filters(data_dir=data_dir, export_to_config=export_config) filters = init_filters(data_dir=data_dir, export_config=export_config)
traj_config = make_traj_config(data_dir=data_dir, export_config=export_config) traj_config = make_traj_config(data_dir=data_dir, export_config=export_config)
map_config = make_map_config(data_dir=data_dir, export_config=export_config) map_config = make_map_config(data_dir=data_dir, export_config=export_config)
plot_config = tpl.make_plot_config(data_dir=data_dir, export_config=export_config) plot_config = tpl.make_plot_config(data_dir=data_dir, export_config=export_config)
......
...@@ -85,7 +85,20 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal ...@@ -85,7 +85,20 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
vector_mean = map_config["vector_mean"] vector_mean = map_config["vector_mean"]
# Filter data # Filter data
filters = tpr.init_filters(data_dir=data_dir, export_to_config=True) if filters is None else filters filters = tpr.init_filters(data_dir=data_dir, export_config=True) if filters is None else filters
# check that all keys are in filters, if not load default
filters_default = tpr.init_filters(data_dir=data_dir, export_config=False)
filters_default_dict = filters_default['filters_list'][0]
for k in filters_default.keys():
if k not in filters.keys():
filters[k] = filters_default[k]
# check all filter_subset
for i,filter_ in enumerate(filters['filters_list']):
for k in filters_default_dict.keys():
if k not in filter_.keys():
filter_[k] = filters_default_dict[k]
filters['filters_list'][i] = filter_
subset_analysis = filters['subset'] # how to deal with subsets subset_analysis = filters['subset'] # how to deal with subsets
filters_ = filters['filters_list'] filters_ = filters['filters_list']
df = tpr.select_sub_data(df, filters=filters_) df = tpr.select_sub_data(df, filters=filters_)
......
...@@ -82,8 +82,23 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa ...@@ -82,8 +82,23 @@ def traj_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fa
voronoi_config = traj_config["voronoi_config"] voronoi_config = traj_config["voronoi_config"]
# Filter data # Filter data
filters = tpr.init_filters(data_dir=data_dir, export_to_config=False) if filters is None else filters filters = tpr.init_filters(data_dir=data_dir, export_config=False) if filters is None else filters
# check that all keys are in filters, if not load default
filters_default = tpr.init_filters(data_dir=data_dir, export_config=False)
filters_default_dict = filters_default['filters_list'][0]
for k in filters_default.keys():
if k not in filters.keys():
filters[k] = filters_default[k]
# check all filter_subset
for i,filter_ in enumerate(filters['filters_list']):
for k in filters_default_dict.keys():
if k not in filter_.keys():
filter_[k] = filters_default_dict[k]
filters['filters_list'][i] = filter_
subset_analysis = filters['subset'] # how to deal with subsets subset_analysis = filters['subset'] # how to deal with subsets
print(subset_analysis)
print(filters)
filters_ = filters['filters_list'] filters_ = filters['filters_list']
df = tpr.select_sub_data(df, filters=filters_) df = tpr.select_sub_data(df, filters=filters_)
if subset_analysis == 'together': if subset_analysis == 'together':
......
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