From 070ca34588a1647f8b4128b7af6bc29e402519d0 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:05:40 -0400 Subject: [PATCH 01/21] debug customization for run conversion --- src/neuroconv/nwbconverter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/neuroconv/nwbconverter.py b/src/neuroconv/nwbconverter.py index 2a354b6e6..a69ae57f9 100644 --- a/src/neuroconv/nwbconverter.py +++ b/src/neuroconv/nwbconverter.py @@ -220,10 +220,9 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: - if backend_configuration is None: - # Otherwise assume the data has already been added to the NWBFile - self.add_to_nwbfile(nwbfile_out, metadata=metadata, conversion_options=conversion_options) + self.add_to_nwbfile(nwbfile_out, metadata=metadata, conversion_options=conversion_options) + if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) configure_backend(nwbfile=nwbfile_out, backend_configuration=backend_configuration) From 27897dbb2b1e93e614b0527e6282272fa459a8bf Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:32:08 -0400 Subject: [PATCH 02/21] protect non-None passed file --- src/neuroconv/nwbconverter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/neuroconv/nwbconverter.py b/src/neuroconv/nwbconverter.py index a69ae57f9..c524c74ba 100644 --- a/src/neuroconv/nwbconverter.py +++ b/src/neuroconv/nwbconverter.py @@ -220,7 +220,8 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: - self.add_to_nwbfile(nwbfile_out, metadata=metadata, conversion_options=conversion_options) + if nwbfile is not None: + self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, conversion_options=conversion_options) if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) From 723a1746bbde5bbecaa1a97af91d137e2f8dfe01 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:31:45 -0400 Subject: [PATCH 03/21] correct for mutation logic --- src/neuroconv/nwbconverter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/neuroconv/nwbconverter.py b/src/neuroconv/nwbconverter.py index c524c74ba..a460fe906 100644 --- a/src/neuroconv/nwbconverter.py +++ b/src/neuroconv/nwbconverter.py @@ -203,6 +203,7 @@ def run_conversion( conversion specification is requested. """ backend = _resolve_backend(backend, backend_configuration) + no_nwbfile_provided = nwbfile is None # Otherwise, variable reference may mutate later on inside the context if metadata is None: metadata = self.get_metadata() @@ -220,7 +221,7 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: - if nwbfile is not None: + if no_nwbfile_provided: self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, conversion_options=conversion_options) if backend_configuration is None: From a6fe35d939ab04b1af689500899c3c8ddcbdb760 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:07:01 -0400 Subject: [PATCH 04/21] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 628dd18fc..ec6778e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * Fixed a bug when adding ragged arrays to the electrode and units table. [PR #870](https://github.com/catalystneuro/neuroconv/pull/870) * Fixed a bug where `write_recording` will call an empty nwbfile when passing a path. [PR #877](https://github.com/catalystneuro/neuroconv/pull/877) * Fixed a bug that failed to properly include time alignment information in the output NWB file for objects added from any `RecordingInterface` in combination with `stub_test=True`. [PR #884](https://github.com/catalystneuro/neuroconv/pull/884) +* Fixed a bug that prevented passing `nwbfile=None` and a `backend_configuration` to `NWBConverter.run_conversion`. [PR #885](https://github.com/catalystneuro/neuroconv/pull/885) ### Improvements * Fixed docstrings related to backend configurations for various methods. [PR #822](https://github.com/catalystneuro/neuroconv/pull/822) From 17fbb02baac58d814cada99da59c05039d6661fc Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:08:12 -0400 Subject: [PATCH 05/21] mirror in base interface as well --- src/neuroconv/basedatainterface.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/neuroconv/basedatainterface.py b/src/neuroconv/basedatainterface.py index adb0528ce..192d30ed8 100644 --- a/src/neuroconv/basedatainterface.py +++ b/src/neuroconv/basedatainterface.py @@ -153,6 +153,7 @@ def run_conversion( " use DataInterface.add_to_nwbfile." ) backend = _resolve_backend(backend, backend_configuration) + no_nwbfile_provided = nwbfile is None # Otherwise, variable reference may mutate later on inside the context if metadata is None: metadata = self.get_metadata() @@ -165,10 +166,10 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: + if no_nwbfile_provided: + self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, conversion_options=conversion_options) + if backend_configuration is None: - # In this case, assume the relevant data has not been added to the NWBFile - self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) - backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) configure_backend(nwbfile=nwbfile_out, backend_configuration=backend_configuration) From 26b174641fe98942b068adbc8647d25d2f2e96ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:08:25 +0000 Subject: [PATCH 06/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/neuroconv/basedatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/basedatainterface.py b/src/neuroconv/basedatainterface.py index 192d30ed8..1658ba302 100644 --- a/src/neuroconv/basedatainterface.py +++ b/src/neuroconv/basedatainterface.py @@ -168,7 +168,7 @@ def run_conversion( ) as nwbfile_out: if no_nwbfile_provided: self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, conversion_options=conversion_options) - + if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) From 194a77de7d3147c1d8fd43f37e20661f31f32490 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:21:31 -0400 Subject: [PATCH 07/21] adjust passing of conversion options in interface --- src/neuroconv/basedatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/basedatainterface.py b/src/neuroconv/basedatainterface.py index 1658ba302..961e234ae 100644 --- a/src/neuroconv/basedatainterface.py +++ b/src/neuroconv/basedatainterface.py @@ -167,7 +167,7 @@ def run_conversion( verbose=getattr(self, "verbose", False), ) as nwbfile_out: if no_nwbfile_provided: - self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, conversion_options=conversion_options) + self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) From 2d3e44d22ccb1a90727284d30b04e2ab4671666d Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:00:33 -0400 Subject: [PATCH 08/21] fix interface behavior --- src/neuroconv/basedatainterface.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/neuroconv/basedatainterface.py b/src/neuroconv/basedatainterface.py index 961e234ae..3ebb5f1fa 100644 --- a/src/neuroconv/basedatainterface.py +++ b/src/neuroconv/basedatainterface.py @@ -153,7 +153,6 @@ def run_conversion( " use DataInterface.add_to_nwbfile." ) backend = _resolve_backend(backend, backend_configuration) - no_nwbfile_provided = nwbfile is None # Otherwise, variable reference may mutate later on inside the context if metadata is None: metadata = self.get_metadata() @@ -166,8 +165,8 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: - if no_nwbfile_provided: - self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) + # Unlike an NWBConverter, the interface usage always assumes you want to add the objects to the NWB file + self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) From 0bbdbddd41a2a283c2f7ad495a213001b93858ec Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:02:19 -0400 Subject: [PATCH 09/21] revert for consistency --- src/neuroconv/basedatainterface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/neuroconv/basedatainterface.py b/src/neuroconv/basedatainterface.py index 3ebb5f1fa..961e234ae 100644 --- a/src/neuroconv/basedatainterface.py +++ b/src/neuroconv/basedatainterface.py @@ -153,6 +153,7 @@ def run_conversion( " use DataInterface.add_to_nwbfile." ) backend = _resolve_backend(backend, backend_configuration) + no_nwbfile_provided = nwbfile is None # Otherwise, variable reference may mutate later on inside the context if metadata is None: metadata = self.get_metadata() @@ -165,8 +166,8 @@ def run_conversion( backend=backend, verbose=getattr(self, "verbose", False), ) as nwbfile_out: - # Unlike an NWBConverter, the interface usage always assumes you want to add the objects to the NWB file - self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) + if no_nwbfile_provided: + self.add_to_nwbfile(nwbfile=nwbfile_out, metadata=metadata, **conversion_options) if backend_configuration is None: backend_configuration = self.get_default_backend_configuration(nwbfile=nwbfile_out, backend=backend) From c947c74b04b40533ce24098fcded0ca311616749 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:04:36 -0400 Subject: [PATCH 10/21] adjust test --- tests/test_ecephys/test_mock_nidq_interface.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index bfe5ae0e6..51eddd366 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -1,3 +1,4 @@ +import pathlib from datetime import datetime from hdmf.testing import TestCase @@ -74,13 +75,13 @@ def test_mock_metadata(self): expected_start_time = datetime(2020, 11, 3, 10, 35, 10) assert metadata["NWBFile"]["session_start_time"] == expected_start_time - def test_mock_run_conversion(self): + def test_mock_run_conversion(self, tmpdir: pathlib.Path): interface = MockSpikeGLXNIDQInterface() metadata = interface.get_metadata() - nwbfile = mock_NWBFile() - interface.run_conversion(nwbfile=nwbfile, metadata=metadata) + nwbfile_path = tmpdir / "TestMockSpikeGLXNIDQInterface" / "test_mock_run_conversion.nwb" + interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata) assert "Neuropixel-Imec" in nwbfile.devices assert "NIDQChannelGroup" in nwbfile.electrode_groups From b8db570e617aa2736897030efcd5f5487fa0d589 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:51:23 -0400 Subject: [PATCH 11/21] undo unittest.TestCase --- .../test_ecephys/test_mock_nidq_interface.py | 142 +++++++++--------- 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 51eddd366..07482f466 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -8,82 +8,80 @@ from neuroconv.tools.testing import MockSpikeGLXNIDQInterface -class TestMockSpikeGLXNIDQInterface(TestCase): - maxDiff = None - - def test_current_default_inferred_ttl_times(self): - interface = MockSpikeGLXNIDQInterface() - - channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] - inferred_starting_times = list() - for channel_index, channel_name in enumerate(channel_names): - inferred_starting_times.append(interface.get_event_times_from_ttl(channel_name=channel_name)) - - expected_ttl_times = [[1.0 * (1 + 2 * period) + 0.1 * channel for period in range(3)] for channel in range(8)] - for channel_index, channel_name in enumerate(channel_names): - inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) - assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) - - def test_explicit_original_default_inferred_ttl_times(self): - interface = MockSpikeGLXNIDQInterface(signal_duration=7.0, ttl_times=None, ttl_duration=1.0) - - channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] - expected_ttl_times = [[1.0 * (1 + 2 * period) + 0.1 * channel for period in range(3)] for channel in range(8)] - for channel_index, channel_name in enumerate(channel_names): - inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) - assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) - - def test_custom_inferred_ttl_times(self): - custom_ttl_times = [[1.2], [3.6], [0.7, 4.5], [5.1]] - interface = MockSpikeGLXNIDQInterface(ttl_times=custom_ttl_times) - - channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3"] - for channel_index, channel_name in enumerate(channel_names): - inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) - assert_array_almost_equal(x=inferred_ttl_times, y=custom_ttl_times[channel_index], decimal=4) - - def test_mock_metadata(self): - interface = MockSpikeGLXNIDQInterface() - - metadata = interface.get_metadata() - - expected_ecephys_metadata = { - "Ecephys": { - "Device": [ - {"description": "no description", "manufacturer": "Imec", "name": "Neuropixel-Imec"}, - ], - "ElectrodeGroup": [ - { - "name": "NIDQChannelGroup", - "description": "A group representing the NIDQ channels.", - "device": "Neuropixel-Imec", - "location": "unknown", - }, - ], - "Electrodes": [ - {"name": "group_name", "description": "Name of the ElectrodeGroup this electrode is a part of."} - ], - "ElectricalSeriesNIDQ": { - "name": "ElectricalSeriesNIDQ", - "description": "Raw acquisition traces from the NIDQ (.nidq.bin) channels.", + +def test_current_default_inferred_ttl_times(self): + interface = MockSpikeGLXNIDQInterface() + + channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] + inferred_starting_times = list() + for channel_index, channel_name in enumerate(channel_names): + inferred_starting_times.append(interface.get_event_times_from_ttl(channel_name=channel_name)) + + expected_ttl_times = [[1.0 * (1 + 2 * period) + 0.1 * channel for period in range(3)] for channel in range(8)] + for channel_index, channel_name in enumerate(channel_names): + inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) + assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) + +def test_explicit_original_default_inferred_ttl_times(self): + interface = MockSpikeGLXNIDQInterface(signal_duration=7.0, ttl_times=None, ttl_duration=1.0) + + channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] + expected_ttl_times = [[1.0 * (1 + 2 * period) + 0.1 * channel for period in range(3)] for channel in range(8)] + for channel_index, channel_name in enumerate(channel_names): + inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) + assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) + +def test_custom_inferred_ttl_times(self): + custom_ttl_times = [[1.2], [3.6], [0.7, 4.5], [5.1]] + interface = MockSpikeGLXNIDQInterface(ttl_times=custom_ttl_times) + + channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3"] + for channel_index, channel_name in enumerate(channel_names): + inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) + assert_array_almost_equal(x=inferred_ttl_times, y=custom_ttl_times[channel_index], decimal=4) + +def test_mock_metadata(self): + interface = MockSpikeGLXNIDQInterface() + + metadata = interface.get_metadata() + + expected_ecephys_metadata = { + "Ecephys": { + "Device": [ + {"description": "no description", "manufacturer": "Imec", "name": "Neuropixel-Imec"}, + ], + "ElectrodeGroup": [ + { + "name": "NIDQChannelGroup", + "description": "A group representing the NIDQ channels.", + "device": "Neuropixel-Imec", + "location": "unknown", }, - } + ], + "Electrodes": [ + {"name": "group_name", "description": "Name of the ElectrodeGroup this electrode is a part of."} + ], + "ElectricalSeriesNIDQ": { + "name": "ElectricalSeriesNIDQ", + "description": "Raw acquisition traces from the NIDQ (.nidq.bin) channels.", + }, } - print(metadata["Ecephys"]) - self.assertDictEqual(d1=metadata["Ecephys"], d2=expected_ecephys_metadata["Ecephys"]) + } + print(metadata["Ecephys"]) + self.assertDictEqual(d1=metadata["Ecephys"], d2=expected_ecephys_metadata["Ecephys"]) - expected_start_time = datetime(2020, 11, 3, 10, 35, 10) - assert metadata["NWBFile"]["session_start_time"] == expected_start_time + expected_start_time = datetime(2020, 11, 3, 10, 35, 10) + assert metadata["NWBFile"]["session_start_time"] == expected_start_time - def test_mock_run_conversion(self, tmpdir: pathlib.Path): - interface = MockSpikeGLXNIDQInterface() +def test_mock_run_conversion(self, tmpdir: pathlib.Path): + interface = MockSpikeGLXNIDQInterface() - metadata = interface.get_metadata() + metadata = interface.get_metadata() - nwbfile_path = tmpdir / "TestMockSpikeGLXNIDQInterface" / "test_mock_run_conversion.nwb" - interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata) + nwbfile_path = tmpdir / "TestMockSpikeGLXNIDQInterface" / "test_mock_run_conversion.nwb" + interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata) - assert "Neuropixel-Imec" in nwbfile.devices - assert "NIDQChannelGroup" in nwbfile.electrode_groups - assert nwbfile.electrodes.id[:] == [0, 1, 2, 3, 4, 5, 6, 7] - assert "ElectricalSeriesNIDQ" in nwbfile.acquisition + assert "Neuropixel-Imec" in nwbfile.devices + assert "NIDQChannelGroup" in nwbfile.electrode_groups + assert nwbfile.electrodes.id[:] == [0, 1, 2, 3, 4, 5, 6, 7] + assert "ElectricalSeriesNIDQ" in nwbfile.acquisition From 4aeb979b40140f7a069617ae60f3e637fddafbe9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:51:34 +0000 Subject: [PATCH 12/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_ecephys/test_mock_nidq_interface.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 07482f466..a64dc3f61 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -8,7 +8,6 @@ from neuroconv.tools.testing import MockSpikeGLXNIDQInterface - def test_current_default_inferred_ttl_times(self): interface = MockSpikeGLXNIDQInterface() @@ -22,6 +21,7 @@ def test_current_default_inferred_ttl_times(self): inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) + def test_explicit_original_default_inferred_ttl_times(self): interface = MockSpikeGLXNIDQInterface(signal_duration=7.0, ttl_times=None, ttl_duration=1.0) @@ -31,6 +31,7 @@ def test_explicit_original_default_inferred_ttl_times(self): inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) + def test_custom_inferred_ttl_times(self): custom_ttl_times = [[1.2], [3.6], [0.7, 4.5], [5.1]] interface = MockSpikeGLXNIDQInterface(ttl_times=custom_ttl_times) @@ -40,6 +41,7 @@ def test_custom_inferred_ttl_times(self): inferred_ttl_times = interface.get_event_times_from_ttl(channel_name=channel_name) assert_array_almost_equal(x=inferred_ttl_times, y=custom_ttl_times[channel_index], decimal=4) + def test_mock_metadata(self): interface = MockSpikeGLXNIDQInterface() @@ -73,6 +75,7 @@ def test_mock_metadata(self): expected_start_time = datetime(2020, 11, 3, 10, 35, 10) assert metadata["NWBFile"]["session_start_time"] == expected_start_time + def test_mock_run_conversion(self, tmpdir: pathlib.Path): interface = MockSpikeGLXNIDQInterface() From 22dba430ea03661b96e9a615578ccf504a3e2568 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:34:58 -0400 Subject: [PATCH 13/21] remove self --- tests/test_ecephys/test_mock_nidq_interface.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index a64dc3f61..e8c2ec821 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -8,7 +8,7 @@ from neuroconv.tools.testing import MockSpikeGLXNIDQInterface -def test_current_default_inferred_ttl_times(self): +def test_current_default_inferred_ttl_times(): interface = MockSpikeGLXNIDQInterface() channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] @@ -22,7 +22,7 @@ def test_current_default_inferred_ttl_times(self): assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) -def test_explicit_original_default_inferred_ttl_times(self): +def test_explicit_original_default_inferred_ttl_times(): interface = MockSpikeGLXNIDQInterface(signal_duration=7.0, ttl_times=None, ttl_duration=1.0) channel_names = ["nidq#XA0", "nidq#XA1", "nidq#XA2", "nidq#XA3", "nidq#XA4", "nidq#XA5", "nidq#XA6", "nidq#XA7"] @@ -32,7 +32,7 @@ def test_explicit_original_default_inferred_ttl_times(self): assert_array_almost_equal(x=inferred_ttl_times, y=expected_ttl_times[channel_index], decimal=4) -def test_custom_inferred_ttl_times(self): +def test_custom_inferred_ttl_times(): custom_ttl_times = [[1.2], [3.6], [0.7, 4.5], [5.1]] interface = MockSpikeGLXNIDQInterface(ttl_times=custom_ttl_times) @@ -42,7 +42,7 @@ def test_custom_inferred_ttl_times(self): assert_array_almost_equal(x=inferred_ttl_times, y=custom_ttl_times[channel_index], decimal=4) -def test_mock_metadata(self): +def test_mock_metadata(): interface = MockSpikeGLXNIDQInterface() metadata = interface.get_metadata() @@ -76,7 +76,7 @@ def test_mock_metadata(self): assert metadata["NWBFile"]["session_start_time"] == expected_start_time -def test_mock_run_conversion(self, tmpdir: pathlib.Path): +def test_mock_run_conversion(tmpdir: pathlib.Path): interface = MockSpikeGLXNIDQInterface() metadata = interface.get_metadata() From b76d36f90cac7195eeacd584649567b1edbee63a Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:51:56 -0400 Subject: [PATCH 14/21] make parent folder first and overwrite if necessary --- .../test_ecephys/test_mock_nidq_interface.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index e8c2ec821..ea92c75d6 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -3,6 +3,7 @@ from hdmf.testing import TestCase from numpy.testing import assert_array_almost_equal +from pynwb import NWBHDF5IO from pynwb.testing.mock.file import mock_NWBFile from neuroconv.tools.testing import MockSpikeGLXNIDQInterface @@ -81,10 +82,16 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): metadata = interface.get_metadata() - nwbfile_path = tmpdir / "TestMockSpikeGLXNIDQInterface" / "test_mock_run_conversion.nwb" - interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata) + test_directory = tmpdir / "TestMockSpikeGLXNIDQInterface" + test_directory.mkdir(exist_ok=True) + nwbfile_path = test_directory / "test_mock_run_conversion.nwb" + interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) - assert "Neuropixel-Imec" in nwbfile.devices - assert "NIDQChannelGroup" in nwbfile.electrode_groups - assert nwbfile.electrodes.id[:] == [0, 1, 2, 3, 4, 5, 6, 7] - assert "ElectricalSeriesNIDQ" in nwbfile.acquisition + + with NWBHDF5IO(path=nwbfile_path, mode="r") as io: + nwbfile = io.read() + + assert "Neuropixel-Imec" in nwbfile.devices + assert "NIDQChannelGroup" in nwbfile.electrode_groups + assert nwbfile.electrodes.id[:] == [0, 1, 2, 3, 4, 5, 6, 7] + assert "ElectricalSeriesNIDQ" in nwbfile.acquisition From 1c1fb8f2e4288d4197c2eb142377a865db73818a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:52:35 +0000 Subject: [PATCH 15/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_ecephys/test_mock_nidq_interface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index ea92c75d6..5c7937ffc 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -87,7 +87,6 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): nwbfile_path = test_directory / "test_mock_run_conversion.nwb" interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) - with NWBHDF5IO(path=nwbfile_path, mode="r") as io: nwbfile = io.read() From 35f2606c6f2d5aacda6d67fbeb09a489a37dab1c Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:56:47 -0400 Subject: [PATCH 16/21] Update tests/test_ecephys/test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 5c7937ffc..7af2de6ba 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -71,7 +71,7 @@ def test_mock_metadata(): } } print(metadata["Ecephys"]) - self.assertDictEqual(d1=metadata["Ecephys"], d2=expected_ecephys_metadata["Ecephys"]) + assert metadata["Ecephys"] == expected_ecephys_metadata["Ecephys"] expected_start_time = datetime(2020, 11, 3, 10, 35, 10) assert metadata["NWBFile"]["session_start_time"] == expected_start_time From bfb3ab3dff16c1ae9040fcf5c13e999163154952 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:04:01 -0400 Subject: [PATCH 17/21] Update tests/test_ecephys/test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 7af2de6ba..b3fba81f1 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -83,7 +83,7 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): metadata = interface.get_metadata() test_directory = tmpdir / "TestMockSpikeGLXNIDQInterface" - test_directory.mkdir(exist_ok=True) + test_directory.mkdir(exists_ok=True) nwbfile_path = test_directory / "test_mock_run_conversion.nwb" interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) From f92c82207bde6133d5e312ecf40d23bbab1dce28 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:12:10 -0400 Subject: [PATCH 18/21] Update tests/test_ecephys/test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index b3fba81f1..7af2de6ba 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -83,7 +83,7 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): metadata = interface.get_metadata() test_directory = tmpdir / "TestMockSpikeGLXNIDQInterface" - test_directory.mkdir(exists_ok=True) + test_directory.mkdir(exist_ok=True) nwbfile_path = test_directory / "test_mock_run_conversion.nwb" interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) From bffd106e92ea69933ce7fc366ffb847d2b16c0d0 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:14:08 -0400 Subject: [PATCH 19/21] Update tests/test_ecephys/test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 7af2de6ba..617e684c0 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -82,7 +82,7 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): metadata = interface.get_metadata() - test_directory = tmpdir / "TestMockSpikeGLXNIDQInterface" + test_directory = pathllib.Path(tmpdir) / "TestMockSpikeGLXNIDQInterface" test_directory.mkdir(exist_ok=True) nwbfile_path = test_directory / "test_mock_run_conversion.nwb" interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) From e6930dcdfcb701395b7c1b8ce01fdc73ccf09eda Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:08:43 -0400 Subject: [PATCH 20/21] Update tests/test_ecephys/test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 617e684c0..134551546 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -82,7 +82,7 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): metadata = interface.get_metadata() - test_directory = pathllib.Path(tmpdir) / "TestMockSpikeGLXNIDQInterface" + test_directory = pathlib.Path(tmpdir) / "TestMockSpikeGLXNIDQInterface" test_directory.mkdir(exist_ok=True) nwbfile_path = test_directory / "test_mock_run_conversion.nwb" interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata, overwrite=True) From c221b5239350d0a861e7e1620778ea97debd6e4c Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:19:12 -0400 Subject: [PATCH 21/21] Update test_mock_nidq_interface.py --- tests/test_ecephys/test_mock_nidq_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ecephys/test_mock_nidq_interface.py b/tests/test_ecephys/test_mock_nidq_interface.py index 134551546..cd4287fc0 100644 --- a/tests/test_ecephys/test_mock_nidq_interface.py +++ b/tests/test_ecephys/test_mock_nidq_interface.py @@ -92,5 +92,5 @@ def test_mock_run_conversion(tmpdir: pathlib.Path): assert "Neuropixel-Imec" in nwbfile.devices assert "NIDQChannelGroup" in nwbfile.electrode_groups - assert nwbfile.electrodes.id[:] == [0, 1, 2, 3, 4, 5, 6, 7] + assert list(nwbfile.electrodes.id[:]) == [0, 1, 2, 3, 4, 5, 6, 7] assert "ElectricalSeriesNIDQ" in nwbfile.acquisition