Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to overwrite while doing correct_motion and saving to a folder #3088

Merged
merged 15 commits into from
Jul 2, 2024
Merged
11 changes: 11 additions & 0 deletions src/spikeinterface/preprocessing/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def correct_motion(
recording,
preset="nonrigid_accurate",
folder=None,
overwrite=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not consistent with some otherplace in spikeinterface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use it at many places! Save, analyzers, etc..

Only in run sorter this is different...

output_motion_info=False,
detect_kwargs={},
select_kwargs={},
Expand Down Expand Up @@ -253,6 +254,8 @@ def correct_motion(
The preset name
folder : Path str or None, default: None
If not None then intermediate motion info are saved into a folder
overwrite : bool, default False
If folder is not None and already existing, should we overwrite
output_motion_info : bool, default: False
If True, then the function returns a `motion_info` dictionary that contains variables
to check intermediate steps (motion_histogram, non_rigid_windows, pairwise_displacement)
Expand Down Expand Up @@ -316,6 +319,14 @@ def correct_motion(

if folder is not None:
folder = Path(folder)
if overwrite:
if folder.is_dir():
import shutil

shutil.rmtree(folder)
else:
assert not folder.is_dir(), f"Folder {folder} already exists"

folder.mkdir(exist_ok=True, parents=True)

(folder / "parameters.json").write_text(json.dumps(parameters, indent=4, cls=SIJsonEncoder), encoding="utf8")
Expand Down
Loading