Created
August 3, 2017 20:09
-
-
Save nicain/9f03154823678fc74fed674913fb08ee to your computer and use it in GitHub Desktop.
NWBGroupSpec example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynwb import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec | |
| import numpy as np | |
| from pynwb import get_class, load_namespaces | |
| from datetime import datetime | |
| from pynwb import NWBFile | |
| from form.backends.hdf5 import HDF5IO | |
| from pynwb import get_build_manager | |
| ns_path = "mylab.namespace.yaml" | |
| ext_source = "mylab.extensions.yaml" | |
| nwb_as = NWBAttributeSpec('data', 'int', 'gid') | |
| ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', "mylab") | |
| ext = NWBGroupSpec('A custom TimeSeries for my lab', | |
| attributes=[nwb_as], | |
| dtype='float', | |
| neurodata_type_inc='TimeSeries', | |
| neurodata_type_def='PopulationSpikeTrain') | |
| ns_builder.add_spec(ext_source, ext) | |
| ns_builder.export(ns_path) | |
| ns_path = "mylab.namespace.yaml" | |
| load_namespaces(ns_path) | |
| PopulationSpikeTrain = get_class('PopulationSpikeTrain', 'mylab') | |
| fs = PopulationSpikeTrain(data=(10*np.random.random(5)).astype(np.int), | |
| name='my_population', | |
| source='acquisition', | |
| unit='second', | |
| timestamps=np.random.rand(5)) | |
| f = NWBFile('tmp.nwb', | |
| 'my first synthetic recording', | |
| 'EXAMPLE_ID', | |
| datetime.now(), | |
| experimenter='Dr. Bilbo Baggins', | |
| lab='Bag End Labatory', | |
| institution='University of Middle Earth at the Shire', | |
| experiment_description='empty', | |
| session_id='LONELYMTN') | |
| f.add_raw_timeseries(fs) | |
| manager = get_build_manager() | |
| io = HDF5IO('tmp.nwb', manager, mode='w') | |
| io.write(f) |
Author
nicain
commented
Aug 3, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment