def setUpContainer(self): """ Return the test TetrodeSeries to read/write """ self.device = Device(name='device_name') self.group = ElectrodeGroup(name='electrode_group', description='description', location='location', device=self.device) self.table = get_electrode_table( ) # manually create a table of electrodes for i in range(10): self.table.add_row(x=i, y=i, z=i, imp=np.nan, location='location', filtering='filtering', group=self.group, group_name='electrode_group') all_electrodes = DynamicTableRegion(data=list(range(0, 10)), description='all the electrodes', name='electrodes', table=self.table) data = np.random.rand(100, 3) tetrode_series = TetrodeSeries(name='name', description='description', data=data, rate=1000., electrodes=all_electrodes, trode_id=1) return tetrode_series
def setUpContainer(self): self.device = Device(name='dev1') self.optical_channel = OpticalChannel('optchan1', 'a fake OpticalChannel', 500.) return ImagingPlane('imgpln1', self.optical_channel, 'a fake ImagingPlane', self.device, 600., 300., 'GFP', 'somewhere in the brain')
def buildPlaneSegmentationNoRois(self): """ Return an PlaneSegmentation and set related objects """ ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.device = Device(name='dev1') self.optical_channel = OpticalChannel( name='test_optical_channel', description='optical channel description', emission_lambda=500.) self.imaging_plane = ImagingPlane( name='test_imaging_plane', optical_channel=self.optical_channel, description='imaging plane description', device=self.device, excitation_lambda=600., imaging_rate=300., indicator='GFP', location='somewhere in the brain', reference_frame='a frame to refer to') return PlaneSegmentation(description='description', imaging_plane=self.imaging_plane, name='test_plane_seg_name', reference_images=self.image_series)
def __init__(self, nwbfile, emission_lambda=np.nan, excitation_lambda=np.nan, frame_rate=np.nan, indicator='unknown', location='unknown'): super(OphysProcessing2NWB, self).__init__(nwbfile) device = Device('microscope') self.nwbfile.add_device(device) optical_channel = OpticalChannel('OpticalChannel', 'description', emission_lambda=emission_lambda) imaging_plane = self.nwbfile.create_imaging_plane( 'ImagingPlane', optical_channel, description='description', device=device, excitation_lambda=excitation_lambda, imaging_rate=frame_rate, indicator=indicator, location=location) self.ophys_mod = self.nwbfile.create_processing_module( 'ophys', 'contains optical physiology processed data') img_seg = ImageSegmentation() self.ophys_mod.add_data_interface(img_seg) self.ps = img_seg.create_plane_segmentation( 'output from segmenting my favorite imaging plane', imaging_plane, 'PlaneSegmentation')
def test_init(self): oc = OpticalChannel('test_name', 'description', 500.) self.assertEqual(oc.description, 'description') self.assertEqual(oc.emission_lambda, 500.) device = Device(name='device_name') ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', (50, 100, 3), 4.0, 'unit', 'reference_frame') self.assertEqual(ip.optical_channel[0], oc) self.assertEqual(ip.device, device) self.assertEqual(ip.excitation_lambda, 600.) self.assertEqual(ip.imaging_rate, 300.) self.assertEqual(ip.indicator, 'indicator') self.assertEqual(ip.location, 'location') self.assertEqual(ip.manifold, (50, 100, 3)) self.assertEqual(ip.conversion, 4.0) self.assertEqual(ip.unit, 'unit') self.assertEqual(ip.reference_frame, 'reference_frame') tPS = TwoPhotonSeries('test_tPS', unit='unit', field_of_view=[2., 3.], imaging_plane=ip, pmt_gain=1.0, scan_line_rate=2.0, external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list()) self.assertEqual(tPS.name, 'test_tPS') self.assertEqual(tPS.unit, 'unit') self.assertEqual(tPS.field_of_view, [2., 3.]) self.assertEqual(tPS.imaging_plane, ip) self.assertEqual(tPS.pmt_gain, 1.0) self.assertEqual(tPS.scan_line_rate, 2.0) self.assertEqual(tPS.external_file, ['external_file']) self.assertEqual(tPS.starting_frame, [1, 2, 3]) self.assertEqual(tPS.format, 'tiff') self.assertIsNone(tPS.dimension)
def test_electrode_group(self): ut = Units() device = Device('test_device') electrode_group = ElectrodeGroup('test_electrode_group', 'description', 'location', device) ut.add_unit(electrode_group=electrode_group) self.assertEqual(ut['electrode_group'][0], electrode_group)
def buildPlaneSegmentation(self): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [(1, 2, 1.0), (3, 4, 1.0), (5, 6, 1.0), (7, 8, 2.0), (9, 10, 2.)] ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.device = Device(name='dev1') self.optical_channel = OpticalChannel('test_optical_channel', 'optical channel description', 500.) self.imaging_plane = ImagingPlane('ophys integration tests', self.optical_channel, 'imaging plane description', self.device, 600., 300., 'GFP', 'somewhere in the brain', (1, 2, 1, 2, 3), 4.0, 'manifold unit', 'A frame to refer to') self.img_mask = deepcopy(img_mask) self.pix_mask = deepcopy(pix_mask) self.pxmsk_index = [3, 5] pS = PlaneSegmentation('plane segmentation description', self.imaging_plane, 'test_plane_seg_name', self.image_series) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) return pS
def setUpContainer(self): """ Return the test SweepTable to read/write """ self.device = Device(name='device_name') self.elec = IntracellularElectrode( name="elec0", slice='tissue slice', resistance='something measured in ohms', seal='sealing method', description='a fake electrode object', location='Springfield Elementary School', filtering='a meaningless free-form text field', initial_access_resistance='I guess this changes', device=self.device) self.pcs = PatchClampSeries(name="pcs", data=[1, 2, 3, 4, 5], unit='A', starting_time=123.6, rate=10e3, electrode=self.elec, gain=0.126, stimulus_description="gotcha ya!", sweep_number=np.uint(4711)) # Create the SweepTable but ignore the DeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter('ignore', DeprecationWarning) sweeptable = SweepTable(name='sweep_table') # Reissue any other warnings that may have occured for i in w: warnings.warn(i.message, i.category) return sweeptable
def test_read_nwb_nwb_electrode_group_successfully(self): device = Device('device_0') self.nwb_file_content.add_device(device) nwb_electrode_group = NwbElectrodeGroup( name='nwb_electrode_group_0', description='Sample description', location='Sample location', device=device, targeted_location='predicted location', targeted_x=1.0, targeted_y=2.0, targeted_z=3.0, units='um') self.nwb_file_content.add_electrode_group(nwb_electrode_group) nwb_file_handler = NWBHDF5IO('nwb_electrode_group.nwb', mode='w') nwb_file_handler.write(self.nwb_file_content) nwb_file_handler.close() self.assertTrue(os.path.exists('nwb_electrode_group.nwb')) with pynwb.NWBHDF5IO('nwb_electrode_group.nwb', 'r') as nwb_file_handler: nwb_file = nwb_file_handler.read() self.assertEqual( nwb_file.electrode_groups['nwb_electrode_group_0'].name, nwb_electrode_group.name) self.assertEqual( nwb_file.electrode_groups['nwb_electrode_group_0']. targeted_location, nwb_electrode_group.targeted_location) self.delete_nwb('nwb_electrode_group')
def addContainer(self, nwbfile): device = Device(name='device_name') nwbfile.add_device(device) elec = IntracellularElectrode( name="elec0", slice='tissue slice', resistance='something measured in ohms', seal='sealing method', description='a fake electrode object', location='Springfield Elementary School', filtering='a meaningless free-form text field', initial_access_resistance='I guess this changes', device=device) nwbfile.add_ic_electrode(elec) pcs = PatchClampSeries(name="pcs", data=[1, 2, 3, 4, 5], unit='A', starting_time=123.6, rate=10e3, electrode=elec, gain=0.126, stimulus_description="gotcha ya!", sweep_number=4711) nwbfile.add_acquisition(pcs) self.container = nwbfile.sweep_table self.assertEqual(len(self.container['series'].data), 1) self.assertEqual(self.container.id[0], 0) self.assertEqual(self.container['sweep_number'].data[0], 4711)
def CreatePlaneSegmentation(): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS = 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.]) oc = OpticalChannel('test_optical_channel', 'description', 500.) device = Device(name='device_name') ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) return pS
def test_show_single_sweep_sequence(): device = Device(name='Axon Patch-Clamp') electrode = IntracellularElectrode(name='Patch Clamp', device=device, description='whole-cell') stimulus_data = np.random.rand(160, 2) stimulus = TimeSeries(name='test_timeseries', data=stimulus_data, unit='m', starting_time=0.0, rate=1.0) response_data = np.random.rand(160, 2) response = TimeSeries(name='test_timeseries', data=response_data, unit='m', starting_time=0.0, rate=1.0) icr = IntracellularRecordings() icr.add_recording(electrode=electrode, stimulus_start_index=0, stimulus_index_count=100, stimulus=stimulus, response_start_index=0, response_index_count=100, response=response) sweeps_table = Sweeps(intracellular_recordings_table=icr) assert isinstance(show_single_sweep_sequence(sweeps_table), plt.Figure)
def test_init(self): device = Device(name='device_name', description='description', manufacturer='manufacturer') self.assertEqual(device.name, 'device_name') self.assertEqual(device.description, 'description') self.assertEqual(device.manufacturer, 'manufacturer')
def make_imaging_plane(self): self.device = Device(name='dev1') self.optical_channel = OpticalChannel('optchan1', 'a fake OpticalChannel', 500.) self.imaging_plane = ImagingPlane('imgpln1', self.optical_channel, 'a fake ImagingPlane', self.device, 600., 300., 'GFP', 'somewhere in the brain')
def setUpContainer(self): """ Return the test ElectrodeGroup to read/write """ self.dev1 = Device(name='dev1') eg = ElectrodeGroup(name='elec1', description='a test ElectrodeGroup', location='a nonexistent place', device=self.dev1) return eg
def setUpContainer(self): """ Return the test OptogeneticStimulusSite to read/write """ self.device = Device(name='dev1') return OptogeneticStimulusSite(name='stim_site', device=self.device, description='my stim site', excitation_lambda=300., location='in the brain')
def test_init(self): dev1 = Device('dev1') # noqa: F405 group = ElectrodeGroup( # noqa: F405 'elec1', 'electrode description', 'electrode location', dev1) self.assertEqual(group.name, 'elec1') self.assertEqual(group.description, 'electrode description') self.assertEqual(group.location, 'electrode location') self.assertEqual(group.device, dev1)
def test_init_position_none(self): dev1 = Device('dev1') group = ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1) self.assertEqual(group.name, 'elec1') self.assertEqual(group.description, 'electrode description') self.assertEqual(group.location, 'electrode location') self.assertEqual(group.device, dev1) self.assertIsNone(group.position)
def _createDevice(self): """ Create a pynwb Device object from the cfs file contents. """ digitizer = self.refcfs.fileVars[0]['desc'] telegraph = self.refcfs.fileVars[0]['desc'] return Device(f"{digitizer} with {telegraph}")
def make_electrode_table(self): """ Make an electrode table, electrode group, and device """ self.table = get_electrode_table() self.dev1 = Device('dev1') self.group = ElectrodeGroup('tetrode1', 'tetrode description', 'tetrode location', self.dev1) for i in range(4): self.table.add_row(x=i, y=2.0, z=3.0, imp=-1.0, location='CA1', filtering='none', group=self.group, group_name='tetrode1')
def _createDevice(self): """ Create a pynwb Device object from the ABF file contents. """ digitizer = self.refabf._protocolSection.sDigitizerType telegraph = self.refabf._adcSection.sTelegraphInstrument[0] return Device(f"{digitizer} with {telegraph}")
def test_args(self): oc = OpticalChannel('test_name', 'description', 500.) device = Device(name='device_name') ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', (50, 100, 3), 4.0, 'unit', 'reference_frame') with self.assertRaises(ValueError): # no data or external file TwoPhotonSeries('test_tPS', unit='unit', field_of_view=[2., 3.], imaging_plane=ip, pmt_gain=1.0, scan_line_rate=2.0, starting_frame=[1, 2, 3], format='tiff', timestamps=[1., 2.])
def getBoilerPlateObjects(self): iSS = ImageSeries(name='test_iS', data=np.ones((2, 2, 2)), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list()) device = Device(name='device_name') oc = OpticalChannel('test_optical_channel', 'description', 500.) ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') return iSS, ip
def setUpElectrode(self): """ Set up the test IntracellularElectrode """ self.device = Device(name='device_name') self.elec = IntracellularElectrode(name="elec0", slice='tissue slice', resistance='something measured in ohms', seal='sealing method', description='a fake electrode object', location='Springfield Elementary School', filtering='a meaningless free-form text field', initial_access_resistance='I guess this changes', device=self.device)
def test_init(self): dev1 = Device('dev1') # noqa: F405 group = ElectrodeGroup( # noqa: F405, F841 'tetrode1', 'tetrode description', 'tetrode location', dev1) table = make_electrode_table() region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', table) eS = ElectricalSeries( # noqa: F405 'test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4]) fe = FilteredEphys(eS) # noqa: F405 self.assertEqual(fe.electrical_series.get('test_eS'), eS) self.assertEqual(fe['test_eS'], fe.electrical_series.get('test_eS'))
def test_conversion_deprecated(self): oc = OpticalChannel('test_name', 'description', 500.) self.assertEqual(oc.description, 'description') self.assertEqual(oc.emission_lambda, 500.) device = Device(name='device_name') msg = "The 'conversion' argument is deprecated in favor of 'origin_coords' and 'grid_spacing'." with self.assertWarnsWith(DeprecationWarning, msg): ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', None, 2.0)
def _createDevice(self): """ Create a pynwb Device object from the DAT file contents. Returns ------- pynwb.Device """ name = DatConverter._formatDeviceString(self.bundle.amp[0][0]) return Device(name)
def __init__(self, metadata, nwbfile=None, source_paths=None): super(OphysNWBConverter, self).__init__(metadata, nwbfile=nwbfile, source_paths=source_paths) device = Device('microscope') self.nwbfile.add_device(device) self.imaging_plane = self.add_imaging_plane() self.ophys_mod = self.nwbfile.create_processing_module( 'ophys', 'contains optical physiology processed data')
def test_add_electrical_series(self): lfp = LFP() # noqa: F405 dev1 = Device('dev1') # noqa: F405 group = ElectrodeGroup( # noqa: F405, F841 'tetrode1', 'tetrode description', 'tetrode location', dev1) table = make_electrode_table() region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', table) eS = ElectricalSeries( # noqa: F405 'test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4]) lfp.add_electrical_series(eS) self.assertEqual(lfp.electrical_series.get('test_eS'), eS) self.assertEqual(lfp['test_eS'], lfp.electrical_series.get('test_eS'))
def test_init(self): dev1 = Device('dev1') # noqa: F405 group = ElectrodeGroup( # noqa: F405, F841 'tetrode1', 'tetrode description', 'tetrode location', dev1) table = make_electrode_table() region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', table) sES = SpikeEventSeries( # noqa: F405 'test_sES', list(range(10)), list(range(10)), region) ew = EventWaveform(sES) # noqa: F405 self.assertEqual(ew.spike_event_series['test_sES'], sES) self.assertEqual(ew['test_sES'], ew.spike_event_series['test_sES'])