In [1]:
!rm My_first_dataset_neo9.nwb


rm: cannot remove 'My_first_dataset_neo9.nwb': No such file or directory

In [2]:
# Pip installs
!pip install pynwb
!pip install nwb-docutils
!pip install git+https://github.com/legouee/python-neo@NWB_updated


Requirement already satisfied: pynwb in /opt/conda/lib/python3.6/site-packages
Requirement already satisfied: ruamel.yaml in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: python-dateutil in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: numpy in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: hdmf==1.3.3 in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: chardet in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: h5py in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (from pynwb)
Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8" in /opt/conda/lib/python3.6/site-packages (from ruamel.yaml->pynwb)
Requirement already satisfied: scipy in /opt/conda/lib/python3.6/site-packages (from hdmf==1.3.3->pynwb)
Requirement already satisfied: pytz>=2011k in /opt/conda/lib/python3.6/site-packages (from pandas->pynwb)
You are using pip version 9.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied: nwb-docutils in /opt/conda/lib/python3.6/site-packages
Requirement already satisfied: sphinx-gallery in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: sphinx-rtd-theme in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: matplotlib in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: pillow in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: hdmf in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: sphinx==1.6.5 in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: pynwb in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: networkx in /opt/conda/lib/python3.6/site-packages (from nwb-docutils)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.6/site-packages (from sphinx-gallery->nwb-docutils)
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: six>=1.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: python-dateutil in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: pytz in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in /opt/conda/lib/python3.6/site-packages (from matplotlib->nwb-docutils)
Requirement already satisfied: h5py in /opt/conda/lib/python3.6/site-packages (from hdmf->nwb-docutils)
Requirement already satisfied: scipy in /opt/conda/lib/python3.6/site-packages (from hdmf->nwb-docutils)
Requirement already satisfied: ruamel.yaml in /opt/conda/lib/python3.6/site-packages (from hdmf->nwb-docutils)
Requirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (from hdmf->nwb-docutils)
Requirement already satisfied: chardet in /opt/conda/lib/python3.6/site-packages (from hdmf->nwb-docutils)
Requirement already satisfied: snowballstemmer>=1.1 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: requests>=2.0.0 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: babel!=2.0,>=1.3 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: Pygments>=2.0 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: Jinja2>=2.3 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: imagesize in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: sphinxcontrib-websupport in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: docutils>=0.11 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: alabaster<0.8,>=0.7 in /opt/conda/lib/python3.6/site-packages (from sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: decorator>=4.3.0 in /opt/conda/lib/python3.6/site-packages (from networkx->nwb-docutils)
Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8" in /opt/conda/lib/python3.6/site-packages (from ruamel.yaml->hdmf->nwb-docutils)
Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.6/site-packages (from requests>=2.0.0->sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/lib/python3.6/site-packages (from requests>=2.0.0->sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.6/site-packages (from requests>=2.0.0->sphinx==1.6.5->nwb-docutils)
Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/lib/python3.6/site-packages (from Jinja2>=2.3->sphinx==1.6.5->nwb-docutils)
You are using pip version 9.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting git+https://github.com/legouee/python-neo@NWB_updated
  Cloning https://github.com/legouee/python-neo (to NWB_updated) to /tmp/pip-2ma6_kxh-build
  Requirement already satisfied (use --upgrade to upgrade): neo==0.9.0.dev0 from git+https://github.com/legouee/python-neo@NWB_updated in /opt/conda/lib/python3.6/site-packages
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/lib/python3.6/site-packages (from neo==0.9.0.dev0)
Requirement already satisfied: quantities>=0.9.0 in /opt/conda/lib/python3.6/site-packages (from neo==0.9.0.dev0)
You are using pip version 9.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

In [3]:
import neo
from neo import Block, Segment, AnalogSignal
from neo.io.nwbio import NWBIO
import pynwb
import quantities as pq
from quantities import s, ms, kHz, Hz, uV
import numpy as np
print("neo = ", neo.__version__)
print("pynwb = ", pynwb.__version__)


neo =  0.9.0.dev
pynwb =  1.1.2

Create a nwb file from Neo

Create 3 Neo blocks and populate each block with 4 Neo segments, and each segment with 3 Neo analogsignals objects


In [4]:
blocks = []

# Define Neo blocks
bl0 = neo.Block(name='First block')
bl1 = neo.Block(name='Second block')
bl2 = neo.Block(name='Third block')
print("bl0.segments = ", bl0.segments)      
print("bl1.segments = ", bl1.segments)
print("bl2.segments = ", bl2.segments)
blocks = [bl0, bl1, bl2]
print("blocks = ", blocks)

num_seg = 4 # number of segments

for blk in blocks: 
    for ind in range(num_seg): # number of Segment
        seg = neo.Segment(name='segment %s %d' % (blk.name, ind), index=ind)
        blk.segments.append(seg)

    for seg in blk.segments: # AnalogSignal objects
        # 3 AnalogSignals
        a = AnalogSignal(np.random.randn(num_seg, 44)*pq.nA, sampling_rate=10*kHz)
        b = AnalogSignal(np.random.randn(num_seg, 64)*pq.nA, sampling_rate=10*kHz)
        c = AnalogSignal(np.random.randn(num_seg, 33)*pq.nA, sampling_rate=10*kHz)

        seg.analogsignals.append(a)
        seg.analogsignals.append(b)
        seg.analogsignals.append(c)

blocks


bl0.segments =  []
bl1.segments =  []
bl2.segments =  []
blocks =  [<neo.core.block.Block object at 0x7fa6d6a241d0>, <neo.core.block.Block object at 0x7fa6d6a24198>, <neo.core.block.Block object at 0x7fa6d6a242b0>]
Out[4]:
[Block with 4 segments
 name: 'First block'
 # segments (N=4)
 0: Segment with 3 analogsignals
    name: 'segment First block 0'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 1: Segment with 3 analogsignals
    name: 'segment First block 1'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 2: Segment with 3 analogsignals
    name: 'segment First block 2'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 3: Segment with 3 analogsignals
    name: 'segment First block 3'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s,
 Block with 4 segments
 name: 'Second block'
 # segments (N=4)
 0: Segment with 3 analogsignals
    name: 'segment Second block 0'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 1: Segment with 3 analogsignals
    name: 'segment Second block 1'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 2: Segment with 3 analogsignals
    name: 'segment Second block 2'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 3: Segment with 3 analogsignals
    name: 'segment Second block 3'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s,
 Block with 4 segments
 name: 'Third block'
 # segments (N=4)
 0: Segment with 3 analogsignals
    name: 'segment Third block 0'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 1: Segment with 3 analogsignals
    name: 'segment Third block 1'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 2: Segment with 3 analogsignals
    name: 'segment Third block 2'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
 3: Segment with 3 analogsignals
    name: 'segment Third block 3'
    # analogsignals (N=3)
    0: AnalogSignal with 44 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    1: AnalogSignal with 64 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s
    2: AnalogSignal with 33 channels of length 4; units nA; datatype float64 
       sampling rate: 10.0 kHz
       time: 0.0 s to 0.0004 s]

Write a nwb file

Using Neo NWBIO


In [5]:
filename = 'My_first_dataset_neo9.nwb'

In [6]:
writer = NWBIO(filename, mode='w')
writer.write(blocks)


block in all_blocks =  <neo.core.block.Block object at 0x7fa6d6a241d0>
segment.name =  segment First block 0
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment First block 1
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment First block 2
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment First block 3
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
/opt/conda/lib/python3.6/site-packages/pynwb/file.py:691: UserWarning: Date is missing timezone information. Updating to local timezone.
  warn("Date is missing timezone information. Updating to local timezone.")
/opt/conda/lib/python3.6/site-packages/hdmf/build/map.py:949: MissingRequiredWarning: attribute 'unit' for 'data' (TimeSeries)
  warnings.warn(msg, MissingRequiredWarning)
block in all_blocks =  <neo.core.block.Block object at 0x7fa6d6a24198>
segment.name =  segment Second block 0
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Second block 1
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Second block 2
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Second block 3
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
block in all_blocks =  <neo.core.block.Block object at 0x7fa6d6a242b0>
segment.name =  segment Third block 0
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Third block 1
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Third block 2
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2
segment.name =  segment Third block 3
signal_name =  signal0
signal_name =  signal1
signal_name =  signal2

Read the NWB file

Using pynwb


In [7]:
io = pynwb.NWBHDF5IO(filename, mode='r') # Open a file with NWBHDF5IO
_file = io.read()

In [8]:
print(_file)
_file.acquisition


root pynwb.file.NWBFile at 0x140356112966712
Fields:
  acquisition: {
    segment First block 0 <class 'pynwb.base.TimeSeries'>,
    segment First block 1 <class 'pynwb.base.TimeSeries'>,
    segment First block 2 <class 'pynwb.base.TimeSeries'>,
    segment First block 3 <class 'pynwb.base.TimeSeries'>,
    segment Second block 0 <class 'pynwb.base.TimeSeries'>,
    segment Second block 1 <class 'pynwb.base.TimeSeries'>,
    segment Second block 2 <class 'pynwb.base.TimeSeries'>,
    segment Second block 3 <class 'pynwb.base.TimeSeries'>,
    segment Third block 0 <class 'pynwb.base.TimeSeries'>,
    segment Third block 1 <class 'pynwb.base.TimeSeries'>,
    segment Third block 2 <class 'pynwb.base.TimeSeries'>,
    segment Third block 3 <class 'pynwb.base.TimeSeries'>
  }
  file_create_date: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
  session_description: My_first_dataset_neo9.nwb
  session_start_time: 2020-01-16 15:27:26.713582+00:00
  timestamps_reference_time: 2020-01-16 15:27:26.713582+00:00

Out[8]:
{'segment First block 0': segment First block 0 pynwb.base.TimeSeries at 0x140354542269440
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment First block 1': segment First block 1 pynwb.base.TimeSeries at 0x140354533740384
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment First block 2': segment First block 2 pynwb.base.TimeSeries at 0x140354530931264
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment First block 3': segment First block 3 pynwb.base.TimeSeries at 0x140354530931488
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Second block 0': segment Second block 0 pynwb.base.TimeSeries at 0x140354530931824
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Second block 1': segment Second block 1 pynwb.base.TimeSeries at 0x140354530932160
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Second block 2': segment Second block 2 pynwb.base.TimeSeries at 0x140354530932048
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Second block 3': segment Second block 3 pynwb.base.TimeSeries at 0x140354530932384
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Third block 0': segment Third block 0 pynwb.base.TimeSeries at 0x140354530932608
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Third block 1': segment Third block 1 pynwb.base.TimeSeries at 0x140354530932832
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Third block 2': segment Third block 2 pynwb.base.TimeSeries at 0x140354530933056
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds,
 'segment Third block 3': segment Third block 3 pynwb.base.TimeSeries at 0x140354530933280
 Fields:
   comments: no comments
   conversion: 1.0
   data: <HDF5 dataset "data": shape (4, 33), type "<f8">
   interval: 1
   resolution: -1.0
   timestamps: <HDF5 dataset "timestamps": shape (1,), type "<f8">
   timestamps_unit: seconds}

Using Neo NWBIO


In [9]:
reader = NWBIO(filename, mode='r')

In [10]:
all_blocks = reader.read()


node =  segment First block 0
node =  segment First block 1
node =  segment First block 2
node =  segment First block 3
node =  segment Second block 0
node =  segment Second block 1
node =  segment Second block 2
node =  segment Second block 3
node =  segment Third block 0
node =  segment Third block 1
node =  segment Third block 2
node =  segment Third block 3

In [11]:
all_blocks


Out[11]:
[Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0),
 Block with 1 segments
 description: 'My_first_dataset_neo9.nwb'
 annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
   'file_read_log': ''}
 file_origin: 'My_first_dataset_neo9.nwb'
 file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
 rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
 # segments (N=1)
 0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0)]

