本文整理汇总了Python中pyfits.PrimaryHDU方法的典型用法代码示例。如果您正苦于以下问题:Python pyfits.PrimaryHDU方法的具体用法?Python pyfits.PrimaryHDU怎么用?Python pyfits.PrimaryHDU使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyfits
的用法示例。
在下文中一共展示了pyfits.PrimaryHDU方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_res
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [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: saveScrns
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [as 别名]
def saveScrns(self, DIR):
"""
Saves the currently loaded phase screens to file,
saving the r0 value in the fits header (in units of pixels).
Saved phase data is in radians @500nm
Args:
DIR (string): The directory to save the screens
"""
for scrn in range(self.scrnNo):
logger.info("Write Sreen {}....".format(scrn))
hdu = fits.PrimaryHDU(self.wholeScrns[scrn])
hdu.header["R0"] = self.wholeScrnR0 / self.pixel_scale
hdulist = fits.HDUList([hdu])
hdulist.writeto(DIR+"/scrn{}.fits".format(scrn))
hdulist.close()
logger.info("Done!")
示例3: write_template
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [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)
示例4: phoe_vac
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [as 别名]
def phoe_vac():
from read_harps import airtovac
hdulist = pyfits.open('/home/astro56/husser/PhoenixModels/HiResFITS/WAVE_PHOENIX-ACES-AGSS-COND-2011.fits')
wavevac = airtovac(hdulist[0].data)
hdu = pyfits.PrimaryHDU(wavevac)
hdu.writeto('/home/astro43/zechmeister/carmenes/serval/lib/WAVE_VAC_PHOENIX-ACES-AGSS-COND-2011.fits')
示例5: PrimaryHDU
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [as 别名]
def PrimaryHDU(model):
'''
Construct the primary HDU file containing basic header info.
'''
# Get mission cards
cards = model._mission.HDUCards(model.meta, hdu=0)
if 'KEPMAG' not in [c[0] for c in cards]:
cards.append(('KEPMAG', model.mag, 'Kepler magnitude'))
# Add EVEREST info
cards.append(('COMMENT', '************************'))
cards.append(('COMMENT', '* EVEREST INFO *'))
cards.append(('COMMENT', '************************'))
cards.append(('MISSION', model.mission, 'Mission name'))
cards.append(('VERSION', EVEREST_MAJOR_MINOR, 'EVEREST pipeline version'))
cards.append(('SUBVER', EVEREST_VERSION, 'EVEREST pipeline subversion'))
cards.append(('DATE', strftime('%Y-%m-%d'),
'EVEREST file creation date (YYYY-MM-DD)'))
# Create the HDU
header = pyfits.Header(cards=cards)
hdu = pyfits.PrimaryHDU(header=header)
return hdu
示例6: MakeFITS
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [as 别名]
def MakeFITS(model, fitsfile=None):
'''
Generate a FITS file for a given :py:mod:`everest` run.
:param model: An :py:mod:`everest` model instance
'''
# Get the fits file name
if fitsfile is None:
outfile = os.path.join(model.dir, model._mission.FITSFile(
model.ID, model.season, model.cadence))
else:
outfile = os.path.join(model.dir, fitsfile)
if os.path.exists(outfile) and not model.clobber:
return
elif os.path.exists(outfile):
os.remove(outfile)
log.info('Generating FITS file...')
# Create the HDUs
primary = PrimaryHDU(model)
lightcurve = LightcurveHDU(model)
pixels = PixelsHDU(model)
aperture = ApertureHDU(model)
images = ImagesHDU(model)
hires = HiResHDU(model)
# Combine to get the HDUList
hdulist = pyfits.HDUList(
[primary, lightcurve, pixels, aperture, images, hires])
# Output to the FITS file
hdulist.writeto(outfile)
return
示例7: _fits_writeto
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [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: makePhaseScreens
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import PrimaryHDU [as 别名]
def makePhaseScreens(
nScrns, r0, N, pxlScale, L0, l0, returnScrns=True, DIR=None, SH=False):
"""
Creates and saves a set of phase screens to be used by the simulation.
Creates ``nScrns`` phase screens, with the required parameters, then saves
them to the directory specified by ``DIR``. Each screen is given a FITS
header with its value of r0, which will be scaled by on simulation when
its loaded.
Parameters:
nScrns (int): The number of screens to make.
r0 (float): r0 value of the phase screens in metres.
N (int): Number of elements across each screen.
pxlScale (float): Size of each element in metres.
L0 (float): Outer scale of each screen.
l0 (float): Inner scale of each screen.
returnScrns (bool, optional): Whether to return a list of screens. True by default, but if screens are very large, False might be preferred so they aren't kept in memory if saving to disk.
DIR (str, optional): The directory to save the screens.
SH (bool, optional): If True, add sub-harmonics to screens for more
accurate power spectra, though screens no-longer periodic.
Returns:
list: A list containing all the screens.
"""
#Make directory if it doesnt exist already
if DIR:
if not os.path.isdir(DIR):
os.makedirs(DIR)
#An empty container to put our screens in
if returnScrns:
scrns = []
#Now loop over and create all the screens (Currently with the same params)
for i in range(nScrns):
if SH:
scrn = phasescreen.ft_sh_phase_screen(r0, N, pxlScale, L0, l0)
else:
scrn = phasescreen.ft_phase_screen(r0, N, pxlScale, L0, l0)
if returnScrns:
scrns.append(scrn)
#If given a directory, save them too!
if DIR!=None:
hdu = fits.PrimaryHDU(scrn)
hdu.header["R0"] = str(r0/pxlScale)
hdu.writeto(DIR+"/scrn{}.fits".format(i))
if returnScrns:
return scrns