本文整理汇总了Python中astropy.io.fits.Header方法的典型用法代码示例。如果您正苦于以下问题:Python fits.Header方法的具体用法?Python fits.Header怎么用?Python fits.Header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.io.fits
的用法示例。
在下文中一共展示了fits.Header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def get_header(self, ext=0):
"""Returns the metadata embedded in the file.
Target Pixel Files contain embedded metadata headers spread across three
different FITS extensions:
1. The "PRIMARY" extension (``ext=0``) provides a metadata header
providing details on the target and its CCD position.
2. The "PIXELS" extension (``ext=1``) provides details on the
data column and their coordinate system (WCS).
3. The "APERTURE" extension (``ext=2``) provides details on the
aperture pixel mask and the expected coordinate system (WCS).
Parameters
----------
ext : int or str
FITS extension name or number.
Returns
-------
header : `~astropy.io.fits.header.Header`
Header object containing metadata keywords.
"""
return self.hdu[ext].header
示例2: ApertureHDU
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def ApertureHDU(model):
'''
Construct the HDU containing the aperture used to de-trend.
'''
# Get mission cards
cards = model._mission.HDUCards(model.meta, hdu=3)
# 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.ImageHDU(data=model.aperture,
header=header, name='APERTURE MASK')
return hdu
示例3: test_makes_a_sensible_master_flat
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_makes_a_sensible_master_flat(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nimages = 50
flat_level = 10000.0
nx = 100
ny = 100
master_flat_variation = 0.05
image_header = Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'FLATLVL': flat_level,
'OBSTYPE': 'SKYFLAT',
'RA': 0.0,
'DEC': 0.0})
flat_pattern = np.random.normal(1.0, master_flat_variation, size=(ny, nx))
images = [FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=flat_pattern + np.random.normal(0.0, 0.02, size=(ny, nx)),
meta=image_header)])
for _ in range(nimages)]
maker = FlatMaker(FakeContext())
stacked_image = maker.do_stage(images)
np.testing.assert_allclose(stacked_image.primary_hdu.data, flat_pattern, atol=0.1, rtol=0.1)
示例4: test_header_cal_type_dark
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_header_cal_type_dark(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nx = 100
ny = 100
maker = DarkMaker(FakeContext())
image_header = Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'OBSTYPE': 'DARK'})
image = maker.do_stage([FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=np.zeros((ny,nx)),
meta=image_header)])
for x in range(6)])
assert image.meta['OBSTYPE'].upper() == 'DARK'
示例5: test_makes_a_sensible_master_dark
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_makes_a_sensible_master_dark(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nimages = 20
nx = 100
ny = 100
image_header = Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'OBSTYPE': 'DARK'})
images = [FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=np.ones((ny, nx)) * x,
meta=image_header)])
for x in range(nimages)]
expected_master_dark = stats.sigma_clipped_mean(np.arange(nimages), 3.0)
maker = DarkMaker(FakeContext())
stacked_image = maker.do_stage(images)
assert (stacked_image.data == expected_master_dark).all()
示例6: test_header_cal_type_bias
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_header_cal_type_bias(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nx = 100
ny = 100
maker = BiasMaker(FakeContext())
image_header = Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'OBSTYPE': 'BIAS', 'RA': 0.0, 'DEC': 0.0})
image = maker.do_stage([FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=np.zeros((ny, nx)),
meta=image_header,
bias_level=0.0)])
for x in range(6)])
assert image.meta['OBSTYPE'].upper() == 'BIAS'
示例7: test_bias_level_is_average_of_inputs
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_bias_level_is_average_of_inputs(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nimages = 20
bias_levels = np.arange(nimages, dtype=float)
images = [FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=np.random.normal(i, size=(99,99)),
bias_level=i, meta=Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'OBSTYPE': 'BIAS',
'RA': 0.0,
'DEC': 0.0}))])
for i in bias_levels]
fake_context = FakeContext()
maker = BiasMaker(fake_context)
master_bias = maker.do_stage(images)
assert master_bias.meta['BIASLVL'] == np.mean(bias_levels)
示例8: test_makes_a_sensible_master_bias
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_makes_a_sensible_master_bias(mock_namer):
mock_namer.return_value = lambda *x: 'foo.fits'
nimages = 20
expected_readnoise = 15.0
images = [FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=np.random.normal(0.0, size=(99, 99), scale=expected_readnoise),
bias_level=0.0,
read_noise= expected_readnoise,
meta=Header({'DATE-OBS': '2019-12-04T14:34:00',
'DETSEC': '[1:100,1:100]',
'DATASEC': '[1:100,1:100]',
'OBSTYPE': 'BIAS', 'RA': 0.0, 'DEC': 0.0}))])
for i in range(nimages)]
maker = BiasMaker(FakeContext())
stacked_image = maker.do_stage(images)
master_bias = stacked_image.data
assert np.abs(np.mean(master_bias)) < 0.1
actual_readnoise = np.std(master_bias)
assert np.abs(actual_readnoise - expected_readnoise / (nimages ** 0.5)) < 0.2
示例9: init_master_header
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def init_master_header(old_header, images):
header = fits.Header()
for key in old_header.keys():
try:
# Dump empty header keywords and ignore old histories.
if len(key) > 0 and key != 'HISTORY':
for i in range(old_header.count(key)):
header[key] = (old_header[(key, i)], old_header.comments[(key, i)])
except ValueError as e:
logger.error('Could not add keyword {key}: {error}'.format(key=key, error=e))
continue
header = fits_utils.sanitize_header(header)
observation_dates = [image.dateobs for image in images]
mean_dateobs = date_utils.mean_date(observation_dates)
header['DATE-OBS'] = (date_utils.date_obs_to_string(mean_dateobs), '[UTC] Mean observation start time')
header['DAY-OBS'] = (max(images, key=lambda x: datetime.datetime.strptime(x.epoch, '%Y%m%d')).epoch, '[UTC] Date at start of local observing night')
header['ISMASTER'] = (True, 'Is this a master calibration frame')
header.add_history("Images combined to create master calibration image:")
for i, image in enumerate(images):
header[f'IMCOM{i+1:03d}'] = (image.filename, 'Image combined to create master')
return header
示例10: __init__
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def __init__(self, campaign=0, channel=1, cadenceno=1, data_store=None,
shape=KEPLER_CHANNEL_SHAPE, add_background=False, time=None,
quality=None, dateobs=None, dateend=None, mjdbeg=None,
mjdend=None, template_tpf_header0=None,
template_tpf_header1=None):
self.campaign = campaign
self.channel = channel
self.cadenceno = cadenceno
self.data_store = data_store
self.header = fits.Header()
self.data = np.empty(shape, dtype=np.float32)
self.data[:] = np.nan
self.uncert = np.empty(shape, dtype=np.float32)
self.uncert[:] = np.nan
self.add_background = add_background
self.time = time
self.quality = quality
self.template_tpf_header0 = template_tpf_header0
self.template_tpf_header1 = template_tpf_header1
self.dateobs = dateobs
self.dateend = dateend
self.mjdbeg = mjdbeg
self.mjdend = mjdend
示例11: from_tree
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def from_tree(cls, data, ctx):
hdus = []
first = True
for hdu_entry in data:
header = fits.Header([fits.Card(*x) for x in hdu_entry['header']])
data = hdu_entry.get('data')
if data is not None:
try:
data = data.__array__()
except ValueError:
data = None
if first:
hdu = fits.PrimaryHDU(data=data, header=header)
first = False
elif data.dtype.names is not None:
hdu = fits.BinTableHDU(data=data, header=header)
else:
hdu = fits.ImageHDU(data=data, header=header)
hdus.append(hdu)
hdulist = fits.HDUList(hdus)
return hdulist
示例12: test_set_card_value
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_set_card_value(self):
"""Similar to test_update_header_card(), but tests the the
`header['FOO'] = 'bar'` method of updating card values.
"""
header = fits.Header()
comment = 'number of bits per data pixel'
card = fits.Card.fromstring(f'BITPIX = 32 / {comment}')
header.append(card)
header['BITPIX'] = 32
assert 'BITPIX' in header
assert header['BITPIX'] == 32
assert header.cards[0].keyword == 'BITPIX'
assert header.cards[0].value == 32
assert header.cards[0].comment == comment
示例13: test_writeto_2
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def test_writeto_2(self):
"""
Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/107
Test of `writeto()` with a trivial header containing a single keyword.
"""
filename = self.temp('array.fits')
data = np.zeros((100, 100))
header = fits.Header()
header.set('CRPIX1', 1.)
fits.writeto(filename, data, header=header,
overwrite=True, output_verify='silentfix')
with fits.open(filename) as hdul:
assert len(hdul) == 1
assert (data == hdul[0].data).all()
assert 'CRPIX1' in hdul[0].header
assert hdul[0].header['CRPIX1'] == 1.0
示例14: copy
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def copy(self):
"""Create a mutable and independent copy of the header."""
# This method exists because io.fits.Header.copy has a docstring that
# refers to `Header` which breaks sphinx...
return super().copy()
示例15: fromfile
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import Header [as 别名]
def fromfile(cls, fh, verify=True):
"""Reads in GUPPI header block from a file.
Parameters
----------
fh : filehandle
To read data from.
verify: bool, optional
Whether to do basic checks on whether the header is valid. Verify
is automatically called by `~astropy.io.fits.Header.fromstring`, so
this flag exists only to standardize the API.
"""
header_start = fh.tell()
# Find the size of the header. GUPPI header entries are 80 char long
# with <=8 char keyword names. "=" is always the 9th char.
line = '========='
while line[8] in ('=', ' '):
line = fh.read(80).decode('ascii')
if line[:3] == 'END':
break
if line == '':
raise EOFError
header_end = fh.tell()
fh.seek(header_start)
hdr = fh.read(header_end - header_start).decode('ascii')
# Create the header using the base class.
self = cls.fromstring(hdr)
self.mutable = False
if verify:
self.verify()
# GUPPI headers are not a proper FITS standard, and we're reading
# from a file that the user likely cannot control, so let's not bother
# with card verification (this avoids warnings in repr(); gh-282)
for c in self.cards:
c._verified = True
return self