Write the header to a fits file.
        :param filename:
        :return:
168820
def writeto(self, filename, **kwargs):
        
        fits.PrimaryHDU(header=self).writeto(filename, output_verify='ignore', **kwargs)
902324
def WriteHeader(self):
    """"""
    self._column_widths = {}
    bold = self._workbook.add_format({'bold': True})
    bold.set_align('center')
    for index, field_name in enumerate(self._fields):
      self._sheet.write(self._current_row, index, field_name, bold)
      self._column_widths[index] = len(field_name) + 2
    self._current_row += 1
    self._sheet.autofilter(0, len(self._fields) - 1, 0, 0)
    self._sheet.freeze_panes(1, 0)
1125309
def write_to_fitsfile(self, fitsfile, clobber=True):
        
        from fermipy.skymap import Map
        hpx_header = self._hpx.make_header()
        index_map = Map(self.ipixs, self.wcs)
        mult_map = Map(self.mult_val, self.wcs)
        prim_hdu = index_map.create_primary_hdu()
        mult_hdu = index_map.create_image_hdu()
        for key in ['COORDSYS', 'ORDERING', 'PIXTYPE',
                    'ORDERING', 'ORDER', 'NSIDE',
                    'FIRSTPIX', 'LASTPIX']:
            prim_hdu.header[key] = hpx_header[key]
            mult_hdu.header[key] = hpx_header[key]

        hdulist = fits.HDUList([prim_hdu, mult_hdu])
        hdulist.writeto(fitsfile, overwrite=clobber)
463257
def write_shiftfile(image_list, filename, outwcs='tweak_wcs.fits'):
    
    rows = ''
    nrows = 0
    for img in image_list:
        row = img.get_shiftfile_row()
        if row is not None:
            rows += row
            nrows += 1
    if nrows == 0:  # If there are no fits to report, do not write out a file
        return

    # write out reference WCS now
    if os.path.exists(outwcs):
        os.remove(outwcs)
    p = fits.HDUList()
    p.append(fits.PrimaryHDU())
    p.append(createWcsHDU(image_list[0].refWCS))
    p.writeto(outwcs)

    # Write out shiftfile to go with reference WCS
    with open(filename, 'w') as f:
        f.write('# frame: output\n')
        f.write('# refimage: %s[wcs]\n' % outwcs)
        f.write('# form: delta\n')
        f.write('# units: pixels\n')
        f.write(rows)
    print('Writing out shiftfile :', filename)
1166401
def _par_write(self, dirname):
        
        filename = dirname + '/' + 'template_parameters.csv'
        with open(filename, 'w') as parfile:
            for template in self.templates:
                for key in template.__dict__.keys():
                    if key not in ['st', 'event']:
                        parfile.write(key + ': ' +
                                      str(template.__dict__[key]) + ', ')
                parfile.write('\n')
        return self
763317
def write(self, file_name):
        
        try:
            assert file_name[-6:] == '.xhtml'
        except (AssertionError, IndexError):
            raise ValueError('filename must end with .xhtml')
        with open(file_name, 'wb') as f:
            f.write(self.content.encode('utf-8'))
715164
def save_headers(cls, filename: str, response: HTTPResponse):
        '''
        '''
        new_filename = filename + '-new'

        with open('wb') as new_file:
            new_file.write(response.header())

            with wpull.util.reset_file_offset(response.body):
                response.body.seek(0)
                shutil.copyfileobj(response.body, new_file)

        os.remove(filename)
        os.rename(new_filename, filename)
202067
def save_to_file(self, filename: str) -> ConfigFile:
        
        newclass = ConfigFile(fd=filename, load_hook=self.normal_class_hook[0],
                              dump_hook=self.normal_class_hook[1], safe_load=self.safe_load)
        return newclass
