Skip to content

Commit

Permalink
Merge branch 'master' into spikesorting_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khl02007 committed Jul 24, 2023
2 parents 79e842b + ecc3a0c commit 6f012fb
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 78 deletions.
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies:
- bottleneck
- ipympl
- tqdm
- nb_conda
- pyfftw<=0.12.0 # used by ghostipy. install from conda-forge so that it works on Mac ARM processors
- pip:
- pubnub<6.4.0
Expand Down
1 change: 0 additions & 1 deletion environment_position.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies:
- bottleneck
- ipympl
- tqdm
- nb_conda
- ffmpeg
- pytorch<1.12.0
- torchvision
Expand Down
2 changes: 2 additions & 0 deletions src/spyglass/lfp/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from spyglass.lfp.lfp_merge import LFPOutput
from spyglass.lfp.lfp_electrode import LFPElectrodeGroup
from spyglass.lfp.lfp_imported import ImportedLFP
57 changes: 57 additions & 0 deletions src/spyglass/lfp/lfp_electrode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import datajoint as dj

from spyglass.common.common_ephys import Electrode
from spyglass.common.common_session import Session

schema = dj.schema("lfp_electrode")


@schema
class LFPElectrodeGroup(dj.Manual):
definition = """
-> Session # the session to which this LFP belongs
lfp_electrode_group_name: varchar(200) # the name of this group of electrodes
"""

class LFPElectrode(dj.Part):
definition = """
-> LFPElectrodeGroup # the group of electrodes to be filtered
-> Electrode # the electrode to be filtered
"""

@staticmethod
def create_lfp_electrode_group(
nwb_file_name: str, group_name: str, electrode_list: list[int]
):
"""Adds an LFPElectrodeGroup and the individual electrodes
Parameters
----------
nwb_file_name : str
The name of the nwb file (e.g. the session)
group_name : str
The name of this group (< 200 char)
electrode_list : list
A list of the electrode ids to include in this group.
"""
# remove the session and then recreate the session and Electrode list
# check to see if the user allowed the deletion
key = {
"nwb_file_name": nwb_file_name,
"lfp_electrode_group_name": group_name,
}
LFPElectrodeGroup().insert1(key, skip_duplicates=True)

# TODO: do this in a better way
all_electrodes = (Electrode() & {"nwb_file_name": nwb_file_name}).fetch(
as_dict=True
)
primary_key = Electrode.primary_key
for e in all_electrodes:
# create a dictionary so we can insert the electrodes
if e["electrode_id"] in electrode_list:
lfpelectdict = {k: v for k, v in e.items() if k in primary_key}
lfpelectdict["lfp_electrode_group_name"] = group_name
LFPElectrodeGroup().LFPElectrode.insert1(
lfpelectdict, skip_duplicates=True
)
26 changes: 26 additions & 0 deletions src/spyglass/lfp/lfp_imported.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import datajoint as dj

from spyglass.common.common_interval import IntervalList
from spyglass.common.common_nwbfile import AnalysisNwbfile
from spyglass.common.common_session import Session
from spyglass.lfp.lfp_electrode import LFPElectrodeGroup

schema = dj.schema("lfp_imported")


@schema
class ImportedLFP(dj.Imported):
definition = """
-> Session # the session to which this LFP belongs
-> LFPElectrodeGroup # the group of electrodes to be filtered
-> IntervalList # the original set of times to be filtered
lfp_object_id: varchar(40) # the NWB object ID for loading this object from the file
---
lfp_sampling_rate: float # the sampling rate, in samples/sec
-> AnalysisNwbfile
"""

def make(self, key):
raise NotImplementedError(
"For `insert`, use `allow_direct_insert=True`"
)
7 changes: 4 additions & 3 deletions src/spyglass/lfp/lfp_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from spyglass.common.common_ephys import LFP as CommonLFP # noqa: F401
from spyglass.common.common_filter import FirFilterParameters # noqa: F401
from spyglass.common.common_interval import IntervalList # noqa: F401
from spyglass.lfp.v1.lfp import LFPV1, ImportedLFPV1 # noqa: F401
from spyglass.lfp.v1.lfp import LFPV1 # noqa: F401
from spyglass.lfp.lfp_imported import ImportedLFP # noqa: F401
from spyglass.utils.dj_merge_tables import _Merge

