Skip to content

Commit

Permalink
Adding option to overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
yger committed Jun 26, 2024
1 parent 2867d7c commit 926afdb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 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,
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,13 @@ def correct_motion(

if folder is not None:
folder = Path(folder)
if overwrite:
if folder.exists():
import shutil
shutil.rmtree(folder)
else:
assert not folder.exists(), 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

0 comments on commit 926afdb

Please sign in to comment.