Example #1
0
def main_fcn():
    e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'

    from ptsa.data.readers import BaseEventReader

    base_e_reader = BaseEventReader(filename=e_path, eliminate_events_with_no_eeg=True)

    base_events = base_e_reader.read()



    base_events = base_events[base_events.type == 'WORD']

    # selecting only one session
    base_events = base_events[base_events.eegfile == base_events[0].eegfile]

    from ptsa.data.readers.TalReader import TalReader

    tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'
    tal_reader = TalReader(filename=tal_path)
    monopolar_channels = tal_reader.get_monopolar_channels()
    bipolar_pairs = tal_reader.get_bipolar_pairs()

    print('bipolar_pairs=', bipolar_pairs)


    from ptsa.data.readers.EEGReader import EEGReader

    sessions = np.unique(base_events.session)
    dataroot = base_events[0].eegfile

    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()





    time_series_reader = EEGReader(events=base_events, channels=monopolar_channels, start_time=0.0,
                                             end_time=1.6, buffer_time=1.0)


    base_eegs = time_series_reader.read()


    m2b = MonopolarToBipolarMapper(time_series=base_eegs, bipolar_pairs=bipolar_pairs)
    ts_filtered = m2b.filter()

    del base_eegs
    del time_series_reader

    print()

    pass
Example #2
0
def main_fcn():
    e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'

    from ptsa.data.readers import BaseEventReader

    base_e_reader = BaseEventReader(filename=e_path,
                                    eliminate_events_with_no_eeg=True)

    base_events = base_e_reader.read()

    base_events = base_events[base_events.type == 'WORD']

    # selecting only one session
    base_events = base_events[base_events.eegfile == base_events[0].eegfile]

    from ptsa.data.readers.TalReader import TalReader

    tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'
    tal_reader = TalReader(filename=tal_path)
    monopolar_channels = tal_reader.get_monopolar_channels()
    bipolar_pairs = tal_reader.get_bipolar_pairs()

    print 'bipolar_pairs=', bipolar_pairs

    from ptsa.data.readers.EEGReader import EEGReader

    sessions = np.unique(base_events.session)
    dataroot = base_events[0].eegfile

    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()

    time_series_reader = EEGReader(events=base_events,
                                   channels=monopolar_channels,
                                   start_time=0.0,
                                   end_time=1.6,
                                   buffer_time=1.0)

    base_eegs = time_series_reader.read()

    m2b = MonopolarToBipolarMapper(time_series=base_eegs,
                                   bipolar_pairs=bipolar_pairs)
    ts_filtered = m2b.filter()

    del base_eegs
    del time_series_reader

    print

    pass
Example #3
0
    def setUp(self):
        self.e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'
        tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'

        # ---------------- NEW STYLE PTSA -------------------
        base_e_reader = BaseEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)

        self.base_events = base_e_reader.read()



        tal_reader = TalReader(filename=tal_path)
        self.monopolar_channels = tal_reader.get_monopolar_channels()
        self.bipolar_pairs = tal_reader.get_bipolar_pairs()


        self.base_events = self.base_events[self.base_events.type == 'WORD']

        # retaining first session
        dataroot = self.base_events[0].eegfile
        self.base_events = self.base_events[self.base_events.eegfile == dataroot]

        eeg_reader = EEGReader(events=self.base_events, channels=self.monopolar_channels,
                               start_time=0.0, end_time=1.6, buffer_time=1.0)

        self.base_eegs = eeg_reader.read()
