當前位置: 首頁>>代碼示例>>Python>>正文


Python pyfits.writeto方法代碼示例

本文整理匯總了Python中pyfits.writeto方法的典型用法代碼示例。如果您正苦於以下問題:Python pyfits.writeto方法的具體用法?Python pyfits.writeto怎麽用?Python pyfits.writeto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyfits的用法示例。


在下文中一共展示了pyfits.writeto方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_res

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def write_res(filename, datas, extnames, header='', hdrref=None, clobber=False):
   if not header and hdrref: header = pyfits.getheader(hdrref)
   hdu = pyfits.PrimaryHDU(header=header)
   warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
   warnings.filterwarnings('ignore', category=UserWarning, append=True)
   hdu.writeto(filename, clobber=clobber, output_verify='fix')
   warnings.resetwarnings()
   warnings.filterwarnings('always', category=UserWarning, append=True)

   for i,extname in enumerate(extnames):
     data = datas[extname]
     if isinstance(data, np.ndarray):
        pyfits.append(filename, data)
     else:
        1/0

     pyfits.setval(filename, 'EXTNAME', value=extname, ext=i+1)
   #fitsio.write(filename, flux) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:20,代碼來源:read_spec.py

示例2: write_template

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def write_template(filename, flux, wave, header=None, hdrref=None, clobber=False):
   if not header and hdrref: header = pyfits.getheader(hdrref)
   hdu = pyfits.PrimaryHDU(header=header)
   warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
   warnings.filterwarnings('ignore', category=UserWarning, append=True)
   hdu.writeto(filename, clobber=clobber, output_verify='fix')
   warnings.resetwarnings()
   warnings.filterwarnings('always', category=UserWarning, append=True)

   if isinstance(flux, np.ndarray):
      pyfits.append(filename, flux)
      pyfits.append(filename, wave)
   else:
      # pad arrays with zero to common size
      maxpix = max(arr.size for arr in flux if isinstance(arr, np.ndarray))
      flux_new = np.zeros((len(flux), maxpix))
      wave_new = np.zeros((len(flux), maxpix))
      for o,arr in enumerate(flux):
          if isinstance(arr, np.ndarray): flux_new[o,:len(arr)] = arr
      for o,arr in enumerate(wave):
          if isinstance(arr, np.ndarray): wave_new[o,:len(arr)] = arr
      pyfits.append(filename, flux_new)
      pyfits.append(filename, wave_new)

   pyfits.setval(filename, 'EXTNAME', value='SPEC', ext=1)
   pyfits.setval(filename, 'EXTNAME', value='WAVE', ext=2)
   #fitsio.write(filename, flux) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:29,代碼來源:read_spec.py

示例3: write_fits

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def write_fits(filename, data, header='', hdrref=None, clobber=True):
   if not header and hdrref: header = pyfits.getheader(hdrref)
   warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
   warnings.filterwarnings('ignore', category=UserWarning, append=True)
   pyfits.writeto(filename, data, header, clobber=clobber, output_verify='fix')
   warnings.resetwarnings()
   warnings.filterwarnings('always', category=UserWarning, append=True) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:9,代碼來源:read_spec.py

示例4: saveCMat

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def saveCMat(self):
        """
        Writes the current control Matrix to FITS file
        """
        filename = self.sim_config.simName+"/cMat.fits"

        fits.writeto(
                filename, self.control_matrix,
                header=self.sim_config.saveHeader, overwrite=True) 
開發者ID:AOtools,項目名稱:soapy,代碼行數:11,代碼來源:reconstruction.py

示例5: save_interaction_matrix

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def save_interaction_matrix(self):
        """
        Writes the current control Matrix to FITS file

        Writes the current interaction matrix to a FITS file in the simulation directory. Also
        writes the "valid actuators" as accompanying FITS files, and potentially premade DM
        influence functions.
        """
        imat_filename = self.sim_config.simName+"/iMat.fits"

        fits.writeto(
                imat_filename, self.interaction_matrix,
                header=self.sim_config.saveHeader, overwrite=True)

        for i in range(self.n_dms):
            valid_acts_filename =  self.sim_config.simName+"/active_acts_dm{}.fits".format(i)
            valid_acts = self.dms[i].valid_actuators
            fits.writeto(valid_acts_filename, valid_acts, header=self.sim_config.saveHeader, overwrite=True)

            # If DM has pre made influence funcs, save them too
            try:
                dm_shapes_filename = self.sim_config.simName + "/dmShapes_dm{}.fits".format(i)
                fits.writeto(
                        dm_shapes_filename, self.dms[i].iMatShapes,
                        header=self.simConfig.saveHeader, overwrite=True)
            # If not, don't worry about it! Must be a DM with no pre-made influence funcs
            except AttributeError:
                pass 
開發者ID:AOtools,項目名稱:soapy,代碼行數:30,代碼來源:reconstruction.py

