Table Of Contents

Previous topic

Neo IO

Next topic

API Reference

This Page

Examples

Introduction

A set of examples in neo/examples/ illustrates the use of neo classes.

"""
This is an example for reading files with neo.io
"""

import neo
import urllib




# Plexon files
distantfile = 'https://portal.g-node.org/neo/plexon/File_plexon_3.plx'
localfile = './File_plexon_3.plx'
urllib.urlretrieve(distantfile, localfile)

#create a reader
reader = neo.io.PlexonIO(filename = 'File_plexon_3.plx')
# read the block
bl = reader.read(cascade = True, lazy = False)
print bl
# acces to segments
for seg in bl.segments:
    print seg
    for asig in seg.analogsignals:
        print asig
    for st in seg.spiketrains:
        print st


# CED Spike2 files
distantfile = 'https://portal.g-node.org/neo/spike2/File_spike2_1.smr'
localfile = './File_spike2_1.smr'
urllib.urlretrieve(distantfile, localfile)

#create a reader
reader = neo.io.Spike2IO(filename = 'File_spike2_1.smr')
# read the block
bl = reader.read(cascade = True, lazy = False)
print bl
# acces to segments
for seg in bl.segments:
    print seg
    for asig in seg.analogsignals:
        print asig
    for st in seg.spiketrains:
        print st
"""
This is an example for plotting neo object with maplotlib.
"""

import neo
import urllib
from matplotlib import pyplot
import numpy

distantfile = 'https://portal.g-node.org/neo/neuroexplorer/File_neuroexplorer_2.nex'
localfile = 'File_neuroexplorer_2.nex'
urllib.urlretrieve(distantfile, localfile)


reader = neo.io.NeuroExplorerIO(filename = 'File_neuroexplorer_2.nex')
bl = reader.read(cascade = True, lazy = False)
for seg in bl.segments:
    fig = pyplot.figure()
    ax1 = fig.add_subplot(2,1,1)
    ax2 = fig.add_subplot(2,1,2, sharex = ax1)
    ax1.set_title(seg.file_origin)
    for asig in seg.analogsignals:
        ax1.plot(asig.times, asig)
    for s,st in enumerate(seg.spiketrains):
        print st.units
        ax2.plot(st, s*numpy.ones(st.size), linestyle = 'None', 
                    marker = '|', color = 'k')
pyplot.show()