'Generate an `astropy.io.fits.HDUList` object with all of the
information stored in this object.  This should be logically identical
to the input FITS file, but it will be normalized in a number of ways.
See `to_header` for some warnings about the output produced.
Parameters
relax : bool or int, optional
Degree of permissiveness:
- `False` (default): Write all extensions that are
considered to be safe and recommended.
- `True`: Write all recognized informal extensions of the
WCS standard.
- `int`: a bit field selecting specific extensions to
write.  See :ref:`relaxwrite` for details.
key : str
The name of a particular WCS transform to use.  This may be
either ``\' \'`` or ``\'A\'``-``\'Z\'`` and corresponds to the ``"a"``
part of the ``CTYPEia`` cards.
Returns
hdulist : `astropy.io.fits.HDUList`'

def to_fits(self, relax=False, key=None):

    header = self.to_header(relax=relax, key=key)
    hdu = fits.PrimaryHDU(header=header)
    hdulist = fits.HDUList(hdu)
    self._write_det2im(hdulist)
    self._write_distortion_kw(hdulist)
    return hdulist
