Skip to content

Commit 1446caa

Browse files
authored
SpikeSortingRecording v0: generator, short-transation make (#1338)
* SpikeSortingRecording: generator, short-transation make * Update changelog * blackify * Update dj depencency to unreleased 0.14.5 * Add SpikeSortingRecording generator submethod docstrings * Fix docstrings: ',' -> ':'
1 parent 9c09021 commit 1446caa

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ When altering tables, import all foreign key references.
9090
present in nwb file electrodes table #1310, #1334
9191
- Ensure matching order of returned merge_ids and nwb files in
9292
`SortedSpikesGroup.fetch_spike_data` #1320
93+
- Implement short-transaction `SpikeSortingRecording.make` #1338
9394
- Behavior
9495
- Implement pipeline for keypoint-moseq extraction of behavior syllables #1056
9596
- LFP

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies = [
4040
"black[jupyter]",
4141
"bottleneck",
4242
"dask",
43-
"datajoint>=0.14.4",
43+
"datajoint>=0.14.5",
4444
# "ghostipy", # removed from list bc M1 users need to install pyfftw first
4545
"hdmf>=3.4.6",
4646
"ipympl",

src/spyglass/spikesorting/v0/spikesorting_recording.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
from shutil import rmtree as shutil_rmtree
3+
from typing import List, Tuple
34

45
import datajoint as dj
56
import numpy as np
@@ -312,7 +313,6 @@ class SpikeSortingRecordingSelection(SpyglassMixin, dj.Manual):
312313

313314
@schema
314315
class SpikeSortingRecording(SpyglassMixin, dj.Computed):
315-
316316
definition = """
317317
-> SpikeSortingRecordingSelection
318318
---
@@ -322,34 +322,68 @@ class SpikeSortingRecording(SpyglassMixin, dj.Computed):
322322
"""
323323

324324
_parallel_make = True
325-
_use_transaction, _allow_insert = False, True
326-
327-
def make(self, key):
328-
"""Populates the SpikeSortingRecording table with the recording data.
329-
330-
1. Fetches ...
331-
- Sort interval and parameters from SpikeSortingRecordingSelection
332-
and SpikeSortingPreprocessingParameters
333-
- Channel IDs and reference electrode from SortGroup, filtered by
334-
filtereing parameters
335-
2. Saves the recording data to the recording directory
336-
3. Inserts the path to the recording data into SpikeSortingRecording
325+
326+
def make_fetch(self, key: dict) -> List[Interval]:
327+
"""Fetch times for compute.
328+
329+
Parameters
330+
----------
331+
key: dict
332+
Key of SpikeSortingRecordingSelection table
333+
334+
Returns
335+
-------
336+
List[Interval]
337+
Sort Interval object, as a list of length 1
337338
"""
338-
rec_info = self._make_file(key)
339+
# make decomposes passed obj, so make it a list if only one item
340+
return [self._get_sort_interval_valid_times(key)]
341+
342+
def make_compute(
343+
self, key: dict, sort_interval_valid_times: Interval
344+
) -> Tuple[dict, Interval]:
345+
"""Run computation. Generate the file, set Interval key, prep insert.
346+
347+
Parameters
348+
----------
349+
key: dict
350+
Key of SpikeSortingRecordingSelection table
351+
sort_interval_valid_times, sort
352+
Interval object of the sort
339353
340-
sort_interval_valid_times = self._get_sort_interval_valid_times(key)
354+
Returns
355+
-------
356+
Tuple[dict, Interval]
357+
Dictionary of self-insert, and updated Interval object
358+
"""
359+
rec_info = self._make_file(key)
341360
sort_interval_valid_times.set_key(
342361
nwb_file_name=key["nwb_file_name"],
343362
interval_list_name=rec_info["name"],
344363
pipeline="spikesorting_recording_v0",
345364
)
346-
IntervalList.insert1(sort_interval_valid_times.as_dict, replace=True)
347-
348365
self_insert = dict(
349366
key,
350367
sort_interval_list_name=rec_info["name"],
351368
recording_path=rec_info["path"],
352369
)
370+
return self_insert, sort_interval_valid_times
371+
372+
def make_insert(
373+
self, key: dict, self_insert: dict, sort_interval_valid_times: Interval
374+
) -> None:
375+
"""Insert into self and IntervalList, document environment.
376+
377+
Parameters
378+
----------
379+
key: dict
380+
Key of SpikeSortingRecordingSelection table
381+
self_insert: dict
382+
Dict of keys for this table
383+
sort_interval_valid_times: sort
384+
Interval object of the sort
385+
"""
386+
IntervalList.insert1(sort_interval_valid_times.as_dict, replace=True)
353387
self.insert1(self_insert)
354388
self._record_environment(self_insert)
355389

0 commit comments

Comments
 (0)