def test_talreader_on_database():
    old_reader = TalReader(
        filename=
        '/Volumes/rhino_root/data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat'
    )
    jr = JsonIndexReader('/Volumes/rhino_root/protocols/r1.json')
    new_reader = TalReader(
        filename=jr.get_value('pairs', subject='R1234D', experiment='FR1'))
    assert new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs()
    assert new_reader.get_monopolar_channels(
    ) == old_reader.get_monopolar_channels()
Exemple #2
0
def test_talreader_on_database():
    old_reader = TalReader(filename=osp.join(
        utils.get_rhino_root(),
        'data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat'))
    jr = JsonIndexReader(osp.join(utils.get_rhino_root(), 'protocols/r1.json'))
    new_reader = TalReader(
        filename=jr.get_value('pairs', subject='R1234D', experiment='FR1'))
    assert (new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs()
            ).all()
    assert (new_reader.get_monopolar_channels() ==
            old_reader.get_monopolar_channels()).all()
Exemple #3
0
def read_session(subject, root, experiment, rhino_root):
    jr = JsonIndexReader(rhino_root + '/protocols/r1.json')  # Build JSON reader
    pairs_path = jr.get_value('pairs', subject=subject, experiment=experiment)
    tal_reader = TalReader(filename=pairs_path)
    monopolar_channels = tal_reader.get_monopolar_channels()
    bipolar_channels = tal_reader.get_bipolar_pairs()

    jr = JsonIndexReader(rhino_root + '/protocols/r1.json')  # Build JSON reader
    pairs_path = jr.get_value('pairs', subject=subject, experiment=experiment)
    tal_reader = TalReader(filename=pairs_path)
    monopolar_channels = tal_reader.get_monopolar_channels()
    p_reader = ParamsReader(dataroot=root)
    params = p_reader.read()
    samplerate = params['samplerate']
    print samplerate
    try:
        raw_eeg = EEGReader(session_dataroot=root, channels = monopolar_channels)
        raw_eeg = raw_eeg.read()
        print raw_eeg.shape

    except:
        with h5py.File(root, 'r') as hfile:
            raw_eeg = H5RawReader.H5RawReader.read_h5file(hfile, monopolar_channels,[0])[0]
            print raw_eeg.shape
            raw_eeg = TimeSeriesX.TimeSeriesX(raw_eeg,
                                  dims=['channels', 'start_offsets', 'time'],
                                  coords={
                                      'channels': monopolar_channels,
                                      'start_offsets': [0],
                                      'time': np.arange(raw_eeg.shape[2])*1000/samplerate,
                                      'offsets': ('time',np.arange(raw_eeg.shape[2])),
                                      'samplerate': samplerate})
    return raw_eeg
def get_bp_tal_struct(sub, montage=0):

    from ptsa.data.readers import TalReader

    #Get electrode information -- bipolar
    tal_path = '/protocols/r1/subjects/' + sub + '/localizations/0/montages/' + str(
        montage) + '/neuroradiology/current_processed/pairs.json'
    tal_reader = TalReader(filename=tal_path)
    tal_struct = tal_reader.read()
    monopolar_channels = tal_reader.get_monopolar_channels()
    bipolar_pairs = tal_reader.get_bipolar_pairs()

    return tal_struct, bipolar_pairs, monopolar_channels
Exemple #5
0
def test_talreader_on_database():
    old_reader = TalReader(filename='/Volumes/rhino_root/data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat')
    jr = JsonIndexReader('/Volumes/rhino_root/protocols/r1.json')
    new_reader = TalReader(filename=jr.get_value('pairs',subject='R1234D',experiment='FR1'))
    assert new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs()
    assert new_reader.get_monopolar_channels() == old_reader.get_monopolar_channels()
Exemple #6
0
            osp.join(test_index_root, 'protocols', 'r1', 'subjects', subject,
                     'localizations', '0', 'neuroradiology'))
    except OSError as ose:
        if ose.errno != 17:
            raise ose
    return run_montage_import(inputs, force=True)