Example #4
0
    def setUp(self):
        self.event_range = range(0, 30, 1)
        self.e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'
        self.tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'

        if sys.platform.startswith('win'):
            self.e_path = 'D:/data/events/RAM_FR1/R1060M_events.mat'
            self.tal_path = 'D:/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'

        # --------------- TAL STRUCTS READ
        tal_reader = TalReader(filename=self.tal_path)
        self.monopolar_channels = tal_reader.get_monopolar_channels()


        # ---------------- ORIG PTSA -------------------
        e_reader = PTSAEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)
        events = e_reader.read()

        events = events[events.type == 'WORD']

        events = events[self.event_range]

        ev_order = np.argsort(events, order=('session','list','mstime'))
        self.events = events[ev_order]

        # self.events = self.read_ptsa_events()

        # in case fancy indexing looses Eventness of events we need to create Events object explicitely
        if not isinstance(self.events, Events):
            self.events = Events(self.events)

        start_time = 0.0
        end_time = 1.6
        buffer_time = 1.0

        self.eegs = self.events.get_data(channels=['002', '003'], start_time=start_time, end_time=end_time,
                                         buffer_time=buffer_time, eoffset='eegoffset', keep_buffer=True,
                                         eoffset_in_time=False, verbose=True)

        # ---------------- NEW STYLE PTSA -------------------
        base_e_reader = BaseEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)

        base_events = base_e_reader.read()

        base_events = base_events[base_events.type == 'WORD']

        base_ev_order = np.argsort(base_events, order=('session','list','mstime'))
        base_events = base_events[base_ev_order]

        self.base_events = base_events[self.event_range]

        # self.base_events = self.read_base_events()

        eeg_reader = EEGReader(events=self.base_events, channels=np.array(['002', '003']),
                               start_time=start_time, end_time=end_time, buffer_time=buffer_time)

        self.base_eegs = eeg_reader.read()
def test_1():
    import time
    start = time.time()

    e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'

    from ptsa.data.readers import BaseEventReader

    base_e_reader = BaseEventReader(filename=e_path)

    base_events = base_e_reader.read()

    base_events = base_events[base_events.type == 'WORD']

    # selecting only one session
    base_events = base_events[base_events.eegfile == base_events[0].eegfile]

    from ptsa.data.readers.TalReader import TalReader
    tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'
    tal_reader = TalReader(filename=tal_path)
    monopolar_channels = tal_reader.get_monopolar_channels()
    bipolar_pairs = tal_reader.get_bipolar_pairs()

    print 'bipolar_pairs=', bipolar_pairs

    from ptsa.data.readers.EEGReader import EEGReader

    time_series_reader = EEGReader(events=base_events, start_time=0.0,channels=monopolar_channels, end_time=1.6, buffer_time=1.0)

    base_eegs = time_series_reader.read()

    # base_eegs = base_eegs[:, 0:10, :]
    # bipolar_pairs = bipolar_pairs[0:10]

    from ptsa.data.filters import MorletWaveletFilter
    wf = MorletWaveletFilter(time_series=base_eegs,
                             freqs=np.logspace(np.log10(3), np.log10(180), 8),
                             # freqs=np.array([3.]),
                             output='power',
                             )

    pow_wavelet, phase_wavelet = wf.filter()

    print 'total time = ', time.time() - start

    res_start = time.time()

    # from ptsa.data.filters.ResampleFilter import ResampleFilter
    # rsf = ResampleFilter (resamplerate=50.0)
    # rsf.set_input(pow_wavelet)
    # pow_wavelet = rsf.filter()



    print 'resample_time=', time.time() - res_start
    return pow_wavelet