389661
def writeHeaderlet(self,**kwargs):
        
        # Insure filehandle is open and available...
        self.openFile()

        pars = kwargs.copy()
        rms_pars = self.fit['rms_keys']

        str_kw = ['descrip','history','author','hdrfile']
        for kw in str_kw:
            if pars[kw] == '': pars[kw] = None

        # Call function with properly interpreted input parameters
        # Syntax: write_headerlet(filename, hdrname, output, sciext='SCI',
        #                    wcsname=None, wcskey=None, destim=None,
        #                    sipname=None, npolfile=None, d2imfile=None,
        #                    author=None, descrip=None, history=None,
        #                    rms_ra=None, rms_dec=None, nmatch=None, catalog=None,
        #                    attach=True, clobber=False):
        headerlet.write_headerlet(self._im.hdu, pars['hdrname'],
                output=pars['hdrfile'],
                wcsname=None, wcskey=self.next_key, destim=None,
                sipname=None, npolfile=None, d2imfile=None,
                author=pars['author'], descrip=pars['descrip'],
                history=pars['history'],
                nmatch=rms_pars['NMATCH'],catalog=pars['catalog'],
                attach=pars['attach'], clobber=pars['clobber']
            )
1284375
def write_file(filename, content):
    
    with open_file(filename, 'w') as f:
        f.write(content)

    file_prepender(filename)
867726
def dump(self, filename):
        
        flags = os.O_WRONLY|os.O_CREAT|os.O_NOFOLLOW|os.O_EXCL
        fd = os.open(filename, flags, 0600)
        os.write(fd, str(self))
        os.close(fd)
610552
def write(self, filename='same'):
        
        if filename == 'same':
            filename = self.filename
        if not filename.endswith('.hdr'):
            filename += '.hdr'
        with open(filename, 'w') as out:
            out.write(self.__str__())
354492
def create_mef(filename=None):
    
    import pyfits, time

    if not filename:
        ### here I know what filename is to start with.
        import tempfile
        filename=tempfile.mktemp(suffix='.fits')
    else:
        import string, re
        ### filenames gotta be a string and no lead/trailing space
        filename=string.strip(str(filename))
        ### require that the filename ends in .fits
        suffix=re.match(r'^.*.fits$',filename)
        if not suffix:
            filename = filename+'.fits'

    ### create an HDU list
    temp = pyfits.HDUList()

    ### create a primary HDU
    prihdu = pyfits.PrimaryHDU()

    ### build the header
    h=prihdu.header
    h.update('EXTEND',pyfits.TRUE,after='NAXIS')
    h.update('NEXTEND',0,after='EXTEND')
    h.add_comment('MEF created at CADC')
    h.add_comment('Created using '+__name__+' '+__Version__)
    h.add_comment('Extensions may not be in CCD order')
    #h.update('cfh12k',__Version__,comment='split2mef software at CADC')
    h.add_comment('Use the EXTNAME keyword')
    h.add_history('Primary HDU created on '+time.asctime())

    ### stick the HDU onto the HDU list and write to file
    temp.append(prihdu)
    temp.writeto(filename)
    temp.close()

    return(filename)
29891
def write_uai(self, filename):
        
        writer = self.__str__()
        with open(filename, 'w') as fout:
            fout.write(writer)
708082
def overwrite_fits(hdulist, filename):
    

    assert isinstance(hdulist, (fits.HDUList, fits.PrimaryHDU))
    temp_name = None
    flag_delete_temp = False
    if os.path.isfile(filename):
        # PyFITS does not overwrite file
        temp_name = a99.rename_to_temp(filename)
    try:
        hdulist.writeto(filename, output_verify='warn')
        flag_delete_temp = temp_name is not None
    except:
        # Writing failed, reverts renaming
        os.rename(temp_name, filename)
        raise

    if flag_delete_temp:
        os.unlink(temp_name)
1210706
def write(self, filename):
        """"""
        if file_exists(filename):
            return filename
        out_files = [filename, filename + ".rownames", filename + ".colnames"]
        with file_transaction(out_files) as tx_out_files:
            with open(tx_out_files[0], "wb") as out_handle:
                scipy.io.mmwrite(out_handle, scipy.sparse.csr_matrix(self.matrix))
            pd.Series(self.rownames).to_csv(tx_out_files[1], index=False)
            pd.Series(self.colnames).to_csv(tx_out_files[2], index=False)
        return filename
31117
def write_to_file(self, filename):
        
        if not exists(dirname(filename)):
            return -1
        with open(filename, 'w') as fd:
            needs_json = json.dumps(self.minimum_needs)
            fd.write(needs_json)
        return 0