Skip to content

Commit a4fc53d

Browse files
authored
add read example to extensions tutorial (#587)
add read example to extensions tutorial
1 parent 98f6ed4 commit a4fc53d

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

docs/gallery/general/extensions.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ def __init__(self, **kwargs):
227227
# For more information on writing NWB files, see :ref:`basic_writing`.
228228

229229
####################
230-
# By default, PyNWB does not use the namespaces cached in a file--you must explicitly specify this.
231-
# This behavior is enabled by the *load_namespaces* argument to the :py:class:`~pynwb.NWBHDF5IO`
232-
# constructor.
230+
# By default, PyNWB does not use the namespaces cached in a file--you must
231+
# explicitly specify this. This behavior is enabled by the *load_namespaces*
232+
# argument to the :py:class:`~pynwb.NWBHDF5IO` constructor.
233233

234234
io = NWBHDF5IO('cache_spec_example.nwb', mode='r', load_namespaces=True)
235235
nwbfile = io.read()
@@ -238,9 +238,11 @@ def __init__(self, **kwargs):
238238
# .. _MultiContainerInterface:
239239
# Creating and using a custom MultiContainerInterface
240240
# -----------------------------------------------------
241-
# It is sometimes the case that we need a group to hold zero-or-more or one-or-more of the same object.
242-
# Here we show how to create an extension that defines a group (`PotatoSack`) that holds multiple objects (`Pototo`es)
243-
# and then how to use the new data types. First, we use `pynwb` to define the new data types.
241+
# It is sometimes the case that we need a group to hold zero-or-more or
242+
# one-or-more of the same object. Here we show how to create an extension that
243+
# defines a group (`PotatoSack`) that holds multiple objects (`Pototo` es) and
244+
# then how to use the new data types. First, we use `pynwb` to define the new
245+
# data types.
244246

245247
from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec
246248

@@ -283,7 +285,8 @@ def __init__(self, **kwargs):
283285
ns_builder.export(ns_path)
284286

285287
####################
286-
# Then create Container classes registered to the new data types (this is generally done in a different file)
288+
# Then create Container classes registered to the new data types (this is
289+
# generally done in a different file)
287290

288291
from pynwb import register_class, load_namespaces
289292
from pynwb.file import MultiContainerInterface, NWBContainer
@@ -337,3 +340,14 @@ class PotatoSack(MultiContainerInterface):
337340

338341
with NWBHDF5IO('test_multicontainerinterface.nwb', 'w') as io:
339342
io.write(nwbfile)
343+
344+
####################
345+
# This is how you read the NWB file (again, this would often be done in a
346+
# different file).
347+
348+
load_namespaces(ns_path)
349+
# from xxx import PotatoSack, Potato
350+
io = NWBHDF5IO('test_multicontainerinterface.nwb', 'r')
351+
nwb = io.read()
352+
print(nwb.get_processing_module()['potato_sack'].get_potato().weight)
353+
io.close()

0 commit comments

Comments
 (0)