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]: Spike times are increasing #405

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
11 changes: 4 additions & 7 deletions src/nwbinspector/checks/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ def check_ascending_spike_times(units_table: Units):
"""Check that the values in the timestamps array are strictly increasing."""
if "spike_times" not in units_table:
return
differences = np.diff(np.asarray(units_table["spike_times"].target.data[:]))
if np.all(differences >= 0):
return InspectorMessage(
message=(
"This Units table contains spike times that are not ascending."
)
)
for spike_times_per_unit in units_table["spike_times"]:
differences_per_unit = np.diff(spike_times_per_unit)
if np.all(differences_per_unit >= 0):
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved
return InspectorMessage(message=("This Units table contains spike times that are not ascending."))
22 changes: 22 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_ascending_spike_times,
)


Expand Down Expand Up @@ -215,3 +216,24 @@ def test_check_spike_times_not_in_unobserved_interval_multiple_units():
object_name="TestUnits",
location="/",
)


def test_check_ascending_spike_times_pass():
units_table = Units()
units_table.add_unit(spike_times=[0.0, 0.1])
units_table.add_unit(spike_times=[1.0, 2.0])
assert check_ascending_spike_times(units_table=units_table) is None


def test_check_ascending_spike_times_fail():
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
units_table = Units(name="TestUnits")
units_table.add_unit(spike_times=[0.0, 0.1])
units_table.add_unit(spike_times=[2.0, 1.0])
assert check_ascending_spike_times(units_table=units_table) == InspectorMessage(
message=("This Units table contains spike times that are not ascending."),
importance=Importance.BEST_PRACTICE_VIOLATION,
check_function_name="check_ascending_spike_times",
object_type="Units",
object_name="TestUnits",
location="/",
)
Loading