Skip to content

Commit

Permalink
Fix relative_position_in_mm should be in um
Browse files Browse the repository at this point in the history
  • Loading branch information
rly committed Jul 22, 2024
1 parent fd700a6 commit 3151258
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ classDiagram
columns
--------------------------------------
id : VectorData[int]
relative_position_in_mm : List[Tuple[float, float], Tuple[float, float, float]]
relative_position_in_um : List[Tuple[float, float], Tuple[float, float, float]]
--> reference : str, optional
contact_id : VectorData[str], optional
shank_id : VectorData[str], optional
Expand Down
4 changes: 2 additions & 2 deletions spec/ndx-extracellular-channels.extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ groups:
doc: Metadata about the contacts of a probe, compatible with the ProbeInterface
specification.
datasets:
- name: relative_position_in_mm
- name: relative_position_in_um
neurodata_type_inc: VectorData
dtype: float
dims:
Expand All @@ -18,7 +18,7 @@ groups:
- 2
- - null
- 3
doc: Relative position of the contact in millimeters, relative to `reference`.
doc: Relative position of the contact in micrometers, relative to `reference`.
attributes:
- name: reference
dtype: text
Expand Down
6 changes: 3 additions & 3 deletions src/pynwb/ndx_extracellular_channels/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def to_probeinterface(ndx_probe: ndx_extracellular_channels.Probe) -> probeinter
ndx_extracellular_channels.Probe.probe_model.manufacturer -> probeinterface.Probe.manufacturer
ndx_extracellular_channels.Probe.probe_model.ndim -> probeinterface.Probe.ndim
ndx_extracellular_channels.Probe.probe_model.planar_contour_in_um -> probeinterface.Probe.probe_planar_contour
ndx_extracellular_channels.Probe.probe_model.contacts_table["relative_position_in_mm"] ->
ndx_extracellular_channels.Probe.probe_model.contacts_table["relative_position_in_um"] ->
probeinterface.Probe.contact_positions
ndx_extracellular_channels.Probe.probe_model.contacts_table["shape"] -> probeinterface.Probe.contact_shapes
ndx_extracellular_channels.Probe.probe_model.contacts_table["contact_id"] -> probeinterface.Probe.contact_ids
Expand Down Expand Up @@ -121,7 +121,7 @@ def to_probeinterface(ndx_probe: ndx_extracellular_channels.Probe) -> probeinter
possible_shape_keys = ["radius_in_um", "width_in_um", "height_in_um"]
contacts_table = ndx_probe.probe_model.contacts_table

positions.append(contacts_table["relative_position_in_mm"][:])
positions.append(contacts_table["relative_position_in_um"][:])
shapes.append(contacts_table["shape"][:])
if "contact_id" in contacts_table.colnames:
if contact_ids is None:
Expand Down Expand Up @@ -198,7 +198,7 @@ def _single_probe_to_ndx_probe(

for index in np.arange(probe.get_contact_count()):
kwargs = dict(
relative_position_in_mm=probe.contact_positions[index],
relative_position_in_um=probe.contact_positions[index],
plane_axes=probe.contact_plane_axes[index],
shape=contacts_arr["contact_shapes"][index],
)
Expand Down
32 changes: 16 additions & 16 deletions src/pynwb/tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_constructor_add_row(self):

# for testing, mix and match different shapes. np.nan means the radius/width/height does not apply
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
contact_id="C1",
shank_id="shank0",
Expand All @@ -45,7 +45,7 @@ def test_constructor_add_row(self):
)

ct.add_row(
relative_position_in_mm=[20.0, 10.0],
relative_position_in_um=[20.0, 10.0],
shape="square",
contact_id="C2",
shank_id="shank0",
Expand All @@ -57,13 +57,13 @@ def test_constructor_add_row(self):

# TODO might be nice to put this on the constructor of ContactsTable as relative_position__reference
# without using a custom mapper
ct["relative_position_in_mm"].reference = "The bottom tip of the probe"
ct["relative_position_in_um"].reference = "The bottom tip of the probe"

assert ct.name == "ContactsTable"
assert ct.description == "Test contacts table"
assert ct["relative_position_in_mm"].reference == "The bottom tip of the probe"
assert ct["relative_position_in_um"].reference == "The bottom tip of the probe"

assert ct["relative_position_in_mm"].data == [[10.0, 10.0], [20.0, 10.0]]
assert ct["relative_position_in_um"].data == [[10.0, 10.0], [20.0, 10.0]]
assert ct["shape"].data == ["circle", "square"]
assert ct["contact_id"].data == ["C1", "C2"]
assert ct["shank_id"].data == ["shank0", "shank0"]
Expand All @@ -89,7 +89,7 @@ def addContainer(self):

# for testing, mix and match different shapes. np.nan means the radius/width/height does not apply
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
contact_id="C1",
shank_id="shank0",
Expand All @@ -100,7 +100,7 @@ def addContainer(self):
)

