Skip to content

Instantly share code, notes, and snippets.

@nicain
Created July 31, 2017 19:51
Show Gist options
  • Save nicain/22649031a68db6b2053977004c111ed5 to your computer and use it in GitHub Desktop.
Save nicain/22649031a68db6b2053977004c111ed5 to your computer and use it in GitHub Desktop.
import sys
sys.path.append('/Users/nicholasc/Janelia_NWB_Hackathon/pynwb/src')
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],
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='I went on an adventure with thirteen dwarves to reclaim vast treasures.',
session_id='LONELYMTN')
f.add_raw_timeseries(fs)
manager = get_build_manager()
io = HDF5IO('tmp.nwb', manager, mode='w')
io.write(f)
io.close()
@ajtritt
Copy link

ajtritt commented Jul 31, 2017

Try the following:

nwb_as should be an NWBDatasetSpec. Within the constructor, you need to specify name=data and attributes=[NWBAttributeSpec('unit', value='gid')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment