Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_tags(self):
nwbfile = NWBFile("a file with header data", "NB123A", datetime(1970, 1, 1, tzinfo=tz.tzutc()))
df = self.get_dataframe()
for i, row in df.iterrows():
nwbfile.add_epoch(start_time=row['start_time'], stop_time=row['stop_time'])
def test_create_electrode_group_invalid_index(self):
"""
Test the case where the user creates an electrode table region with
indexes that are out of range of the amount of electrodes added.
"""
nwbfile = NWBFile('a', 'b', datetime.now(tzlocal()))
device = nwbfile.create_device('a')
elecgrp = nwbfile.create_electrode_group('a', 'b', device=device, location='a')
for i in range(4):
nwbfile.add_electrode(np.nan, np.nan, np.nan, np.nan, 'a', 'a', elecgrp, id=i)
with self.assertRaises(IndexError):
nwbfile.create_electrode_table_region(list(range(6)), 'test')
def setUpContainer(self):
container = NWBFile('a test NWB File', 'TEST123',
self.start_time,
timestamps_reference_time=self.ref_time,
file_create_date=self.create_date,
experimenter='test experimenter',
stimulus_notes='test stimulus notes',
experiment_description='test experiment description',
data_collection='test data collection notes',
institution='nomad',
lab='nolab',
notes='nonotes',
pharmacology='nopharmacology',
protocol='noprotocol',
related_publications='nopubs',
session_id='007',
slices='noslices',
source_script='nosources',
def setUp(self):
self.nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))
def test_container(self):
""" Test properties of the SweepTable read from file """
description = 'a file to test writing and reading a %s' % self.container_type
identifier = 'TEST_%s' % self.container_type
nwbfile = NWBFile(description, identifier, self.start_time, file_create_date=self.create_date)
self.addContainer(nwbfile)
sweep_table = self.getContainer(nwbfile)
self.assertEqual(len(sweep_table['series'].data), 1)
self.assertEqual(sweep_table.id[0], 0)
self.assertEqual(sweep_table['sweep_number'].data[0], 4711)
ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', self.prefix, version='0.1.0')
test_meta_ext = NWBGroupSpec(
neurodata_type_def='MyTestMetaData',
neurodata_type_inc='LabMetaData',
doc='my test meta data',
attributes=[
NWBAttributeSpec(name='test_attr', dtype='float', doc='test_dtype')])
ns_builder.add_spec(self.ext_source, test_meta_ext)
ns_builder.export(self.ns_path, outdir=self.tempdir)
ns_abs_path = os.path.join(self.tempdir, self.ns_path)
load_namespaces(ns_abs_path)
MyTestMetaData = get_class('MyTestMetaData', self.prefix)
nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))
nwbfile.add_lab_meta_data(MyTestMetaData(name='test_name', test_attr=5.))
def get_container_location(container):
location = list()
curr = container
top_container = curr
while curr.parent:
location.append(HDF5ContainerRenderer.relative_location(curr.parent, curr))
top_container = curr.parent
curr = curr.parent
if not isinstance(top_container, NWBFile):
raise Exception('highest container not a file: %s (%s) --> ... --> %s (%s)' % (container, type(container), top_container, type(top_container)))
container_source = top_container.container_source
container_path = '/%s' % posixpath.join(*reversed(location))
#container_path = posixpath.join(*reversed(location))
return (container_source, container_path)
def main():
nwb_path = 'ophys_example.nwb'
# create your NWBFile object
nwbfile = NWBFile('the PyNWB tutorial', 'my first synthetic recording', 'EXAMPLE_ID', datetime.now(),
experimenter='Dr. Bilbo Baggins',
lab='Bag End Laboratory',
institution='University of Middle Earth at the Shire',
experiment_description='I went on an adventure with thirteen dwarves to reclaim vast treasures.',
session_id='LONELYMTN')
# create acquisition metadata
optical_channel = OpticalChannel('test_optical_channel', 'optical channel source',
'optical channel description', '3.14')
imaging_plane = nwbfile.create_imaging_plane('test_imaging_plane',
'ophys integration tests',
optical_channel,
'imaging plane description',
'imaging_device_1',
'6.28', '2.718', 'GFP', 'somewhere in the brain',
(1, 2, 1, 2, 3), 4.0, 'manifold unit', 'A frame to refer to')
"""
####################
# The NWB file
# ------------
#
#
from datetime import datetime
from pynwb import NWBFile
start_time = datetime(2017, 4, 3, 11, 0, 0)
create_date = datetime(2017, 4, 15, 12, 0, 0)
nwbfile = NWBFile('PyNWB tutorial', 'demonstrate NWBFile basics', 'NWB123', start_time,
file_create_date=create_date)
####################
# .. _basic_timeseries:
#
# Time series data
# ----------------
#
# PyNWB stores time series data using the :py:class:`~pynwb.base.TimeSeries` class and its subclasses.
# The main components of a :py:class:`~pynwb.base.TimeSeries` are the *data* and the *timestamps*.
# You will also need to supply a *source* and *description* of the data and the unit for *data*.
from pynwb import TimeSeries
data = list(range(100, 200, 10))
timestamps = list(range(10))
# Create data representing the ImageSegmentation results
iS = ImageSegmentation('test source', ps, name='test_iS')
#####################
# Now create our ROI dF/F data
rrs = RoiResponseSeries('test_ts', 'a hypothetical source', list(), 'unit', ['name1'], iS, timestamps=list())
dof = DfOverF('test_dof', rrs)
#####################
# Create the NWBFile object
NA = 'THIS FIELD INTENTIONALLY LEFT BLANK'
import datetime as dt
from pynwb import NWBFile
nwb = NWBFile(
source = NA,
session_description = NA,
identifier = NA,
session_start_time = dt.datetime.now(),
)
#####################
# create a processing module to put it all in
ophys_module = nwb.create_processing_module(
name="ophys",
description="calcium responses",
source="Allen Brain Observatory: Visual Behavior",
)
#####################
# only add the top level container?