Exemplo n.º 1
0
 def test_init(self):
     data = list(range(10))
     ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     eS = ElectricalSeries('test_eS', data, region, timestamps=ts)
     self.assertEqual(eS.name, 'test_eS')
     self.assertEqual(eS.data, data)
     self.assertEqual(eS.timestamps, ts)
Exemplo n.º 2
0
 def test_init(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     eS = ElectricalSeries('test_eS', [0, 1, 2, 3],
                           region,
                           timestamps=[0.1, 0.2, 0.3, 0.4])
     fe = FilteredEphys(eS)
     self.assertEqual(fe.electrical_series.get('test_eS'), eS)
     self.assertEqual(fe['test_eS'], fe.electrical_series.get('test_eS'))
Exemplo n.º 3
0
 def test_invalid_init_mismatched_event_times(self):
     event_times = []  # Need 1 event time but give 0
     table = make_electrode_table()
     electrodes = DynamicTableRegion('electrodes', [0, 2],
                                     'the first and third electrodes',
                                     table)
     description = ['desc1', 'desc2', 'desc3']
     features = [[[0, 1, 2], [3, 4, 5]]]
     self.assertRaises(ValueError, FeatureExtraction, electrodes,
                       description, event_times, features)
Exemplo n.º 4
0
 def test_add_electrical_series(self):
     lfp = LFP()
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     eS = ElectricalSeries('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)
Exemplo n.º 5
0
    def test_init(self):
        table = make_electrode_table()
        region = DynamicTableRegion('electrodes', [0, 2],
                                    'the first and third electrodes', table)
        sES = SpikeEventSeries('test_sES', list(range(10)), list(range(10)),
                               region)

        ew = EventWaveform(sES)
        self.assertEqual(ew.spike_event_series['test_sES'], sES)
        self.assertEqual(ew['test_sES'], ew.spike_event_series['test_sES'])
Exemplo n.º 6
0
 def setUpContainer(self):
     event_times = [1.9, 3.5]
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes',
                                 self.table)
     description = ['desc1', 'desc2', 'desc3']
     features = [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
     fe = FeatureExtraction(region, description, event_times, features)
     return fe
Exemplo n.º 7
0
 def test_init(self):
     event_times = [1.9, 3.5]
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     description = ['desc1', 'desc2', 'desc3']
     features = [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
     fe = FeatureExtraction(region, description, event_times, features)
     self.assertEqual(fe.description, description)
     self.assertEqual(fe.times, event_times)
     self.assertEqual(fe.features, features)
Exemplo n.º 8
0
 def test_init(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [1, 3],
                                 'the second and fourth electrodes', table)
     data = ((1, 1, 1), (2, 2, 2))
     timestamps = np.arange(2)
     sES = SpikeEventSeries('test_sES', data, timestamps, region)
     self.assertEqual(sES.name, 'test_sES')
     # self.assertListEqual(sES.data, data)
     np.testing.assert_array_equal(sES.data, data)
     np.testing.assert_array_equal(sES.timestamps, timestamps)
Exemplo n.º 9
0
 def setUpContainer(self):
     data = list(range(10))
     ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes',
                                 self.table)
     self.eS = ElectricalSeries('test_eS', data, region, timestamps=ts)
     eD = EventDetection('detection_method', self.eS, (1, 2, 3),
                         (0.1, 0.2, 0.3))
     return eD
Exemplo n.º 10
0
 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'))
Exemplo n.º 11
0
 def setUpElectricalSeriesContainers(self):
     TestElectricalSeriesIO.make_electrode_table(self)
     region1 = DynamicTableRegion('electrodes', [0, 2],
                                  'the first and third electrodes',
                                  self.table)
     region2 = DynamicTableRegion('electrodes', [1, 3],
                                  'the second and fourth electrodes',
                                  self.table)
     data1 = list(zip(range(10), range(10, 20)))
     data2 = list(zip(reversed(range(10)), reversed(range(10, 20))))
     timestamps = list(map(lambda x: x / 10, range(10)))
     es1 = ElectricalSeries('test_eS1',
                            data1,
                            region1,
                            timestamps=timestamps)
     es2 = ElectricalSeries('test_eS2',
                            data2,
                            region2,
                            timestamps=timestamps)
     return (es1, es2)
Exemplo n.º 12
0
    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'])
Exemplo n.º 13
0
 def test_init(self):
     data = list(range(10))
     ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', table)
     eS = ElectricalSeries('test_eS', data, region, timestamps=ts)  # noqa: F405
     eD = EventDetection('detection_method', eS, (1, 2, 3), (0.1, 0.2, 0.3))  # noqa: F405
     self.assertEqual(eD.detection_method, 'detection_method')
     self.assertEqual(eD.source_electricalseries, eS)
     self.assertEqual(eD.source_idx, (1, 2, 3))
     self.assertEqual(eD.times, (0.1, 0.2, 0.3))
     self.assertEqual(eD.unit, 'Seconds')
Exemplo n.º 14
0
 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'))
Exemplo n.º 15
0
 def test_init(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [1, 3],
                                 'the second and fourth electrodes', table)
     data = np.zeros(10)
     timestamps = np.arange(10)
     sES = SpikeEventSeries('test_sES', 'a hypothetical source', data,
                            timestamps, region)  # noqa: F405
     self.assertEqual(sES.name, 'test_sES')
     self.assertEqual(sES.source, 'a hypothetical source')
     # self.assertListEqual(sES.data, data)
     np.testing.assert_array_equal(sES.data, data)
     np.testing.assert_array_equal(sES.timestamps, timestamps)
Exemplo n.º 16
0
 def test_link(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     ts1 = ElectricalSeries('test_ts1', [0, 1, 2, 3, 4, 5],
                            region,
                            timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
     ts2 = ElectricalSeries('test_ts2', ts1, region, timestamps=ts1)
     ts3 = ElectricalSeries('test_ts3', ts2, region, timestamps=ts2)
     self.assertEqual(ts2.data, [0, 1, 2, 3, 4, 5])
     self.assertEqual(ts2.timestamps, [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
     self.assertEqual(ts3.data, [0, 1, 2, 3, 4, 5])
     self.assertEqual(ts3.timestamps, [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
Exemplo n.º 17
0
 def test_invalid_data_shape(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     with self.assertRaisesRegex(
             ValueError,
             re.escape(
                 "incorrect shape for 'data' (got '(2, 2, 2, 2)', expected "
                 "'((None,), (None, None), (None, None, None))')")):
         ElectricalSeries('test_ts1',
                          np.ones((2, 2, 2, 2)),
                          region,
                          timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
Exemplo n.º 18
0
 def test_invalid_init_mismatched_description2(self):  # noqa: F811
     event_times = [1]
     table = make_electrode_table()
     electrodes = DynamicTableRegion('electrodes', [0, 2],
                                     'the first and third electrodes',
                                     table)
     description = ['desc1', 'desc2', 'desc3']
     features = [[0, 1, 2],
                 [3, 4, 5]]  # Need 3D feature array but give only 2D array
     self.assertRaises(
         ValueError,
         FeatureExtraction,  # noqa: F405
         electrodes,
         description,
         event_times,
         features)
Exemplo n.º 19
0
)

# Important: we add the fibers to the fibers table _after_ adding the metadata
# This ensures that we can find this data in their tables of origin
fibers_table.add_fiber(
    excitation_source=0, #integers indicated rows of excitation sources table
    photodetector=0,
    fluorophores=[0], #potentially multiple fluorophores, so list of indices
    location='my location',
    notes='notes'
)

# Here we set up a list of fibers that our recording came from
fibers_ref = DynamicTableRegion(
    name="rois", 
    data=[0], # potentially multiple fibers
    description="source fibers", 
    table=fibers_table
)

# Create a raw roiresponseseries, this is your main acquisition
roi_response_series = RoiResponseSeries(
    name="raw_fluorescence_trace",
    description="my roi response series",
    data=np.random.randn(100, 1),
    unit='F',
    rate=30.0,
    rois=fibers_ref,
)

# This is your processed data
deconv_roi_response_series = DeconvolvedRoiResponseSeries(
Exemplo n.º 20
0
    def test_dynamic_table_iteration(self):
        table = self.with_columns_and_data()

        dynamic_table_region = DynamicTableRegion('dtr', [0, 1, 2, 3, 4], 'desc', table=table)
        for ii, item in enumerate(dynamic_table_region):
            self.assertEqual(table[ii], item)
Exemplo n.º 21
0
    def test_indexed_dynamic_table_region(self):
        table = self.with_columns_and_data()

        dynamic_table_region = DynamicTableRegion('dtr', [0, 1, 1], 'desc', table=table)
        fetch_ids = [x[1] for x in dynamic_table_region[:3]]
        self.assertEqual(fetch_ids, [1, 2, 2])
Exemplo n.º 22
0
    def test_roundtrip(self):
        multi_commanded_voltage = MultiCommandedVoltage()

        commandedvoltage_series = (
            multi_commanded_voltage.create_commanded_voltage_series(
                name="commanded_voltage",
                data=[1.0, 2.0, 3.0],
                frequency=30.0,
                power=500.0,
                rate=30.0,
                unit='volts'))

        cmmandedvoltage_series2 = (
            multi_commanded_voltage.create_commanded_voltage_series(
                name="commanded_voltage2",
                data=[1.0, 2.0, 3.0],
                frequency=30.0,
                power=500.0,
                rate=30.0,
            ))

        excitationsources_table = ExcitationSourcesTable(
            description="excitation sources table")

        excitationsources_table.add_row(
            peak_wavelength=700.0,
            source_type="laser",
            commanded_voltage=commandedvoltage_series,
        )

        photodetectors_table = PhotodetectorsTable(
            description="photodetectors table")
        photodetectors_table.add_row(peak_wavelength=500.0,
                                     type="PMT",
                                     gain=100.0)

        fluorophores_table = FluorophoresTable(description='fluorophores')
        fluorophores_table.add_row(label='dlight',
                                   location='VTA',
                                   coordinates=(3.0, 2.0, 1.0))

        fibers_table = FibersTable(description="fibers table")

        fibers_ref = DynamicTableRegion(name="rois",
                                        data=[0],
                                        description="source fibers",
                                        table=fibers_table)

        roi_response_series = RoiResponseSeries(
            name="roi_response_series",
            description="my roi response series",
            data=np.random.randn(100, 1),
            unit='F',
            rate=30.0,
            rois=fibers_ref,
        )

        deconv_roi_response_series = DeconvolvedRoiResponseSeries(
            name="DeconvolvedRoiResponseSeries",
            description="my roi response series",
            data=np.random.randn(100, 1),
            unit='F',
            rate=30.0,
            rois=fibers_ref,
            raw=roi_response_series,
        )

        ophys_module = self.nwbfile.create_processing_module(
            name="ophys", description="fiber photometry")

        self.nwbfile.add_lab_meta_data(
            FiberPhotometry(fibers=fibers_table,
                            excitation_sources=excitationsources_table,
                            photodetectors=photodetectors_table,
                            fluorophores=fluorophores_table,
                            commanded_voltages=multi_commanded_voltage))

        fibers_table.add_fiber(excitation_source=0,
                               photodetector=0,
                               fluorophores=[0],
                               location='my location',
                               notes='notes')

        self.nwbfile.add_acquisition(roi_response_series)
        ophys_module.add(deconv_roi_response_series)

        with NWBHDF5IO(self.path, mode="w") as io:
            io.write(self.nwbfile)

        with NWBHDF5IO(self.path, mode="r", load_namespaces=True) as io:
            read_nwbfile = io.read()
            self.assertContainerEqual(ophys_module,
                                      read_nwbfile.processing["ophys"])
            self.assertContainerEqual(
                self.nwbfile.lab_meta_data['fiber_photometry'],
                read_nwbfile.lab_meta_data['fiber_photometry'])
            self.assertContainerEqual(
                roi_response_series,
                read_nwbfile.acquisition["roi_response_series"])