コード例 #1
0
    def test_classifier(self):
        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_eegs = m2b.filter()

        wf = MorletWaveletFilter(time_series=bp_eegs,
                                 freqs=np.logspace(np.log10(3), np.log10(180), 8),
                                 output='power',
                                 frequency_dim_pos=0,
                                 verbose=True
                                 )

        pow_wavelet, phase_wavelet = wf.filter()

        pow_wavelet = pow_wavelet.remove_buffer(duration=1.0)
        print pow_wavelet
        np.log10(pow_wavelet.data, out=pow_wavelet.data)
        print pow_wavelet
        mean_powers = pow_wavelet.mean(dim='time')
        print mean_powers




        # sess_pow_mat_post[ev,i,:] = np.nanmean(pow_ev_stripped, axis=1)

        print
コード例 #2
0
def get_bp_data(evs):
    eeg_reader = EEGReader(events=evs, channels=monopolar_channels,
                           start_time=start_time, end_time=end_time, buffer_time=buffer_time)

    base_eegs = eeg_reader.read()

    m2b = MonopolarToBipolarMapper(time_series=base_eegs, bipolar_pairs=bipolar_pairs)
    bp_eegs = m2b.filter()
    return bp_eegs
コード例 #3
0
ファイル: test_filters.py プロジェクト: ctw/ptsa_new
    def test_monopolar_to_bipolar_filter(self):
        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_base_eegs = m2b.filter()

        bipolar_pairs = bp_base_eegs['bipolar_pairs'].data
        for i, bp in enumerate(bipolar_pairs):
            e0 = self.base_eegs.sel(channels=bp[0])
            e1 = self.base_eegs.sel(channels=bp[1])
            # res = e0.__sub__(e1)
            assert_array_equal(e0 - e1, bp_base_eegs[i])
コード例 #4
0
ファイル: testfilters.py プロジェクト: isaac-ped/ptsa_new
    def test_monopolar_to_bipolar_filter(self):
        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_base_eegs = m2b.filter()

        bipolar_pairs = bp_base_eegs['bipolar_pairs'].data
        for i, bp in enumerate(bipolar_pairs):
            e0 = self.base_eegs.sel(channels=bp[0])
            e1 = self.base_eegs.sel(channels=bp[1])
            # res = e0.__sub__(e1)
            assert_array_equal(e0 - e1, bp_base_eegs[i])
コード例 #5
0
def compute_continuous_wavelets(dataroot):
    session_reader = EEGReader(session_dataroot=dataroot, channels=monopolar_channels)
    session_eegs = session_reader.read()

    m2b = MonopolarToBipolarMapper(time_series=session_eegs, bipolar_pairs=bipolar_pairs)
    session_bp_eegs = m2b.filter()

    wf = MorletWaveletFilter(time_series=session_bp_eegs,
                             freqs=np.logspace(np.log10(3), np.log10(180), 8),
                             output='power',
                             frequency_dim_pos=0,
                             verbose=True
                             )

    pow_wavelet_session, phase_wavelet_session = wf.filter()
    return pow_wavelet_session
