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

[New Check]: Add check electricalseries of dtype int16 #408

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upcoming

### New Checks

* Add `check_electrical_series_dtype` [#395](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/395)
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved

# v0.4.30

### Fixes
Expand Down
13 changes: 13 additions & 0 deletions src/nwbinspector/checks/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved
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"
)
71 changes: 71 additions & 0 deletions tests/unit_tests/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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),
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved
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")
Expand Down
Loading