code: def build_self_reference(filename, clean_wcs=False):
      
      if 'sipwcs' in filename:
          sciname = 'sipwcs'
      else:
          sciname = 'sci'
  
      wcslin = build_reference_wcs([filename], sciname=sciname)
  
      if clean_wcs:
          wcsbase = wcslin.wcs
          customwcs = build_hstwcs(wcsbase.crval[0], wcsbase.crval[1], wcsbase.crpix[0],
                                   wcsbase.crpix[1], wcslin._naxis1, wcslin._naxis2,
                                   wcslin.pscale, wcslin.orientat)
      else:
          customwcs = wcslin
      return customwcs
docs: This function creates a reference, undistorted WCS that can be used to
      apply a correction to the WCS of the input file.
  
      Parameters
      ----------
      filename : str
          Filename of image which will be corrected, and which will form the basis
          of the undistorted WCS.
  
      clean_wcs : bool
          Specify whether or not to return the WCS object without any distortion
          information, or any history of the original input image.  This converts
          the output from `utils.output_wcs()` into a pristine `~stwcs.wcsutils.HSTWCS` object.
  
      Returns
      -------
      customwcs : `stwcs.wcsutils.HSTWCS`
          HSTWCS object which contains the undistorted WCS representing the entire
          field-of-view for the input image.
  
      Examples
      --------
      This function can be used with the following syntax to apply a shift/rot/scale
      change to the same image:
  
      >>> import buildref
      >>> from drizzlepac import updatehdr
      >>> filename = "jce501erq_flc.fits"
      >>> wcslin = buildref.build_self_reference(filename)
      >>> updatehdr.updatewcs_with_shift(filename, wcslin, xsh=49.5694,
      ... ysh=19.2203, rot = 359.998, scale = 0.9999964)