示例6: learn

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def learn(self, callback=None, progressCallback=None):
        '''
        Takes "self.learnFrames" WFS frames, and computes the tomographic
        reconstructor for the system. This method uses the "truth" sensor, and
        assumes that this is WFS0
        '''

        self.learnSlopes = numpy.zeros( (self.learnIters,self.sim_config.totalWfsData) )
        for i in xrange(self.learnIters):
            self.learnIter=i

            scrns = self.moveScrns()
            self.learnSlopes[i] = self.runWfs(scrns)


            logger.statusMessage(i+1, self.learnIters, "Performing Learn")
            if callback!=None:
                callback()
            if progressCallback!=None:
               progressCallback("Performing Learn", i, self.learnIters )

        if self.sim_config.saveLearn:
            #FITS.Write(self.learnSlopes,self.sim_config.simName+"/learn.fits")
            fits.writeto(
                    self.sim_config.simName+"/learn.fits",
                    self.learnSlopes, header=self.sim_config.saveHeader,
                    overwrite=True ) 
開發者ID:AOtools,項目名稱:soapy,代碼行數:29,代碼來源:reconstruction.py

示例7: _fits_writeto

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def _fits_writeto(filename, data, header=None, output_verify='exception',
                  clobber=False, checksum=False):
    """
    Create a new FITS file using the supplied data/header.
    Patched version of pyfits to correctly include provided header

    Parameters
    ----------
    filename : file path, file object, or file like object
        File to write to.  If opened, must be opened in a writeable binary
        mode such as 'wb' or 'ab+'.

    data : array, record array, or groups data object
        data to write to the new file

    header : `Header` object, optional
        the header associated with ``data``. If `None`, a header
        of the appropriate type is created for the supplied data. This
        argument is optional.

    output_verify : str
        Output verification option.  Must be one of ``"fix"``, ``"silentfix"``,
        ``"ignore"``, ``"warn"``, or ``"exception"``.  May also be any
        combination of ``"fix"`` or ``"silentfix"`` with ``"+ignore"``,
        ``+warn``, or ``+exception" (e.g. ``"fix+warn"``).  See :ref:`verify`
        for more info.

    clobber : bool, optional
        If `True`, and if filename already exists, it will overwrite
        the file.  Default is `False`.

    checksum : bool, optional
        If `True`, adds both ``DATASUM`` and ``CHECKSUM`` cards to the
        headers of all HDU's written to the file
    """

    hdu = pyfits.convenience._makehdu(data, header)
    hdu.header.update(header.cards)
    if hdu.is_image and not isinstance(hdu, pyfits.PrimaryHDU):
        hdu = pyfits.PrimaryHDU(data, header=header)
    hdu.writeto(filename, clobber=clobber, output_verify=output_verify,
                checksum=checksum) 
開發者ID:annayqho,項目名稱:TheCannon,代碼行數:44,代碼來源:simpletable.py

示例8: write

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def write(self, fname, **kwargs):
        """ write table into file

        Parameters
        ----------
        fname: str
            filename to export the table into

        .. note::
            additional keywords are forwarded to the corresponding libraries
            :func:`pyfits.writeto` or :func:`pyfits.append`
            :func:`np.savetxt`
        """
        extension = fname.split('.')[-1]
        if (extension == 'csv'):
            comments = kwargs.pop('comments', '#')
            delimiter = kwargs.pop('delimiter', ',')
            commentedHeader = kwargs.pop('commentedHeader', False)
            hdr = _ascii_generate_header(self, comments=comments, delimiter=delimiter,
                                         commentedHeader=commentedHeader)
            np.savetxt(fname, self.data, delimiter=delimiter, header=hdr,
                       comments='', **kwargs)
        elif (extension in ['txt', 'dat']):
            comments = kwargs.pop('comments', '#')
            delimiter = kwargs.pop('delimiter', ' ')
            commentedHeader = kwargs.pop('commentedHeader', True)
            hdr = _ascii_generate_header(self, comments=comments, delimiter=delimiter,
                                         commentedHeader=commentedHeader)
            np.savetxt(fname, self.data, delimiter=delimiter, header=hdr,
                       comments='', **kwargs)
        elif (extension == 'fits'):
            hdr0 = kwargs.pop('header', None)
            append = kwargs.pop('append', False)
            hdr = _fits_generate_header(self)
            if hdr0 is not None:
                hdr.update(**hdr0)
            if append:
                _fits_append(fname, self.data, hdr, **kwargs)
            else:
                # patched version to correctly include the header
                _fits_writeto(fname, self.data, hdr, **kwargs)
        elif (extension in ('hdf', 'hdf5', 'hd5')):
            _hdf5_write_data(fname, self.data, header=self.header,
                             units=self._units, comments=self._desc,
                             aliases=self._aliases, **kwargs)
        else:
            raise Exception('Format {0:s} not handled'.format(extension)) 
