From 0dc4bd409f9f9a3fe28d5456e5bcbe01c3b53ee1 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Thu, 7 Aug 2025 15:44:56 -0400 Subject: [PATCH 1/5] Make sure parent directory exists --- src/spyglass/decoding/v1/clusterless.py | 1 + src/spyglass/decoding/v1/sorted_spikes.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/spyglass/decoding/v1/clusterless.py b/src/spyglass/decoding/v1/clusterless.py index baa281152..9433efa02 100644 --- a/src/spyglass/decoding/v1/clusterless.py +++ b/src/spyglass/decoding/v1/clusterless.py @@ -288,6 +288,7 @@ def make(self, key): / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" ) path_exists = results_path.exists() + results_path.parent.mkdir(parents=True, exist_ok=True) classifier.save_results( results, results_path, diff --git a/src/spyglass/decoding/v1/sorted_spikes.py b/src/spyglass/decoding/v1/sorted_spikes.py index 7b4ede194..71e1a6d74 100644 --- a/src/spyglass/decoding/v1/sorted_spikes.py +++ b/src/spyglass/decoding/v1/sorted_spikes.py @@ -245,6 +245,7 @@ def make(self, key): / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" ) path_exists = results_path.exists() + results_path.parent.mkdir(parents=True, exist_ok=True) classifier.save_results( results, results_path, From e97e48761af6425250a0072766443d2668e51686 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Fri, 8 Aug 2025 10:20:10 -0400 Subject: [PATCH 2/5] Create directory first --- src/spyglass/decoding/v1/clusterless.py | 11 +++++++---- src/spyglass/decoding/v1/sorted_spikes.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/spyglass/decoding/v1/clusterless.py b/src/spyglass/decoding/v1/clusterless.py index 9433efa02..9a2ef685b 100644 --- a/src/spyglass/decoding/v1/clusterless.py +++ b/src/spyglass/decoding/v1/clusterless.py @@ -279,16 +279,19 @@ def make(self, key): nwb_file_name = key["nwb_file_name"].replace("_.nwb", "") + # Make sure the results directory exists + results_dir = Path(config["SPYGLASS_ANALYSIS_DIR"]) / nwb_file_name + results_dir.parent.mkdir(parents=True, exist_ok=True) + # Generate a unique path for the results file path_exists = True while path_exists: results_path = ( - Path(config["SPYGLASS_ANALYSIS_DIR"]) - / nwb_file_name - / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" + results_dir / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" ) + # if the results_path already exists, try a different uuid path_exists = results_path.exists() - results_path.parent.mkdir(parents=True, exist_ok=True) + classifier.save_results( results, results_path, diff --git a/src/spyglass/decoding/v1/sorted_spikes.py b/src/spyglass/decoding/v1/sorted_spikes.py index 71e1a6d74..5c1cf2d89 100644 --- a/src/spyglass/decoding/v1/sorted_spikes.py +++ b/src/spyglass/decoding/v1/sorted_spikes.py @@ -236,16 +236,19 @@ def make(self, key): nwb_file_name = key["nwb_file_name"].replace("_.nwb", "") + # Make sure the results directory exists + results_dir = Path(config["SPYGLASS_ANALYSIS_DIR"]) / nwb_file_name + results_dir.parent.mkdir(parents=True, exist_ok=True) + # Generate a unique path for the results file path_exists = True while path_exists: results_path = ( - Path(config["SPYGLASS_ANALYSIS_DIR"]) - / nwb_file_name - / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" + results_dir / f"{nwb_file_name}_{str(uuid.uuid4())}.nc" ) + # if the results_path already exists, try a different uuid path_exists = results_path.exists() - results_path.parent.mkdir(parents=True, exist_ok=True) + classifier.save_results( results, results_path, From 2e39bb2f6d2c6590615029e4d97b360e0cf31792 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Fri, 8 Aug 2025 10:21:42 -0400 Subject: [PATCH 3/5] Fix directory --- src/spyglass/decoding/v1/clusterless.py | 2 +- src/spyglass/decoding/v1/sorted_spikes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spyglass/decoding/v1/clusterless.py b/src/spyglass/decoding/v1/clusterless.py index 9a2ef685b..6b0449591 100644 --- a/src/spyglass/decoding/v1/clusterless.py +++ b/src/spyglass/decoding/v1/clusterless.py @@ -281,7 +281,7 @@ def make(self, key): # Make sure the results directory exists results_dir = Path(config["SPYGLASS_ANALYSIS_DIR"]) / nwb_file_name - results_dir.parent.mkdir(parents=True, exist_ok=True) + results_dir.mkdir(parents=True, exist_ok=True) # Generate a unique path for the results file path_exists = True diff --git a/src/spyglass/decoding/v1/sorted_spikes.py b/src/spyglass/decoding/v1/sorted_spikes.py index 5c1cf2d89..9be6bdced 100644 --- a/src/spyglass/decoding/v1/sorted_spikes.py +++ b/src/spyglass/decoding/v1/sorted_spikes.py @@ -238,7 +238,7 @@ def make(self, key): # Make sure the results directory exists results_dir = Path(config["SPYGLASS_ANALYSIS_DIR"]) / nwb_file_name - results_dir.parent.mkdir(parents=True, exist_ok=True) + results_dir.mkdir(parents=True, exist_ok=True) # Generate a unique path for the results file path_exists = True From a2a6bac897fca8ba10a1a746a2bbbb44a13f4ffe Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Fri, 8 Aug 2025 10:23:37 -0400 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4dddf4ba..61be5b0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ When altering tables, import all foreign key references. - Thing --> +### Decoding + +- Ensure results directory is created if it doesn't exist #1362 + ## [0.5.5] (Aug 6, 2025) ### Infrastructure From f2fd46c5e8ff9a17050b80783d10437562b509d1 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Mon, 11 Aug 2025 11:10:06 -0400 Subject: [PATCH 5/5] Fix changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4910ab0c..ef0fd002a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ When altering tables, import all foreign key references. - Ensure results directory is created if it doesn't exist #1362 +### Spikesorting + +- Implement short-transaction `SpikeSortingRecording.make` for v0 #1338 + ## [0.5.5] (Aug 6, 2025) ### Infrastructure @@ -94,7 +98,6 @@ When altering tables, import all foreign key references. present in nwb file electrodes table #1310, #1334 - Ensure matching order of returned merge_ids and nwb files in `SortedSpikesGroup.fetch_spike_data` #1320 - - Implement short-transaction `SpikeSortingRecording.make` #1338 - Behavior - Implement pipeline for keypoint-moseq extraction of behavior syllables #1056 - LFP