-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensions.py to showcase issue hdmf-dev/hdmf#354
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pynwb | ||
from pynwb import NWBHDF5IO, NWBFile, ProcessingModule | ||
from pynwb import register_class, load_namespaces | ||
from pynwb.ecephys import ElectricalSeries | ||
from pynwb import NWBData | ||
from hdmf.utils import docval, call_docval_func, getargs, get_docval | ||
|
||
ns_path = "spec/ndx-mies.namespace.yaml" | ||
ext_source = "spec/ndx-mies.extensions.yaml" | ||
|
||
from pynwb import get_class, load_namespaces | ||
|
||
load_namespaces(ns_path) | ||
|
||
from datetime import datetime | ||
from dateutil.tz import tzlocal | ||
from pynwb import NWBFile | ||
|
||
start_time = datetime(2017, 4, 3, 11, tzinfo=tzlocal()) | ||
create_date = datetime(2017, 4, 15, 12, tzinfo=tzlocal()) | ||
|
||
@register_class('GeneratedBy', 'ndx-mies') | ||
class GeneratedBy(NWBData): | ||
|
||
__nwbfields__ = ('data',) | ||
|
||
@docval(*get_docval(NWBData.__init__)) | ||
def __init__(self, **kwargs): | ||
call_docval_func(super(NWBData, self).__init__, kwargs) | ||
self.data = getargs('data', kwargs) | ||
|
||
|
||
nwbfile = NWBFile('demonstrate caching', 'NWB456', start_time, | ||
file_create_date=create_date, lab_meta_data=[GeneratedBy(name="GeneratedBy", data=[1, 2, [1, 2]])]) | ||
|
||
device = nwbfile.create_device(name='device_ITC18USB_Dev_0') | ||
|
||
io = NWBHDF5IO('cache_spec_example.nwb', mode='w') | ||
io.write(nwbfile) | ||
io.close() | ||
|
||
#################### | ||
# By default, PyNWB does not use the namespaces cached in a file--you must | ||
# explicitly specify this. This behavior is enabled by the *load_namespaces* | ||
# argument to the :py:class:`~pynwb.NWBHDF5IO` constructor. | ||
|
||
with NWBHDF5IO('cache_spec_example.nwb', mode='r+', load_namespaces=True) as nwb_io: | ||
nwb = nwb_io.read() | ||
|
||
spike_module = ProcessingModule(name='spikes', description='detected spikes') | ||
nwb.add_processing_module(spike_module) | ||
|
||
# This is the container which is causing the problem | ||
dev = nwb.devices["device_ITC18USB_Dev_0"] | ||
print(type(dev)) | ||
print(dev) | ||
print(type(dev.parent)) | ||
print(dev.parent) | ||
|
||
nwb_io.write(nwb) |