コード例 #1
0
    def setup_recordingchannels(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        self.rchan1 = RecordingChannel(index=10,
                                       coordinate=[1.1, 1.5, 1.7] * pq.mm,
                                       name='test',
                                       description='tester 1',
                                       file_origin='test.file',
                                       testarg1=1,
                                       **params)
        self.rchan2 = RecordingChannel(index=100,
                                       coordinate=[11., 15., 17.] * pq.mm,
                                       name='test',
                                       description='tester 2',
                                       file_origin='test.file',
                                       testarg1=1,
                                       **params)
        self.rchan1.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        self.rchan2.annotate(testarg11=1.1, testarg10=[1, 2, 3])

        self.rchan1.analogsignals = self.sig1
        self.rchan2.analogsignals = self.sig2

        self.rchan1.irregularlysampledsignals = self.irsig1
        self.rchan2.irregularlysampledsignals = self.irsig2

        create_many_to_one_relationship(self.rchan1)
        create_many_to_one_relationship(self.rchan2)
コード例 #2
0
    def setup_recordingchannels(self):
        rchanname11 = 'chan 1 1'
        rchanname12 = 'chan 1 2'
        rchanname21 = 'chan 2 1'
        rchanname22 = 'chan 2 2'

        self.rchannames1 = [rchanname11, rchanname12]
        self.rchannames2 = [rchanname21, rchanname22, rchanname11]
        self.rchannames = [rchanname11, rchanname12, rchanname21, rchanname22]

        rchan11 = RecordingChannel(name=rchanname11)
        rchan12 = RecordingChannel(name=rchanname12)
        rchan21 = RecordingChannel(name=rchanname21)
        rchan22 = RecordingChannel(name=rchanname22)
        rchan23 = RecordingChannel(name=rchanname11)

        self.rchan1 = [rchan11, rchan12]
        self.rchan2 = [rchan21, rchan22, rchan23]
        self.rchan = [rchan11, rchan12, rchan21, rchan22]
コード例 #3
0
    def setup_recordingchannels(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        self.rchan1 = RecordingChannel(index=10,
                                       coordinate=[1.1, 1.5, 1.7]*pq.mm,
                                       name='test', description='tester 1',
                                       file_origin='test.file',
                                       testarg1=1, **params)
        self.rchan2 = RecordingChannel(index=100,
                                       coordinate=[11., 15., 17.]*pq.mm,
                                       name='test', description='tester 2',
                                       file_origin='test.file',
                                       testarg1=1, **params)
        self.rchan1.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        self.rchan2.annotate(testarg11=1.1, testarg10=[1, 2, 3])

        self.rchan1.analogsignals = self.sig1
        self.rchan2.analogsignals = self.sig2

        self.rchan1.irregularlysampledsignals = self.irsig1
        self.rchan2.irregularlysampledsignals = self.irsig2

        self.rchan1.create_many_to_one_relationship()
        self.rchan2.create_many_to_one_relationship()
コード例 #4
0
ファイル: test_block.py プロジェクト: testvidya11/python-neo
    def setUp(self):
        unitname11 = 'unit 1 1'
        unitname12 = 'unit 1 2'
        unitname21 = 'unit 2 1'
        unitname22 = 'unit 2 2'

        channame11 = 'chan 1 1'
        channame12 = 'chan 1 2'
        channame21 = 'chan 2 1'
        channame22 = 'chan 2 2'

        segname11 = 'seg 1 1'
        segname12 = 'seg 1 2'
        segname21 = 'seg 2 1'
        segname22 = 'seg 2 2'

        self.rcgname1 = 'rcg 1'
        self.rcgname2 = 'rcg 2'
        self.rcgnames = [self.rcgname1, self.rcgname2]

        self.unitnames1 = [unitname11, unitname12]
        self.unitnames2 = [unitname21, unitname22, unitname11]
        self.unitnames = [unitname11, unitname12, unitname21, unitname22]

        self.channames1 = [channame11, channame12]
        self.channames2 = [channame21, channame22, channame11]
        self.channames = [channame11, channame12, channame21, channame22]

        self.segnames1 = [segname11, segname12]
        self.segnames2 = [segname21, segname22, segname11]
        self.segnames = [segname11, segname12, segname21, segname22]

        unit11 = Unit(name=unitname11)
        unit12 = Unit(name=unitname12)
        unit21 = Unit(name=unitname21)
        unit22 = Unit(name=unitname22)
        unit23 = unit11

        chan11 = RecordingChannel(name=channame11)
        chan12 = RecordingChannel(name=channame12)
        chan21 = RecordingChannel(name=channame21)
        chan22 = RecordingChannel(name=channame22)
        chan23 = chan11

        seg11 = Segment(name=segname11)
        seg12 = Segment(name=segname12)
        seg21 = Segment(name=segname21)
        seg22 = Segment(name=segname22)
        seg23 = seg11

        self.units1 = [unit11, unit12]
        self.units2 = [unit21, unit22, unit23]
        self.units = [unit11, unit12, unit21, unit22]

        self.chan1 = [chan11, chan12]
        self.chan2 = [chan21, chan22, chan23]
        self.chan = [chan11, chan12, chan21, chan22]

        self.seg1 = [seg11, seg12]
        self.seg2 = [seg21, seg22, seg23]
        self.seg = [seg11, seg12, seg21, seg22]

        self.rcg1 = RecordingChannelGroup(name=self.rcgname1)
        self.rcg2 = RecordingChannelGroup(name=self.rcgname2)
        self.rcg = [self.rcg1, self.rcg2]

        self.rcg1.units = self.units1
        self.rcg2.units = self.units2
        self.rcg1.recordingchannels = self.chan1
        self.rcg2.recordingchannels = self.chan2
コード例 #5
0
class TestRecordingChannel(unittest.TestCase):
    def setUp(self):
        self.setup_analogsignals()
        self.setup_irregularlysampledsignals()
        self.setup_recordingchannels()

    def setup_recordingchannels(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        self.rchan1 = RecordingChannel(index=10,
                                       coordinate=[1.1, 1.5, 1.7] * pq.mm,
                                       name='test',
                                       description='tester 1',
                                       file_origin='test.file',
                                       testarg1=1,
                                       **params)
        self.rchan2 = RecordingChannel(index=100,
                                       coordinate=[11., 15., 17.] * pq.mm,
                                       name='test',
                                       description='tester 2',
                                       file_origin='test.file',
                                       testarg1=1,
                                       **params)
        self.rchan1.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        self.rchan2.annotate(testarg11=1.1, testarg10=[1, 2, 3])

        self.rchan1.analogsignals = self.sig1
        self.rchan2.analogsignals = self.sig2

        self.rchan1.irregularlysampledsignals = self.irsig1
        self.rchan2.irregularlysampledsignals = self.irsig2

        create_many_to_one_relationship(self.rchan1)
        create_many_to_one_relationship(self.rchan2)

    def setup_analogsignals(self):
        signame11 = 'analogsignal 1 1'
        signame12 = 'analogsignal 1 2'
        signame21 = 'analogsignal 2 1'
        signame22 = 'analogsignal 2 2'

        sigdata11 = np.arange(0, 10) * pq.mV
        sigdata12 = np.arange(10, 20) * pq.mV
        sigdata21 = np.arange(20, 30) * pq.V
        sigdata22 = np.arange(30, 40) * pq.V

        self.signames1 = [signame11, signame12]
        self.signames2 = [signame21, signame22]
        self.signames = [signame11, signame12, signame21, signame22]

        sig11 = AnalogSignal(sigdata11,
                             name=signame11,
                             sampling_rate=1 * pq.Hz)
        sig12 = AnalogSignal(sigdata12,
                             name=signame12,
                             sampling_rate=1 * pq.Hz)
        sig21 = AnalogSignal(sigdata21,
                             name=signame21,
                             sampling_rate=1 * pq.Hz)
        sig22 = AnalogSignal(sigdata22,
                             name=signame22,
                             sampling_rate=1 * pq.Hz)

        self.sig1 = [sig11, sig12]
        self.sig2 = [sig21, sig22]
        self.sig = [sig11, sig12, sig21, sig22]

    def setup_irregularlysampledsignals(self):
        irsigname11 = 'irregularsignal 1 1'
        irsigname12 = 'irregularsignal 1 2'
        irsigname21 = 'irregularsignal 2 1'
        irsigname22 = 'irregularsignal 2 2'

        irsigdata11 = np.arange(0, 10) * pq.mA
        irsigdata12 = np.arange(10, 20) * pq.mA
        irsigdata21 = np.arange(20, 30) * pq.A
        irsigdata22 = np.arange(30, 40) * pq.A

        irsigtimes11 = np.arange(0, 10) * pq.ms
        irsigtimes12 = np.arange(10, 20) * pq.ms
        irsigtimes21 = np.arange(20, 30) * pq.s
        irsigtimes22 = np.arange(30, 40) * pq.s

        self.irsignames1 = [irsigname11, irsigname12]
        self.irsignames2 = [irsigname21, irsigname22]
        self.irsignames = [irsigname11, irsigname12, irsigname21, irsigname22]

        irsig11 = IrregularlySampledSignal(irsigtimes11,
                                           irsigdata11,
                                           name=irsigname11)
        irsig12 = IrregularlySampledSignal(irsigtimes12,
                                           irsigdata12,
                                           name=irsigname12)
        irsig21 = IrregularlySampledSignal(irsigtimes21,
                                           irsigdata21,
                                           name=irsigname21)
        irsig22 = IrregularlySampledSignal(irsigtimes22,
                                           irsigdata22,
                                           name=irsigname22)

        self.irsig1 = [irsig11, irsig12]
        self.irsig2 = [irsig21, irsig22]
        self.irsig = [irsig11, irsig12, irsig21, irsig22]

    def test_recordingchannel_creation(self):
        assert_neo_object_is_compliant(self.rchan1)
        assert_neo_object_is_compliant(self.rchan2)

        self.assertEqual(self.rchan1.index, 10)
        self.assertEqual(self.rchan2.index, 100)

        assert_arrays_equal(self.rchan1.coordinate, [1.1, 1.5, 1.7] * pq.mm)
        assert_arrays_equal(self.rchan2.coordinate, [11., 15., 17.] * pq.mm)

        self.assertEqual(self.rchan1.name, 'test')
        self.assertEqual(self.rchan2.name, 'test')

        self.assertEqual(self.rchan1.description, 'tester 1')
        self.assertEqual(self.rchan2.description, 'tester 2')

        self.assertEqual(self.rchan1.file_origin, 'test.file')
        self.assertEqual(self.rchan2.file_origin, 'test.file')

        self.assertEqual(self.rchan1.annotations['testarg0'], [1, 2, 3])
        self.assertEqual(self.rchan2.annotations['testarg10'], [1, 2, 3])

        self.assertEqual(self.rchan1.annotations['testarg1'], 1.1)
        self.assertEqual(self.rchan2.annotations['testarg1'], 1)
        self.assertEqual(self.rchan2.annotations['testarg11'], 1.1)

        self.assertEqual(self.rchan1.annotations['testarg2'], 'yes')
        self.assertEqual(self.rchan2.annotations['testarg2'], 'yes')

        self.assertTrue(self.rchan1.annotations['testarg3'])
        self.assertTrue(self.rchan2.annotations['testarg3'])

        self.assertTrue(hasattr(self.rchan1, 'analogsignals'))
        self.assertTrue(hasattr(self.rchan2, 'analogsignals'))

        self.assertEqual(len(self.rchan1.analogsignals), 2)
        self.assertEqual(len(self.rchan2.analogsignals), 2)

        for res, targ in zip(self.rchan1.analogsignals, self.sig1):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        for res, targ in zip(self.rchan2.analogsignals, self.sig2):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        self.assertTrue(hasattr(self.rchan1, 'irregularlysampledsignals'))
        self.assertTrue(hasattr(self.rchan2, 'irregularlysampledsignals'))

        self.assertEqual(len(self.rchan1.irregularlysampledsignals), 2)
        self.assertEqual(len(self.rchan2.irregularlysampledsignals), 2)

        for res, targ in zip(self.rchan1.irregularlysampledsignals,
                             self.irsig1):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        for res, targ in zip(self.rchan2.irregularlysampledsignals,
                             self.irsig2):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        self.assertTrue(hasattr(self.rchan1, 'recordingchannelgroups'))
        self.assertTrue(hasattr(self.rchan2, 'recordingchannelgroups'))

    def test_recordingchannel_merge(self):
        self.rchan1.merge(self.rchan2)

        sigres1 = [sig.name for sig in self.rchan1.analogsignals]
        sigres2 = [sig.name for sig in self.rchan2.analogsignals]

        irsigres1 = [sig.name for sig in self.rchan1.irregularlysampledsignals]
        irsigres2 = [sig.name for sig in self.rchan2.irregularlysampledsignals]

        self.assertEqual(sigres1, self.signames)
        self.assertEqual(sigres2, self.signames2)

        self.assertEqual(irsigres1, self.irsignames)
        self.assertEqual(irsigres2, self.irsignames2)

        for res, targ in zip(self.rchan1.analogsignals, self.sig):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan2.analogsignals, self.sig2):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan1.irregularlysampledsignals,
                             self.irsig):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan2.irregularlysampledsignals,
                             self.irsig2):
            assert_arrays_equal(res, targ)
