コード例 #1
0
 def setUpTwoElectricalSeries(self):
     """ Return two test ElectricalSeries to read/write """
     TestElectricalSeriesIO.make_electrode_table(self)
     region1 = DynamicTableRegion(
         name='electrodes',
         data=[0, 2],
         description='the first and third electrodes',
         table=self.table)
     region2 = DynamicTableRegion(
         name='electrodes',
         data=[1, 3],
         description='the second and fourth electrodes',
         table=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(name='test_eS1',
                            data=data1,
                            electrodes=region1,
                            timestamps=timestamps)
     es2 = ElectricalSeries(name='test_eS2',
                            data=data2,
                            electrodes=region2,
                            channel_conversion=[4., .4],
                            timestamps=timestamps)
     return es1, es2
コード例 #2
0
 def setUpContainer(self):
     """ Return a test EventWaveform to read/write """
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', self.table)
     sES = SpikeEventSeries('test_sES', ((1, 1, 1), (2, 2, 2)), list(range(2)), region)
     ew = EventWaveform(sES)
     return ew
コード例 #3
0
 def test_no_rate(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [1, 3],
                                 'the second and fourth electrodes', table)
     data = ((1, 1, 1), (2, 2, 2))
     with self.assertRaises(TypeError):
         SpikeEventSeries('test_sES', data, region, rate=1.)
コード例 #4
0
ファイル: dna_table.py プロジェクト: kellyhuang21/deep-taxon
    def __init__(self, **kwargs):
        sequence_name, index, sequence, taxon, taxon_table = popargs('sequence_name',
                                                             'sequence_index',
                                                             'sequence',
                                                             'taxon',
                                                             'taxon_table',
                                                             kwargs)
        self._bitpacked = popargs('bitpacked', kwargs)
        vocab = popargs('vocab', kwargs)

        self.pad = popargs('pad', kwargs)
        seqlens = popargs('length', kwargs)
        columns = list()
        self.maxlen = None
        if isinstance(sequence_name, VectorData):      # data is being read -- here we assume that everything is a VectorData
            columns.append(sequence_name)
            columns.append(index)
            columns.append(sequence)
            columns.append(seqlens)
            columns.append(taxon)
            if self.pad:   # if we need to pad, compute the maxlen
                self.maxlen = np.max(seqlens.data[:])
        else:
            columns.append(VectorData('sequence_name', 'sequence names', data=sequence_name))
            seq = self.get_sequence_data(sequence)
            columns.append(self.get_sequence_index(index, seq))
            columns.append(seq)
            columns.append(VectorData('length', 'sequence lengths', data=seqlens))
            columns.append(DynamicTableRegion('taxon', taxon, 'taxa for each sequence', taxon_table))
        kwargs['columns'] = columns
        call_docval_func(super().__init__, kwargs)
        self.convert = self.get_numpy_conversion(maxlen=self.maxlen)
コード例 #5
0
 def setUpContainer(self):
     """ Return the test ElectricalSeries to read/write """
     self.make_electrode_table(self)
     region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', self.table)
     data = list(zip(range(10), range(10, 20)))
     timestamps = list(map(lambda x: x/10, range(10)))
     es = ElectricalSeries('test_eS', data, region, channel_conversion=[4., .4], timestamps=timestamps)
     return es
コード例 #6
0
 def test_invalid_init_mismatched_electrodes(self):
     event_times = [1]
     table = make_electrode_table()
     electrodes = DynamicTableRegion('electrodes', [0],
                                     'the first electrodes', table)
     description = ['desc1', 'desc2', 'desc3']
     features = [[[0, 1, 2], [3, 4, 5]]]
     self.assertRaises(ValueError, FeatureExtraction, electrodes,
                       description, event_times, features)
コード例 #7
0
 def setUpContainer(self):
     """ Return a test FeatureExtraction to read/write """
     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
コード例 #8
0
 def setUpContainer(self):
     """ Return a test EventDetection to read/write """
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', self.table)
     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]
     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
