Created
January 13, 2018 01:20
-
-
Save ajtritt/75ee33f5fdc76589ad97e3f7a32b27ca to your computer and use it in GitHub Desktop.
Some code that exposed a bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This code was breaking at write. See https://github.com/NeurodataWithoutBorders/pynwb/issues/317 | |
mschachter hacked PyNWB and then had problems reading. See https://github.com/NeurodataWithoutBorders/pynwb/issues/318 | |
This commit should fix both of these issues: https://github.com/NeurodataWithoutBorders/pynwb/commit/72fafa686748de25571d0abd6aa43cd3ab889bb9 | |
""" | |
import json | |
from datetime import datetime | |
import numpy as np | |
from pynwb import NWBFile, get_manager, NWBHDF5IO | |
from pynwb.ecephys import ElectricalSeries, SpikeEventSeries | |
nf = NWBFile('some recording', 'a session', | |
'bla bla bla', | |
datetime.now(), | |
experimenter='Jane Randn', | |
lab='The Lab', | |
institution='University of Bug Reports', | |
experiment_description='no description', | |
session_id='12345') | |
protocol_epoch = nf.create_epoch(source='', name='the epoch', start=0.0, stop=5200., | |
tags=('bug', 'report'), | |
description="") | |
electrode_array = nf.create_device(name='16 electrode array', source='') | |
electrode_group = nf.create_electrode_group('my group', | |
source='a brain', | |
description='', | |
location='somewhere', | |
device=electrode_array) | |
electrode_indices = np.arange(1) | |
for e in electrode_indices: | |
nf.add_electrode(e, | |
x=0.0, y=0.0, z=0.0, | |
imp=0.0, | |
location='somewhere', | |
filtering='none', | |
description='', | |
group=electrode_group) | |
etable = nf.create_electrode_table_region(list(electrode_indices), 'All electrodes in array') | |
spike_series = SpikeEventSeries('a_unit', 'unit desc', | |
np.random.randn(5, 18), | |
np.arange(5), | |
etable, | |
resolution=1e-12, | |
conversion=1e6, | |
comments='no comments', | |
description='' | |
) | |
nf.add_acquisition(spike_series, [protocol_epoch]) | |
path = 'tmp_somefile.nwb' | |
io = NWBHDF5IO(path, manager=get_manager(), mode='w') | |
io.write(nf) | |
io.close() | |
# now read it back in | |
reader = NWBHDF5IO(path, mode='r') | |
nf_in = reader.read() | |
spikes_in = nf_in.get_acquisition('a_unit') | |
reader.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment