diff --git a/environment.yml b/environment.yml index db92fe90b..8031cd66c 100644 --- a/environment.yml +++ b/environment.yml @@ -21,8 +21,7 @@ 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 + - pyfftw<=0.12.0 # used by ghostipy. install from conda-forge so that it works on Mac ARM processors - pip: - pubnub<6.4.0 - git+https://github.com/SpikeInterface/spikeinterface.git diff --git a/environment_position.yml b/environment_position.yml index 7a1b6dad9..7a69bd751 100644 --- a/environment_position.yml +++ b/environment_position.yml @@ -35,7 +35,6 @@ dependencies: - bottleneck - ipympl - tqdm - - nb_conda - ffmpeg - pytorch<1.12.0 - torchvision diff --git a/src/spyglass/lfp/__init__.py b/src/spyglass/lfp/__init__.py index f0b973f5b..ec2198930 100644 --- a/src/spyglass/lfp/__init__.py +++ b/src/spyglass/lfp/__init__.py @@ -1 +1,3 @@ from spyglass.lfp.lfp_merge import LFPOutput +from spyglass.lfp.lfp_electrode import LFPElectrodeGroup +from spyglass.lfp.lfp_imported import ImportedLFP diff --git a/src/spyglass/lfp/lfp_electrode.py b/src/spyglass/lfp/lfp_electrode.py new file mode 100644 index 000000000..5e4f1b193 --- /dev/null +++ b/src/spyglass/lfp/lfp_electrode.py @@ -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 + ) diff --git a/src/spyglass/lfp/lfp_imported.py b/src/spyglass/lfp/lfp_imported.py new file mode 100644 index 000000000..bdb5f22da --- /dev/null +++ b/src/spyglass/lfp/lfp_imported.py @@ -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`" + ) diff --git a/src/spyglass/lfp/lfp_merge.py b/src/spyglass/lfp/lfp_merge.py index 6db8f8f85..36b0f696b 100644 --- a/src/spyglass/lfp/lfp_merge.py +++ b/src/spyglass/lfp/lfp_merge.py @@ -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") @@ -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): diff --git a/src/spyglass/lfp/v1/__init__.py b/src/spyglass/lfp/v1/__init__.py index 2530a2fc0..64ad9c72a 100644 --- a/src/spyglass/lfp/v1/__init__.py +++ b/src/spyglass/lfp/v1/__init__.py @@ -1,7 +1,6 @@ # flake8: noqa from spyglass.lfp.v1.lfp import ( LFPV1, - ImportedLFPV1, LFPElectrodeGroup, LFPSelection, ) diff --git a/src/spyglass/lfp/v1/lfp.py b/src/spyglass/lfp/v1/lfp.py index c44ff4986..109792d74 100644 --- a/src/spyglass/lfp/v1/lfp.py +++ b/src/spyglass/lfp/v1/lfp.py @@ -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, @@ -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 @@ -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`" - ) diff --git a/src/spyglass/lfp_band/v1/lfp_band.py b/src/spyglass/lfp_band/v1/lfp_band.py index 0077bc7d0..f439e3523 100644 --- a/src/spyglass/lfp_band/v1/lfp_band.py +++ b/src/spyglass/lfp_band/v1/lfp_band.py @@ -383,10 +383,8 @@ def fetch1_dataframe(self, *attrs, **kwargs): """Fetches the filtered data as a dataframe""" filtered_nwb = self.fetch_nwb()[0] return pd.DataFrame( - filtered_nwb["filtered_data"].data, - index=pd.Index( - filtered_nwb["filtered_data"].timestamps, name="time" - ), + filtered_nwb["lfp_band"].data, + index=pd.Index(filtered_nwb["lfp_band"].timestamps, name="time"), ) def compute_analytic_signal(self, electrode_list: list[int], **kwargs): @@ -408,7 +406,7 @@ def compute_analytic_signal(self, electrode_list: list[int], **kwargs): If any electrodes passed to electrode_list are invalid for the dataset """ - filtered_band = self.fetch_nwb()[0]["filtered_data"] + filtered_band = self.fetch_nwb()[0]["lfp_band"] electrode_index = np.isin( filtered_band.electrodes.data[:], electrode_list )