From d76ecdb217ed1bf2cc58ce20145584657ecd4de2 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 27 Sep 2023 16:01:54 +0200 Subject: [PATCH 1/7] add check on electrical series dtype --- src/nwbinspector/checks/ecephys.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/nwbinspector/checks/ecephys.py b/src/nwbinspector/checks/ecephys.py index 5044bd8d..afdaffaf 100644 --- a/src/nwbinspector/checks/ecephys.py +++ b/src/nwbinspector/checks/ecephys.py @@ -79,3 +79,16 @@ def check_spike_times_not_in_unobserved_interval(units_table: Units, nunits: int "observed intervals." ) ) + + +@register_check(importance=Importance.CRITICAL, neurodata_type=ElectricalSeries) +def check_electrical_series_dtype(electrical_series: ElectricalSeries): + data = electrical_series.data + if ( + np.issubdtype(data.dtype, np.integer) + and electrical_series.conversion == electrical_series.DEFAULT_CONVERSION + and electrical_series.offset == electrical_series.DEFAULT_OFFSET + ): + return InspectorMessage( + message="ElectricalSeries data type is integer and conversion factor and offset are both default, the value may not be in the correct unit" + ) From bcf15548bb2e83ed4b0697cf1900ee838a730b42 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 27 Sep 2023 16:02:05 +0200 Subject: [PATCH 2/7] add unit tests --- tests/unit_tests/test_ecephys.py | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/unit_tests/test_ecephys.py b/tests/unit_tests/test_ecephys.py index ccd3ab63..d8bb5cba 100644 --- a/tests/unit_tests/test_ecephys.py +++ b/tests/unit_tests/test_ecephys.py @@ -15,6 +15,7 @@ check_electrical_series_dims, check_electrical_series_reference_electrodes_table, check_spike_times_not_in_unobserved_interval, + check_electrical_series_dtype, ) @@ -155,6 +156,76 @@ def test_trigger_check_electrical_series_reference_electrodes_table(self): == "electrodes does not reference an electrodes table." ) + def test_check_electrical_series_dtype_pass(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=float), + electrodes=electrodes, + rate=30.0, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + + def test_check_electrical_series_dtype_fail(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) == InspectorMessage( + message=( + "ElectricalSeries data type is integer and conversion factor and offset are both default, the value may not be in the correct unit" + ), + importance=Importance.CRITICAL, + check_function_name="check_electrical_series_dtype", + object_type="ElectricalSeries", + object_name="elec_series", + ) + + def test_check_electrical_series_dtype_non_default_conversion_skip(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + conversion=0.1, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + + def test_check_electrical_series_dtype_non_default_offet_skip(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + offset=0.1, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + def test_check_spike_times_not_in_unobserved_interval_pass(): units_table = Units(name="TestUnits") From 6f892a056c9b35d7d6cfab02d8f6c30873a42060 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 27 Sep 2023 16:30:12 +0200 Subject: [PATCH 3/7] update CHENGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b407d934..e67e3f35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Upcoming +### New Checks + +* Add `check_electrical_series_dtype` [#395](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/395) + # v0.4.30 ### Fixes From da6afa0577c137c8f9224b2059c1b85cbbc7bb29 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani <55453048+alessandratrapani@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:12:45 +0200 Subject: [PATCH 4/7] change check function Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- src/nwbinspector/checks/ecephys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nwbinspector/checks/ecephys.py b/src/nwbinspector/checks/ecephys.py index afdaffaf..d853993d 100644 --- a/src/nwbinspector/checks/ecephys.py +++ b/src/nwbinspector/checks/ecephys.py @@ -82,7 +82,7 @@ def check_spike_times_not_in_unobserved_interval(units_table: Units, nunits: int @register_check(importance=Importance.CRITICAL, neurodata_type=ElectricalSeries) -def check_electrical_series_dtype(electrical_series: ElectricalSeries): +def check_electrical_series_conversion_factors(electrical_series: ElectricalSeries): data = electrical_series.data if ( np.issubdtype(data.dtype, np.integer) From 84e524693761ed58906b97b116b89235ee224ce1 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani <55453048+alessandratrapani@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:14:49 +0200 Subject: [PATCH 5/7] explicit float type in test Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- tests/unit_tests/test_ecephys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_ecephys.py b/tests/unit_tests/test_ecephys.py index d8bb5cba..0e5f417b 100644 --- a/tests/unit_tests/test_ecephys.py +++ b/tests/unit_tests/test_ecephys.py @@ -162,7 +162,7 @@ def test_check_electrical_series_dtype_pass(self): electrical_series = ElectricalSeries( name="elec_series", description="desc", - data=np.ones((100, 5), dtype=float), + data=np.ones((100, 5), dtype=np.dtype("float64")), electrodes=electrodes, rate=30.0, ) From f84326e910ad4a193c8a631478245b84043da0f7 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani <55453048+alessandratrapani@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:15:34 +0200 Subject: [PATCH 6/7] Update CHANGELOG.md Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67e3f35..fbb06d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### New Checks -* Add `check_electrical_series_dtype` [#395](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/395) +* Added `check_electrical_series_conversion_factors` for ensuring non-default conversion/offset factors of any `ElectricalSeries` that has an integer data type. [#395](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/395) # v0.4.30 From bf3d77e77e4f9af873d8aff49f360e592a2aa8e0 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 27 Sep 2023 19:18:12 +0200 Subject: [PATCH 7/7] update test functions --- tests/unit_tests/test_ecephys.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_ecephys.py b/tests/unit_tests/test_ecephys.py index 0e5f417b..3cd47f71 100644 --- a/tests/unit_tests/test_ecephys.py +++ b/tests/unit_tests/test_ecephys.py @@ -15,7 +15,7 @@ check_electrical_series_dims, check_electrical_series_reference_electrodes_table, check_spike_times_not_in_unobserved_interval, - check_electrical_series_dtype, + check_electrical_series_conversion_factors, ) @@ -169,7 +169,7 @@ def test_check_electrical_series_dtype_pass(self): self.nwbfile.add_acquisition(electrical_series) - assert check_electrical_series_dtype(electrical_series) is None + assert check_electrical_series_conversion_factors(electrical_series) is None def test_check_electrical_series_dtype_fail(self): electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") @@ -184,7 +184,7 @@ def test_check_electrical_series_dtype_fail(self): self.nwbfile.add_acquisition(electrical_series) - assert check_electrical_series_dtype(electrical_series) == InspectorMessage( + assert check_electrical_series_conversion_factors(electrical_series) == InspectorMessage( message=( "ElectricalSeries data type is integer and conversion factor and offset are both default, the value may not be in the correct unit" ), @@ -208,7 +208,7 @@ def test_check_electrical_series_dtype_non_default_conversion_skip(self): self.nwbfile.add_acquisition(electrical_series) - assert check_electrical_series_dtype(electrical_series) is None + assert check_electrical_series_conversion_factors(electrical_series) is None def test_check_electrical_series_dtype_non_default_offet_skip(self): electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") @@ -224,7 +224,7 @@ def test_check_electrical_series_dtype_non_default_offet_skip(self): self.nwbfile.add_acquisition(electrical_series) - assert check_electrical_series_dtype(electrical_series) is None + assert check_electrical_series_conversion_factors(electrical_series) is None def test_check_spike_times_not_in_unobserved_interval_pass():