Generate sample neo.Block


In [1]:
from neo import Block, Segment, AnalogSignal
from neo.test.generate_datasets import generate_one_simple_block

neo_block = generate_one_simple_block(supported_objects=[Block, Segment, AnalogSignal])
neo_block.name = 'sample dataset'

Save the whole Block to NIX


In [2]:
import nix
from neo2nix.block import Block as NixBlock

f = nix.File.open("/tmp/sample.h5", nix.FileMode.Overwrite)

NixBlock.write_block(f, neo_block)

f.close()

Read Block back from file


In [3]:
f = nix.File.open("/tmp/sample.h5", nix.FileMode.ReadWrite)

nix_block = NixBlock(f, f.blocks[0])

# Note: 
# - nix_block is attached to the file
# - all relations are lazy loaded

nix_block.name


Out[3]:
'sample dataset'

Access data


In [5]:
signal = nix_block.segments[0].analogsignals[0]


from matplotlib.pyplot import figure

fig = figure(figsize=(8, 6))
ax = fig.add_subplot(111)

ax.plot(signal.times, [x for x in signal[:]])


Out[5]:
[<matplotlib.lines.Line2D at 0x7fa459605710>]

In [6]:
f.close()

In [ ]: