Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add age__reference and adjust tests #1540

Merged
merged 31 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0271734
add age__reference and adjust tests
bendichter Aug 15, 2022
dca53ff
add to CHANGELOG.md
bendichter Aug 15, 2022
91e1fde
add period
bendichter Aug 15, 2022
31d0667
Update file.py
bendichter Aug 15, 2022
1774cd9
Update CHANGELOG.md
bendichter Aug 15, 2022
6b13418
Update src/pynwb/file.py
bendichter Aug 15, 2022
032d51c
add arg check for Subject. If age__reference is provided, age must al…
bendichter Aug 15, 2022
1ade248
Merge remote-tracking branch 'origin/age_reference' into age_reference
bendichter Aug 15, 2022
8d6e51b
add regression test for subject age
bendichter Aug 15, 2022
872f503
remove raising ValueError when age is omitted
bendichter Aug 16, 2022
21d5cfe
flake8
bendichter Aug 16, 2022
dd034a3
Update CHANGELOG.md
bendichter Aug 22, 2022
9d9f4b1
Merge branch 'dev' into age_reference
bendichter Nov 28, 2022
940815c
Update CHANGELOG.md
bendichter Nov 28, 2022
4a9ee92
Update src/pynwb/file.py
bendichter Nov 28, 2022
4c43a32
update to allow Subject.age__reference to be None
bendichter Nov 28, 2022
ca60317
test for Subject.age__reference == None
bendichter Nov 28, 2022
fc0a3ff
Update CHANGELOG.md
bendichter Nov 28, 2022
f805609
Update CHANGELOG.md
bendichter Nov 28, 2022
d145f87
use mapper to allow None
bendichter Nov 29, 2022
0467549
Merge branch 'dev' into age_reference
rly Nov 30, 2022
2fba13f
Merge branch 'dev' into age_reference
rly Dec 5, 2022
8bab314
update schema
rly Dec 6, 2022
a775ed3
forbid passing age__reference=None to Subject.__init__
rly Dec 6, 2022
eac4cd1
Update comment
rly Dec 6, 2022
42389f2
Merge branch 'dev' into age_reference
rly Dec 13, 2022
d3dba26
fix flake8
rly Dec 13, 2022
a2c22d3
Run backwards compat tests in coverage
rly Dec 13, 2022
4b11a34
Add tests for get_nwb_version
rly Dec 14, 2022
066e9dc
Fix flake8
rly Dec 14, 2022
e4d1186
Run IO utils tests in test suite
rly Dec 14, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- Support explicit ordering of sphinx gallery tutorials in the docs. @oruebel (#1504), @bdichter (#1495)
- Add developer guide on how to create a new tutorial. @oruebel (#1504)
- Add images tutorial. @weiglszonja (#1470)
- Add example code for s3fs in the streaming tutorial. @bdichter (#1499)
- Add example code for fsspec in the streaming tutorial. @bdichter (#1499)
bendichter marked this conversation as resolved.
Show resolved Hide resolved
- Add age__reference field. @bendichter ([#1540](https://github.com/NeurodataWithoutBorders/pynwb/pull/1540))
bendichter marked this conversation as resolved.
Show resolved Hide resolved

### Enhancements and minor changes
- Update coverage workflow, report separate unit vs integration coverage. @rly (#1509)
Expand Down
15 changes: 13 additions & 2 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class Subject(NWBContainer):
@docval({'name': 'age', 'type': str,
'doc': ('The age of the subject. The ISO 8601 Duration format is recommended, e.g., "P90D" for '
'90 days old.'), 'default': None},
{
"name": "age__reference",
"type": str,
"doc": "Age is with reference to this event. Can be 'birth' or 'gestational'. If reference is "
"omitted, 'birth' is implied.",
"default": "birth",
oruebel marked this conversation as resolved.
Show resolved Hide resolved
},
{'name': 'description', 'type': str,
'doc': 'A description of the subject, e.g., "mouse A10".', 'default': None},
{'name': 'genotype', 'type': str,
Expand All @@ -78,6 +85,7 @@ class Subject(NWBContainer):
{'name': 'strain', 'type': str, 'doc': 'The strain of the subject, e.g., "C57BL/6J"', 'default': None})
def __init__(self, **kwargs):
keys_to_set = ("age",
"age__reference",
"description",
"genotype",
"sex",
Expand All @@ -87,8 +95,11 @@ def __init__(self, **kwargs):
"date_of_birth",
"strain")
args_to_set = popargs_to_dict(keys_to_set, kwargs)
kwargs['name'] = 'subject'
super().__init__(**kwargs)
super().__init__(name="subject", **kwargs)

if args_to_set["age__reference"] is not None:
if args_to_set["age__reference"] not in ("birth", "gestational"):
raise ValueError("age__reference must be 'birth' or 'gestational'.")
bendichter marked this conversation as resolved.
Show resolved Hide resolved
bendichter marked this conversation as resolved.
Show resolved Hide resolved

weight = args_to_set['weight']
if isinstance(weight, float):
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/nwb-schema
Submodule nwb-schema updated 1 files
+6 −0 core/nwb.file.yaml
46 changes: 28 additions & 18 deletions tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,29 +437,35 @@ def test_multi_publications(self):

class SubjectTest(TestCase):
def setUp(self):
self.subject = Subject(age='P90D',
description='An unfortunate rat',
genotype='WT',
sex='M',
species='Rattus norvegicus',
subject_id='RAT123',
weight='2 kg',
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
strain='my_strain')
self.subject = Subject(
age='P90D',
bendichter marked this conversation as resolved.
Show resolved Hide resolved
age__reference="birth",
description='An unfortunate rat',
genotype='WT',
sex='M',
species='Rattus norvegicus',
subject_id='RAT123',
weight='2 kg',
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
strain='my_strain',
)
self.start = datetime(2017, 5, 1, 12, tzinfo=tzlocal())
self.path = 'nwbfile_test.h5'
self.nwbfile = NWBFile('a test session description for a test NWBFile',
'FILE123',
self.start,
experimenter='A test experimenter',
lab='a test lab',
institution='a test institution',
experiment_description='a test experiment description',
session_id='test1',
subject=self.subject)
self.nwbfile = NWBFile(
'a test session description for a test NWBFile',
'FILE123',
self.start,
experimenter='A test experimenter',
lab='a test lab',
institution='a test institution',
experiment_description='a test experiment description',
session_id='test1',
subject=self.subject,
)

def test_constructor(self):
self.assertEqual(self.subject.age, 'P90D')
self.assertEqual(self.subject.age__reference, "birth")
self.assertEqual(self.subject.description, 'An unfortunate rat')
self.assertEqual(self.subject.genotype, 'WT')
self.assertEqual(self.subject.sex, 'M')
Expand All @@ -479,6 +485,10 @@ def test_weight_float(self):
)
self.assertEqual(subject.weight, '2.3 kg')

def test_age_reference_arg_check(self):
with self.assertRaisesWith(ValueError, "age__reference must be 'birth' or 'gestational'."):
Subject(subject_id='RAT123', age='P90D', age__reference='brth')


class TestCacheSpec(TestCase):

Expand Down