In [12]:
first_block = reader.read_block() # Read the first block


node =  segment First block 0
node =  segment First block 1
node =  segment First block 2
node =  segment First block 3
node =  segment Second block 0
node =  segment Second block 1
node =  segment Second block 2
node =  segment Second block 3
node =  segment Third block 0
node =  segment Third block 1
node =  segment Third block 2
node =  segment Third block 3

In [13]:
first_block


Out[13]:
Block with 1 segments
description: 'My_first_dataset_neo9.nwb'
annotations: {'file_access_dates': [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())],
  'file_read_log': ''}
file_origin: 'My_first_dataset_neo9.nwb'
file_datetime: [datetime.datetime(2020, 1, 16, 15, 27, 26, 719229, tzinfo=tzlocal())]
rec_datetime: datetime.datetime(2020, 1, 16, 15, 27, 26, 713582, tzinfo=tzlocal())
# segments (N=1)
0: Segment with  name: 'NeoNWB IO' # analogsignals (N=0)

In [14]:
# Plotting settings
%matplotlib inline
show_bar_plot = False    # Change setting to plot distribution of object sizes in the HDF5 file
plot_single_file = True # Plot all files or a single example file
output_filenames = filename
print("output_filenames = ", output_filenames)
    
# Select the files to plot
filenames = output_filenames
print("filenames = ", filenames)

