Skip to content

Commit

Permalink
initial key decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbray32 committed Nov 26, 2024
1 parent 5e1d26d commit 19930b7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/spyglass/decoding/v1/clusterless.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import copy
import uuid
from functools import wraps
from pathlib import Path

import datajoint as dj
Expand All @@ -37,6 +38,26 @@
schema = dj.schema("decoding_clusterless_v1")


def classmethod_full_key_decorator(required_keys=[]):
def decorator(method):
@wraps(method)
def wrapper(cls, key=None, *args, **kwargs):
# Ensure key is not None
if key is None:
key = {}

# Check if required keys are in key, and fetch if not
if not all([k in key for k in required_keys]):
key = (cls() & key).fetch1("KEY")

# Call the original method with the modified key
return method(cls, key, *args, **kwargs)

return wrapper

return decorator


@schema
class UnitWaveformFeaturesGroup(SpyglassMixin, dj.Manual):
definition = """
Expand Down Expand Up @@ -467,6 +488,9 @@ def fetch_spike_data(key, filter_by_interval=True):
return new_spike_times, new_waveform_features

@classmethod
@classmethod_full_key_decorator(
required_keys=["nwb_file_name", "waveform_features_group_name"]
)
def get_spike_indicator(cls, key, time):
"""get spike indicator matrix for the group
Expand Down

0 comments on commit 19930b7

Please sign in to comment.