Example #6
0
    def setUp(self):
        self.event_range = range(0, 30, 1)
        self.e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'
        self.tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'

        # --------------- TAL STRUCTS READ
        tal_reader = TalReader(filename=self.tal_path)
        self.monopolar_channels = tal_reader.get_monopolar_channels()


        # ---------------- ORIG PTSA -------------------
        e_reader = PTSAEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)
        events = e_reader.read()

        events = events[events.type == 'WORD']

        events = events[self.event_range]

        ev_order = np.argsort(events, order=('session','list','mstime'))
        self.events = events[ev_order]

        # self.events = self.read_ptsa_events()

        # in case fancy indexing looses Eventness of events we need to create Events object explicitely
        if not isinstance(self.events, Events):
            self.events = Events(self.events)

        start_time = 0.0
        end_time = 1.6
        buffer_time = 1.0

        self.eegs = self.events.get_data(channels=['002', '003'], start_time=start_time, end_time=end_time,
                                         buffer_time=buffer_time, eoffset='eegoffset', keep_buffer=True,
                                         eoffset_in_time=False, verbose=True)

        # ---------------- NEW STYLE PTSA -------------------
        base_e_reader = BaseEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)

        base_events = base_e_reader.read()

        base_events = base_events[base_events.type == 'WORD']

        base_ev_order = np.argsort(base_events, order=('session','list','mstime'))
        base_events = base_events[base_ev_order]

        self.base_events = base_events[self.event_range]

        # self.base_events = self.read_base_events()

        eeg_reader = EEGReader(events=self.base_events, channels=np.array(['002', '003']),
                               start_time=start_time, end_time=end_time, buffer_time=buffer_time)

        self.base_eegs = eeg_reader.read()
Example #7
0
    def setUp(self):
        self.start_time = -0.5
        self.end_time = 1.6
        self.buffer_time = 0.5

        self.event_range = range(0, 30, 1)
        self.e_path = '/Users/m/data/events/RAM_FR1/R1060M_events.mat'

        tal_path = '/Users/m/data/eeg/R1060M/tal/R1060M_talLocs_database_bipol.mat'
        tal_reader = TalReader(filename=tal_path)
        self.monopolar_channels = tal_reader.get_monopolar_channels()
        self.bipolar_pairs = tal_reader.get_bipolar_pairs()

        # ---------------- NEW STYLE PTSA -------------------
        base_e_reader = BaseEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)

        base_events = base_e_reader.read()

        base_events = base_events[base_events.type == 'WORD']

        base_ev_order = np.argsort(base_events, order=('session', 'list', 'mstime'))
        self.base_events = base_events[base_ev_order]

        # retaining first session
        dataroot = self.base_events[0].eegfile
        self.base_events = self.base_events[self.base_events.eegfile == dataroot]

        self.base_events = self.base_events[self.event_range]

        # self.base_events = base_events[self.event_range]

        # self.base_events = self.read_base_events()

        eeg_reader = EEGReader(events=self.base_events, channels=self.monopolar_channels,
                               start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time)

        self.base_eegs = eeg_reader.read()

        session_reader = EEGReader(session_dataroot=dataroot, channels=self.monopolar_channels)
        self.session_eegs = session_reader.read()
Example #8
0
    def test_full_session_read(self):

        # ---------------- ORIG PTSA -------------------
        e_reader = PTSAEventReader(filename=self.e_path,
                                   eliminate_events_with_no_eeg=True)
        events = e_reader.read()

        events = events[events.type == 'WORD']

        events = events[self.event_range]

        ev_order = np.argsort(events, order=('session', 'list', 'mstime'))
        self.events = events[ev_order]

        # self.events = self.read_ptsa_events()

        # in case fancy indexing looses Eventness of events we need to create Events object explicitely
        if not isinstance(self.events, Events):
            self.events = Events(self.events)

        eegs = self.events.get_data(channels=self.monopolar_channels,
                                    start_time=0.0,
                                    end_time=1.6,
                                    buffer_time=1.0,
                                    eoffset='eegoffset',
                                    keep_buffer=True,
                                    eoffset_in_time=False,
                                    verbose=True)

        # removing last entry to match dimensions - ptsa adds one extra element at the end of time axis
        eegs = eegs[:, :, :-1]
        eeg_reader = EEGReader(events=self.base_events,
                               channels=self.monopolar_channels,
                               start_time=0.0,
                               end_time=1.6,
                               buffer_time=1.0)

        base_eegs = eeg_reader.read()

        assert_array_equal(x=eegs, y=base_eegs)
        # checking if axes match
        assert_array_equal(np.array(eegs['channels']['name']),
                           base_eegs['channels'].data)
        assert_array_almost_equal(np.array(eegs['time']),
                                  base_eegs['time'].data,
                                  decimal=3)
        assert_array_equal(np.array(eegs['events']['item']),
                           base_eegs['events'].data['item'])

        print()
    def test_event_data_chopper(self):


        dataroot=self.base_events[0].eegfile
        from ptsa.data.readers import EEGReader
        session_reader = EEGReader(session_dataroot=dataroot, channels=self.monopolar_channels)
        session_eegs = session_reader.read()


        sedc = DataChopper(events=self.base_events, session_data=session_eegs, start_time=0.0, end_time=1.6, buffer_time=1.0)
        chopped_session = sedc.filter()

        sedc_so = DataChopper(start_offsets=self.base_events.eegoffset, session_data=session_eegs, start_time=0.0, end_time=1.6, buffer_time=1.0)
        chopped_session_so = sedc_so.filter()

        assert_array_equal(chopped_session,chopped_session_so)
