-
Notifications
You must be signed in to change notification settings - Fork 266
Closed
Description
This is a version of the AxonIO example from documentation which is tested with Python 3.6. This could be useful for people new to library and using Python 3. It shows how to access neo object's data components, particularly extracting raw magnitudes.
import neo
neo.__version__ # tested on 0.5.0alpha1 with Py3.6
from neo.io import AxonIO
import urllib
from matplotlib import pyplot as plt
url = "https://portal.g-node.org/neo/axon/File_axon_3.abf"
filename = './test.abf'
urllib.request.urlretrieve(url, filename)
r = AxonIO(filename=filename)
# Get the first block
bl = r.read()[0]
is_block = isinstance(bl, neo.core.block.Block) # Is this a neo block?
# Extract analog signals from the first segment
ans = bl.segments[0].analogsignals # There are two signals
t = ans[0].times.magnitude
s1 = ans[0] # Signal 1
s2 = ans[1] # Signal 2
# Now plot analog signal
plt.plot(t, s1.magnitude, label=s1.name)
plt.plot(t, s2.magnitude, label=s2.name)
plt.legend(loc="upperright")
xunit = str(s1.times.units)
yunit = str(s1.units)
plt.xlabel("Time" + "(" + xunit + ")")
plt.ylabel("Analog Signal" + "(" + yunit + ")")
plt.show()Note: Thanks to @achilleas-k for magnitude tip.