def get_aligned_artifacts(info=None, trans=None, subject=None, subjects_dir=None,
                          coord_frame='mri', head_surf=None):
    head_mri_t, _ = _get_trans(trans, 'head', 'mri')
    dev_head_t, _ = _get_trans(info['dev_head_t'], 'meg', 'head')
    head_trans = head_mri_t
    mri_trans = Transform('mri', 'mri')

    mri_fiducials = mne.coreg.get_mni_fiducials(subject, subjects_dir)
    fid_loc = _fiducial_coords(mri_fiducials, FIFF.FIFFV_COORD_MRI)
    fid_loc = apply_trans(mri_trans, fid_loc)
    fid_loc = pd.DataFrame(fid_loc, index=[fid["ident"]._name.split("_")[-1] for fid in mri_fiducials],
                           columns=["x", "y", "z"])

    if head_surf is None:
        subject_dir = Path(get_subjects_dir(subjects_dir, raise_error=True)) / subject
        fname = subject_dir / 'bem' / 'sample-head.fif'
        head_surf = read_bem_surfaces(fname)[0]
        head_surf = transform_surface_to(head_surf, coord_frame, [mri_trans, head_trans], copy=True)

    eeg_picks = mne.pick_types(info, meg=False, eeg=True, ref_meg=False)
    eeg_loc = np.array([info['chs'][k]['loc'][:3] for k in eeg_picks])
    eeg_loc = apply_trans(head_trans, eeg_loc)
    eegp_loc = _project_onto_surface(eeg_loc, head_surf, project_rrs=True, return_nn=True)[2]
    eegp_loc = pd.DataFrame(eegp_loc, index=[ch["ch_name"] for ch in info['chs']], columns=["x", "y", "z"])

    return eegp_loc, fid_loc, head_surf
Esempio n. 2
0
def make_coordsys_eeg_json(dir_coordsys_eeg_json, fname_epo, subj_id, task):
    import os.path as op
    import json
    from mne.viz._3d import _fiducial_coords
    import mne

    epo = mne.read_epochs(fname_epo)

    coordys = {
        "EEGCoordinateSystem": "T1w",
        "EEGCoordinateUnits": "m",
        "AnatomicalLandmarkCoordinates": {}
    }

    fids = _fiducial_coords(epo.info['dig'])
    coordys['AnatomicalLandmarkCoordinates']['LPA'] = [
        float(n) for n in fids[0]
    ]  # has to be float and not np.float to be able to json dump
    coordys['AnatomicalLandmarkCoordinates']['NAS'] = [
        float(n) for n in fids[1]
    ]
    coordys['AnatomicalLandmarkCoordinates']['RPA'] = [
        float(n) for n in fids[2]
    ]
    coordys['AnatomicalLandmarkCoordinateSystem'] = "T1w"
    coordys['IntendedFor'] = '/%s/anat/%s_T1.nii' % (subj_id, subj_id)
    coordys['AnatomicalLandmarkCoordinateUnits'] = "m"

    fname_save = op.join(dir_coordsys_eeg_json,
                         '%s_task-%s_coordsystem.json' % (subj_id, task))
    with open(fname_save, 'w') as f:
        json.dump(coordys, f, indent=4)
Esempio n. 3
0
def test_fiducials():
    """Test handling of fiducials."""
    # Eventually the code used here should be unified with montage.py, but for
    # now it uses code in odd places
    for fname in (fif_fname, ctf_fif_fname):
        fids, coord_frame = read_fiducials(fname)
        points = _fiducial_coords(fids, coord_frame)
        assert points.shape == (3, 3)
        # Fids
        assert_allclose(points[:, 2], 0., atol=1e-6)
        assert_allclose(points[::2, 1], 0., atol=1e-6)
        assert points[2, 0] > 0  # RPA
        assert points[0, 0] < 0  # LPA
        # Nasion
        assert_allclose(points[1, 0], 0., atol=1e-6)
        assert points[1, 1] > 0
Esempio n. 4
0
def test_fiducials():
    """Test handling of fiducials."""
    # Eventually the code used here should be unified with montage.py, but for
    # now it uses code in odd places
    for fname in (fif_fname, ctf_fif_fname):
        fids, coord_frame = read_fiducials(fname)
        points = _fiducial_coords(fids, coord_frame)
        assert points.shape == (3, 3)
        # Fids
        assert_allclose(points[:, 2], 0., atol=1e-6)
        assert_allclose(points[::2, 1], 0., atol=1e-6)
        assert points[2, 0] > 0  # RPA
        assert points[0, 0] < 0  # LPA
        # Nasion
        assert_allclose(points[1, 0], 0., atol=1e-6)
        assert points[1, 1] > 0