schema = dj.schema("lfp_merge")
Expand All @@ -25,11 +26,11 @@ class LFPV1(dj.Part):
-> LFPV1
"""

class ImportedLFPV1(dj.Part):
class ImportedLFP(dj.Part):
definition = """
-> master
---
-> ImportedLFPV1
-> ImportedLFP
"""

class CommonLFP(dj.Part):
Expand Down
1 change: 0 additions & 1 deletion src/spyglass/lfp/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# flake8: noqa
from spyglass.lfp.v1.lfp import (
LFPV1,
ImportedLFPV1,
LFPElectrodeGroup,
LFPSelection,
)
Expand Down
72 changes: 2 additions & 70 deletions src/spyglass/lfp/v1/lfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import pandas as pd

from spyglass.common.common_ephys import Electrode, Raw
from spyglass.common.common_ephys import Raw
from spyglass.lfp.lfp_electrode import LFPElectrodeGroup
from spyglass.common.common_filter import FirFilterParameters
from spyglass.common.common_interval import (
IntervalList,
Expand All @@ -20,57 +21,6 @@
MIN_LFP_INTERVAL_DURATION = 1.0 # 1 second minimum interval duration


@schema
class LFPElectrodeGroup(dj.Manual):
definition = """
-> Session # the session to which this LFP belongs
lfp_electrode_group_name: varchar(200) # the name of this group of electrodes
"""

class LFPElectrode(dj.Part):
definition = """
-> LFPElectrodeGroup # the group of electrodes to be filtered
-> Electrode # the electrode to be filtered
"""

@staticmethod
def create_lfp_electrode_group(
nwb_file_name: str, group_name: str, electrode_list: list[int]
):
"""Adds an LFPElectrodeGroup and the individual electrodes
Parameters
----------
nwb_file_name : str
The name of the nwb file (e.g. the session)
group_name : str
The name of this group (< 200 char)
electrode_list : list
A list of the electrode ids to include in this group.
"""
# remove the session and then recreate the session and Electrode list
# check to see if the user allowed the deletion
key = {
"nwb_file_name": nwb_file_name,
"lfp_electrode_group_name": group_name,
}
LFPElectrodeGroup().insert1(key, skip_duplicates=True)

# TODO: do this in a better way
all_electrodes = (Electrode() & {"nwb_file_name": nwb_file_name}).fetch(
as_dict=True
)
primary_key = Electrode.primary_key
for e in all_electrodes:
# create a dictionary so we can insert the electrodes
if e["electrode_id"] in electrode_list:
lfpelectdict = {k: v for k, v in e.items() if k in primary_key}
lfpelectdict["lfp_electrode_group_name"] = group_name
LFPElectrodeGroup().LFPElectrode.insert1(
lfpelectdict, skip_duplicates=True
)


@schema
class LFPSelection(dj.Manual):
"""The user's selection of LFP data to be filtered
Expand Down Expand Up @@ -226,21 +176,3 @@ def fetch1_dataframe(self, *attrs, **kwargs):
nwb_lfp["lfp"].data,
index=pd.Index(nwb_lfp["lfp"].timestamps, name="time"),
)


@schema
class ImportedLFPV1(dj.Imported):
definition = """
-> Session # the session to which this LFP belongs
-> LFPElectrodeGroup # the group of electrodes to be filtered
-> IntervalList # the original set of times to be filtered
lfp_object_id: varchar(40) # the NWB object ID for loading this object from the file
---
lfp_sampling_rate: float # the sampling rate, in samples/sec
-> AnalysisNwbfile
"""

def make(self, key):
raise NotImplementedError(
"For `insert`, use `allow_direct_insert=True`"
)
4 changes: 2 additions & 2 deletions src/spyglass/lfp_band/lfp_band_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import pandas as pd

from spyglass.lfp_band.v1.lfp_band import LFPBandV1 # noqa F401
from spyglass.utils.dj_merge_tables import Merge
from spyglass.utils.dj_merge_tables import _Merge

schema = dj.schema("lfp_band_merge")


@schema
class LFPBandOutput(Merge):
class LFPBandOutput(_Merge):
definition = """
merge_id: uuid
---
Expand Down

0 comments on commit 6f012fb

Please sign in to comment.