flatironinstitute / CaImAn

Computational toolbox for large scale Calcium Imaging Analysis, including movie handling, motion correction, source extraction, spike deconvolution and result visualization.
https://caiman.readthedocs.io
GNU General Public License v2.0
640 stars 370 forks source link

Free up memory in MotionCorrect.py / apply_shifts_movie function #1392

Closed deMalmazet closed 3 months ago

deMalmazet commented 3 months ago

added "del Y" in line 527 to free up memory before recreating stack when calling np.stack(), so movie is not loaded twice on memory.

Description

When dealing with large movies, I always had an out of memory error in caiman.motion_correction.apply_shifts_movie. Turns out here the movie is loaded twice onto the RAM when calling np.stack() I deleted the movie loaded in Y inside the function before the m_reg stack is created. Before this fix, movie took twice RAM space when running caiman.motion_correction.apply_shifts_movie The code has been tested.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

Branching

Has your PR been tested?

If you're fixing a bug or introducing a new feature it is recommended you run the tests by typing

caimanmanager test

and

caimanmanager demotest

prior to submitting your pull request.

Please describe any additional tests that you ran to verify your changes. If they are fast you can also include them in the folder 'caiman/tests/and name themtest_***.py` so they can be included in our lists of tests.

deMalmazet commented 3 months ago

Thank you