code: def undistortWCS(refwcs):
      
      wcslin = stwcs.distortion.utils.output_wcs([refwcs])
  
      outwcs = stwcs.wcsutil.HSTWCS()
      outwcs.wcs = wcslin.wcs
      outwcs.wcs.set()
      outwcs.setPscale()
      outwcs.setOrient()
      outwcs.sip = None
  
      # Update instrument specific keywords
      outwcs.inst_kw = refwcs.inst_kw
      for kw in refwcs.inst_kw:
          outwcs.__dict__[kw] = refwcs.__dict__[kw]
      outwcs.pixel_shape = wcslin.pixel_shape
  
      return outwcs
docs: Generate an undistorted HSTWCS from an HSTWCS object with a distortion model