Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second fix for NWB GUIDE nested converter stubbing #979

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Bug fixes
* Fixed the default naming of multiple electrical series in the `SpikeGLXConverterPipe`. [PR #957](https://github.com/catalystneuro/neuroconv/pull/957)
* Fixed an issue when passing conversion options to a sub-converter (like the popular `SpikeGLXConverterPipe`) nested inside another `NWBConverter`. [PR #979](https://github.com/catalystneuro/neuroconv/pull/979)

### Improvements
* The `OpenEphysBinaryRecordingInterface` now uses `lxml` for extracting the session start time from the settings.xml file and does not depend on `pyopenephys` anymore. [PR #971](https://github.com/catalystneuro/neuroconv/pull/971)
Expand Down
23 changes: 19 additions & 4 deletions src/neuroconv/nwbconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import warnings
from collections import Counter
from inspect import signature
from pathlib import Path
from typing import Dict, List, Literal, Optional, Tuple, Union

Expand Down Expand Up @@ -158,10 +159,24 @@ def create_nwbfile(self, metadata: Optional[dict] = None, conversion_options: Op

def add_to_nwbfile(self, nwbfile: NWBFile, metadata, conversion_options: Optional[dict] = None) -> None:
conversion_options = conversion_options or dict()
for interface_name, data_interface in self.data_interface_objects.items():
data_interface.add_to_nwbfile(
nwbfile=nwbfile, metadata=metadata, **conversion_options.get(interface_name, dict())
)
for interface_key, data_interface in self.data_interface_objects.items():
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(data_interface, NWBConverter):
subconverter_kwargs = dict(nwbfile=nwbfile, metadata=metadata)

# Certain subconverters fully expose control over their interfaces conversion options
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
# (such as iterator options, including progress bar details)
subconverter_keyword_arguments = list(signature(data_interface.add_to_nwbfile).parameters.keys())
if "conversion_options" in subconverter_keyword_arguments:
subconverter_kwargs["conversion_options"] = conversion_options.get(interface_key, None)
# Others do not, and instead expose simplified global keywords similar to a classic interface
else:
subconverter_kwargs.update(conversion_options.get(interface_key, dict()))

data_interface.add_to_nwbfile(**subconverter_kwargs)
else:
data_interface.add_to_nwbfile(
nwbfile=nwbfile, metadata=metadata, **conversion_options.get(interface_key, dict())
)

def run_conversion(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ class TestConverter(NWBConverter):
expected_session_start_time = datetime(2020, 11, 3, 10, 35, 10).astimezone()
self.assertNWBFileStructure(nwbfile_path=nwbfile_path, expected_session_start_time=expected_session_start_time)

def test_single_probe_spikeglx_converter_preview(self):
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
converter = SpikeGLXConverterPipe(folder_path=SPIKEGLX_PATH / "Noise4Sam_g0")

conversion_options = {
interface_key: {"stub_test": True} for interface_key in converter.data_interface_objects.keys()
}

nwbfile_path = self.tmpdir / "test_single_probe_spikeglx_converter_preview.nwb"
converter.run_conversion(nwbfile_path=nwbfile_path, conversion_options=conversion_options)

expected_session_start_time = datetime(2020, 11, 3, 10, 35, 10).astimezone()
self.assertNWBFileStructure(nwbfile_path=nwbfile_path, expected_session_start_time=expected_session_start_time)

with NWBHDF5IO(path=nwbfile_path) as io:
nwbfile = io.read()

assert nwbfile.acquisition["ElectricalSeriesAPImec0"].data.shape == (100, 384)
assert nwbfile.acquisition["ElectricalSeriesLFImec0"].data.shape == (100, 384)
assert nwbfile.acquisition["ElectricalSeriesNIDQ"].data.shape == (100, 9)


class TestMultiProbeSpikeGLXConverter(TestCase):
maxDiff = None
Expand Down
Loading