開發者ID:annayqho,項目名稱:TheCannon,代碼行數:49,代碼來源:simpletable.py

示例9: storeData

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def storeData(self, i):
        """
        Stores data from each frame in an appropriate data structure.

        Called on each frame to store the simulation data into various data 
        structures corresponding to different data sources in the system.

        For some data streams that are very large, data gets saved to disk on 
        each iteration - this also happens here.

        Args:
            i (int): The system iteration number
        """
        if self.config.sim.saveSlopes:
            self.allSlopes[i] = self.slopes

        if self.config.sim.saveDmCommands:
            act=0
            self.allDmCommands[i,act:] = self.dmCommands

        #Quick bodge to save lgs psfs as images
        if self.config.sim.saveLgsPsf:
            lgs=0
            for nwfs in xrange(self.config.sim.nGS):
                if self.config.wfss[nwfs].lgs and self.config.wfss[nwfs].lgs.uplink:
                    self.lgsPsfs[lgs, i] = self.wfss[nwfs].lgs.psf
                    lgs+=1

        if self.config.sim.nSci>0:
            for sci in xrange(self.config.sim.nSci):
                self.instStrehl[sci,i] = self.sciCams[sci].instStrehl
                self.longStrehl[sci,i] = self.sciCams[sci].longExpStrehl

                # Record WFE residual
                self.WFE[sci, i] = self.sciCams[sci].calc_wavefronterror()

            if self.config.sim.saveSciRes:
                for sci in xrange(self.config.sim.nSci):
                    self.sciPhase[sci][i] = self.sciCams[sci].residual

        if self.config.sim.simName!=None:
            if self.config.sim.saveWfsFrames:
                for nwfs in xrange(self.config.sim.nGS):
                    fits.writeto(
                        self.path+"/wfsFPFrames/wfs-%d_frame-%d.fits"%(nwfs,i),
                        self.wfss[nwfs].wfsDetectorPlane,
                        header=self.config.sim.saveHeader)

        # Save Instantaneous PSF
        if self.config.sim.nSci>0 and self.config.sim.saveInstPsf==True:
            for sci in xrange(self.config.sim.nSci):
                self.sciImgsInst[sci][i,:,:] = self.sciCams[sci].detector


        # Save Instantaneous electric field
        if self.config.sim.nSci>0 and self.config.sim.saveInstScieField==True:
            for sci in xrange(self.config.sim.nSci):
                self.scieFieldInst[sci][self.iters,:,:] = self.sciCams[sci].focalPlane_efield 
開發者ID:AOtools,項目名稱:soapy,代碼行數:60,代碼來源:simulation.py

示例10: write

# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import writeto [as 別名]
def write(self, fname, **kwargs):
        """ write table into file

        Parameters
        ----------
        fname: str
            filename to export the table into

        .. note::
            additional keywords are forwarded to the corresponding libraries
            :func:`pyfits.writeto` or :func:`pyfits.append`
            :func:`np.savetxt`
        """
        extension = kwargs.pop('extension', None)
        if extension is None:
            extension = fname.split('.')[-1]
        if (extension == 'csv'):
            comments = kwargs.pop('comments', '#')
            delimiter = kwargs.pop('delimiter', ',')
            commentedHeader = kwargs.pop('commentedHeader', False)
            hdr = _ascii_generate_header(self, comments=comments, delimiter=delimiter,
                                         commentedHeader=commentedHeader)
            header = kwargs.pop('header', hdr)
            np.savetxt(fname, self.data, delimiter=delimiter, header=header,
                       comments='', **kwargs)
        elif (extension in ['txt', 'dat']):
            comments = kwargs.pop('comments', '#')
            delimiter = kwargs.pop('delimiter', ' ')
            commentedHeader = kwargs.pop('commentedHeader', True)
            hdr = _ascii_generate_header(self, comments=comments, delimiter=delimiter,
                                         commentedHeader=commentedHeader)
            header = kwargs.pop('header', hdr)
            np.savetxt(fname, self.data, delimiter=delimiter, header=header,
                       comments='', **kwargs)
        elif (extension == 'fits'):
            hdr0 = kwargs.pop('header', None)
            append = kwargs.pop('append', False)
            hdr = _fits_generate_header(self)
            if hdr0 is not None:
                hdr.update(**hdr0)
            if append:
                _fits_append(fname, self.data, hdr, **kwargs)
            else:
                # patched version to correctly include the header
                _fits_writeto(fname, self.data, hdr, **kwargs)
        elif (extension in ('hdf', 'hdf5', 'hd5')):
            _hdf5_write_data(fname, self.data, header=self.header,
                             units=self._units, comments=self._desc,
                             aliases=self._aliases, **kwargs)
        else:
            raise Exception('Format {0:s} not handled'.format(extension)) 
開發者ID:mfouesneau,項目名稱:pyphot,代碼行數:53,代碼來源:simpletable.py


注:本文中的pyfits.writeto方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。