Skip to content

Commit

Permalink
Merge pull request #538 from catalystneuro/abf_electrode_fixes
Browse files Browse the repository at this point in the history
Abf electrode metadata fixes
  • Loading branch information
CodyCBakerPhD authored Aug 6, 2023
2 parents 7b978ca + ecf8489 commit 6dc72d6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# (Upcoming)

### Fixes

* Propagated additional arguments, such as `cell_id`, from the `metadata["Icephys"]["Electrodes"]` dictionary used in `tools.neo.add_icephys_electrode`. [PR #538](https://github.com/catalystneuro/neuroconv/pull/538)
* Fixed mismatch between expected `Electrodes` key in `tools.neo.add_icephys_electrode` and the metadata automatically generated by the `AbfInterface`. [PR #538](https://github.com/catalystneuro/neuroconv/pull/538)



# v0.4.0

### Back-compatibility break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_metadata(self) -> dict:
metadata = super().get_metadata()
metadata["Icephys"] = dict(
Device=[dict(name="DeviceIcephys", description="no description")],
Electrode=[
Electrodes=[
dict(name=f"electrode-{i}", description="no description", device="DeviceIcephys")
for i in range(get_number_of_electrodes(self.readers_list[0]))
],
Expand Down
9 changes: 6 additions & 3 deletions src/neuroconv/tools/neo/neo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import distutils.version
import uuid
import warnings
from copy import deepcopy
from pathlib import Path
from typing import Optional, Tuple

Expand Down Expand Up @@ -180,7 +181,7 @@ def add_icephys_electrode(neo_reader, nwbfile, metadata: dict = None):
]

if "Electrodes" not in metadata["Icephys"] or len(metadata["Icephys"]["Electrodes"]) == 0:
metadata["Icephys"]["Electrodes"] = defaults
metadata["Icephys"]["Electrodes"] = deepcopy(defaults)

assert all(
[isinstance(x, dict) for x in metadata["Icephys"]["Electrodes"]]
Expand All @@ -189,15 +190,17 @@ def add_icephys_electrode(neo_reader, nwbfile, metadata: dict = None):
# Create Icephys electrode from metadata
for elec in metadata["Icephys"]["Electrodes"]:
if elec.get("name", defaults[0]["name"]) not in nwbfile.icephys_electrodes:
device_name = elec.get("device_name", defaults[0]["device_name"])
device_name = elec.pop("device_name", None) or elec.pop("device", defaults[0]["device_name"])
# elec.pop("device_name", 0)
if device_name not in nwbfile.devices:
new_device_metadata = dict(Ecephys=dict(Device=[dict(name=device_name)]))
add_device_from_metadata(nwbfile, modality="Icephys", metadata=new_device_metadata)
warnings.warn(
f"Device '{device_name}' not detected in "
"attempted link to icephys electrode! Automatically generating."
)
electrode_kwargs = dict(
electrode_kwargs = elec
electrode_kwargs.update(
name=elec.get("name", defaults[0]["name"]),
description=elec.get("description", defaults[0]["description"]),
device=nwbfile.devices[device_name],
Expand Down
4 changes: 2 additions & 2 deletions src/neuroconv/utils/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ def get_schema_from_hdmf_class(hdmf_class):

def get_metadata_schema_for_icephys():
schema = get_base_schema(tag="Icephys")
schema["required"] = ["Device", "Electrode"]
schema["required"] = ["Device", "Electrodes"]
schema["properties"] = dict(
Device=dict(type="array", minItems=1, items={"$ref": "#/properties/Icephys/properties/definitions/Device"}),
Electrode=dict(
Electrodes=dict(
type="array",
minItems=1,
items={"$ref": "#/properties/Icephys/properties/definitions/Electrode"},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_on_data/test_gin_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class TestConverter(NWBConverter):
)
metadata = converter.get_metadata()
metadata["NWBFile"].update(session_start_time=datetime.now().astimezone().strftime("%Y-%m-%dT%H:%M:%S"))

metadata["Icephys"]["Electrodes"][0].update(cell_id="ID001")

converter.run_conversion(nwbfile_path=nwbfile_path, overwrite=True, metadata=metadata)

with NWBHDF5IO(path=nwbfile_path, mode="r") as io:
Expand All @@ -123,6 +126,8 @@ class TestConverter(NWBConverter):
self.check_set_aligned_starting_time()
self.check_set_aligned_segment_starting_times()

assert nwbfile.ic_electrodes["electrode-0"].cell_id == "ID001"


if __name__ == "__main__":
unittest.main()

0 comments on commit 6dc72d6

Please sign in to comment.