本文整理汇总了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)
示例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)
示例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)
示例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)
示例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
示例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 )
示例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)
示例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))
示例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
示例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))