if __name__ == '__main__':
    for subject in bipolar_subjects:
        logger.set_subject(subject, 'R1')
        sucess, _ = make_bipolar_montage(subject)
        if sucess:
            tal = TalReader(filename=pairs_path_template.format(
                protocols_root=test_index_root, subject=subject))
            new_bipolar_pairs = tal.get_bipolar_pairs()
            jr = JsonIndexReader(
                osp.join(reference_index_root, 'protocols', 'r1.json'))
            task_event_files = list(
                jr.aggregate_values('task_events', subject=subject, montage=0))
            events = CMLEventReader(filename=task_event_files[0]).read()
            eeg = EEGReader(events=events[:1],
                            channels=np.array([]),
                            start_time=0.0,
                            end_time=0.1).read()
            hdf_bipolar_pairs = eeg.bipolar_pairs.values
            new_bipolar_pairs = new_bipolar_pairs.astype(
                hdf_bipolar_pairs.dtype)
            if not np.in1d(hdf_bipolar_pairs, new_bipolar_pairs).all():
                logger.info(
                    '\n\n%s missing from new_bipolar_pairs\n\n' %
Exemple #7
0
        pow_vec_orig = []
        pow_vec_recon = []
        print(len(recon_files))
        print(len(orig_files))

        assert (len(recon_files) == len(events))

        experiment = 'FR1'
        jr = JsonIndexReader(rhino_root +
                             '/protocols/r1.json')  # Build JSON reader
        pairs_path = jr.get_value('pairs',
                                  subject=subject,
                                  experiment=experiment)
        tal_reader = TalReader(filename=pairs_path)
        monopolar_channels = tal_reader.get_monopolar_channels()
        bipolar_channels = tal_reader.get_bipolar_pairs()

        recon_files = np.sort(recon_files)
        orig_files = np.sort(orig_files)

        data_orig_vec = []
        data_recon_vec = []

        for i, (recon_file,
                orig_file) in enumerate(zip(recon_files, orig_files)):
            if i % 100 == 0:
                print(i)
            fname_recon = subject_dir + recon_file
            fname_orig = subject_dir + orig_file
            bo_orig = se.load(fname_orig)
            bo_recon = se.load(fname_recon)
        os.symlink(osp.join(reference_index_root,'protocols','r1','subjects',subject,'localizations','0','neuroradiology'),
                   osp.join(test_index_root,'protocols','r1','subjects',subject,'localizations','0','neuroradiology'))
    except OSError as ose:
        if ose.errno != 17:
            raise ose
    return run_montage_import(inputs,force=True)




if __name__ == '__main__':
    for subject in bipolar_subjects:
        logger.set_subject(subject,'R1')
        sucess, _ =make_bipolar_montage(subject)
        if sucess:
            tal = TalReader(filename=pairs_path_template.format(protocols_root=test_index_root,
                                                                subject= subject))
            new_bipolar_pairs = tal.get_bipolar_pairs()
            jr = JsonIndexReader(osp.join(reference_index_root,'protocols','r1.json'))
            task_event_files = list(jr.aggregate_values('task_events',subject=subject,montage=0))
            events = CMLEventReader(filename=task_event_files[0]).read()
            eeg = EEGReader(events=events[:1],channels = np.array([]),start_time=0.0,end_time=0.1).read()
            hdf_bipolar_pairs = eeg.bipolar_pairs.values
            new_bipolar_pairs = new_bipolar_pairs.astype(hdf_bipolar_pairs.dtype)
            if not np.in1d(hdf_bipolar_pairs,new_bipolar_pairs).all():
                logger.info('\n\n%s missing from new_bipolar_pairs\n\n'%str(hdf_bipolar_pairs[~np.in1d(hdf_bipolar_pairs,new_bipolar_pairs)]))
            if not np.in1d(new_bipolar_pairs,hdf_bipolar_pairs).all():
                logger.info('\n\n%s missing from new_bipolar_pairs\n\n'%str(new_bipolar_pairs[~np.in1d(new_bipolar_pairs,hdf_bipolar_pairs)]))