Skip to content

Commit

Permalink
Add optional value column to EventsTable (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Sep 10, 2024
1 parent f48ffb9 commit 666adf8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/ndx-events.extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ groups:
neurodata_type_inc: DurationVectorData
doc: Optional column containing the duration of each event, in seconds.
quantity: '?'
- name: value
neurodata_type_inc: VectorData
doc: Optional column containing a value/parameter associated with each event.
For example, if you have three levels of reward (e.g., 1 drop, 2 drops, 3 drops),
instead of encoding each level of reward as its own event type (e.g., 'reward_value_1',
'reward_value_2', 'reward_value_3', you could encode 'reward' as the event type,
and the value for each event time could be 1, 2, or 3.
quantity: '?'
- neurodata_type_def: TtlTypesTable
neurodata_type_inc: EventTypesTable
default_name: TtlTypesTable
Expand Down
10 changes: 10 additions & 0 deletions src/pynwb/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def test_add_row(self):
stimulus_type="",
event_type=0,
duration=0.1,
value="",
# hed_tags=["(White, Circle)"],
)
events_table.add_row(
Expand All @@ -289,13 +290,15 @@ def test_add_row(self):
stimulus_type="animal",
event_type=1,
duration=0.15,
value="giraffe",
)
events_table.add_row(
timestamp=1.1,
cue_type="green square",
stimulus_type="",
event_type=0,
duration=0.1,
value="",
# hed_tags=["(Green, Square)"],
)
events_table.add_row(
Expand All @@ -304,12 +307,14 @@ def test_add_row(self):
stimulus_type="landscape",
event_type=1,
duration=0.15,
value="farm",
)
assert events_table["timestamp"].data == [0.1, 0.3, 1.1, 1.3]
assert events_table["cue_type"].data == ["white circle", "", "green square", ""]
assert events_table["stimulus_type"].data == ["", "animal", "", "landscape"]
assert events_table["duration"].data == [0.1, 0.15, 0.1, 0.15]
assert events_table["event_type"].data == [0, 1, 0, 1]
assert events_table["value"].data == ["", "giraffe", "", "farm"]
# assert events_table["hed_tags"][0] == ["(White, Circle)"]
# assert events_table["hed_tags"][2] == ["(Green, Square)"]

Expand Down Expand Up @@ -350,6 +355,7 @@ def test_roundtrip(self):
stimulus_type="",
event_type=0,
duration=0.1,
value="",
# hed_tags=["(White, Circle)"],
)
events_table.add_row(
Expand All @@ -358,13 +364,15 @@ def test_roundtrip(self):
stimulus_type="animal",
event_type=1,
duration=0.15,
value="giraffe",
)
events_table.add_row(
timestamp=1.1,
cue_type="green square",
stimulus_type="",
event_type=0,
duration=0.1,
value="",
# hed_tags=["(Green, Square)"],
)
events_table.add_row(
Expand All @@ -373,6 +381,7 @@ def test_roundtrip(self):
stimulus_type="landscape",
event_type=1,
duration=0.15,
value="farm",
)

task = Task()
Expand All @@ -396,6 +405,7 @@ def test_roundtrip(self):
assert all(read_events_table["stimulus_type"].data[:] == ["", "animal", "", "landscape"])
assert all(read_events_table["duration"].data[:] == [0.1, 0.15, 0.1, 0.15])
assert all(read_events_table["event_type"].data[:] == [0, 1, 0, 1])
assert all(read_events_table["value"].data[:] == ["", "giraffe", "", "farm"])
assert read_events_table["event_type"].table is read_event_types_table


Expand Down
13 changes: 13 additions & 0 deletions src/spec/create_extension_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ def main():
doc="Optional column containing the duration of each event, in seconds.",
quantity="?",
),
NWBDatasetSpec(
name="value",
neurodata_type_inc="VectorData",
doc=(
"Optional column containing a value/parameter associated with each event. "
"For example, if you have three levels of reward (e.g., 1 drop, 2 drops, "
"3 drops), instead of encoding each level of reward as its own event "
"type (e.g., 'reward_value_1', 'reward_value_2', 'reward_value_3', "
"you could encode 'reward' as the event type, and the value for each "
"event time could be 1, 2, or 3."
),
quantity="?",
),
],
)

Expand Down

0 comments on commit 666adf8

Please sign in to comment.