Skip to content

Commit

Permalink
Group integrity (LorenFrankLab#1026)
Browse files Browse the repository at this point in the history
* restrict populate calls to sort interval

* prevent adding new pieces to existing groups in create functions

* update changelog

* fix lint

* fix lint version
  • Loading branch information
samuelbray32 authored Jul 15, 2024
1 parent d0ffae4 commit 2c7c988
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PositionGroup.alter()
`processes > 1` #1001
- Speed up fetch_nwb calls through merge tables #1017
- Allow `ModuleNotFoundError` or `ImportError` for optional dependencies #1023
- Ensure integrity of group tables #1026

### Pipelines

Expand Down
5 changes: 5 additions & 0 deletions src/spyglass/decoding/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def create_group(
"nwb_file_name": nwb_file_name,
"position_group_name": group_name,
}
if self & group_key:
raise ValueError(
f"Group {nwb_file_name}: {position_group_name} already exists",
"please delete the group before creating a new one",
)
self.insert1(
{
**group_key,
Expand Down
6 changes: 6 additions & 0 deletions src/spyglass/spikesorting/analysis/v1/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def create_group(
"nwb_file_name": nwb_file_name,
"unit_filter_params_name": unit_filter_params_name,
}
if self & group_key:
raise ValueError(
f"Group {nwb_file_name}: {group_name} already exists",
"please delete the group before creating a new one",
)

parts_insert = [{**key, **group_key} for key in keys]

self.insert1(
Expand Down
6 changes: 3 additions & 3 deletions src/spyglass/spikesorting/v0/spikesorting_populator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ def spikesorting_pipeline_populator(
)
SpikeSortingRecordingSelection.insert1(ssr_key, skip_duplicates=True)

SpikeSortingRecording.populate(interval_dict)
SpikeSortingRecording.populate(sort_dict)

# Artifact detection
logger.info("Running artifact detection")
artifact_keys = [
{**k, "artifact_params_name": artifact_parameters}
for k in (SpikeSortingRecordingSelection() & interval_dict).fetch("KEY")
for k in (SpikeSortingRecordingSelection() & sort_dict).fetch("KEY")
]
ArtifactDetectionSelection().insert(artifact_keys, skip_duplicates=True)
ArtifactDetection.populate(interval_dict)
ArtifactDetection.populate(sort_dict)

# Spike sorting
logger.info("Running spike sorting")
Expand Down
2 changes: 1 addition & 1 deletion src/spyglass/spikesorting/v1/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def set_group_by_shank(
Optional. If True, no sort groups are defined for unitrodes.
"""
# delete any current groups
# (SortGroup & {"nwb_file_name": nwb_file_name}).delete()
(SortGroup & {"nwb_file_name": nwb_file_name}).delete()
# get the electrodes from this NWB file
electrodes = (
Electrode()
Expand Down

0 comments on commit 2c7c988

Please sign in to comment.