2024-07-31 08:27:45 +00:00
|
|
|
from typing import Tuple
|
2024-07-29 23:28:48 +00:00
|
|
|
|
2024-07-29 23:22:29 +00:00
|
|
|
import numpy as np
|
2024-07-29 23:28:48 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-07-31 08:13:31 +00:00
|
|
|
# FIXME: Make this just be the output of the provider by patching into import machinery
|
2024-07-29 23:28:48 +00:00
|
|
|
from nwb_linkml.models.pydantic.core.v2_7_0.namespace import (
|
2024-08-06 03:51:52 +00:00
|
|
|
Device,
|
|
|
|
DynamicTableRegion,
|
2024-07-29 23:28:48 +00:00
|
|
|
ElectricalSeries,
|
2024-07-31 08:13:31 +00:00
|
|
|
ElectrodeGroup,
|
2024-08-05 23:05:44 +00:00
|
|
|
ExtracellularEphysElectrodes,
|
2024-07-29 23:28:48 +00:00
|
|
|
)
|
2024-07-29 23:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2024-08-05 23:05:44 +00:00
|
|
|
def electrical_series() -> Tuple["ElectricalSeries", "ExtracellularEphysElectrodes"]:
|
2024-07-29 23:22:29 +00:00
|
|
|
"""
|
|
|
|
Demo electrical series with adjoining electrodes
|
|
|
|
"""
|
|
|
|
n_electrodes = 5
|
|
|
|
n_times = 100
|
2024-08-06 03:51:52 +00:00
|
|
|
data = np.arange(0, n_electrodes * n_times).reshape(n_times, n_electrodes).astype(float)
|
2024-07-29 23:22:29 +00:00
|
|
|
timestamps = np.linspace(0, 1, n_times)
|
|
|
|
|
2024-08-06 03:51:52 +00:00
|
|
|
device = Device(name="my electrode")
|
|
|
|
|
2024-07-31 08:13:31 +00:00
|
|
|
# electrode group is the physical description of the electrodes
|
|
|
|
electrode_group = ElectrodeGroup(
|
|
|
|
name="GroupA",
|
2024-08-06 03:51:52 +00:00
|
|
|
device=device,
|
|
|
|
description="an electrode group",
|
|
|
|
location="you know where it is",
|
2024-07-31 08:13:31 +00:00
|
|
|
)
|
|
|
|
|
2024-07-29 23:22:29 +00:00
|
|
|
# make electrodes tables
|
2024-08-05 23:05:44 +00:00
|
|
|
electrodes = ExtracellularEphysElectrodes(
|
2024-08-06 03:51:52 +00:00
|
|
|
description="idk these are also electrodes",
|
2024-07-29 23:28:48 +00:00
|
|
|
id=np.arange(0, n_electrodes),
|
2024-08-06 03:51:52 +00:00
|
|
|
x=np.arange(0, n_electrodes).astype(float),
|
|
|
|
y=np.arange(n_electrodes, n_electrodes * 2).astype(float),
|
2024-07-31 08:17:39 +00:00
|
|
|
group=[electrode_group] * n_electrodes,
|
2024-08-06 03:51:52 +00:00
|
|
|
group_name=[electrode_group.name] * n_electrodes,
|
|
|
|
location=[str(i) for i in range(n_electrodes)],
|
|
|
|
extra_column=["sup"] * n_electrodes,
|
|
|
|
)
|
|
|
|
|
|
|
|
electrical_series = ElectricalSeries(
|
|
|
|
name="my recording!",
|
|
|
|
electrodes=DynamicTableRegion(
|
|
|
|
table=electrodes, value=np.arange(0, n_electrodes), name="electrodes", description="hey"
|
|
|
|
),
|
|
|
|
timestamps=timestamps,
|
|
|
|
data=data,
|
2024-07-29 23:28:48 +00:00
|
|
|
)
|
2024-08-06 03:51:52 +00:00
|
|
|
return electrical_series, electrodes
|
|
|
|
|
|
|
|
|
|
|
|
def test_dynamictable_indexing(electrical_series):
|
|
|
|
"""
|
|
|
|
Can index values from a dynamictable
|
|
|
|
"""
|
|
|
|
series, electrodes = electrical_series
|
|
|
|
|
|
|
|
colnames = [
|
|
|
|
"id",
|
|
|
|
"x",
|
|
|
|
"y",
|
|
|
|
"group",
|
|
|
|
"group_name",
|
|
|
|
"location",
|
|
|
|
"extra_column",
|
|
|
|
]
|
|
|
|
dtypes = [
|
|
|
|
np.dtype("int64"),
|
|
|
|
np.dtype("float64"),
|
|
|
|
np.dtype("float64"),
|
|
|
|
] + ([np.dtype("O")] * 4)
|
|
|
|
|
|
|
|
row = electrodes[0]
|
|
|
|
# successfully get a single row :)
|
|
|
|
assert row.shape == (1, 7)
|
|
|
|
assert row.dtypes.values.tolist() == dtypes
|
|
|
|
assert row.columns.tolist() == colnames
|
|
|
|
|
|
|
|
# slice a range of rows
|
|
|
|
rows = electrodes[0:3]
|
|
|
|
assert rows.shape == (3, 7)
|
|
|
|
assert rows.dtypes.values.tolist() == dtypes
|
|
|
|
assert rows.columns.tolist() == colnames
|
|
|
|
|
|
|
|
# get a single column
|
|
|
|
col = electrodes["y"]
|
|
|
|
assert all(col == [5, 6, 7, 8, 9])
|
|
|
|
|
|
|
|
# get a single cell
|
|
|
|
val = electrodes[0, "y"]
|
|
|
|
assert val == 5
|
|
|
|
val = electrodes[0, 2]
|
|
|
|
assert val == 5
|
|
|
|
|
|
|
|
# get a slice of rows and columns
|
|
|
|
subsection = electrodes[0:3, 0:3]
|
|
|
|
assert subsection.shape == (3, 3)
|
|
|
|
assert subsection.columns.tolist() == colnames[0:3]
|
|
|
|
assert subsection.dtypes.values.tolist() == dtypes[0:3]
|
|
|
|
|
|
|
|
|
|
|
|
def test_dynamictable_append_column():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_dynamictable_append_row():
|
|
|
|
pass
|