コード例 #9
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'))
コード例 #10
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)
コード例 #11
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'])
コード例 #12
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)
コード例 #13
0
 def test_invalid_init_mismatched_description2(self):
     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, electrodes,
                       description, event_times, features)
コード例 #14
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)
コード例 #15
0
 def test_invalid_data_shape(self):
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     with self.assertRaisesWith(
             ValueError,
         ("ElectricalSeries.__init__: 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])
コード例 #16
0
ファイル: test_ecephys.py プロジェクト: vatthaphon/pynwb
 def setUpContainer(self):
     """ Return a test EventWaveform to read/write """
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion(name='electrodes',
                                 data=[0, 2],
                                 description='the first and third electrodes',
                                 table=self.table)
     sES = SpikeEventSeries(name='test_sES',
                            data=((1, 1, 1), (2, 2, 2)),
                            timestamps=[0., 1.],
                            electrodes=region)
     ew = EventWaveform(sES)
     return ew
コード例 #17
0
ファイル: file.py プロジェクト: agencyenterprise/pynwb
 def create_electrode_table_region(self, **kwargs):
     if self.electrodes is None:
         msg = "no electrodes available. add electrodes before creating a region"
         raise RuntimeError(msg)
     region = getargs('region', kwargs)
     for idx in region:
         if idx < 0 or idx >= len(self.electrodes):
             raise IndexError('The index ' + str(idx) +
                              ' is out of range for the ElectrodeTable of length '
                              + str(len(self.electrodes)))
     desc = getargs('description', kwargs)
     name = getargs('name', kwargs)
     return DynamicTableRegion(name, region, desc, self.electrodes)
コード例 #18
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])
コード例 #19
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)
     eD = EventDetection('detection_method', eS, (1, 2, 3), (0.1, 0.2, 0.3))
     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')
コード例 #20
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,
                           channel_conversion=[2., 6.3],
                           timestamps=ts)
     self.assertEqual(eS.name, 'test_eS')
     self.assertEqual(eS.data, data)
     self.assertEqual(eS.timestamps, ts)
コード例 #21
0
    def test_init_with_source_channels(self):
        self.make_electrode_table(self)
        region = DynamicTableRegion(name='source_channels',
                                    data=[0, 2],
                                    description='the first and third electrodes',
                                    table=self.table)
        data = np.random.randn(100, 2, 30)
        timestamps = np.arange(100)/100
        ds = DecompositionSeries(name='test_DS',
                                 data=data,
                                 source_channels=region,
                                 timestamps=timestamps,
                                 metric='amplitude')

        self.assertIs(ds.source_channels, region)
コード例 #22
0
ファイル: test_ecephys.py プロジェクト: vatthaphon/pynwb
 def setUpContainer(self):
     """ Return a test EventDetection to read/write """
     TestElectricalSeriesIO.make_electrode_table(self)
     region = DynamicTableRegion(name='electrodes',
                                 data=[0, 2],
                                 description='the first and third electrodes',
                                 table=self.table)
     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]
     self.eS = ElectricalSeries(name='test_eS', data=data, electrodes=region, timestamps=ts)
     eD = EventDetection(detection_method='detection_method',
                         source_electricalseries=self.eS,
                         source_idx=(1, 2, 3),
                         times=(0.1, 0.2, 0.3))
     return eD
コード例 #23
0
ファイル: test_misc.py プロジェクト: agencyenterprise/pynwb
 def setUpContainer(self):
     """ Return the test ElectricalSeries to read/write """
     self.make_electrode_table(self)
     region = DynamicTableRegion(
         name='source_channels',
         data=[0, 2],
         description='the first and third electrodes',
         table=self.table)
     data = np.random.randn(100, 2, 30)
     timestamps = np.arange(100) / 100
     ds = DecompositionSeries(name='test_DS',
                              data=data,
                              source_channels=region,
                              timestamps=timestamps,
                              metric='amplitude')
     return ds
