From 14b84cf93d09ba1029728a159fbc38b51f1ee09d Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 28 Mar 2024 10:16:53 +0100 Subject: [PATCH 1/3] propagate #2639 and #2625 --- src/spikeinterface/core/zarrextractors.py | 4 ++-- src/spikeinterface/extractors/nwbextractors.py | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/spikeinterface/core/zarrextractors.py b/src/spikeinterface/core/zarrextractors.py index 106f8ccc1e..a8a23b5863 100644 --- a/src/spikeinterface/core/zarrextractors.py +++ b/src/spikeinterface/core/zarrextractors.py @@ -381,7 +381,7 @@ def add_recording_to_zarr_group(recording: BaseRecording, zarr_group: zarr.hiera dataset_paths = [f"traces_seg{i}" for i in range(recording.get_num_segments())] zarr_kwargs["dtype"] = kwargs.get("dtype", None) or recording.get_dtype() - if "compressor" not in zarr_group: + if "compressor" not in zarr_kwargs: zarr_kwargs["compressor"] = get_default_zarr_compressor() add_traces_to_zarr( @@ -392,7 +392,7 @@ def add_recording_to_zarr_group(recording: BaseRecording, zarr_group: zarr.hiera **job_kwargs, ) - # # save probe + # save probe if recording.get_property("contact_vector") is not None: probegroup = recording.get_probegroup() zarr_group.attrs["probe"] = check_json(probegroup.to_dict(array_as_list=True)) diff --git a/src/spikeinterface/extractors/nwbextractors.py b/src/spikeinterface/extractors/nwbextractors.py index 287522a870..3234456e0f 100644 --- a/src/spikeinterface/extractors/nwbextractors.py +++ b/src/spikeinterface/extractors/nwbextractors.py @@ -10,15 +10,6 @@ from spikeinterface.core.core_tools import define_function_from_class -def import_lazily(): - "Makes annotations / typing available lazily" - global NWBFile, ElectricalSeries, Units, NWBHDF5IO - from pynwb import NWBFile - from pynwb.ecephys import ElectricalSeries - from pynwb.misc import Units - from pynwb import NWBHDF5IO - - def read_file_from_backend( *, file_path: str | Path | None, @@ -111,7 +102,7 @@ def read_nwbfile( cache: bool = False, stream_cache_path: str | Path | None = None, storage_options: dict | None = None, -) -> NWBFile: +) -> "NWBFile": """ Read an NWB file and return the NWBFile object. @@ -176,8 +167,8 @@ def read_nwbfile( def _retrieve_electrical_series_pynwb( - nwbfile: NWBFile, electrical_series_path: Optional[str] = None -) -> ElectricalSeries: + nwbfile: "NWBFile", electrical_series_path: Optional[str] = None +) -> "ElectricalSeries": """ Get an ElectricalSeries object from an NWBFile. @@ -230,7 +221,7 @@ def _retrieve_electrical_series_pynwb( return electrical_series -def _retrieve_unit_table_pynwb(nwbfile: NWBFile, unit_table_path: Optional[str] = None) -> Units: +def _retrieve_unit_table_pynwb(nwbfile: "NWBFile", unit_table_path: Optional[str] = None) -> "Units": """ Get an Units object from an NWBFile. Units tables can be either the main unit table (nwbfile.units) or in the processing module. From 9bb4b90a162c730c97a6df8a637f0aed0eec27bd Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 28 Mar 2024 10:24:30 +0100 Subject: [PATCH 2/3] Propagate #2637 --- src/spikeinterface/extractors/nwbextractors.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/extractors/nwbextractors.py b/src/spikeinterface/extractors/nwbextractors.py index 3234456e0f..09b462d5ae 100644 --- a/src/spikeinterface/extractors/nwbextractors.py +++ b/src/spikeinterface/extractors/nwbextractors.py @@ -559,8 +559,10 @@ def __init__( # fetch and add main recording properties if use_pynwb: gains, offsets, locations, groups = self._fetch_main_properties_pynwb() + self.extra_requirements.append("pynwb") else: gains, offsets, locations, groups = self._fetch_main_properties_backend() + self.extra_requirements.append("h5py") self.set_channel_gains(gains) self.set_channel_offsets(offsets) if locations is not None: @@ -772,8 +774,6 @@ def _fetch_other_properties(self, electrodes_table, electrodes_indices, columns) ######### # Extract and re-name properties from nwbfile TODO: Should be a function ######## - from pynwb.ecephys import ElectrodeGroup - properties = dict() properties_to_skip = [ "id", @@ -789,9 +789,7 @@ def _fetch_other_properties(self, electrodes_table, electrodes_indices, columns) for column in columns: first_value = electrodes_table[column][0] - if isinstance(first_value, ElectrodeGroup): - continue - elif column in properties_to_skip: + if column in properties_to_skip: continue else: column_name = rename_properties.get(column, column) @@ -1015,8 +1013,10 @@ def __init__( if load_unit_properties: if use_pynwb: columns = [c.name for c in self.units_table.columns] + self.extra_requirements.append("pynwb") else: columns = list(self.units_table.keys()) + self.extra_requirements.append("h5py") properties = self._fetch_properties(columns) for property_name, property_values in properties.items(): values = [x.decode("utf-8") if isinstance(x, bytes) else x for x in property_values] From 5c3345559103176bd1d6651717f26ca59dad54bc Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 28 Mar 2024 10:25:28 +0100 Subject: [PATCH 3/3] Bump up version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e147735523..2a2a072fc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "spikeinterface" -version = "0.100.1" +version = "0.100.3" authors = [ { name="Alessio Buccino", email="alessiop.buccino@gmail.com" }, { name="Samuel Garcia", email="sam.garcia.die@gmail.com" },