'Parameters
header : `~astropy.io.fits.Header`
FITS header.
add_sip : bool
Flag indicating whether "-SIP" should be added or removed from CTYPE keywords.
Remove "-SIP" from CTYPE when writing out a header with relax=False.
This needs to be done outside ``to_header`` because ``to_header`` runs
twice when ``relax=False`` and the second time ``relax`` is set to ``True``
to display the missing keywords.
If the user requested SIP distortion to be written out add "-SIP" to
CTYPE if it is missing.'

def _fix_ctype(self, header, add_sip=True, log_message=True):

    _add_sip_to_ctype = u'\n                                Inconsistent    SIP    distortion    information    is    present    in    the    current    WCS:\n                                SIP    coefficients    were    detected,    but    CTYPE    is    missing    "-SIP"    suffix,\n                                therefore    the    current    WCS    is    internally    inconsistent.\n\n                                Because    relax    has    been    set    to    True,    the    resulting    output    WCS    will    have\n                                "-SIP"    appended    to    CTYPE    in    order    to    make    the    header    internally    consistent.\n\n                                However,    this    may    produce    incorrect    astrometry    in    the    output    WCS,    if\n                                in    fact    the    current    WCS    is    already    distortion-corrected.\n\n                                Therefore,    if    current    WCS    is    already    distortion-corrected    (eg,    drizzled)\n                                then    SIP    distortion    components    should    not    apply.    In    that    case,    for    a    WCS\n                                that    is    already    distortion-corrected,    please    remove    the    SIP    coefficients\n                                from    the    header.\n\n                                '
    if log_message:
        if add_sip:
            log.info(_add_sip_to_ctype)
    for i in range(1, (self.naxis + 1)):
        kw = u'CTYPE{0}{1}'.format(i, self.wcs.alt).strip()
        if (kw in header):
            if add_sip:
                val = (header[kw].strip(u'-SIP') + u'-SIP')
            else:
                val = header[kw].strip(u'-SIP')
            header[kw] = val
        else:
            continue
    return header
