From c28849176c3cd55753b453ff3ebffb4eb50d0ee8 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:06:42 +0100 Subject: [PATCH 01/11] Avoid masks, indexing error --- djimaging/autorois/cellpose_wrapper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/djimaging/autorois/cellpose_wrapper.py b/djimaging/autorois/cellpose_wrapper.py index b2b773d..2a21097 100644 --- a/djimaging/autorois/cellpose_wrapper.py +++ b/djimaging/autorois/cellpose_wrapper.py @@ -1,3 +1,4 @@ +from multiprocessing import Value import numpy as np from matplotlib import pyplot as plt @@ -55,6 +56,8 @@ def create_mask_from_data(self, ch0_stack, ch1_stack=None, use_ch0=True, do_3D=F if isinstance(masks, list): if len(masks) == 0: + raise ValueError("Empty masks") + elif len(masks) == 1: roi_mask = masks[0] else: roi_mask = np.max(masks, axis=0) From 7eafed345f3f89fab0a03719818dd9ed03f462d3 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:08:26 +0100 Subject: [PATCH 02/11] mask whole column instead of only the first elements --- djimaging/autorois/corr_roi_mask_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/autorois/corr_roi_mask_utils.py b/djimaging/autorois/corr_roi_mask_utils.py index c13d432..fb3e04b 100644 --- a/djimaging/autorois/corr_roi_mask_utils.py +++ b/djimaging/autorois/corr_roi_mask_utils.py @@ -126,7 +126,7 @@ def corr_map_rois(stack, cut_x, cut_z, n_pix_max_x=5, n_pix_max_z=5, n_pix_max=2 ignore_map[corr_map < line_threshold] = True ignore_map[:cut_x[0], :] = True ignore_map[nx - cut_x[1]:, :] = True - ignore_map[:, cut_z[0]] = True + ignore_map[:, :cut_z[0]] = True ignore_map[:, nz - cut_z[1]:] = True p_threshold = grow_threshold if grow_threshold is not None else line_threshold From 1c4bc93dbfe8e9137392bb7f2ed053bab9078a81 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:08:54 +0100 Subject: [PATCH 03/11] Set eye to unknown if it's the empty string --- djimaging/tables/core/experiment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/tables/core/experiment.py b/djimaging/tables/core/experiment.py index 5296063..3405212 100644 --- a/djimaging/tables/core/experiment.py +++ b/djimaging/tables/core/experiment.py @@ -152,7 +152,7 @@ def add_experiment(self, key, header_path, pre_data_dir, raw_data_dir, only_new, info_entry["prep"] = "wholemount" eye = header_dict.get("eye", "unknown") - if 'eye' == '': + if eye == '': eye = 'unknown' if ( From 00a70ebed699dad3d0c0aef8dd2a3301e4eba8f7 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:09:27 +0100 Subject: [PATCH 04/11] allow default argument gaussian for spatial_rf_utils function --- djimaging/utils/receptive_fields/spatial_rf_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djimaging/utils/receptive_fields/spatial_rf_utils.py b/djimaging/utils/receptive_fields/spatial_rf_utils.py index 4db0609..4804e0f 100644 --- a/djimaging/utils/receptive_fields/spatial_rf_utils.py +++ b/djimaging/utils/receptive_fields/spatial_rf_utils.py @@ -40,7 +40,7 @@ def fit_rf_model(srf, kind='gaussian', polarity=None, center=None): qi = -1. for polarity_i in polarities: - if kind == 'gauss': + if kind == 'gauss' or kind == 'gaussian': model_i = srf_gauss_model(srf, polarity=polarity_i, center=center) elif kind == 'dog': model_i = srf_dog_model(srf, polarity=polarity_i, center=center) @@ -58,7 +58,7 @@ def fit_rf_model(srf, kind='gaussian', polarity=None, center=None): if qi_i > qi: model, model_fit, model_params, qi = model_i, model_i_fit, model_i_params, qi_i - if kind == 'gauss': + if kind == 'gauss' or kind == 'gaussian': return model_fit, model_params, qi elif kind == 'dog': model_c_fit = model[0](xx, yy) From 68374f4a2594d7b16c0ea972c6a6753967c2794c Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:11:33 +0100 Subject: [PATCH 05/11] Offset values of 0 bug --- djimaging/utils/scanm/traces_and_triggers_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/djimaging/utils/scanm/traces_and_triggers_utils.py b/djimaging/utils/scanm/traces_and_triggers_utils.py index 0d443da..5d5d7f4 100644 --- a/djimaging/utils/scanm/traces_and_triggers_utils.py +++ b/djimaging/utils/scanm/traces_and_triggers_utils.py @@ -51,6 +51,11 @@ def compute_frame_times(n_frames: int, pix_dt: int, npix_x: int, npix_2nd: int, """Compute timepoints of frames and relative delay of individual pixels. npix_2nd can be npix_y (xy-scan) or npix_z (xz-scan) """ + if npix_x_offset_left < 0: + raise ValueError(f"npix_x_offset_left has to be positive or 0, but was {npix_x_offset_left}") + if npix_x_offset_right < 0: + raise ValueError(f"npix_x_offset_right has to be positive or 0, but was {npix_x_offset_right}") + frame_dt = pix_dt * npix_x * npix_2nd frame_dt_offset = (np.arange(npix_x * npix_2nd) * pix_dt).reshape(npix_2nd, npix_x).T @@ -58,7 +63,8 @@ def compute_frame_times(n_frames: int, pix_dt: int, npix_x: int, npix_2nd: int, if precision == 'line': frame_dt_offset = np.tile(frame_dt_offset[0, :], (npix_x, 1)) - frame_dt_offset = frame_dt_offset[npix_x_offset_left:-npix_x_offset_right] + npix_x_offset_right_idx = npix_x_offset_left if npix_x_offset_left > 0 else None + frame_dt_offset = frame_dt_offset[npix_x_offset_left:-npix_x_offset_right_idx] frame_times = np.arange(n_frames) * frame_dt From a17a77b845a8340a7024f003a640634f6e411cc5 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:11:55 +0100 Subject: [PATCH 06/11] Actually raise valueError --- djimaging/utils/scanm/wparams_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/utils/scanm/wparams_utils.py b/djimaging/utils/scanm/wparams_utils.py index b35479b..c3e1bbf 100644 --- a/djimaging/utils/scanm/wparams_utils.py +++ b/djimaging/utils/scanm/wparams_utils.py @@ -71,4 +71,4 @@ def check_dims_ch_stack_wparams(ch_stack, wparams): nzpix = wparams.get("user_dzpix", 0) if not (ch_stack.shape[:2] in [(nxpix, nypix), (nxpix, nzpix)]): - ValueError(f'Stack shape error: {ch_stack.shape} not in [{(nxpix, nypix)}, {(nxpix, nzpix)}]') + raise ValueError(f'Stack shape error: {ch_stack.shape} not in [{(nxpix, nypix)}, {(nxpix, nzpix)}]') From 940a0b8df3a89bc89593b4e430a7c629f9fd9043 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:22:44 +0100 Subject: [PATCH 07/11] None comparison to float --- djimaging/utils/receptive_fields/temporal_rf_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/utils/receptive_fields/temporal_rf_utils.py b/djimaging/utils/receptive_fields/temporal_rf_utils.py index 7726d60..9817911 100644 --- a/djimaging/utils/receptive_fields/temporal_rf_utils.py +++ b/djimaging/utils/receptive_fields/temporal_rf_utils.py @@ -138,7 +138,7 @@ def compute_polarity_and_peak_idxs(trf, nstd=1., npeaks_max=None, rf_time=None, trf = trf.copy() std_trf = np.std(trf) - if (rf_time is not None) or (np.isfinite(max_dt_future)): + if (rf_time is not None) and (np.isfinite(max_dt_future)): trf[rf_time > max_dt_future] = 0. pos_peak_idxs, _ = find_peaks(trf, prominence=nstd * std_trf / 2., height=nstd * std_trf) From 0e41a1864252a217744dbffff9e353ccc727c55c Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:25:42 +0100 Subject: [PATCH 08/11] remove unnec import --- djimaging/autorois/cellpose_wrapper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/djimaging/autorois/cellpose_wrapper.py b/djimaging/autorois/cellpose_wrapper.py index 2a21097..a5bc790 100644 --- a/djimaging/autorois/cellpose_wrapper.py +++ b/djimaging/autorois/cellpose_wrapper.py @@ -1,4 +1,3 @@ -from multiprocessing import Value import numpy as np from matplotlib import pyplot as plt From bc52b794e389a991b2ad3ccfc0b0ebcb0113e87c Mon Sep 17 00:00:00 2001 From: thomasZen Date: Thu, 26 Feb 2026 13:35:39 +0100 Subject: [PATCH 09/11] Check twice against same string --- djimaging/tables/receptivefield/rf_offset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/tables/receptivefield/rf_offset.py b/djimaging/tables/receptivefield/rf_offset.py index aaf5564..8cb3493 100644 --- a/djimaging/tables/receptivefield/rf_offset.py +++ b/djimaging/tables/receptivefield/rf_offset.py @@ -73,7 +73,7 @@ def fetch_and_compute(self, key): """Compute offset w.r.t. stimulus center in microns""" stim_dict = (self.stimulus_tab & key).fetch1('stim_dict') - if ('pix_scale_x_um' not in stim_dict) or ('pix_scale_x_um' not in stim_dict): + if ('pix_scale_x_um' not in stim_dict) or ('pix_scale_y_um' not in stim_dict): raise ValueError("Pixel size not found in stimulus dict") pix_scale_x_um, pix_scale_y_um = stim_dict['pix_scale_x_um'], stim_dict['pix_scale_y_um'] From 618e607960044e84b6a34468e84c12019e29cb5f Mon Sep 17 00:00:00 2001 From: thomasZen Date: Fri, 27 Feb 2026 17:19:30 +0100 Subject: [PATCH 10/11] PR review feedback --- djimaging/utils/scanm/traces_and_triggers_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djimaging/utils/scanm/traces_and_triggers_utils.py b/djimaging/utils/scanm/traces_and_triggers_utils.py index 5d5d7f4..3c83494 100644 --- a/djimaging/utils/scanm/traces_and_triggers_utils.py +++ b/djimaging/utils/scanm/traces_and_triggers_utils.py @@ -63,7 +63,7 @@ def compute_frame_times(n_frames: int, pix_dt: int, npix_x: int, npix_2nd: int, if precision == 'line': frame_dt_offset = np.tile(frame_dt_offset[0, :], (npix_x, 1)) - npix_x_offset_right_idx = npix_x_offset_left if npix_x_offset_left > 0 else None + npix_x_offset_right_idx = npix_x_offset_right if npix_x_offset_right > 0 else None frame_dt_offset = frame_dt_offset[npix_x_offset_left:-npix_x_offset_right_idx] frame_times = np.arange(n_frames) * frame_dt From e601841da0146de6cdfd56c168e4d6494a1ae142 Mon Sep 17 00:00:00 2001 From: thomasZen Date: Fri, 27 Feb 2026 17:20:57 +0100 Subject: [PATCH 11/11] PR review feedback --- djimaging/utils/scanm/traces_and_triggers_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djimaging/utils/scanm/traces_and_triggers_utils.py b/djimaging/utils/scanm/traces_and_triggers_utils.py index 3c83494..666c4fe 100644 --- a/djimaging/utils/scanm/traces_and_triggers_utils.py +++ b/djimaging/utils/scanm/traces_and_triggers_utils.py @@ -63,8 +63,8 @@ def compute_frame_times(n_frames: int, pix_dt: int, npix_x: int, npix_2nd: int, if precision == 'line': frame_dt_offset = np.tile(frame_dt_offset[0, :], (npix_x, 1)) - npix_x_offset_right_idx = npix_x_offset_right if npix_x_offset_right > 0 else None - frame_dt_offset = frame_dt_offset[npix_x_offset_left:-npix_x_offset_right_idx] + npix_x_offset_right_idx = -npix_x_offset_right if npix_x_offset_right > 0 else None + frame_dt_offset = frame_dt_offset[npix_x_offset_left:npix_x_offset_right_idx] frame_times = np.arange(n_frames) * frame_dt