ct.add_row(
relative_position_in_mm=[20.0, 10.0],
relative_position_in_um=[20.0, 10.0],
shape="square",
contact_id="C2",
shank_id="shank0",
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_constructor(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand All @@ -155,7 +155,7 @@ def test_constructor_no_name(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand All @@ -181,7 +181,7 @@ def addContainer(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand Down Expand Up @@ -329,7 +329,7 @@ def test_constructor_minimal(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand Down Expand Up @@ -360,7 +360,7 @@ def test_constructor(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand Down Expand Up @@ -398,7 +398,7 @@ def addContainer(self):
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand Down Expand Up @@ -432,15 +432,15 @@ def _create_test_probe():
description="Test contacts table",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)
ct.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
)

Expand Down
6 changes: 3 additions & 3 deletions src/pynwb/tests/test_example_usage_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_all_classes():
)
# for demonstration, mix and match different shapes. np.nan means the radius/width/height does not apply
contacts_table.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
contact_id="C1",
shank_id="shank0",
plane_axes=[[1.0, 0.0], [0.0, 1.0]],
Expand All @@ -40,7 +40,7 @@ def test_all_classes():
height_in_um=np.nan,
)
contacts_table.add_row(
relative_position_in_mm=[20.0, 10.0],
relative_position_in_um=[20.0, 10.0],
contact_id="C2",
shank_id="shank0",
plane_axes=[[1 / np.sqrt(2), 1 / np.sqrt(2)], [-1 / np.sqrt(2), 1 / np.sqrt(2)]],
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_all_classes():

assert read_contacts_table.name == "contacts_table"
assert read_contacts_table.description == "Test contacts table"
npt.assert_array_equal(read_contacts_table["relative_position_in_mm"].data[:], [[10.0, 10.0], [20.0, 10.0]])
npt.assert_array_equal(read_contacts_table["relative_position_in_um"].data[:], [[10.0, 10.0], [20.0, 10.0]])
npt.assert_array_equal(read_contacts_table["shape"].data[:], ["circle", "square"])
npt.assert_array_equal(read_contacts_table["contact_id"].data[:], ["C1", "C2"])
npt.assert_array_equal(read_contacts_table["shank_id"].data[:], ["shank0", "shank0"])
Expand Down
22 changes: 11 additions & 11 deletions src/pynwb/tests/test_example_usage_probeinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_from_probeinterface():
assert nwbfile.devices["probe0"].probe_model.manufacturer == "Neuronexus"
assert nwbfile.devices["probe0"].probe_model.ndim == 2
npt.assert_array_equal(nwbfile.devices["probe0"].probe_model.planar_contour_in_um, polygon)
npt.assert_allclose(nwbfile.devices["probe0"].probe_model.contacts_table.relative_position_in_mm, positions)
npt.assert_allclose(nwbfile.devices["probe0"].probe_model.contacts_table.relative_position_in_um, positions)
npt.assert_array_equal(nwbfile.devices["probe0"].probe_model.contacts_table["shape"].data[:], "circle")
npt.assert_array_equal(nwbfile.devices["probe0"].probe_model.contacts_table["radius_in_um"].data[:], 5.0)

Expand All @@ -124,7 +124,7 @@ def test_from_probeinterface():
assert nwbfile.devices["probe1"].probe_model.ndim == 2
npt.assert_allclose(nwbfile.devices["probe1"].probe_model.planar_contour_in_um, probe1.probe_planar_contour)
npt.assert_allclose(
nwbfile.devices["probe1"].probe_model.contacts_table.relative_position_in_mm, probe1.contact_positions
nwbfile.devices["probe1"].probe_model.contacts_table.relative_position_in_um, probe1.contact_positions
)
npt.assert_array_equal(nwbfile.devices["probe1"].probe_model.contacts_table["shape"].data[:], "circle")
npt.assert_array_equal(
Expand All @@ -138,7 +138,7 @@ def test_from_probeinterface():
assert nwbfile.devices["probe2"].probe_model.ndim == 2
npt.assert_allclose(nwbfile.devices["probe2"].probe_model.planar_contour_in_um, probe2.probe_planar_contour)
npt.assert_allclose(
nwbfile.devices["probe2"].probe_model.contacts_table.relative_position_in_mm, probe2.contact_positions
nwbfile.devices["probe2"].probe_model.contacts_table.relative_position_in_um, probe2.contact_positions
)
npt.assert_array_equal(nwbfile.devices["probe2"].probe_model.contacts_table["shape"].data[:], "square")
npt.assert_array_equal(
Expand All @@ -154,7 +154,7 @@ def test_from_probeinterface():
nwbfile.devices["renamed_probe3"].probe_model.planar_contour_in_um, probe3.probe_planar_contour
)
npt.assert_allclose(
nwbfile.devices["renamed_probe3"].probe_model.contacts_table.relative_position_in_mm,
nwbfile.devices["renamed_probe3"].probe_model.contacts_table.relative_position_in_um,
probe3.contact_positions,
)
npt.assert_array_equal(nwbfile.devices["renamed_probe3"].probe_model.contacts_table["shape"].data[:], "circle")
Expand Down Expand Up @@ -184,8 +184,8 @@ def test_to_probeinterface():
description="a table with electrode contacts",
columns=[
pynwb.core.VectorData(
name="relative_position_in_mm",
description="the relative position of the contact in mm",
name="relative_position_in_um",
description="the relative position of the contact in micrometers",
data=[
(0.0, 0.0),
(0.0, 20.0),
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_to_probeinterface():
assert pi_probe0.serial_number == "0123"
assert pi_probe0.model_name == "a1x32-edge-5mm-20-177_H32"
assert pi_probe0.manufacturer == "Neuronexus"
npt.assert_array_equal(pi_probe0.contact_positions, probe_model0.contacts_table.relative_position_in_mm)
npt.assert_array_equal(pi_probe0.contact_positions, probe_model0.contacts_table.relative_position_in_um)
npt.assert_array_equal(pi_probe0.contact_shapes, "circle")
npt.assert_array_equal(pi_probe0.to_numpy()["radius"], 5.0)

Expand All @@ -251,7 +251,7 @@ def test_to_probeinterface():

# for testing, mix and match different shapes. np.nan means the radius/width/height does not apply
ct2.add_row(
relative_position_in_mm=[10.0, 10.0],
relative_position_in_um=[10.0, 10.0],
shape="circle",
contact_id="C1",
shank_id="shank0",
Expand All @@ -261,7 +261,7 @@ def test_to_probeinterface():
height_in_um=np.nan,
)
ct2.add_row(
relative_position_in_mm=[20.0, 10.0],
relative_position_in_um=[20.0, 10.0],
shape="square",
contact_id="C2",
shank_id="shank0",
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_to_probeinterface():
assert pi_probe1.serial_number == "7890"
assert pi_probe1.model_name == "Neuropixels 1.0"
assert pi_probe1.manufacturer == "IMEC"
npt.assert_array_equal(pi_probe1.contact_positions, probe_model1.contacts_table.relative_position_in_mm)
npt.assert_array_equal(pi_probe1.contact_positions, probe_model1.contacts_table.relative_position_in_um)
npt.assert_array_equal(pi_probe1.contact_shapes, ["circle", "square"])
npt.assert_array_equal(
pi_probe1.contact_plane_axes,
Expand Down Expand Up @@ -320,6 +320,6 @@ def test_to_probeinterface():
assert pi_probe.serial_number == "0123"
assert pi_probe.model_name == "a1x32-edge-5mm-20-177_H32"
assert pi_probe.manufacturer == "Neuronexus"
npt.assert_array_equal(pi_probe.contact_positions, probe_model0.contacts_table.relative_position_in_mm)
npt.assert_array_equal(pi_probe.contact_positions, probe_model0.contacts_table.relative_position_in_um)
npt.assert_array_equal(pi_probe.to_numpy()["radius"], 5.0)
npt.assert_array_equal(pi_probe.contact_shapes, "circle")
4 changes: 2 additions & 2 deletions src/spec/create_extension_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def main():
default_name="contacts_table",
datasets=[
NWBDatasetSpec(
name="relative_position_in_mm",
name="relative_position_in_um",
neurodata_type_inc="VectorData",
doc="Relative position of the contact in millimeters, relative to `reference`.",
doc="Relative position of the contact in micrometers, relative to `reference`.",
dtype="float",
dims=[["num_contacts", "x, y"], ["num_contacts", "x, y, z"]],
shape=[[None, 2], [None, 3]],
Expand Down

0 comments on commit 3151258

Please sign in to comment.