Example #10
0
    def test_event_data_chopper(self):


        dataroot=self.base_events[0].eegfile
        from ptsa.data.readers import EEGReader
        session_reader = EEGReader(session_dataroot=dataroot, channels=self.monopolar_channels)
        session_eegs = session_reader.read()


        sedc = DataChopper(events=self.base_events, session_data=session_eegs, start_time=0.0, end_time=1.6, buffer_time=1.0)
        chopped_session = sedc.filter()

        sedc_so = DataChopper(start_offsets=self.base_events.eegoffset, session_data=session_eegs, start_time=0.0, end_time=1.6, buffer_time=1.0)
        chopped_session_so = sedc_so.filter()

        assert_array_equal(chopped_session,chopped_session_so)
Example #11
0
    def test_event_data_chopper(self):
        dataroot = self.base_events[0].eegfile

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

        sedc = DataChopper(events=self.base_events, session_data=session_eegs,
                           start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time)
        chopped_session = sedc.filter()

        assert_array_equal(chopped_session, self.base_eegs)

        sedc = DataChopper(start_offsets=self.base_events.eegoffset, session_data=session_eegs,
                           start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time)
        chopped_session = sedc.filter()

        assert_array_equal(chopped_session, self.base_eegs)
Example #12
0
    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)
Example #13
0
    def test_full_session_read(self):


        # ---------------- ORIG PTSA -------------------
        e_reader = PTSAEventReader(filename=self.e_path, eliminate_events_with_no_eeg=True)
        events = e_reader.read()

        events = events[events.type == 'WORD']

        events = events[self.event_range]

        ev_order = np.argsort(events, order=('session','list','mstime'))
        self.events = events[ev_order]

        # self.events = self.read_ptsa_events()

        # in case fancy indexing looses Eventness of events we need to create Events object explicitely
        if not isinstance(self.events, Events):
            self.events = Events(self.events)

        eegs = self.events.get_data(channels=self.monopolar_channels, start_time=0.0, end_time=1.6,
                                         buffer_time=1.0, eoffset='eegoffset', keep_buffer=True,
                                         eoffset_in_time=False, verbose=True)

        # removing last entry to match dimensions - ptsa adds one extra element at the end of time axis
        eegs = eegs[:,:,:-1]
        eeg_reader = EEGReader(events=self.base_events, channels=self.monopolar_channels,
                               start_time=0.0, end_time=1.6, buffer_time=1.0)


        base_eegs = eeg_reader.read()

        assert_array_equal(x=eegs, y=base_eegs)
        # checking if axes match
        assert_array_equal(np.array(eegs['channels']['name']), base_eegs['channels'].data)
        assert_array_almost_equal(np.array(eegs['time']), base_eegs['time'].data, decimal=3)
        assert_array_equal(np.array(eegs['events']['item']), base_eegs['events'].data['item'])


        print
Example #14
0
    def read_eegs(self, events, channels):

        eeg_reader = EEGReader(events=events, channels=channels,
                               start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time)

        self.base_eegs = eeg_reader.read()