Commit 181af706 authored by amichaut's avatar amichaut
Browse files

bugfix in subset handling + bugfix in temporal average calculation

parent 7c48ea18
Pipeline #76539 passed with stages
in 18 seconds
......@@ -50,7 +50,7 @@ If **Track Analyzer** is run using command lines (see below), the data directory
- a text file named info.txt containing the metadata (see example)
- (optional) a tiff file named stack.tif
- (optional) configuration files in a config directory
The default config files can be generated by running :code:`TA_config path_to_directory`. The config files are csv files that can be easily edited.
The default config files can be generated by running :code:`TA_config <path_to_directory>`. The config files are csv files that can be easily edited.
..
add a section descibing config and info files
......
This diff is collapsed.
This diff is collapsed.
......@@ -262,14 +262,25 @@ def interpolate_field(data_dir, df, groups, grids, frame, field_values=['vx', 'v
if frame_ in df['frame'].unique():
group_ = groups.get_group(frame_).reset_index(drop=True)
no_nan_ = group_[np.isfinite(group_[coord_list])]
triang = tri.Triangulation(no_nan_['x'].values, no_nan_['y'].values)
for coord in field_values:
interpolator = tri.LinearTriInterpolator(triang, no_nan_[coord].values)
field_dict[coord].append(interpolator(X, Y))
if no_nan_.shape[0] > 2: # cannot triangulate with less then 3 points
triang = tri.Triangulation(no_nan_['x'].values, no_nan_['y'].values)
for coord in field_values:
interpolator = tri.LinearTriInterpolator(triang, no_nan_[coord].values)
field_dict[coord].append(interpolator(X, Y))
else: # make fully masked array
mask = np.ones(X.shape, dtype=bool)
marray = np.ma.ones(X.shape)
marray[:] = np.nan
marray.mask = mask
for coord in field_values:
field_dict[coord].append(marray)
for coord in field_values:
# average interpolated vfield over the frame list
stack = np.ma.stack(field_dict[coord], axis=2)
field = np.ma.filled(np.sum(stack, axis=2) / len(frame_l), np.nan)
stack = np.ma.stack(field_dict[coord], axis=2) # stack frames along axis 2
denom = len(frame_l) - np.sum(stack.mask, axis=2) # denominator = number of non-masked data for each frame
field = np.ma.filled(np.sum(stack, axis=2) / denom, np.nan)
data[coord] = field
if export_field:
......
......@@ -112,7 +112,10 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
print("WARNING: subsets won't be plotted in different colors in maps if plotted together")
df_list = [df] # a single df is kept
elif subset_analysis == 'separately':
df_list = [df[df['subset'] == sub] for sub in df['subset'].unique()] # a list of df filtered by subset
if "subset" in df.columns:
df_list = [df[df['subset'] == sub] for sub in df['subset'].unique()] # a list of df filtered by subset
else:
df_list = [df]
# Make grid
if image['image_size'] is None: # get image size using data, making it slighlty larger
......@@ -137,7 +140,7 @@ def map_analysis(data_dir, data=None, image=None, refresh=False, parallelize=Fal
for i, df in enumerate(df_list):
# name subset directory
dir_name = ''
if subset_analysis == 'separately':
if subset_analysis == 'separately' and "subset" in df.columns:
subset_name = df['subset'].values[0]
dir_name = '_' + subset_name if subset_name != '' else ''
dir_name_ = '{}{}'.format(len(tpr.listdir_nohidden(map_dir)) + 1, dir_name)
......
......@@ -42,7 +42,7 @@ def make_default_config(data_dir):
data_config = tpr.make_data_config(data_dir=data_dir, export_config=True)
plot_config = tpl.make_plot_config(data_dir=data_dir, export_config=True)
traj_config = tpr.make_traj_config(data_dir=data_dir, export_config=True)
map_config = tpr.make_map_config(data_dir=data_dir, export_config=True)
map_config = tpr.make_map_config(data_dir=data_dir, export_config=True,empty_run=False)
config = {'data_config':data_config,
'plot_config':plot_config,
......
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