本文整理汇总了Python中astropy.io.fits.getheader方法的典型用法代码示例。如果您正苦于以下问题:Python fits.getheader方法的具体用法?Python fits.getheader怎么用?Python fits.getheader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.io.fits
的用法示例。
在下文中一共展示了fits.getheader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_res
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [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: from_file
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def from_file(cls, filename, beam=None, psf_file=None):
"""
Create a new WCSHelper class from a given fits file.
Parameters
----------
filename : string
The file to be read
beam : :class:`AegeanTools.wcs_helpers.Beam` or None
The synthesized beam. If the supplied beam is None then one is constructed form the header.
psf_file : str
Filename for a psf map
Returns
-------
obj : :class:`AegeanTools.wcs_helpers.WCSHelper`
A helper object
"""
header = fits.getheader(filename)
return cls.from_header(header, beam, psf_file=psf_file)
示例3: test_fileobj_not_closed
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_fileobj_not_closed(self):
"""
Tests that file-like objects are not closed after being passed
to convenience functions.
Regression test for https://github.com/astropy/astropy/issues/5063
"""
f = open(self.data('test0.fits'), 'rb')
_ = fits.getdata(f)
assert not f.closed
f.seek(0)
_ = fits.getheader(f)
assert not f.closed
f.close() # Close it now
示例4: test_image_extension_update_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_image_extension_update_header(self):
"""
Test that _makehdu correctly includes the header. For example in the
fits.update convenience function.
"""
filename = self.temp('twoextension.fits')
hdus = [fits.PrimaryHDU(np.zeros((10, 10))),
fits.ImageHDU(np.zeros((10, 10)))]
fits.HDUList(hdus).writeto(filename)
fits.update(filename,
np.zeros((10, 10)),
header=fits.Header([('WHAT', 100)]),
ext=1)
h_out = fits.getheader(filename, ext=1)
assert h_out['WHAT'] == 100
示例5: __init__
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def __init__(self, flt_files=DEMO_LIST, info=None, driz_image=DEMO_IMAGE, driz_hdu=None, beams=None):
"""
Object for making drizzled PSFs
Parameters
----------
flt_files : list
List of FLT files that were used to create the drizzled image.
driz_image : str
Filename of the drizzled image.
"""
if info is None:
if beams is not None:
info = self._get_wcs_from_beams(beams)
else:
if flt_files is None:
info = self._get_wcs_from_hdrtab(driz_image)
else:
info = self._get_flt_wcs(flt_files)
self.flt_keys, self.wcs, self.footprint = info
self.flt_files = list(np.unique([key[0] for key in self.flt_keys]))
self.ePSF = utils.EffectivePSF()
if driz_hdu is None:
self.driz_image = driz_image
self.driz_header = pyfits.getheader(driz_image)
self.driz_wcs = pywcs.WCS(self.driz_header)
self.driz_pscale = utils.get_wcs_pscale(self.driz_wcs)
else:
self.driz_image = driz_image
self.driz_header = driz_hdu.header
self.driz_wcs = pywcs.WCS(self.driz_header)
self.driz_pscale = utils.get_wcs_pscale(self.driz_wcs)
self.driz_wcs.pscale = self.driz_pscale
示例6: write_template
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [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)
示例7: write_fits
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [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)
示例8: bary_harps
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def bary_harps(file, ra=None, dec=None, epoch=2000, pma=0.0, pmd=0.0):
''' compute barycentric correction for HARPS spctrum using coordinates from
input or fits header
ra - rammss e.g. -142942.94 (for 14:29:42.94)
dec - demmss e.g. -624046.16 (-62:40:46.16)
pma - [mas/yr] proper motion in alpha (-3775.75)
pmd - [mas/yr] proper motion in delta (765.54)
epoch - epoch of coordinates
'''
head = pyfits.getheader(file)
if ra is None:
ra = head['HIERARCH ESO TEL TARG ALPHA']
dec = head['HIERARCH ESO TEL TARG DELTA']
epoch = head['HIERARCH ESO TEL TARG EPOCH']
pma = head['HIERARCH ESO TEL TARG PMA']*1000
pmd = head['HIERARCH ESO TEL TARG PMD']*1000
exptime = head['EXPTIME'] * 2*head['HIERARCH ESO INS DET1 TMMEAN']
dateobs = head['DATE-OBS']
#bjd = head['HIERARCH ESO DRS BERV']
#berv = head['HIERARCH ESO DRS BJD']
x = str(ra).split('.')
rammss = float(x[0][:-4]), float(x[0][-4:-2]), float(x[0][-2:]+'.'+x[1])
# rammss = divmod(ra,10000); rammss = (rammss[0],) + divmod(rammss[1],100)
x = str(dec).split('.')
demmss = float(x[0][:-4]), float(x[0][-4:-2]), float(x[0][-2:]+'.'+x[1])
#print ra, dec, pma, pmd
return bary(dateobs, rammss, demmss, 14, epoch, exptime, pma, pmd) #, bjd, berv
示例9: psf_wcs
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def psf_wcs(self):
if self._psf_wcs is None:
header = fits.getheader(self.psf_file)
try:
wcs = WCS(header, naxis=2)
except:
wcs = WCS(str(header), naxis=2)
self._psf_wcs = wcs
return self._psf_wcs
示例10: test_get_pixinfo
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_get_pixinfo():
"""Test that we can get info from various header styles"""
header = fits.getheader('tests/test_files/1904-66_SIN.fits')
area, scale = AegeanTools.wcs_helpers.get_pixinfo(header)
if not area > 0: raise AssertionError()
if not len(scale) == 2: raise AssertionError()
header['CD1_1'] = header['CDELT1']
del header['CDELT1']
header['CD2_2'] = header['CDELT2']
del header['CDELT2']
area, scale = AegeanTools.wcs_helpers.get_pixinfo(header)
if not area > 0: raise AssertionError()
if not len(scale) == 2: raise AssertionError()
header['CD1_2'] = 0
header['CD2_1'] = 0
area, scale = AegeanTools.wcs_helpers.get_pixinfo(header)
if not area > 0: raise AssertionError()
if not len(scale) == 2: raise AssertionError()
header['CD1_2'] = header['CD1_1']
header['CD2_1'] = header['CD2_2']
area, scale = AegeanTools.wcs_helpers.get_pixinfo(header)
if not area == 0: raise AssertionError()
if not len(scale) == 2: raise AssertionError()
for f in ['CD1_1', 'CD1_2', 'CD2_2', 'CD2_1']:
del header[f]
area, scale = AegeanTools.wcs_helpers.get_pixinfo(header)
if not area == 0: raise AssertionError()
if not scale == (0, 0): raise AssertionError()
示例11: test_get_beam
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_get_beam():
"""Test that we can recover the beam from the fits header"""
header = fits.getheader('tests/test_files/1904-66_SIN.fits')
beam = AegeanTools.wcs_helpers.get_beam(header)
print(beam)
if beam is None : raise AssertionError()
if beam.pa != header['BPA']: raise AssertionError()
del header['BMAJ'], header['BMIN'], header['BPA']
beam = AegeanTools.wcs_helpers.get_beam(header)
if beam is not None : raise AssertionError()
示例12: test_fix_aips_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_fix_aips_header():
"""TEst that we can fix an aips generated fits header"""
header = fits.getheader('tests/test_files/1904-66_SIN.fits')
# test when this function is not needed
_ = AegeanTools.wcs_helpers.fix_aips_header(header)
# test when beam params are not present, but there is no aips history
del header['BMAJ'], header['BMIN'], header['BPA']
_ = AegeanTools.wcs_helpers.fix_aips_header(header)
# test with some aips history
header['HISTORY'] = 'AIPS CLEAN BMAJ= 1.2500E-02 BMIN= 1.2500E-02 BPA= 0.00'
_ = AegeanTools.wcs_helpers.fix_aips_header(header)
示例13: test_from_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def test_from_header():
"""Test that we can make a beam from a fitsheader"""
fname = 'tests/test_files/1904-66_SIN.fits'
header = fits.getheader(fname)
helper = WCSHelper.from_header(header)
if helper.beam is None: raise AssertionError()
del header['BMAJ'], header['BMIN'], header['BPA']
# Raise an error when the beam information can't be determined
try:
_ = WCSHelper.from_header(header)
except AssertionError as e:
pass
else:
raise AssertionError("Header with no beam information should thrown an exception.")
return
示例14: get_primary_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def get_primary_header(filename) -> Optional[fits.Header]:
try:
header = fits.getheader(filename, ext=0)
for keyword in header:
if keyword not in FITS_MANDATORY_KEYWORDS:
return header
return fits.getheader(filename, ext=1)
except Exception:
logger.error("Unable to open fits file: {}".format(logs.format_exception()), extra_tags={'filename': filename})
return None
# Stop after 4 attempts, and back off exponentially with a minimum wait time of 4 seconds, and a maximum of 10.
# If it fails after 4 attempts, "reraise" the original exception back up to the caller.
示例15: _load_itm_library
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import getheader [as 别名]
def _load_itm_library(library_file):
"""Load ITM FITS file
Parameters
----------
library_path : str
Path pointing to the location of the PSF library
Returns
-------
library : photutils.griddedPSFModel
Object containing PSF library
"""
data = fits.getdata(library_file)
hdr = fits.getheader(library_file)
if data.shape == (2048, 2048):
# Normalize the data
data /= np.sum(data)
# Add PSF location and oversampling keywords
hdr['DET_YX0'] = ('(1023, 1023)', "The #0 PSF's (y,x) detector pixel position")
hdr['OVERSAMP'] = (1, 'Oversampling factor for FFTs in computation')
# Convert to HDUList and create library
phdu = fits.PrimaryHDU(data, hdr)
hdulist = fits.HDUList(phdu)
library = to_griddedpsfmodel(hdulist)
return library
else:
raise ValueError('Expecting ITM data of size (2048, 2048), not {}'.format(data.shape))