'Remove SCAMP\'s PVi_m distortion parameters if SIP distortion parameters
are also present. Some projects (e.g., Palomar Transient Factory)
convert SCAMP\'s distortion parameters (which abuse the PVi_m cards) to
SIP. However, wcslib gets confused by the presence of both SCAMP and
SIP distortion parameters.
See https://github.com/astropy/astropy/issues/299.'

def _fix_scamp(self):

    if (self.wcs is None):
        return
    pv = self.wcs.get_pv()
    if (not pv):
        return
    if (self.sip is None):
        return
    pv = np.asarray(pv)
    for i in set(pv[:, 0]):
        js = set(pv[:, 1][(pv[:, 0] == i)])
        max_j = max(js)
        for j in (3, 11, 23, 39):
            if ((j < max_j) and (j in js)):
                return
    self.wcs.set_pv([])
    warnings.warn((u'Removed    redundant    SCAMP    distortion    parameters    ' + u'because    SIP    parameters    are    also    present'), FITSFixedWarning)
