'Create a `distortion paper`_ type lookup table for detector to
image plane correction.'

def _read_det2im_kw(self, header, fobj, err=0.0):

    if (fobj is None):
        return (None, None)
    if (not isinstance(fobj, fits.HDUList)):
        return (None, None)
    try:
        axiscorr = header[str(u'AXISCORR')]
        d2imdis = self._read_d2im_old_format(header, fobj, axiscorr)
        return d2imdis
    except KeyError:
        pass
    dist = u'D2IMDIS'
    d_kw = u'D2IM'
    err_kw = u'D2IMERR'
    tables = {}
    for i in range(1, (self.naxis + 1)):
        d_error = header.get((err_kw + str(i)), 0.0)
        if (d_error < err):
            tables[i] = None
            continue
        distortion = (dist + str(i))
        if (distortion in header):
            dis = header[distortion].lower()
            if (dis == u'lookup'):
                del header[distortion]
                assert isinstance(fobj, fits.HDUList), u'An    astropy.io.fits.HDUListis    required    for    Lookup    table    distortion.'
                dp = (d_kw + str(i)).strip()
                dp_extver_key = (dp + str(u'.EXTVER'))
                if (dp_extver_key in header):
                    d_extver = header[dp_extver_key]
                    del header[dp_extver_key]
                else:
                    d_extver = 1
                dp_axis_key = (dp + str(u'.AXIS.{0:d}').format(i))
                if (i == header[dp_axis_key]):
                    d_data = fobj[(str(u'D2IMARR'), d_extver)].data
                else:
                    d_data = fobj[(str(u'D2IMARR'), d_extver)].data.transpose()
                del header[dp_axis_key]
                d_header = fobj[(str(u'D2IMARR'), d_extver)].header
                d_crpix = (d_header.get(str(u'CRPIX1'), 0.0), d_header.get(str(u'CRPIX2'), 0.0))
                d_crval = (d_header.get(str(u'CRVAL1'), 0.0), d_header.get(str(u'CRVAL2'), 0.0))
                d_cdelt = (d_header.get(str(u'CDELT1'), 1.0), d_header.get(str(u'CDELT2'), 1.0))
                d_lookup = DistortionLookupTable(d_data, d_crpix, d_crval, d_cdelt)
                tables[i] = d_lookup
            else:
                warnings.warn(u'Polynomial    distortion    is    not    implemented.\n', AstropyUserWarning)
            for key in list(header):
                if key.startswith((dp + str(u'.'))):
                    del header[key]
        else:
            tables[i] = None
    if (not tables):
        return (None, None)
    else:
        return (tables.get(1), tables.get(2))
