Skip to content

Commit

Permalink
Merge pull request #551 from NeurodataWithoutBorders/bug/missing_gene…
Browse files Browse the repository at this point in the history
…ral_meta

Bug/missing general meta
  • Loading branch information
oruebel authored Jul 9, 2018
2 parents 5300644 + 62f2652 commit 09207e9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class NWBFile(MultiContainerInterface):
]

__nwbfields__ = ('experimenter',
'data_collection',
'description',
'experiment_description',
'session_id',
Expand All @@ -155,8 +156,10 @@ class NWBFile(MultiContainerInterface):
'related_publications',
'slices',
'source_script',
'source_script_file_name',
'surgery',
'virus',
'stimulus_notes',
{'name': 'ec_electrodes', 'child': True},
{'name': 'epochs', 'child': True},
{'name': 'trials', 'child': True},
Expand Down Expand Up @@ -192,12 +195,18 @@ class NWBFile(MultiContainerInterface):
'thickness, orientation, temperature and bath solution', 'default': None},
{'name': 'source_script', 'type': str,
'doc': 'Script file used to create this NWB file.', 'default': None},
{'name': 'source_script_file_name', 'type': str,
'doc': 'Name of the sourc_script file', 'default': None},
{'name': 'data_collection', 'type': str,
'doc': 'Notes about data collection and analysis.', 'default': None},
{'name': 'surgery', 'type': str,
'doc': 'Narrative description about surgery/surgeries, including date(s) '
'and who performed surgery.', 'default': None},
{'name': 'virus', 'type': str,
'doc': 'Information about virus(es) used in experiments, including virus ID, '
'source, date made, injection location, volume, etc.', 'default': None},
{'name': 'stimulus_notes', 'type': str,
'doc': 'Notes about stimuli, such as how and where presented.', 'default': None},
{'name': 'lab', 'type': str, 'doc': 'lab where experiment was performed', 'default': None},
{'name': 'acquisition', 'type': (list, tuple),
'doc': 'Raw TimeSeries objects belonging to this NWBFile', 'default': None},
Expand Down Expand Up @@ -273,18 +282,24 @@ def __init__(self, **kwargs):
'session_id',
'lab',
'institution',
'data_collection',
'notes',
'pharmacology',
'protocol',
'related_publications',
'slices',
'source_script',
'source_script_file_name',
'surgery',
'virus',
'stimulus_notes',
]
for attr in recommended:
setattr(self, attr, kwargs.get(attr, None))

if getargs('source_script', kwargs) is None and getargs('source_script_file_name', kwargs) is not None:
raise ValueError("'source_script' cannot be None when 'source_script_file_name' is set")

def all_children(self):
stack = [self]
ret = list()
Expand Down
4 changes: 3 additions & 1 deletion src/pynwb/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def __init__(self, spec):
self.map_spec(
'modules',
self.spec.get_group('processing').get_neurodata_type('ProcessingModule'))
self.unmap(general_spec.get_dataset('stimulus'))
# self.unmap(general_spec.get_dataset('stimulus'))
self.map_spec('stimulus_notes', general_spec.get_dataset('stimulus'))
self.map_spec('source_script_file_name', general_spec.get_dataset('source_script').get_attribute('file_name'))

self.map_spec('subject', general_spec.get_group('subject'))
self.map_spec('devices', general_spec.get_group('devices').get_neurodata_type('Device'))
Expand Down
2 changes: 2 additions & 0 deletions tests/build_fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
lab='Bag End Labatory',
institution='University of Middle Earth at the Shire',
experiment_description='I went on an adventure with thirteen dwarves to reclaim vast treasures.',
stimulus_notes='The one ring to rule them all has been found',
data_collection='The ring was found in cave and stolen from Gollum',
session_id='LONELYMTN')

# Create the electrode group this simulated data is generated from
Expand Down
43 changes: 41 additions & 2 deletions tests/integration/ui_write/test_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,34 @@ def setUpBuilder(self):
DatasetBuilder('description',
"A fake Clustering interface")})})

