Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertEqual(cCSS.name, 'test_cCSS')
self.assertEqual(cCSS.unit, 'amperes')
self.assertEqual(cCSS.electrode, electrode_name)
self.assertEqual(cCSS.gain, 1.0)
def test_unit_warning(self):
electrode_name = GetElectrode()
msg = ("Unit 'unit' for CurrentClampStimulusSeries 'test_cCSS' is ignored and will be set "
"to 'amperes' as per NWB 2.1.0.")
with self.assertWarnsWith(UserWarning, msg):
cCSS = CurrentClampStimulusSeries('test_cCSS', list(), electrode_name, 1.0, timestamps=list(), unit='unit')
self.assertEqual(cCSS.unit, 'amperes')
class VoltageClampSeriesConstructor(TestCase):
def test_init(self):
electrode_name = GetElectrode()
vCS = VoltageClampSeries('test_vCS', list(), electrode_name,
1.0, "stimset", 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, timestamps=list())
self.assertEqual(vCS.name, 'test_vCS')
self.assertEqual(vCS.unit, 'amperes')
self.assertEqual(vCS.electrode, electrode_name)
self.assertEqual(vCS.stimulus_description, "stimset")
self.assertEqual(vCS.gain, 1.0)
self.assertEqual(vCS.capacitance_fast, 2.0)
self.assertEqual(vCS.capacitance_slow, 3.0)
self.assertEqual(vCS.resistance_comp_bandwidth, 4.0)
self.assertEqual(vCS.resistance_comp_correction, 5.0)
self.assertEqual(vCS.resistance_comp_prediction, 6.0)
import numpy as np
from hdmf.common import DynamicTable, VectorData
from pynwb import TimeSeries
from pynwb.misc import Units, DecompositionSeries
from pynwb.testing import NWBH5IOMixin, AcquisitionH5IOMixin, TestCase
class TestUnitsIO(AcquisitionH5IOMixin, TestCase):
""" Test adding Units into acquisition and accessing Units after read """
def setUpContainer(self):
""" Return the test Units to read/write """
ut = Units(name='UnitsTest', description='a simple table for testing Units')
ut.add_unit(spike_times=[0, 1, 2], obs_intervals=[[0, 1], [2, 3]])
ut.add_unit(spike_times=[3, 4, 5], obs_intervals=[[2, 5], [6, 7]])
return ut
def test_get_spike_times(self):
""" Test whether the Units spike times read from file are what was written """
ut = self.roundtripContainer()
received = ut.get_unit_spike_times(0)
self.assertTrue(np.array_equal(received, [0, 1, 2]))
received = ut.get_unit_spike_times(1)
self.assertTrue(np.array_equal(received, [3, 4, 5]))
return pS
class OpticalChannelConstructor(TestCase):
def test_init(self):
oc = OpticalChannel(
name='test_optical_channel',
description='description',
emission_lambda=500.
)
self.assertEqual(oc.name, 'test_optical_channel')
self.assertEqual(oc.description, 'description')
self.assertEqual(oc.emission_lambda, 500.)
class ImagingPlaneConstructor(TestCase):
def set_up_dependencies(self):
oc = OpticalChannel(
name='test_optical_channel',
description='description',
emission_lambda=500.
)
device = Device(name='device_name')
return oc, device
def test_init(self):
oc, device = self.set_up_dependencies()
ip = ImagingPlane(
name='test_imaging_plane',
optical_channel=oc,
aS = AnnotationSeries('test_aS', timestamps=list())
self.assertEqual(aS.name, 'test_aS')
aS.add_annotation(2.0, 'comment')
class AbstractFeatureSeriesConstructor(TestCase):
def test_init(self):
aFS = AbstractFeatureSeries('test_aFS', ['feature units'], ['features'], timestamps=list())
self.assertEqual(aFS.name, 'test_aFS')
self.assertEqual(aFS.feature_units, ['feature units'])
self.assertEqual(aFS.features, ['features'])
aFS.add_features(2.0, [1.])
class DecompositionSeriesConstructor(TestCase):
def test_init(self):
timeseries = TimeSeries(name='dummy timeseries', description='desc',
data=np.ones((3, 3)), unit='Volts',
timestamps=np.ones((3,)))
bands = DynamicTable(name='bands', description='band info for LFPSpectralAnalysis', columns=[
VectorData(name='band_name', description='name of bands', data=['alpha', 'beta', 'gamma']),
VectorData(name='band_limits', description='low and high cutoffs in Hz', data=np.ones((3, 2)))
])
spec_anal = DecompositionSeries(name='LFPSpectralAnalysis',
description='my description',
data=np.ones((3, 3, 3)),
timestamps=np.ones((3,)),
source_timeseries=timeseries,
metric='amplitude',
bands=bands)
timestamps=list()
)
self.assertIsNone(iS.starting_frame)
class IndexSeriesConstructor(TestCase):
def test_init(self):
ts = TimeSeries('test_ts', list(), 'unit', timestamps=list())
iS = IndexSeries('test_iS', list(), ts, unit='unit', timestamps=list())
self.assertEqual(iS.name, 'test_iS')
self.assertEqual(iS.unit, 'unit')
self.assertEqual(iS.indexed_timeseries, ts)
class ImageMaskSeriesConstructor(TestCase):
def test_init(self):
iS = ImageSeries(name='test_iS', data=np.ones((2, 2, 2)), unit='unit',
external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff',
timestamps=[1., .2])
ims = ImageMaskSeries(name='test_ims', data=np.ones((2, 2, 2)), unit='unit',
masked_imageseries=iS, external_file=['external_file'], starting_frame=[1, 2, 3],
format='tiff', timestamps=[1., 2.])
self.assertEqual(ims.name, 'test_ims')
self.assertEqual(ims.unit, 'unit')
self.assertEqual(ims.masked_imageseries, iS)
self.assertEqual(ims.external_file, ['external_file'])
self.assertEqual(ims.starting_frame, [1, 2, 3])
self.assertEqual(ims.format, 'tiff')
ps = create_plane_segmentation()
rt_region = ps.create_roi_table_region(description='the second ROI', region=[1])
ts = RoiResponseSeries(
name='test_ts',
data=list(),
rois=rt_region,
unit='unit',
timestamps=list()
)
ff = Fluorescence(ts)
self.assertEqual(ff.roi_response_series['test_ts'], ts)
class ImageSegmentationConstructor(TestCase):
def test_init(self):
ps = create_plane_segmentation()
iS = ImageSegmentation(ps, name='test_iS')
self.assertEqual(iS.name, 'test_iS')
self.assertEqual(iS.plane_segmentations[ps.name], ps)
self.assertEqual(iS[ps.name], iS.plane_segmentations[ps.name])
class PlaneSegmentationConstructor(TestCase):
def set_up_dependencies(self):
iSS = ImageSeries(
name='test_iS',
data=np.ones((2, 2, 2)),
with self.assertWarnsWith(DeprecationWarning, 'use pynwb.misc.Units or NWBFile.units instead'):
cw = ClusterWaveforms(self.clustering, 'filtering', means, stdevs)
return cw
def addContainer(self, nwbfile):
""" Add the test ClusterWaveforms and related objects to the given NWBFile """
nwbfile.add_acquisition(self.clustering)
nwbfile.add_acquisition(self.container)
def roundtripContainer(self, cache_spec=False):
# catch the DeprecationWarning raised when reading the Clustering object from file
with self.assertWarnsWith(DeprecationWarning, 'use pynwb.misc.Units or NWBFile.units instead'):
return super().roundtripContainer(cache_spec)
class FeatureExtractionConstructor(AcquisitionH5IOMixin, TestCase):
def setUpContainer(self):
""" Return a test FeatureExtraction to read/write """
event_times = [1.9, 3.5]
TestElectricalSeriesIO.make_electrode_table(self)
region = DynamicTableRegion(name='electrodes',
data=[0, 2],
description='the first and third electrodes',
table=self.table)
description = ['desc1', 'desc2', 'desc3']
features = [[[0., 1., 2.], [3., 4., 5.]], [[6., 7., 8.], [9., 10., 11.]]]
fe = FeatureExtraction(electrodes=region, description=description, times=event_times, features=features)
return fe
def addContainer(self, nwbfile):
""" Add the test FeatureExtraction and related objects to the given NWBFile """
nwbfile = reader.read()
class TestTimestampsRefDefault(TestCase):
def setUp(self):
self.start_time = datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())
self.nwbfile = NWBFile('test session description',
'TEST123',
self.start_time)
def test_reftime_default(self):
# 'timestamps_reference_time' should default to 'session_start_time'
self.assertEqual(self.nwbfile.timestamps_reference_time, self.start_time)
class TestTimestampsRefAware(TestCase):
def setUp(self):
self.start_time = datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())
self.ref_time_notz = datetime(1979, 1, 1, 0, 0, 0)
def test_reftime_tzaware(self):
with self.assertRaises(ValueError):
# 'timestamps_reference_time' must be a timezone-aware datetime
NWBFile('test session description',
'TEST124',
self.start_time,
timestamps_reference_time=self.ref_time_notz)
device = Device(name='device_name')
msg = "NWBFile.create_ic_electrode has been replaced by NWBFile.create_icephys_electrode."
with self.assertWarnsWith(DeprecationWarning, msg):
nwbfile.create_ic_electrode(
name='test_iS',
device=device,
description='description',
slice='slice',
seal='seal',
location='location',
resistance='resistance',
filtering='filtering',
initial_access_resistance='initial_access_resistance')
class IntracellularElectrodeConstructor(TestCase):
def test_constructor(self):
device = Device(name='device_name')
elec = IntracellularElectrode('test_iS',
device,
'description',
'slice',
'seal',
'location',
'resistance',
'filtering',
'initial_access_resistance')
self.assertEqual(elec.name, 'test_iS')
self.assertEqual(elec.device, device)
self.assertEqual(elec.description, 'description')
self.assertEqual(elec.slice, 'slice')
nwbfile.add_device(self.dev1)
nwbfile.add_electrode_group(self.group)
nwbfile.set_electrode_table(self.table)
nwbfile.add_acquisition(self.container)
class TestLFPIO(MultiElectricalSeriesIOMixin, TestCase):
def setUpContainer(self):
""" Return a test LFP to read/write """
es = self.setUpTwoElectricalSeries()
lfp = LFP(es)
return lfp
class TestFilteredEphysIO(MultiElectricalSeriesIOMixin, TestCase):
def setUpContainer(self):
""" Return a test FilteredEphys to read/write """
es = self.setUpTwoElectricalSeries()
fe = FilteredEphys(es)
return fe
class TestClusteringIO(AcquisitionH5IOMixin, TestCase):
def setUpContainer(self):
""" Return a test Clustering to read/write """
with self.assertWarnsWith(DeprecationWarning, 'use pynwb.misc.Units or NWBFile.units instead'):
return Clustering("A fake Clustering interface",
[0, 1, 2, 0, 1, 2], [100., 101., 102.], [float(i) for i in range(10, 61, 10)])