diff --git a/CHANGELOG.md b/CHANGELOG.md index 23b6e84cc..4d2fa2741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ dj.FreeTable(dj.conn(), "common_session.session_group").drop() - Fix bug in `_compute_metric` #1099 - Fix bug in `insert_curation` returned key #1114 - Fix handling of waveform extraction sparse parameter #1132 + - Limit Artifact detection intervals to valid times #1196 ## [0.5.3] (August 27, 2024) diff --git a/src/spyglass/spikesorting/v0/spikesorting_artifact.py b/src/spyglass/spikesorting/v0/spikesorting_artifact.py index 71edc5de1..da46be139 100644 --- a/src/spyglass/spikesorting/v0/spikesorting_artifact.py +++ b/src/spyglass/spikesorting/v0/spikesorting_artifact.py @@ -276,7 +276,10 @@ def _get_artifact_times( for interval_idx, interval in enumerate(artifact_intervals): artifact_intervals_s[interval_idx] = [ valid_timestamps[interval[0]] - half_removal_window_s, - valid_timestamps[interval[1]] + half_removal_window_s, + np.minimum( + valid_timestamps[interval[1]] + half_removal_window_s, + valid_timestamps[-1], + ), ] # make the artifact intervals disjoint if len(artifact_intervals_s) > 1: diff --git a/src/spyglass/spikesorting/v1/artifact.py b/src/spyglass/spikesorting/v1/artifact.py index 14c82dba6..d795d94c9 100644 --- a/src/spyglass/spikesorting/v1/artifact.py +++ b/src/spyglass/spikesorting/v1/artifact.py @@ -308,7 +308,10 @@ def _get_artifact_times( ), np.searchsorted( valid_timestamps, - valid_timestamps[interval[1]] + half_removal_window_s, + np.minimum( + valid_timestamps[interval[1]] + half_removal_window_s, + valid_timestamps[-1], + ), ), ] artifact_intervals_s[interval_idx] = [