# Changed
from nwb_docutils.doctools.render import HierarchyDescription, NXGraphHierarchyDescription
import matplotlib.pyplot as plt
        
# Create the plots for all files
file_hierarchy = HierarchyDescription.from_hdf5(filenames)
file_graph = NXGraphHierarchyDescription(file_hierarchy)          
fig = file_graph.draw(show_plot=False,
                      figsize=(12,16),
                      label_offset=(0.0, 0.0065),
                      label_font_size=10)
plot_title = filenames + " \n " + "#Datasets=%i, #Attributes=%i, #Groups=%i, #Links=%i" % (len(file_hierarchy['datasets']), len(file_hierarchy['attributes']), len(file_hierarchy['groups']), len(file_hierarchy['links']))
plt.title(plot_title)
plt.show()
        
# Show a sorted bar plot with the sizes of all datasets in the file
if show_bar_plot:
    d = {i['name']: np.prod(i['size']) for i in file_hierarchy['datasets']}
    l = [w for w in sorted(d, key=d.get, reverse=True)]
    s = [d[w] for w in l]   
    p = np.arange(len(l))   
    fig,ax = plt.subplots(figsize=(16,7))
    ax.set_title(filename)
    ax.bar(p, s, width=1, color='r')
    ax.set_xticks(p+1)  
    ax.set_xticklabels(l)  
    ax.set_yscale("log", nonposy='clip')
    fig.autofmt_xdate(bottom=0.2, rotation=90, ha='right')
    plt.show()
plt.show()


output_filenames =  My_first_dataset_neo9.nwb
filenames =  My_first_dataset_neo9.nwb