コード例 #24
0
ファイル: dna_table.py プロジェクト: exabiome/deep-taxon
 def __init__(self, **kwargs):
     columns = kwargs['columns']
     if columns is None:
         taxon_id, rep_idx, taxa_table = popargs('taxon_id', 'rep_idx',
                                                 'taxa_table', kwargs)
         if not isinstance(taxon_id, VectorData):
             taxon_id = VectorData('taxon_id',
                                   'NCBI accession',
                                   data=taxon_id)
         if not isinstance(rep_idx, VectorData):
             if taxa_table is None:
                 raise ValueError('taxa_table must be provided if writing')
             rep_idx = DynamicTableRegion('rep_idx', rep_idx,
                                          'representative taxon',
                                          taxa_table)
         kwargs['columns'] = [taxon_id, rep_idx]
     call_docval_func(super().__init__, kwargs)
コード例 #25
0
 def setUpContainer(self):
     """ Return the test ElectricalSeries to read/write """
     self.make_electrode_table(self)
     region = DynamicTableRegion(
         name='electrodes',
         data=[0, 2],
         description='the first and third electrodes',
         table=self.table)
     data = list(zip(range(10), range(10, 20)))
     timestamps = list(map(lambda x: x / 10., range(10)))
     channel_conversion = [1., 2., 3., 4.]
     filtering = 'Low-pass filter at 300 Hz'
     es = ElectricalSeries(name='test_eS',
                           data=data,
                           electrodes=region,
                           channel_conversion=channel_conversion,
                           filtering=filtering,
                           timestamps=timestamps)
     return es
コード例 #26
0
 def test_dynamictable_region_to_aligneddynamictable(self):
     """
     Test to ensure data is being retrieved correctly when pointing to an AlignedDynamicTable.
     In particular, make sure that all columns are being used, including those of the
     category tables, not just the ones from the main table.
     """
     temp_table = DynamicTable(name='t1',
                               description='t1',
                               colnames=['c1', 'c2'],
                               columns=[
                                   VectorData(name='c1',
                                              description='c1',
                                              data=np.arange(4)),
                                   VectorData(name='c2',
                                              description='c2',
                                              data=np.arange(4))
                               ])
     temp_aligned_table = AlignedDynamicTable(
         name='my_aligned_table',
         description='my test table',
         category_tables=[temp_table],
         colnames=['a1', 'a2'],
         columns=[
             VectorData(name='a1', description='c1', data=np.arange(4)),
             VectorData(name='a2', description='c1', data=np.arange(4))
         ])
     dtr = DynamicTableRegion(name='test',
                              description='test',
                              data=np.arange(4),
                              table=temp_aligned_table)
     dtr_df = dtr[:]
     # Full number of rows
     self.assertEqual(len(dtr_df), 4)
     # Test num columns: 2 columns from the main table, 2 columns from the category, 1 id columns from the category
     self.assertEqual(len(dtr_df.columns), 5)
     # Test that the data is correct
     for i, v in enumerate([('my_aligned_table', 'a1'),
                            ('my_aligned_table', 'a2'), ('t1', 'id'),
                            ('t1', 'c1'), ('t1', 'c2')]):
         self.assertTupleEqual(dtr_df.columns[i], v)
     # Test the column data
     for c in dtr_df.columns:
         self.assertListEqual(dtr_df[c].to_list(), list(range(4)))
コード例 #27
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]
     channel_conversion = [2., 6.3]
     filtering = 'Low-pass filter at 300 Hz'
     table = make_electrode_table()
     region = DynamicTableRegion('electrodes', [0, 2],
                                 'the first and third electrodes', table)
     eS = ElectricalSeries(name='test_eS',
                           data=data,
                           electrodes=region,
                           channel_conversion=channel_conversion,
                           filtering=filtering,
                           timestamps=ts)
     self.assertEqual(eS.name, 'test_eS')
     self.assertEqual(eS.data, data)
     self.assertEqual(eS.electrodes, region)
     self.assertEqual(eS.timestamps, ts)
     self.assertEqual(eS.channel_conversion, [2., 6.3])
     self.assertEqual(eS.filtering, filtering)