code: def createWcsHDU(wcs):  # noqa: N802
      
      header = wcs.to_header()
  
      header['EXTNAME'] = 'WCS'
      header['EXTVER'] = 1
  
      # Now, update original image size information
      header['NPIX1'] = (wcs.pixel_shape[0], "Length of array axis 1")
      header['NPIX2'] = (wcs.pixel_shape[1], "Length of array axis 2")
      header['PIXVALUE'] = (0.0, "values of pixels in array")
  
      if hasattr(wcs, 'orientat'):
          orientat = wcs.orientat
      else:
          # find orientat from CD or PC matrix
          if wcs.wcs.has_cd():
              cd12 = wcs.wcs.cd[0][1]
              cd22 = wcs.wcs.cd[1][1]
          elif wcs.wcs.has_pc():
              cd12 = wcs.wcs.cdelt[0] * wcs.wcs.pc[0][1]
              cd22 = wcs.wcs.cdelt[1] * wcs.wcs.pc[1][1]
          else:
              raise ValueError("Invalid WCS: WCS does not contain neither "
                               "a CD nor a PC matrix.")
          orientat = np.rad2deg(np.arctan2(cd12, cd22))
      header['ORIENTAT'] = (orientat, "position angle of "
                            "image y axis (deg. e of n)")
  
      return fits.ImageHDU(None, header)
docs: Generate a WCS header object that can be used to populate a reference
      WCS HDU.
  
      For most applications, stwcs.wcsutil.HSTWCS.wcs2header()
      will work just as well.