Skip to content

Commit 08f776e

Browse files
Handle no Reference Electrode (#127)
* handle no ref case * add test for no ref case * Update src/trodes_to_nwb/tests/test_convert_yaml.py Co-authored-by: Copilot <[email protected]> * update test order in file for readability --------- Co-authored-by: Copilot <[email protected]>
1 parent 883a2a4 commit 08f776e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/trodes_to_nwb/convert_yaml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def add_electrode_groups(
300300
for nwb_group in list(electrode_table["group_name"]):
301301
# use the refference electrode map and defined electrode table to find index of the reference electrode
302302
ref_group, ref_electrode = ref_electrode_map[str(nwb_group)]
303+
if ref_group == "-1":
304+
# handle case where no reference electrode is defined
305+
ref_electrode_id.append(-1)
306+
continue
303307
ref_electrode_id.append(
304308
electrode_table.index[
305309
(electrode_table["group_name"] == ref_group)

src/trodes_to_nwb/tests/test_convert_yaml.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,31 @@ def test_electrode_creation_reconfigured():
236236
assert list(nwbfile.electrodes.to_dataframe()["hwChan"][-2:]) == ["115", "107"]
237237

238238

239+
def test_no_reference_electrode():
240+
metadata_path = data_path / "20230622_sample_metadata.yml"
241+
probe_metadata = [data_path / "tetrode_12.5.yml"]
242+
metadata, probe_metadata = convert_yaml.load_metadata(metadata_path, probe_metadata)
243+
nwbfile = convert_yaml.initialize_nwb(metadata, default_test_xml_tree())
244+
245+
# create the hw_channel map using rec data
246+
recfile = data_path / "20230622_sample_01_a1.rec"
247+
rec_header = convert_rec_header.read_header(recfile)
248+
hw_channel_map = convert_rec_header.make_hw_channel_map(
249+
metadata, rec_header.find("SpikeConfiguration")
250+
)
251+
ref_electrode_map = convert_rec_header.make_ref_electrode_map(
252+
metadata, rec_header.find("SpikeConfiguration")
253+
)
254+
# set one tetrode to no reference
255+
ref_electrode_map["0"] = ("-1", -1)
256+
convert_yaml.add_electrode_groups(
257+
nwbfile, metadata, probe_metadata, hw_channel_map, ref_electrode_map
258+
)
259+
df = nwbfile.electrodes.to_dataframe()
260+
assert (df[df["group_name"] == "0"].ref_elect_id.unique() == -1).all()
261+
assert (df[df["group_name"] != "0"].ref_elect_id.unique() == 0).all()
262+
263+
239264
def test_add_tasks():
240265
# Set up test data
241266
metadata_path = data_path / "20230622_sample_metadata.yml"

0 commit comments

Comments
 (0)