From ae820a3fefb200af3e5ace00f8f7659b5052b5dc Mon Sep 17 00:00:00 2001 From: tdincer Date: Tue, 18 Jan 2022 15:55:50 -0600 Subject: [PATCH 01/24] added user given output directory --- caiman/mmapping.py | 2 +- caiman/motion_correction.py | 55 ++++++++++++++++----------- caiman/source_extraction/cnmf/cnmf.py | 14 +++++-- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/caiman/mmapping.py b/caiman/mmapping.py index 23c88a140..45d9d9ebb 100644 --- a/caiman/mmapping.py +++ b/caiman/mmapping.py @@ -25,7 +25,7 @@ def prepare_shape(mytuple: Tuple) -> Tuple: raise Exception("Internal error: prepare_shape() passed a non-tuple") return tuple(map(lambda x: np.uint64(x), mytuple)) -def load_memmap(filename: str, mode: str = 'r') -> Tuple[Any, Tuple, int]: +def load_memmap(filename: str, mode: str = 'r', output_dir: str = '') -> Tuple[Any, Tuple, int]: """ Load a memory mapped file created by the function save_memmap Args: diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index 6d7178e86..1b80cb32b 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -48,6 +48,7 @@ import cv2 import gc import h5py +import pathlib import itertools import logging import numpy as np @@ -99,7 +100,7 @@ def __init__(self, fname, min_mov=None, dview=None, max_shifts=(6, 6), niter_rig strides=(96, 96), overlaps=(32, 32), splits_els=14, num_splits_to_process_els=None, upsample_factor_grid=4, max_deviation_rigid=3, shifts_opencv=True, nonneg_movie=True, gSig_filt=None, use_cuda=False, border_nan=True, pw_rigid=False, num_frames_split=80, var_name_hdf5='mov',is3D=False, - indices=(slice(None), slice(None))): + indices=(slice(None), slice(None)), output_dir=''): """ Constructor class for motion correction operations @@ -173,15 +174,19 @@ def __init__(self, fname, min_mov=None, dview=None, max_shifts=(6, 6), niter_rig indices: tuple(slice), default: (slice(None), slice(None)) Use that to apply motion correction only on a part of the FOV + + output_dir: str, default: '' + directory to save the output + Returns: self """ if 'ndarray' in str(type(fname)): - logging.info('Creating file for motion correction "tmp_mov_mot_corr.hdf5"') - cm.movie(fname).save('tmp_mov_mot_corr.hdf5') - fname = ['tmp_mov_mot_corr.hdf5'] + logging.info(f'Creating file for motion correction "{pathlib.Path(output_dir).joinpath("tmp_mov_mot_corr.hdf5")}"') + cm.movie(fname).save(f'{output_dir}/tmp_mov_mot_corr.hdf5') + fname = [pathlib.Path(output_dir).joinpath("tmp_mov_mot_corr.hdf5").as_posix()] if not isinstance(fname, list): fname = [fname] @@ -211,10 +216,11 @@ def __init__(self, fname, min_mov=None, dview=None, max_shifts=(6, 6), niter_rig self.var_name_hdf5 = var_name_hdf5 self.is3D = bool(is3D) self.indices = indices + self.output_dir = output_dir if self.use_cuda and not HAS_CUDA: logging.debug("pycuda is unavailable. Falling back to default FFT.") - def motion_correct(self, template=None, save_movie=False): + def motion_correct(self, template=None, save_movie=False, output_dir=''): """general function for performing all types of motion correction. The function will perform either rigid or piecewise rigid motion correction depending on the attribute self.pw_rigid and will perform high pass @@ -254,7 +260,7 @@ def motion_correct(self, template=None, save_movie=False): subindices=slice(400))]).min() if self.pw_rigid: - self.motion_correct_pwrigid(template=template, save_movie=save_movie) + self.motion_correct_pwrigid(template=template, save_movie=save_movie, output_dir=output_dir) if self.is3D: # TODO - error at this point after saving b0 = np.ceil(np.max([np.max(np.abs(self.x_shifts_els)), @@ -264,13 +270,13 @@ def motion_correct(self, template=None, save_movie=False): b0 = np.ceil(np.maximum(np.max(np.abs(self.x_shifts_els)), np.max(np.abs(self.y_shifts_els)))) else: - self.motion_correct_rigid(template=template, save_movie=save_movie) + self.motion_correct_rigid(template=template, save_movie=save_movie, output_dir=output_dir) # This line saves files to the raw image directory b0 = np.ceil(np.max(np.abs(self.shifts_rig))) self.border_to_0 = b0.astype(np.int) self.mmap_file = self.fname_tot_els if self.pw_rigid else self.fname_tot_rig return self - def motion_correct_rigid(self, template=None, save_movie=False) -> None: + def motion_correct_rigid(self, template=None, save_movie=False, output_dir='') -> None: """ Perform rigid motion correction @@ -315,7 +321,8 @@ def motion_correct_rigid(self, template=None, save_movie=False) -> None: border_nan=self.border_nan, var_name_hdf5=self.var_name_hdf5, is3D=self.is3D, - indices=self.indices) + indices=self.indices, + output_dir=output_dir) if template is None: self.total_template_rig = _total_template_rig @@ -323,7 +330,7 @@ def motion_correct_rigid(self, template=None, save_movie=False) -> None: self.fname_tot_rig += [_fname_tot_rig] self.shifts_rig += _shifts_rig - def motion_correct_pwrigid(self, save_movie:bool=True, template:np.ndarray=None, show_template:bool=False) -> None: + def motion_correct_pwrigid(self, save_movie:bool=True, template:np.ndarray=None, show_template:bool=False, output_dir='') -> None: """Perform pw-rigid motion correction Args: @@ -375,7 +382,7 @@ def motion_correct_pwrigid(self, save_movie:bool=True, template:np.ndarray=None, num_splits_to_process=None, num_iter=num_iter, template=self.total_template_els, shifts_opencv=self.shifts_opencv, save_movie=save_movie, nonneg_movie=self.nonneg_movie, gSig_filt=self.gSig_filt, use_cuda=self.use_cuda, border_nan=self.border_nan, var_name_hdf5=self.var_name_hdf5, is3D=self.is3D, - indices=self.indices) + indices=self.indices, output_dir=output_dir) if not self.is3D: if show_template: pl.imshow(new_template_els) @@ -2715,7 +2722,8 @@ def compute_metrics_motion_correction(fname, final_size_x, final_size_y, swap_di def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_splits_to_process=None, num_iter=1, template=None, shifts_opencv=False, save_movie_rigid=False, add_to_movie=None, nonneg_movie=False, gSig_filt=None, subidx=slice(None, None, 1), use_cuda=False, - border_nan=True, var_name_hdf5='mov', is3D=False, indices=(slice(None), slice(None))): + border_nan=True, var_name_hdf5='mov', is3D=False, indices=(slice(None), slice(None)), + output_dir=''): """ Function that perform memory efficient hyper parallelized rigid motion corrections while also saving a memory mappable file @@ -2829,14 +2837,14 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl if isinstance(fname, tuple): base_name=os.path.split(fname[0])[-1][:-4] + '_rig_' else: - base_name=os.path.split(fname)[-1][:-4] + '_rig_' + base_name=os.path.split(fname)[-1][:-4] + '_rig_' fname_tot_rig, res_rig = motion_correction_piecewise(fname, splits, strides=None, overlaps=None, add_to_movie=add_to_movie, template=old_templ, max_shifts=max_shifts, max_deviation_rigid=0, dview=dview, save_movie=save_movie, base_name=base_name, subidx = subidx, num_splits=num_splits_to_process, shifts_opencv=shifts_opencv, nonneg_movie=nonneg_movie, gSig_filt=gSig_filt, use_cuda=use_cuda, border_nan=border_nan, var_name_hdf5=var_name_hdf5, is3D=is3D, - indices=indices) + indices=indices, output_dir=output_dir) if is3D: new_templ = np.nanmedian(np.stack([r[-1] for r in res_rig]), 0) else: @@ -2866,7 +2874,7 @@ def motion_correct_batch_pwrigid(fname, max_shifts, strides, overlaps, add_to_mo splits=56, num_splits_to_process=None, num_iter=1, template=None, shifts_opencv=False, save_movie=False, nonneg_movie=False, gSig_filt=None, use_cuda=False, border_nan=True, var_name_hdf5='mov', is3D=False, - indices=(slice(None), slice(None))): + indices=(slice(None), slice(None)), output_dir=''): """ Function that perform memory efficient hyper parallelized rigid motion corrections while also saving a memory mappable file @@ -2957,9 +2965,9 @@ def motion_correct_batch_pwrigid(fname, max_shifts, strides, overlaps, add_to_mo logging.debug(f'saving mmap of {fname}') if isinstance(fname, tuple): - base_name=os.path.split(fname[0])[-1][:-4] + '_els_' + base_name = os.path.split(fname[0])[-1][:-4] + '_els_' else: - base_name=os.path.split(fname)[-1][:-4] + '_els_' + base_name = os.path.split(fname)[-1][:-4] + '_els_' fname_tot_els, res_el = motion_correction_piecewise(fname, splits, strides, overlaps, add_to_movie=add_to_movie, template=old_templ, max_shifts=max_shifts, @@ -2969,7 +2977,7 @@ def motion_correct_batch_pwrigid(fname, max_shifts, strides, overlaps, add_to_mo base_name=base_name, num_splits=num_splits_to_process, shifts_opencv=shifts_opencv, nonneg_movie=nonneg_movie, gSig_filt=gSig_filt, use_cuda=use_cuda, border_nan=border_nan, var_name_hdf5=var_name_hdf5, is3D=is3D, - indices=indices) + indices=indices, output_dir=output_dir) new_templ = np.nanmedian(np.dstack([r[-1] for r in res_el]), -1) if gSig_filt is not None: @@ -3082,7 +3090,7 @@ def motion_correction_piecewise(fname, splits, strides, overlaps, add_to_movie=0 upsample_factor_grid=4, order='F', dview=None, save_movie=True, base_name=None, subidx = None, num_splits=None, shifts_opencv=False, nonneg_movie=False, gSig_filt=None, use_cuda=False, border_nan=True, var_name_hdf5='mov', is3D=False, - indices=(slice(None), slice(None))): + indices=(slice(None), slice(None)), output_dir=''): """ """ @@ -3125,11 +3133,12 @@ def motion_correction_piecewise(fname, splits, strides, overlaps, add_to_movie=0 if save_movie: if base_name is None: base_name = os.path.split(fname)[1][:-4] + + if not output_dir: + output_dir = pathlib.Path(fname[0] if isinstance(fname, tuple) else fname).parent + fname_tot:Optional[str] = caiman.paths.memmap_frames_filename(base_name, dims, T, order) - if isinstance(fname, tuple): - fname_tot = os.path.join(os.path.split(fname[0])[0], fname_tot) - else: - fname_tot = os.path.join(os.path.split(fname)[0], fname_tot) + fname_tot = pathlib.Path(output_dir).joinpath(fname_tot).as_posix() np.memmap(fname_tot, mode='w+', dtype=np.float32, shape=prepare_shape(shape_mov), order=order) diff --git a/caiman/source_extraction/cnmf/cnmf.py b/caiman/source_extraction/cnmf/cnmf.py index 3f59e7706..20bb37a09 100644 --- a/caiman/source_extraction/cnmf/cnmf.py +++ b/caiman/source_extraction/cnmf/cnmf.py @@ -307,7 +307,7 @@ def __init__(self, n_processes, k=5, gSig=[4, 4], gSiz=None, merge_thresh=0.8, p self.estimates = Estimates(A=Ain, C=Cin, b=b_in, f=f_in, dims=self.params.data['dims']) - def fit_file(self, motion_correct=False, indices=None, include_eval=False): + def fit_file(self, motion_correct=False, indices=None, include_eval=False, output_dir='', return_mc=False): """ This method packages the analysis pipeline (motion correction, memory mapping, patch based CNMF processing and component evaluation) in a @@ -324,8 +324,13 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False): perform analysis only on a part of the FOV include_eval (bool) flag for performing component evaluation + output_dir (str) + directory to save the outputs + return_mc (bool) + flag to return motion correction object Returns: cnmf object with the current estimates + (optional) motion correction object """ if indices is None: indices = (slice(None), slice(None)) @@ -337,7 +342,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False): logging.warning("Error: File not found, with file list:\n" + fnames[0]) raise Exception('File not found!') - base_name = pathlib.Path(fnames[0]).stem + "_memmap_" + base_name = (pathlib.Path(output_dir) / (pathlib.Path(fnames[0]).stem + "_memmap_")).as_posix() if extension == '.mmap': fname_new = fnames[0] Yr, dims, T = mmapping.load_memmap(fnames[0]) @@ -346,7 +351,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False): else: if motion_correct: mc = MotionCorrect(fnames, dview=self.dview, **self.params.motion) - mc.motion_correct(save_movie=True) + mc.motion_correct(save_movie=True, output_dir=output_dir) fname_mc = mc.fname_tot_els if self.params.motion['pw_rigid'] else mc.fname_tot_rig if self.params.get('motion', 'pw_rigid'): b0 = np.ceil(np.maximum(np.max(np.abs(mc.x_shifts_els)), @@ -392,6 +397,9 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False): for log_file in log_files: os.remove(log_file) + if return_mc: + return cnm2, mc + return cnm2 From 650a0f59cba3d45a2164656550c8d8921a2ff785 Mon Sep 17 00:00:00 2001 From: Tolga Dincer Date: Wed, 19 Jan 2022 10:07:45 -0600 Subject: [PATCH 02/24] Update caiman/motion_correction.py Co-authored-by: jverswijver <49455164+jverswijver@users.noreply.github.com> --- 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 1b80cb32b..cad77e169 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -2837,7 +2837,7 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl if isinstance(fname, tuple): base_name=os.path.split(fname[0])[-1][:-4] + '_rig_' else: - base_name=os.path.split(fname)[-1][:-4] + '_rig_' + base_name=os.path.split(fname)[-1][:-4] + '_rig_' fname_tot_rig, res_rig = motion_correction_piecewise(fname, splits, strides=None, overlaps=None, add_to_movie=add_to_movie, template=old_templ, max_shifts=max_shifts, max_deviation_rigid=0, From d367646a144561daa873d35f0a782da32d93d71d Mon Sep 17 00:00:00 2001 From: Tolga Dincer Date: Wed, 19 Jan 2022 10:59:03 -0600 Subject: [PATCH 03/24] Update caiman/motion_correction.py Co-authored-by: Thinh Nguyen --- caiman/motion_correction.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index cad77e169..0e0136c34 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -184,9 +184,10 @@ def __init__(self, fname, min_mov=None, dview=None, max_shifts=(6, 6), niter_rig """ if 'ndarray' in str(type(fname)): - logging.info(f'Creating file for motion correction "{pathlib.Path(output_dir).joinpath("tmp_mov_mot_corr.hdf5")}"') - cm.movie(fname).save(f'{output_dir}/tmp_mov_mot_corr.hdf5') - fname = [pathlib.Path(output_dir).joinpath("tmp_mov_mot_corr.hdf5").as_posix()] + tmp_mov_mot_corr_fp = pathlib.Path(output_dir) / 'tmp_mov_mot_corr.hdf5' + logging.info(f'Creating file for motion correction "{tmp_mov_mot_corr_fp }"') + cm.movie(fname).save(tmp_mov_mot_corr_fp.as_posix()) + fname = [tmp_mov_mot_corr_fp.as_posix()] if not isinstance(fname, list): fname = [fname] From f2dbb576b2398f68f7724c6e1d640d0d8f82352c Mon Sep 17 00:00:00 2001 From: Tolga Dincer Date: Wed, 19 Jan 2022 11:05:57 -0600 Subject: [PATCH 04/24] Update cnmf.py changed `if return_mc:` to ` if return_mc & motion_correct:` to make sure that motion correction is applied if we want to return the `motion correction object` --- caiman/source_extraction/cnmf/cnmf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/source_extraction/cnmf/cnmf.py b/caiman/source_extraction/cnmf/cnmf.py index 20bb37a09..2952f24de 100644 --- a/caiman/source_extraction/cnmf/cnmf.py +++ b/caiman/source_extraction/cnmf/cnmf.py @@ -397,7 +397,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False, outpu for log_file in log_files: os.remove(log_file) - if return_mc: + if return_mc & motion_correct: return cnm2, mc return cnm2 From 9c0c21f05462227d5fec6054f711df388ccc9e62 Mon Sep 17 00:00:00 2001 From: Tolga Dincer Date: Tue, 25 Jan 2022 13:43:03 -0600 Subject: [PATCH 05/24] Update cnmf.py `base_name` line is changed to its original form. --- caiman/source_extraction/cnmf/cnmf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/source_extraction/cnmf/cnmf.py b/caiman/source_extraction/cnmf/cnmf.py index 2952f24de..da31c044b 100644 --- a/caiman/source_extraction/cnmf/cnmf.py +++ b/caiman/source_extraction/cnmf/cnmf.py @@ -342,7 +342,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False, outpu logging.warning("Error: File not found, with file list:\n" + fnames[0]) raise Exception('File not found!') - base_name = (pathlib.Path(output_dir) / (pathlib.Path(fnames[0]).stem + "_memmap_")).as_posix() + base_name = pathlib.Path(fnames[0]).stem + "_memmap_" if extension == '.mmap': fname_new = fnames[0] Yr, dims, T = mmapping.load_memmap(fnames[0]) From 4ee1ff99a8143e76edc6a5f2795e716b507201d0 Mon Sep 17 00:00:00 2001 From: Tolga Dincer Date: Tue, 25 Jan 2022 19:56:30 -0600 Subject: [PATCH 06/24] adjusted .npz file output directory --- caiman/mmapping.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/caiman/mmapping.py b/caiman/mmapping.py index 45d9d9ebb..aed87bb45 100644 --- a/caiman/mmapping.py +++ b/caiman/mmapping.py @@ -215,7 +215,8 @@ def save_memmap_join(mmap_fnames: List[str], base_name: str = None, n_chunks: in else: list(map(save_portion, pars)) - np.savez(caiman.paths.fn_relocated(base_name + '.npz'), mmap_fnames=mmap_fnames, fname_tot=fname_tot) + npz_file = pathlib.Path(fname_tot).parent / (base_name + '.npz') + np.savez(caiman.paths.fn_relocated(npz_file), mmap_fnames=mmap_fnames, fname_tot=fname_tot) logging.info('Deleting big mov') del big_mov From 5904bc99faa04b123aea19cfbd55a6f1e08d3d99 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Tue, 3 Oct 2023 17:32:05 -0500 Subject: [PATCH 07/24] include `indices` argument to the motion correction step --- caiman/source_extraction/cnmf/cnmf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/source_extraction/cnmf/cnmf.py b/caiman/source_extraction/cnmf/cnmf.py index e5a04ec89..9036abe6c 100644 --- a/caiman/source_extraction/cnmf/cnmf.py +++ b/caiman/source_extraction/cnmf/cnmf.py @@ -352,7 +352,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False, outpu else: data_set_name = self.params.get('data', 'var_name_hdf5') if motion_correct: - mc = MotionCorrect(fnames, dview=self.dview, **self.params.motion) + mc = MotionCorrect(fnames, dview=self.dview, indices=indices, **self.params.motion) mc.motion_correct(save_movie=True, output_dir=output_dir) fname_mc = mc.fname_tot_els if self.params.motion['pw_rigid'] else mc.fname_tot_rig if self.params.get('motion', 'pw_rigid'): From 6951f7e4be1426a16faabc9ee8529e468881310f Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Wed, 18 Oct 2023 10:36:48 -0500 Subject: [PATCH 08/24] Remove `indices` arg from `MotionCorrect` --- caiman/source_extraction/cnmf/cnmf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/source_extraction/cnmf/cnmf.py b/caiman/source_extraction/cnmf/cnmf.py index 9036abe6c..e5a04ec89 100644 --- a/caiman/source_extraction/cnmf/cnmf.py +++ b/caiman/source_extraction/cnmf/cnmf.py @@ -352,7 +352,7 @@ def fit_file(self, motion_correct=False, indices=None, include_eval=False, outpu else: data_set_name = self.params.get('data', 'var_name_hdf5') if motion_correct: - mc = MotionCorrect(fnames, dview=self.dview, indices=indices, **self.params.motion) + mc = MotionCorrect(fnames, dview=self.dview, **self.params.motion) mc.motion_correct(save_movie=True, output_dir=output_dir) fname_mc = mc.fname_tot_els if self.params.motion['pw_rigid'] else mc.fname_tot_rig if self.params.get('motion', 'pw_rigid'): From a53973ac26e3e1ce280bd2d35a6ea4fe84981e07 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Fri, 23 Feb 2024 13:46:33 -0500 Subject: [PATCH 09/24] VERSION: 1.10.4 postrelease --- VERSION | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 8b107faae..18b311420 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1 @@ -1.10.3 - +1.10.4 From e27ead4b6ccb1b9909426351a87c536b37a70b25 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Sun, 3 Mar 2024 23:17:50 -0500 Subject: [PATCH 10/24] Fix issue with dev release and last refactor of pathing --- caiman/base/movies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/base/movies.py b/caiman/base/movies.py index b0f9fec3d..e94ddd218 100644 --- a/caiman/base/movies.py +++ b/caiman/base/movies.py @@ -2261,7 +2261,7 @@ def get_file_size(file_name, var_name_hdf5:str='mov') -> tuple[tuple, Union[int, dims[0], dims[1] = pims_movie.frame_shape[0:2] elif extension == '.mmap': filename = os.path.split(file_name)[-1] - Yr, dims, T = load_memmap(os.path.join( + Yr, dims, T = caiman.mmapping.load_memmap(os.path.join( os.path.split(file_name)[0], filename)) elif extension in ('.h5', '.hdf5', '.nwb', 'n5', 'zarr'): # FIXME this doesn't match the logic in load() From 9f26fc6388fb259182fd80fcb14ff795ec12e78b Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Wed, 31 Jan 2024 15:44:46 -0500 Subject: [PATCH 11/24] Fix typo --- caiman/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/utils/utils.py b/caiman/utils/utils.py index 866d117d6..caf82d906 100644 --- a/caiman/utils/utils.py +++ b/caiman/utils/utils.py @@ -649,7 +649,7 @@ def get_caiman_version() -> tuple[str, str]: # 'GITW') git rev-parse if caiman is built from "pip install -e ." and we are working # out of the checkout directory (the user may have since updated without reinstall) # 'RELF') A release file left in the process to cut a release. Should have a single line - # in it whick looks like "Version:1.4" + # in it which looks like "Version:1.4" # 'FILE') The date of some frequently changing files, which act as a very rough # approximation when no other methods are possible # From 83ce6ceea568d2bb6ee5f0af64e65993397e5dc3 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Mon, 4 Mar 2024 20:23:25 -0500 Subject: [PATCH 12/24] VERSION: post release to 1.10.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 18b311420..db77e0ee9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.4 +1.10.5 From 9681c64f8f6575ad8b5a701ce1bc57d2a35ed920 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Tue, 2 Apr 2024 15:06:26 -0400 Subject: [PATCH 13/24] VERSION to 1.10.6 after release: main branch --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index db77e0ee9..7b4d9a4ff 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.5 +1.10.6 From 3cf859e2c5b3b77ed3780bee02c450330972009e Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Tue, 2 Apr 2024 22:31:10 -0400 Subject: [PATCH 14/24] VERSION to 1.10.7 after release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7b4d9a4ff..ccff224b7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.6 +1.10.7 From d5cc46641b41fea673f14984cc22071b448a120c Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Wed, 3 Apr 2024 09:29:03 -0400 Subject: [PATCH 15/24] VERSION to 1.10.8 after release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ccff224b7..3cc3669ff 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.7 +1.10.8 From 1d6ee38e974e9adfdf916cf5e98517c6c5285e9d Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Wed, 3 Apr 2024 13:56:59 -0400 Subject: [PATCH 16/24] VERSION to 1.10.9 post release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3cc3669ff..b0dd75320 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.8 +1.10.9 From 9ea86c77cf7570fac2b631df3533743ae7a211e8 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Wed, 3 Apr 2024 16:39:34 -0400 Subject: [PATCH 17/24] VERSION: 1.10.10 post-release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b0dd75320..2ee4474a1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.9 +1.10.10 From 59708bd21561660f629a20d178c9446430ccfc0d Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Fri, 3 May 2024 11:44:19 -0400 Subject: [PATCH 18/24] VERSION: next release will be 1.11.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 2ee4474a1..1cac385c6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.10 +1.11.0 From 7174b3bceca437230efd926b9607f635e31b6820 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Fri, 3 May 2024 12:01:32 -0400 Subject: [PATCH 19/24] VERSION to 1.11.1 after release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1cac385c6..720c7384c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.0 +1.11.1 From 97b178475ff181dd71a7c0ba5de2605d9e8fc030 Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Fri, 31 May 2024 11:31:57 -0400 Subject: [PATCH 20/24] Update(motion_correction.py): Remove unused imports --- caiman/motion_correction.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index 29b7ae75a..7b7947364 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -39,7 +39,6 @@ import collections import cv2 import gc -import h5py import pathlib import itertools import logging @@ -64,8 +63,6 @@ except: pass -from cv2 import dft as fftn -from cv2 import idft as ifftn try: profile From 1ca315291d6ef2f0ab5b6535a756995e0f911114 Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Fri, 31 May 2024 13:17:48 -0400 Subject: [PATCH 21/24] Fix(mmapping.py): Tuple -> tuple case-match --- caiman/mmapping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caiman/mmapping.py b/caiman/mmapping.py index 1ff1f8edf..cd88575f4 100644 --- a/caiman/mmapping.py +++ b/caiman/mmapping.py @@ -21,7 +21,7 @@ def prepare_shape(mytuple:tuple) -> tuple: raise Exception("Internal error: prepare_shape() passed a non-tuple") return tuple(map(lambda x: np.uint64(x), mytuple)) -def load_memmap(filename: str, mode: str = 'r', output_dir: str = '') -> Tuple[Any, Tuple, int]: +def load_memmap(filename: str, mode: str = 'r', output_dir: str = '') -> tuple[Any, tuple, int]: """ Load a memory mapped file created by the function save_memmap Args: From e7e86411e80639c81d8ea58026660913739704f7 Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Fri, 31 May 2024 15:26:29 -0400 Subject: [PATCH 22/24] VERSION to 1.11.2 after release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 720c7384c..ca7176690 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.1 +1.11.2 From 6ecc83ab2d35987a7a71d5ccb993ddcceb4f35fc Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Mon, 3 Jun 2024 17:38:30 -0400 Subject: [PATCH 23/24] Add `output_dir` argument to `motion_correct_batch_rigid()` --- 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 7b7947364..133eee1f0 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -3371,7 +3371,7 @@ def compute_metrics_motion_correction( def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_splits_to_process=None, num_iter=1, template=None, shifts_opencv=False, save_movie_rigid=False, add_to_movie=None, nonneg_movie=False, gSig_filt=None, subidx=slice(None, None, 1), use_cuda=False, - border_nan=True, var_name_hdf5='mov', is3D=False, indices=(slice(None), slice(None))): + border_nan=True, var_name_hdf5='mov', is3D=False, indices=(slice(None), slice(None)), output_dir=""): """ Function that perform memory efficient hyper parallelized rigid motion corrections while also saving a memory mappable file From 4e9394a92b441a65a0988e95663edd5c10b204f9 Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Tue, 4 Jun 2024 17:15:45 -0400 Subject: [PATCH 24/24] Fix(motion_correction.py): update `old_div()` to division operator --- caiman/motion_correction.py | 44 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/caiman/motion_correction.py b/caiman/motion_correction.py index 133eee1f0..4d483e226 100644 --- a/caiman/motion_correction.py +++ b/caiman/motion_correction.py @@ -1147,12 +1147,10 @@ def motion_correct_online(movie_iterable, add_to_movie, max_shift_w=25, max_shif logging.debug( "Relative change in template:" + str( - old_div( - np.sum(np.abs(template - template_old)), - np.sum(np.abs(template)), + np.sum(np.abs(template - template_old)) // + np.sum(np.abs(template)) ) ) - ) logging.debug("Iteration:" + str(count)) if border_to_0 > 0: @@ -1181,7 +1179,7 @@ def motion_correct_online(movie_iterable, add_to_movie, max_shift_w=25, max_shif mov.append(new_img) if show_movie: - cv2.imshow("frame", old_div(new_img, 500)) + cv2.imshow("frame", new_img // 500) logging.info(shift) if not np.any(np.remainder(shift, 1) == (0, 0)): cv2.waitKey(int(1.0 / 500 * 1000)) @@ -1231,15 +1229,15 @@ def motion_correct_iteration(img, template, frame_num, max_shift_w=25, sh_x_n = -( sh_x - ms_h - + old_div( - (log_xm1_y - log_xp1_y), (2 * log_xm1_y - four_log_xy + 2 * log_xp1_y) + + ( + (log_xm1_y - log_xp1_y) // (2 * log_xm1_y - four_log_xy + 2 * log_xp1_y) ) ) sh_y_n = -( sh_y - ms_w - + old_div( - (log_x_ym1 - log_x_yp1), (2 * log_x_ym1 - four_log_xy + 2 * log_x_yp1) + + ( + (log_x_ym1 - log_x_yp1) // (2 * log_x_ym1 - four_log_xy + 2 * log_x_yp1) ) ) else: @@ -1289,15 +1287,15 @@ def motion_correct_iteration_fast(img, template, max_shift_w=10, max_shift_h=10) sh_x_n = -( sh_x - ms_h - + old_div( - (log_xm1_y - log_xp1_y), (2 * log_xm1_y - four_log_xy + 2 * log_xp1_y) + + ( + (log_xm1_y - log_xp1_y) // (2 * log_xm1_y - four_log_xy + 2 * log_xp1_y) ) ) sh_y_n = -( sh_y - ms_w - + old_div( - (log_x_ym1 - log_x_yp1), (2 * log_x_ym1 - four_log_xy + 2 * log_x_yp1) + + ( + (log_x_ym1 - log_x_yp1) // (2 * log_x_ym1 - four_log_xy + 2 * log_x_yp1) ) ) else: @@ -1649,14 +1647,14 @@ def _upsampled_dft(data, upsampled_region_size, (-1j * 2 * np.pi / (data.shape[1] * upsample_factor)) * ( ifftshift(np.arange(data.shape[1]))[:, None] - - np.floor(old_div(data.shape[1], 2)) + - np.floor(data.shape[1] // 2) ).dot(np.arange(upsampled_region_size[1])[None, :] - axis_offsets[1]) ) row_kernel = np.exp( (-1j * 2 * np.pi / (data.shape[0] * upsample_factor)) * (np.arange(upsampled_region_size[0])[:, None] - axis_offsets[0]).dot( ifftshift(np.arange(data.shape[0]))[None, :] - - np.floor(old_div(data.shape[0], 2)) + - np.floor(data.shape[0] // 2) ) ) @@ -1665,7 +1663,7 @@ def _upsampled_dft(data, upsampled_region_size, (-1j * 2 * np.pi / (data.shape[2] * upsample_factor)) * (np.arange(upsampled_region_size[2])[:, None] - axis_offsets[2]).dot( ifftshift(np.arange(data.shape[2]))[None, :] - - np.floor(old_div(data.shape[2], 2)) + - np.floor(data.shape[2] // 2) ) ) @@ -1854,7 +1852,7 @@ def register_translation_3d(src_image, target_image, upsample_factor = 1, midpoints = np.array([np.fix(axis_size // 2) for axis_size in shape]) # maxima = np.unravel_index(np.argmax(new_cross_corr),cross_correlation.shape) - # midpoints = np.array([np.fix(old_div(axis_size, 2)) for axis_size in shape]) + # midpoints = np.array([np.fix(axis_size // 2) for axis_size in shape]) shifts = np.array(maxima, dtype=np.float32) shifts[shifts > midpoints] -= np.array(shape)[shifts > midpoints] @@ -2116,15 +2114,15 @@ def register_translation(src_image, target_image, upsample_factor=1, new_cross_corr[:, max_shifts[1] : -max_shifts[1]] = 0 maxima = np.unravel_index(np.argmax(new_cross_corr), cross_correlation.shape) - midpoints = np.array([np.fix(old_div(axis_size, 2)) for axis_size in shape]) + midpoints = np.array([np.fix(axis_size // 2) for axis_size in shape]) shifts = np.array(maxima, dtype=np.float64) shifts[shifts > midpoints] -= np.array(shape)[shifts > midpoints] if upsample_factor == 1: - src_amp = old_div(np.sum(np.abs(src_freq) ** 2), src_freq.size) - target_amp = old_div(np.sum(np.abs(target_freq) ** 2), target_freq.size) + src_amp = np.sum(np.abs(src_freq) ** 2) // src_freq.size + target_amp = np.sum(np.abs(target_freq) ** 2) // target_freq.size CCmax = cross_correlation.max() # If upsampling > 1, then refine estimate with matrix multiply DFT else: @@ -2797,7 +2795,7 @@ def tile_and_correct( img_show = cv2.resize(img_show, None, fx=1, fy=1) - cv2.imshow("frame", old_div(img_show, np.percentile(template, 99))) + cv2.imshow("frame", img_show // np.percentile(template, 99)) cv2.waitKey(int(1.0 / 500 * 1000)) else: @@ -3176,7 +3174,7 @@ def tile_and_correct_3d(img:np.ndarray, template:np.ndarray, strides:tuple, over img_show = resize_sk(img_show, None, fx=1, fy=1, fz=1) - cv2.imshow("frame", old_div(img_show, np.percentile(template, 99))) + cv2.imshow("frame", img_show // np.percentile(template, 99)) cv2.waitKey(int(1.0 / 500 * 1000)) else: @@ -3522,7 +3520,7 @@ def motion_correct_batch_rigid(fname, max_shifts, dview=None, splits=56, num_spl if gSig_filt is not None: new_templ = high_pass_filter_space(new_templ, gSig_filt) - # logging.debug((old_div(np.linalg.norm(new_templ - old_templ), np.linalg.norm(old_templ)))) + # logging.debug((np.linalg.norm(new_templ - old_templ) // np.linalg.norm(old_templ)))) total_template = new_templ templates = []