general_builder = GroupBuilder('general',
datasets={
'experimenter': DatasetBuilder('experimenter', 'test experimenter'),
'stimulus': DatasetBuilder('stimulus', 'test stimulus notes'),
'experiment_description': DatasetBuilder('experiment_description',
'test experiment description'),
'data_collection': DatasetBuilder('data_collection',
'test data collection notes'),
'institution': DatasetBuilder('institution', 'nomad'),
'lab': DatasetBuilder('lab', 'nolab'),
'notes': DatasetBuilder('notes', 'nonotes'),
'pharmacology': DatasetBuilder('pharmacology', 'nopharmacology'),
'protocol': DatasetBuilder('protocol', 'noprotocol'),
'related_publications': DatasetBuilder('related_publications', 'nopubs'),
'session_id': DatasetBuilder('session_id', '007'),
'slices': DatasetBuilder('slices', 'noslices'),
'source_script': DatasetBuilder('source_script', 'nosources',
attributes={'file_name': 'nofilename'}),
'surgery': DatasetBuilder('surgery', 'nosurgery'),
'virus': DatasetBuilder('virus', 'novirus')}
)

return GroupBuilder('root',
groups={'acquisition': GroupBuilder(
'acquisition',
groups={'test_timeseries': ts_builder}),
'analysis': GroupBuilder('analysis'),
'general': GroupBuilder('general'),
'general': general_builder,
'processing': GroupBuilder('processing', groups={'test_module': module_builder}),
'stimulus': GroupBuilder(
'stimulus',
Expand All @@ -84,7 +106,24 @@ def setUpBuilder(self):

def setUpContainer(self):
container = NWBFile('a test source', 'a test NWB File', 'TEST123',
self.start_time, file_create_date=self.create_date)
self.start_time,
file_create_date=self.create_date,
experimenter='test experimenter',
stimulus_notes='test stimulus notes',
experiment_description='test experiment description',
data_collection='test data collection notes',
institution='nomad',
lab='nolab',
notes='nonotes',
pharmacology='nopharmacology',
protocol='noprotocol',
related_publications='nopubs',
session_id='007',
slices='noslices',
source_script='nosources',
surgery='nosurgery',
virus='novirus',
source_script_file_name='nofilename')
self.ts = TimeSeries('test_timeseries', 'example_source', list(range(100, 200, 10)),
'SIunit', timestamps=list(range(10)), resolution=0.1)
container.add_acquisition(self.ts)
Expand Down
17 changes: 16 additions & 1 deletion tests/unit/pynwb_tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def setUp(self):
related_publications='my pubs',
slices='my slices',
surgery='surgery',
virus='a virus')
virus='a virus',
source_script='noscript',
source_script_file_name='nofilename',
stimulus_notes='test stimulus notes',
data_collection='test data collection notes')

def test_constructor(self):
self.assertEqual(self.nwbfile.session_description, 'a test session description for a test NWBFile')
Expand All @@ -39,6 +43,10 @@ def test_constructor(self):
self.assertEqual(self.nwbfile.institution, 'a test institution')
self.assertEqual(self.nwbfile.experiment_description, 'a test experiment description')
self.assertEqual(self.nwbfile.session_id, 'test1')
self.assertEqual(self.nwbfile.stimulus_notes, 'test stimulus notes')
self.assertEqual(self.nwbfile.data_collection, 'test data collection notes')
self.assertEqual(self.nwbfile.source_script, 'noscript')
self.assertEqual(self.nwbfile.source_script_file_name, 'nofilename')

def test_create_electrode_group(self):
name = 'example_electrode_group'
Expand Down Expand Up @@ -160,6 +168,13 @@ def test_all_children(self):
self.assertIn(device, children)
self.assertIn(elecgrp, children)

def test_fail_if_source_script_file_name_without_source_script(self):
with self.assertRaises(ValueError):
# <-- source_script_file_name without source_script is not allowed
NWBFile('a fake source', 'a test session description for a test NWBFile', 'FILE123', self.start,
source_script=None,
source_script_file_name='nofilename')


class SubjectTest(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 09207e9

Please sign in to comment.