MaimonLab / SiffPy

Code for fast analysis of ScanImage .tiffs and .siffs
GNU General Public License v3.0
4 stars 1 forks source link

Reduce memory footprint in suite2p registration by restricting the cast to float32 to single planes. #14

Open MaximilianHoffmann opened 4 months ago

MaximilianHoffmann commented 4 months ago
ef register(self,
        siffio : 'SiffIO',
        *args,
        alignment_color_channel : int = 0,
        **kwargs
        ):
        """
        Registers individual planes using suite2p's registration method.

        If a kwarg called `ops` is provided, that's passed to suite2p's
        registration_wrapper function. Otherwise, the default_ops are used.
        """

        try:
            from suite2p import default_ops
            from suite2p.registration import register
        except ImportError:
            raise ImportError(
                "Suite2p is not installed. Please install suite2p to use this module."
            )

        frames = siffio.get_frames(
            frames = self.im_params.flatten_by_timepoints(color_channel=alignment_color_channel),
            registration = {}, # guarantee the raw frames
        ).astype(np.float32).reshape(-1, *self.im_params.volume_one_color)

        registered_frames = np.zeros_like(frames)

Right now at the beginning memory is allocated for 2x dataset size(one color channel only) as dtype single. At least for me this blow up my machine pretty quickly. One solution would be to cast the dataset to single only for the slice that's currently being registered.