We install a development branch of Neo with preliminary support for Neurodata Without Borders (NWB) format.
In [1]:
%matplotlib inline
In [2]:
%%capture
!pip install https://github.com/apdavison/python-neo/archive/nwb.zip
!pip install igor
In [3]:
import requests
import random
import zipfile
import StringIO
import neo
print(neo.__version__)
In [4]:
bbp_uncurated_url = "http://microcircuits.epfl.ch/data/uncurated.json"
In [5]:
uncurated = requests.get(bbp_uncurated_url).json()
In [6]:
print("{}\n\n{}".format(uncurated['title'], uncurated['introduction']['text']))
In [7]:
items = uncurated['data_table']['table']['rows']
In [8]:
items[0]
Out[8]:
In [9]:
# we filter to try to ensure we get a dataset containing Igor Pro files
filtered_items = [item for item in items if "tkb" in item[0]]
folder = random.sample(filtered_items, 1)[0]
print(folder)
In [10]:
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "a":
for attr in attrs:
if attr[0] == "href":
self.url = attr[1]
In [11]:
def get_zipfile(data_item):
parser = MyHTMLParser()
parser.feed(data_item[0])
data_file_url = parser.url
f = StringIO.StringIO()
response = requests.get("http://microcircuits.epfl.ch" + data_file_url)
f.write(response.content)
return zipfile.ZipFile(f)
In [12]:
archive = get_zipfile(folder)
In [13]:
len(archive.filelist)
Out[13]:
In [14]:
igor_file_path = random.sample([path for path in archive.namelist() if path.endswith(".ibw")], 1)[0]
In [15]:
igor_file_path
Out[15]:
In [16]:
from neo.io.igorproio import IgorIO
In [17]:
local_path = archive.extract(igor_file_path)
print(local_path)
In [18]:
block = IgorIO(local_path).read()[0]
In [19]:
block
Out[19]:
In [20]:
import matplotlib.pyplot as plt
In [21]:
signal = block.segments[0].analogsignals[0]
In [22]:
plt.plot(signal.times, signal)
plt.ylabel("Signal ({})".format(signal.units.dimensionality.string))
plt.xlabel("Time ({})".format(signal.times.units.dimensionality.string))
plt.title(signal.name)
Out[22]:
In [23]:
if signal.annotations['note']:
annotations = dict(line.split("#") for line in signal.annotations['note'].strip().split("\r"))
else:
annotations = {}
In [24]:
annotations
Out[24]:
In [25]:
%%capture
!pip install h5py
!pip install https://github.com/NeurodataWithoutBorders/api-python/archive/master.zip
In [26]:
from neo.io import NWBIO
Here we save a single trace into the NWB file. In practice, you would probably want to combine the data from all Igor Pro files in the zip archive into a single Neo block
In [27]:
io = NWBIO(local_path.replace(".ibw", ".nwb"))
In [28]:
block.segments[0].name = "Segment #0" # workaround a bug in NWBIO
In [29]:
io.write(block)
At this point, the exported NWB file fails validation. Development of the NWBIO is ongoing.
An alternative HDF5-based format
In [34]:
%%capture
!pip install nixio
In [36]:
from neo.io import NixIO
In [38]:
io = NixIO(local_path.replace(".ibw", ".h5"), 'rw')
In [39]:
io.write(block)
In [ ]: