'Transform digitizer points to Neuromag head coordinates.'

def transform_to_head(self):

    if (self.coord_frame == 'head'):
        return
    (nasion, rpa, lpa) = (self.nasion, self.rpa, self.lpa)
    if any(((x is None) for x in (nasion, rpa, lpa))):
        if ((self.elp is None) or (self.point_names is None)):
            raise ValueError('ELP    points    and    names    must    be    specified    for    transformation.')
        names = [name.lower() for name in self.point_names]
        kinds = ('nasion', 'lpa', 'rpa')
        missing = [name for name in kinds if (name not in names)]
        if (len(missing) > 0):
            raise ValueError(('The    points    %s    are    missing,    but    are    needed    to    transform    the    points    to    the    MNE    coordinate    system.    Either    add    the    points,    or    read    the    montage    with    transform=False.' % str(missing)))
        (nasion, lpa, rpa) = [self.elp[names.index(kind)] for kind in kinds]
        mask = np.ones(len(names), dtype=bool)
        for fid in ['nasion', 'lpa', 'rpa']:
            mask[names.index(fid)] = False
        self.elp = self.elp[mask]
        self.point_names = [p for (pi, p) in enumerate(self.point_names) if mask[pi]]
    native_head_t = get_ras_to_neuromag_trans(nasion, lpa, rpa)
    (self.nasion, self.lpa, self.rpa) = apply_trans(native_head_t, np.array([nasion, lpa, rpa]))
    if (self.elp is not None):
        self.elp = apply_trans(native_head_t, self.elp)
    if (self.hsp is not None):
        self.hsp = apply_trans(native_head_t, self.hsp)
    if (self.dig_ch_pos is not None):
        for (key, val) in self.dig_ch_pos.items():
            self.dig_ch_pos[key] = apply_trans(native_head_t, val)
    self.coord_frame = 'head'
