Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/silverlabnwb/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def determine_trial_times(self):
"""
raise NotImplementedError

def get_subject_info(self):
"""Extract information about the subject if there is any in the header.

Return an empty string if no information is found. This is always the case in legacy LabView versions,
and sometimes the case in newer LabView versions.
"""
return ""

def get_raw_fields(self):
"""Get the fields of the header as directly read from the file.

Expand Down Expand Up @@ -253,3 +261,10 @@ def determine_trial_times(self):
end = None # determine final 'end' later from speed data
trial_times.append((start, end))
return trial_times

def get_subject_info(self):
return "\n".join(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether ". ".join(... is better (to have everything in a single line. It could get quite long if we have a lot of information though.

f'{field}: {value}'
for field, value in self['BIOLOGY INFORMATION'].items()
if value
)
5 changes: 5 additions & 0 deletions src/silverlabnwb/nwb_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, nwb_path, mode='r', verbose=True):
self.custom_silverlab_dict = dict()
self.labview_version = None
self.imaging_info = None
self.subject = None
self.trial_times = None
self.compress = None

Expand Down Expand Up @@ -220,6 +221,10 @@ def add_core_metadata(self):
# even though it is still stored under /general/stimulus
if 'stimulus' in self.experiment:
self.add_general_info('stimulus_notes', self.experiment['stimulus'])
# If both metadata and header have a non-empty subject entry, the header gets priority.
# If neither have an entry, pynwb defaults to not writing a subject field in the file.
if self.subject:
self.add_subject(self.subject)
Comment on lines +224 to +227

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that this way prioritises the header over the metadata? If they both have subject information, does the second call to add_subject not do anything, or does it fail (or overwrite it with the second argument)?

if 'subject' in self.experiment:
self.add_subject(self.experiment['subject'])
# Update the file on disk:
Expand Down
5 changes: 5 additions & 0 deletions tests/data/real life Experiment Header v231 pointing.ini
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ Integral Scale Z = 20.000
Scan Interval = 2.000
Ref Plot Refresh Rate = 0.000

[BIOLOGY INFORMATION]
Animal Code or Name = ""
Animal DoB = ""
Animal Age = ""

[Intertrial FIFO Times]
0.000000 16.428930
1.000000 32.850058
Expand Down
5 changes: 5 additions & 0 deletions tests/data/synthetic experiment Header v231 no last time.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Functional Mode = "Patch"
[VOLUME IMAGING]
Functional Mode = "Point"

[BIOLOGY INFORMATION]
Animal Code or Name = ""
Animal DoB = ""
Animal Age = ""

[Intertrial FIFO Times]
0.000000 0.000000
1.000000 12.345678
Expand Down
6 changes: 6 additions & 0 deletions tests/data/synthetic experiment Header v231.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Functional Mode = "Patch"
[VOLUME IMAGING]
Functional Mode = "Point"

[BIOLOGY INFORMATION]
Animal Code or Name = "Test1"
Animal DoB = ""
Region of brain imaged = "crus"


[Intertrial FIFO Times]
0.000000 0.000000
1.000000 12.345678
Expand Down
9 changes: 9 additions & 0 deletions tests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def test_pre2018_trial_times_raises_error(self, header):
with pytest.raises(NotImplementedError):
header.determine_trial_times()

@pytest.mark.parametrize("header, expected_subject",
[(synthetic_header_path_v231, "Animal Code or Name: Test1\nRegion of brain imaged: crus"),
(synthetic_header_path_v231_no_last_time, ""),
(synthetic_header_path_pre2018, ""),
(real_life_header_path_v231_pointing, "")],
indirect=["header"])
def test_subject_info(self, header, expected_subject):
assert header.get_subject_info() == expected_subject

def test_unrecognised_line_causes_warning(self):
with pytest.warns(UserWarning) as list_of_warnings:
LabViewHeader.from_file(os.path.join("tests", "data", self.header_with_unrecognised_line_path))
Expand Down