コード例 #6
0
ファイル: test_filters.py プロジェクト: ctw/ptsa_new
    def test_monopolar_to_bipolar_filter_and_data_chopper(self):
        dataroot = self.base_events[0].eegfile

        session_reader = EEGReader(session_dataroot=dataroot, channels=self.monopolar_channels)
        session_eegs = session_reader.read()

        m2b = MonopolarToBipolarMapper(time_series=session_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_session_eegs = m2b.filter()

        sedc = DataChopper(events=self.base_events, session_data=bp_session_eegs, start_time=self.start_time,
                           end_time=self.end_time, buffer_time=self.buffer_time)

        bp_session_eegs_chopped = sedc.filter()

        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_base_eegs = m2b.filter()

        assert_array_equal(bp_session_eegs_chopped, bp_base_eegs)
コード例 #7
0
ファイル: test_classifier.py プロジェクト: ctw/ptsa_new
    def test_classifier(self):
        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_eegs = m2b.filter()

        wf = MorletWaveletFilter(time_series=bp_eegs,
                                 freqs=np.logspace(np.log10(3), np.log10(180), 8),
                                 output='power',
                                 frequency_dim_pos=0,
                                 verbose=True
                                 )

        pow_wavelet, phase_wavelet = wf.filter()

        pow_wavelet = pow_wavelet.remove_buffer(duration=1.0)
        print(pow_wavelet)
        np.log10(pow_wavelet.data, out=pow_wavelet.data)
        print(pow_wavelet)
        mean_powers = pow_wavelet.mean(dim='time')
        print(mean_powers)
コード例 #8
0
ファイル: test_classifier.py プロジェクト: cliliana/ptsa_new
    def test_classifier(self):
        m2b = MonopolarToBipolarMapper(timeseries=self.base_eegs,
                                       bipolar_pairs=self.bipolar_pairs)
        bp_eegs = m2b.filter()

        wf = MorletWaveletFilter(timeseries=bp_eegs,
                                 freqs=np.logspace(np.log10(3), np.log10(180),
                                                   8),
                                 output='power',
                                 verbose=True)

        pow_wavelet = wf.filter()['power']

        pow_wavelet = pow_wavelet.remove_buffer(duration=1.0)
        print(pow_wavelet)
        np.log10(pow_wavelet.data, out=pow_wavelet.data)
        print(pow_wavelet)
        mean_powers = pow_wavelet.mean(dim='time')
        print(mean_powers)
コード例 #9
0
def get_stim_eeg(evs_on,
                 tal_struct,
                 bipolar_pairs,
                 monopolar_channels,
                 chans=np.array([]),
                 start_time=-1.0,
                 end_time=1.5):

    from ptsa.data.readers import EEGReader
    from ptsa.data.filters import MonopolarToBipolarMapper

    #Get EEG clips
    eeg_reader = EEGReader(events=evs_on,
                           channels=chans,
                           start_time=start_time,
                           end_time=end_time,
                           buffer_time=0.0)
    eegs = eeg_reader.read()
    eegs = eegs.baseline_corrected((-1.0, 2.5))

    if tal_struct is np.nan:
        return eegs, np.nan

    if ('bipolar_pairs'
            in list(eegs.coords)):  #Gotta do this for bipolar ENS subjects
        bps_eeg = [list(i) for i in np.array(eegs['bipolar_pairs'])]
        bps_tal = [list(i) for i in np.array(tal_struct['channel'])]
        bps_eeg_good = []
        bps_tal_good = []
        for iidx, i in enumerate(bps_eeg):
            for jidx, j in enumerate(bps_tal):
                if i == j:
                    bps_eeg_good.append(iidx)
                    bps_tal_good.append(jidx)
        bps_eeg_good = np.array(bps_eeg_good)
        bps_tal_good = np.array(bps_tal_good)

        eegs_raw = eegs[bps_eeg_good]
        tal_struct = tal_struct[bps_tal_good]
    else:
        try:
            m2b = MonopolarToBipolarMapper(time_series=eegs,
                                           bipolar_pairs=bipolar_pairs)
            eegs_raw = m2b.filter()
        except KeyError:  #we've got to do this subject with specified channels
            eeg_reader = EEGReader(events=evs_on,
                                   channels=monopolar_channels,
                                   start_time=start_time,
                                   end_time=end_time,
                                   buffer_time=0.0)
            eegs = eeg_reader.read()
            eegs = eegs.baseline_corrected((-1.0, 2.5))

            #Bipolar rereference
            m2b = MonopolarToBipolarMapper(time_series=eegs,
                                           bipolar_pairs=bipolar_pairs)
            eegs_raw = m2b.filter()

    return eegs_raw, tal_struct
コード例 #10
0
ファイル: testfilters.py プロジェクト: isaac-ped/ptsa_new
    def test_monopolar_to_bipolar_filter_and_data_chopper(self):
        dataroot = self.base_events[0].eegfile

        session_reader = EEGReader(session_dataroot=dataroot, channels=self.monopolar_channels)
        session_eegs = session_reader.read()

        m2b = MonopolarToBipolarMapper(time_series=session_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_session_eegs = m2b.filter()

        sedc = DataChopper(events=self.base_events, session_data=bp_session_eegs, start_time=self.start_time,
                           end_time=self.end_time, buffer_time=self.buffer_time)

        bp_session_eegs_chopped = sedc.filter()

        m2b = MonopolarToBipolarMapper(time_series=self.base_eegs, bipolar_pairs=self.bipolar_pairs)
        bp_base_eegs = m2b.filter()

        assert_array_equal(bp_session_eegs_chopped, bp_base_eegs)
コード例 #11
0
def test_monopolar_to_bipolar_filter_norhino():
    data = np.random.random((20, 10, 5))
    rate = 1000
    dims = ('time', 'channels', 'events')
    coords = {
        'time': np.linspace(0, 1, 20),
        'channels': range(10),
        'events': ['A', 'B', 'C', 'D', 'E']
    }
    ts = timeseries.TimeSeries.create(data,
                                      rate,
                                      coords=coords,
                                      dims=dims,
                                      name="test",
                                      attrs={'test_attr': 1})

    bipolar_pairs1 = np.array([range(9), range(1, 10)])
    m2b1 = MonopolarToBipolarMapper(timeseries=ts,
                                    bipolar_pairs=bipolar_pairs1)
    ts_m2b1 = m2b1.filter()

    bipolar_pairs2 = np.array([(i, j) for i, j in zip(range(9), range(1, 10))],
                              dtype=[('ch0', '<i8'), ('ch1', '<i8')])
    m2b2 = MonopolarToBipolarMapper(timeseries=ts,
                                    bipolar_pairs=bipolar_pairs2)
    ts_m2b2 = m2b2.filter()

    assert np.all(ts_m2b1 == ts_m2b2)

    # checking each coord is probably redundant (mismatching coords
    # should cause failure in the above assertion), but won't hurt
    for coord in ts_m2b1.coords:
        assert np.all(ts_m2b1[coord] == ts_m2b2[coord])
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b1[coord])

    # sanity check that we haven't lost any coords:
    for coord in ts.coords:
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b1[coord])
    for attr in ts.attrs:
        assert np.all(ts_m2b1.attrs[attr] == ts_m2b2.attrs[attr])
        assert np.all(ts.attrs[attr] == ts_m2b1.attrs[attr])

    assert ts.name == ts_m2b1.name
    assert ts.name == ts_m2b2.name
    assert np.all(ts_m2b1['channels'] == bipolar_pairs2)
    assert np.all(ts_m2b1 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))
    assert np.all(ts_m2b2 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))

    dims2 = ('time', 'electrodes', 'events')
    coords2 = {
        'time': np.linspace(0, 1, 20),
        'electrodes': range(10),
        'events': ['A', 'B', 'C', 'D', 'E']
    }
    ts2 = timeseries.TimeSeries.create(data,
                                       rate,
                                       coords=coords2,
                                       dims=dims2,
                                       name="test",
                                       attrs={'test_attr': 1})
    m2b3 = MonopolarToBipolarMapper(timeseries=ts2,
                                    channels_dim='electrodes',
                                    bipolar_pairs=bipolar_pairs1)
    ts_m2b3 = m2b3.filter()
    assert np.all(ts_m2b3.values == ts_m2b1.values)
    # checking each coord is probably redundant (mismatching coords
    # should cause failure in the above assertion), but won't hurt
    for coord in ts_m2b3.coords:
        if coord != 'electrodes':
            assert np.all(ts[coord] == ts_m2b3[coord])
    assert np.all(ts_m2b3['electrodes'].values == ts_m2b1['channels'].values)
    # sanity check that we haven't lost any coords:
    for coord in ts.coords:
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b3[coord])
    for attr in ts.attrs:
        assert np.all(ts_m2b3.attrs[attr] == ts_m2b1.attrs[attr])
        assert np.all(ts.attrs[attr] == ts_m2b3.attrs[attr])
    assert ts.name == ts_m2b3.name
    assert np.all(ts_m2b3['electrodes'] == bipolar_pairs2)
    assert np.all(ts_m2b3 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))
    m2b4 = MonopolarToBipolarMapper(timeseries=ts2,
                                    channels_dim='electrodes',
                                    bipolar_pairs=bipolar_pairs2)
    ts_m2b4 = m2b4.filter()
    assert np.all(ts_m2b4 == ts_m2b3)
    # checking each coord is probably redundant (mismatching coords
    # should cause failure in the above assertion), but won't hurt
    for coord in ts_m2b4.coords:
        assert np.all(ts_m2b3[coord] == ts_m2b4[coord])
    # sanity check that we haven't lost any coords:
    for coord in ts.coords:
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b4[coord])
    for attr in ts.attrs:
        assert np.all(ts_m2b4.attrs[attr] == ts_m2b1.attrs[attr])
        assert np.all(ts.attrs[attr] == ts_m2b4.attrs[attr])
    assert ts.name == ts_m2b4.name
    assert np.all(ts_m2b4['electrodes'] == bipolar_pairs2)
    assert np.all(ts_m2b4 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))

    bipolar_pairs3 = np.array([(i, j) for i, j in zip(range(9), range(1, 10))],
                              dtype=[('channel0', '<i8'), ('channel1', '<i8')])
    m2b5 = MonopolarToBipolarMapper(timeseries=ts2,
                                    channels_dim='electrodes',
                                    bipolar_pairs=bipolar_pairs1,
                                    chan_names=['channel0', 'channel1'])
    ts_m2b5 = m2b5.filter()
    assert np.all(ts_m2b5.values == ts_m2b1.values)
    # checking each coord is probably redundant (mismatching coords
    # should cause failure in the above assertion), but won't hurt
    for coord in ts_m2b5.coords:
        if coord != 'electrodes':
            assert np.all(ts[coord] == ts_m2b5[coord])
    for a, b in zip(ts_m2b5['electrodes'], ts_m2b1['channels']):
        assert np.all(
            np.array(a.values.tolist()) == np.array(b.values.tolist()))
    # sanity check that we haven't lost any coords:
    for coord in ts.coords:
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b5[coord])
    for attr in ts.attrs:
        assert np.all(ts_m2b5.attrs[attr] == ts_m2b1.attrs[attr])
        assert np.all(ts.attrs[attr] == ts_m2b5.attrs[attr])
    assert ts.name == ts_m2b5.name
    assert np.all(ts_m2b5['electrodes'] == bipolar_pairs3)
    assert np.all(ts_m2b5 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))
    m2b6 = MonopolarToBipolarMapper(timeseries=ts2,
                                    channels_dim='electrodes',
                                    chan_names=['channel0', 'channel1'],
                                    bipolar_pairs=bipolar_pairs3)
    ts_m2b6 = m2b6.filter()
    assert np.all(ts_m2b6 == ts_m2b5)
    # checking each coord is probably redundant (mismatching coords
    # should cause failure in the above assertion), but won't hurt
    for coord in ts_m2b6.coords:
        assert np.all(ts_m2b6[coord] == ts_m2b5[coord])
    # sanity check that we haven't lost any coords:
    for coord in ts.coords:
        if coord != 'channels':
            assert np.all(ts[coord] == ts_m2b6[coord])
    for attr in ts.attrs:
        assert np.all(ts_m2b6.attrs[attr] == ts_m2b1.attrs[attr])
        assert np.all(ts.attrs[attr] == ts_m2b6.attrs[attr])
    assert ts.name == ts_m2b6.name
    assert np.all(ts_m2b6['electrodes'] == bipolar_pairs3)
    assert np.all(ts_m2b6 == (ts.sel(channels=range(9)).values -
                              ts.sel(channels=range(1, 10)).values))