コード例 #6
0
class TestRecordingChannel(unittest.TestCase):
    def setUp(self):
        self.setup_analogsignals()
        self.setup_irregularlysampledsignals()
        self.setup_recordingchannels()

    def setup_recordingchannels(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        self.rchan1 = RecordingChannel(index=10,
                                       coordinate=[1.1, 1.5, 1.7]*pq.mm,
                                       name='test', description='tester 1',
                                       file_origin='test.file',
                                       testarg1=1, **params)
        self.rchan2 = RecordingChannel(index=100,
                                       coordinate=[11., 15., 17.]*pq.mm,
                                       name='test', description='tester 2',
                                       file_origin='test.file',
                                       testarg1=1, **params)
        self.rchan1.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        self.rchan2.annotate(testarg11=1.1, testarg10=[1, 2, 3])

        self.rchan1.analogsignals = self.sig1
        self.rchan2.analogsignals = self.sig2

        self.rchan1.irregularlysampledsignals = self.irsig1
        self.rchan2.irregularlysampledsignals = self.irsig2

        self.rchan1.create_many_to_one_relationship()
        self.rchan2.create_many_to_one_relationship()

    def setup_analogsignals(self):
        signame11 = 'analogsignal 1 1'
        signame12 = 'analogsignal 1 2'
        signame21 = 'analogsignal 2 1'
        signame22 = 'analogsignal 2 2'

        sigdata11 = np.arange(0, 10) * pq.mV
        sigdata12 = np.arange(10, 20) * pq.mV
        sigdata21 = np.arange(20, 30) * pq.V
        sigdata22 = np.arange(30, 40) * pq.V

        self.signames1 = [signame11, signame12]
        self.signames2 = [signame21, signame22]
        self.signames = [signame11, signame12, signame21, signame22]

        sig11 = AnalogSignal(sigdata11, name=signame11, sampling_rate=1*pq.Hz)
        sig12 = AnalogSignal(sigdata12, name=signame12, sampling_rate=1*pq.Hz)
        sig21 = AnalogSignal(sigdata21, name=signame21, sampling_rate=1*pq.Hz)
        sig22 = AnalogSignal(sigdata22, name=signame22, sampling_rate=1*pq.Hz)

        self.sig1 = [sig11, sig12]
        self.sig2 = [sig21, sig22]
        self.sig = [sig11, sig12, sig21, sig22]

    def setup_irregularlysampledsignals(self):
        irsigname11 = 'irregularsignal 1 1'
        irsigname12 = 'irregularsignal 1 2'
        irsigname21 = 'irregularsignal 2 1'
        irsigname22 = 'irregularsignal 2 2'

        irsigdata11 = np.arange(0, 10) * pq.mA
        irsigdata12 = np.arange(10, 20) * pq.mA
        irsigdata21 = np.arange(20, 30) * pq.A
        irsigdata22 = np.arange(30, 40) * pq.A

        irsigtimes11 = np.arange(0, 10) * pq.ms
        irsigtimes12 = np.arange(10, 20) * pq.ms
        irsigtimes21 = np.arange(20, 30) * pq.s
        irsigtimes22 = np.arange(30, 40) * pq.s

        self.irsignames1 = [irsigname11, irsigname12]
        self.irsignames2 = [irsigname21, irsigname22]
        self.irsignames = [irsigname11, irsigname12, irsigname21, irsigname22]

        irsig11 = IrregularlySampledSignal(irsigtimes11, irsigdata11,
                                           name=irsigname11)
        irsig12 = IrregularlySampledSignal(irsigtimes12, irsigdata12,
                                           name=irsigname12)
        irsig21 = IrregularlySampledSignal(irsigtimes21, irsigdata21,
                                           name=irsigname21)
        irsig22 = IrregularlySampledSignal(irsigtimes22, irsigdata22,
                                           name=irsigname22)

        self.irsig1 = [irsig11, irsig12]
        self.irsig2 = [irsig21, irsig22]
        self.irsig = [irsig11, irsig12, irsig21, irsig22]

    def test_recordingchannel_creation(self):
        assert_neo_object_is_compliant(self.rchan1)
        assert_neo_object_is_compliant(self.rchan2)

        self.assertEqual(self.rchan1.index, 10)
        self.assertEqual(self.rchan2.index, 100)

        assert_arrays_equal(self.rchan1.coordinate, [1.1, 1.5, 1.7]*pq.mm)
        assert_arrays_equal(self.rchan2.coordinate, [11., 15., 17.]*pq.mm)

        self.assertEqual(self.rchan1.name, 'test')
        self.assertEqual(self.rchan2.name, 'test')

        self.assertEqual(self.rchan1.description, 'tester 1')
        self.assertEqual(self.rchan2.description, 'tester 2')

        self.assertEqual(self.rchan1.file_origin, 'test.file')
        self.assertEqual(self.rchan2.file_origin, 'test.file')

        self.assertEqual(self.rchan1.annotations['testarg0'], [1, 2, 3])
        self.assertEqual(self.rchan2.annotations['testarg10'], [1, 2, 3])

        self.assertEqual(self.rchan1.annotations['testarg1'], 1.1)
        self.assertEqual(self.rchan2.annotations['testarg1'], 1)
        self.assertEqual(self.rchan2.annotations['testarg11'], 1.1)

        self.assertEqual(self.rchan1.annotations['testarg2'], 'yes')
        self.assertEqual(self.rchan2.annotations['testarg2'], 'yes')

        self.assertTrue(self.rchan1.annotations['testarg3'])
        self.assertTrue(self.rchan2.annotations['testarg3'])

        self.assertTrue(hasattr(self.rchan1, 'analogsignals'))
        self.assertTrue(hasattr(self.rchan2, 'analogsignals'))

        self.assertEqual(len(self.rchan1.analogsignals), 2)
        self.assertEqual(len(self.rchan2.analogsignals), 2)

        for res, targ in zip(self.rchan1.analogsignals, self.sig1):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        for res, targ in zip(self.rchan2.analogsignals, self.sig2):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        self.assertTrue(hasattr(self.rchan1, 'irregularlysampledsignals'))
        self.assertTrue(hasattr(self.rchan2, 'irregularlysampledsignals'))

        self.assertEqual(len(self.rchan1.irregularlysampledsignals), 2)
        self.assertEqual(len(self.rchan2.irregularlysampledsignals), 2)

        for res, targ in zip(self.rchan1.irregularlysampledsignals,
                             self.irsig1):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        for res, targ in zip(self.rchan2.irregularlysampledsignals,
                             self.irsig2):
            assert_arrays_equal(res, targ)
            self.assertEqual(res.name, targ.name)

        self.assertTrue(hasattr(self.rchan1, 'recordingchannelgroups'))
        self.assertTrue(hasattr(self.rchan2, 'recordingchannelgroups'))

    def test_recordingchannel_merge(self):
        self.rchan1.merge(self.rchan2)

        sigres1 = [sig.name for sig in self.rchan1.analogsignals]
        sigres2 = [sig.name for sig in self.rchan2.analogsignals]

        irsigres1 = [sig.name for sig in self.rchan1.irregularlysampledsignals]
        irsigres2 = [sig.name for sig in self.rchan2.irregularlysampledsignals]

        self.assertEqual(sigres1, self.signames)
        self.assertEqual(sigres2, self.signames2)

        self.assertEqual(irsigres1, self.irsignames)
        self.assertEqual(irsigres2, self.irsignames2)

        for res, targ in zip(self.rchan1.analogsignals, self.sig):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan2.analogsignals, self.sig2):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan1.irregularlysampledsignals,
                             self.irsig):
            assert_arrays_equal(res, targ)

        for res, targ in zip(self.rchan2.irregularlysampledsignals,
                             self.irsig2):
            assert_arrays_equal(res, targ)

    def test__children(self):
        rcg = RecordingChannelGroup(name='rcg1')
        rcg.recordingchannels = [self.rchan1]
        rcg.create_many_to_many_relationship()

        self.assertEqual(self.rchan1._container_child_objects, ())
        self.assertEqual(self.rchan1._data_child_objects,
                         ('AnalogSignal', 'IrregularlySampledSignal'))
        self.assertEqual(self.rchan1._single_parent_objects, ())
        self.assertEqual(self.rchan1._multi_child_objects, ())
        self.assertEqual(self.rchan1._multi_parent_objects,
                         ('RecordingChannelGroup',))
        self.assertEqual(self.rchan1._child_properties, ())

        self.assertEqual(self.rchan1._single_child_objects,
                         ('AnalogSignal', 'IrregularlySampledSignal'))

        self.assertEqual(self.rchan1._container_child_containers, ())
        self.assertEqual(self.rchan1._data_child_containers,
                         ('analogsignals', 'irregularlysampledsignals',))
        self.assertEqual(self.rchan1._single_child_containers,
                         ('analogsignals', 'irregularlysampledsignals',))
        self.assertEqual(self.rchan1._single_parent_containers, ())
        self.assertEqual(self.rchan1._multi_child_containers, ())
        self.assertEqual(self.rchan1._multi_parent_containers,
                         ('recordingchannelgroups',))

        self.assertEqual(self.rchan1._child_objects,
                         ('AnalogSignal', 'IrregularlySampledSignal'))
        self.assertEqual(self.rchan1._child_containers,
                         ('analogsignals', 'irregularlysampledsignals',))
        self.assertEqual(self.rchan1._parent_objects,
                         ('RecordingChannelGroup',))
        self.assertEqual(self.rchan1._parent_containers,
                         ('recordingchannelgroups',))

        self.assertEqual(len(self.rchan1.children),
                         len(self.sig1) + len(self.irsig1))
        self.assertEqual(self.rchan1.children[0].name, self.signames1[0])
        self.assertEqual(self.rchan1.children[1].name, self.signames1[1])
        self.assertEqual(self.rchan1.children[2].name, self.irsignames1[0])
        self.assertEqual(self.rchan1.children[3].name, self.irsignames1[1])
        self.assertEqual(len(self.rchan1.parents), 1)
        self.assertEqual(self.rchan1.parents[0].name, 'rcg1')

        self.rchan1.create_many_to_one_relationship()
        self.rchan1.create_many_to_many_relationship()
        self.rchan1.create_relationship()
        assert_neo_object_is_compliant(self.rchan1)