From e8b77c87f6fb1dd7317e42b32f76556bd008114c Mon Sep 17 00:00:00 2001 From: epnev Date: Fri, 25 Jan 2019 09:46:44 -0500 Subject: [PATCH 1/2] fixed bug occuring when max_shifts is not the same along all dimensions --- caiman/motion_correction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index 907faa01a..ed89db746 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -2216,7 +2216,7 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl np.array([high_pass_filter_space(m_, gSig_filt) for m_ in m])) template = cm.motion_correction.bin_median( - m.motion_correct(max_shifts[0], max_shifts[1], template=None)[0]) + m.motion_correct(max_shifts[1], max_shifts[0], template=None)[0]) new_templ = template if add_to_movie is None: From ef7f21c860e2bedfe4b2fcef2eebc924f280a668 Mon Sep 17 00:00:00 2001 From: epnev Date: Tue, 29 Jan 2019 15:44:25 -0500 Subject: [PATCH 2/2] warning messages for single page tiffs --- caiman/base/movies.py | 2 +- caiman/motion_correction.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/caiman/base/movies.py b/caiman/base/movies.py index ce0ead9db..a0953c5a0 100644 --- a/caiman/base/movies.py +++ b/caiman/base/movies.py @@ -1174,7 +1174,7 @@ def load(file_name,fr=30,start_time=0,meta_data=None,subindices=None,shape=None, except: logging.warning('Your tif file is saved a single page file. Performance will be affected') input_arr = tffl.asarray() - input_arr = input_arr[subindices[0]] + input_arr = input_arr[subindices] else: input_arr = tffl.asarray() diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index ed89db746..953ad9db1 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -256,7 +256,7 @@ def motion_correct_rigid(self, template=None, save_movie=False): self.shifts_rig: shifts in x and y per frame """ logging.debug('Entering Rigid Motion Correction') - logging.debug(-self.min_mov) # XXX why the minus? + logging.debug(-self.min_mov) # XXX why the minus? self.total_template_rig = template self.templates_rig = [] self.fname_tot_rig = [] @@ -2200,7 +2200,7 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl """ corrected_slicer = slice(subidx.start, subidx.stop, subidx.step * 10) m = cm.load(fname, subindices=corrected_slicer) - + if m.shape[0] < 300: m = cm.load(fname, subindices=corrected_slicer) elif m.shape[0] < 500: @@ -2209,7 +2209,13 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl else: corrected_slicer = slice(subidx.start, subidx.stop, subidx.step * 30) m = cm.load(fname, subindices=corrected_slicer) - + + if len(m.shape) < 3: + m = cm.load(fname) + m = m[corrected_slicer] + logging.warning("Your original file was saved as a single page " + + "file. Consider saving it in multiple smaller files" + + "with size smaller than 4GB (if it is a .tif file)") if template is None: if gSig_filt is not None: m = cm.movie( @@ -2462,7 +2468,11 @@ def motion_correction_piecewise(fname, splits, strides, overlaps, add_to_movie=0 T = len(tf.pages) if T == 1: # Fiji-generated TIF is_fiji = True - T, d1, d2 = tf[0].shape + try: + T, d1, d2 = tf[0].shape + except: + T, d1, d2 = tf.asarray().shape + tf.close() else: d1, d2 = tf.pages[0].shape