本文整理汇总了Python中astropy.io.fits.PrimaryHDU方法的典型用法代码示例。如果您正苦于以下问题:Python fits.PrimaryHDU方法的具体用法?Python fits.PrimaryHDU怎么用?Python fits.PrimaryHDU使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.io.fits
的用法示例。
在下文中一共展示了fits.PrimaryHDU方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_class
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def setup_class(self) -> None:
self.limit = 1e-10
self.test_dir = os.path.dirname(__file__) + '/'
np.random.seed(1)
images = np.random.normal(loc=0, scale=2e-4, size=(5, 11, 11))
hdu = fits.PrimaryHDU()
header = hdu.header
header['INSTRUME'] = 'IMAGER'
header['HIERARCH ESO DET EXP NO'] = 1
header['HIERARCH ESO DET NDIT'] = 5
header['HIERARCH ESO INS PIXSCALE'] = 0.01
header['HIERARCH ESO ADA POSANG'] = 10.
header['HIERARCH ESO ADA POSANG END'] = 20.
header['HIERARCH ESO SEQ CUMOFFSETX'] = 5.
header['HIERARCH ESO SEQ CUMOFFSETY'] = 5.
hdu.data = images
hdu.writeto(self.test_dir+'images.fits')
示例2: test_is_fits_image_file_table_img
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def test_is_fits_image_file_table_img(self, dp_mock):
with tempfile.TemporaryDirectory() as tmpdir:
with self.settings(MEDIA_ROOT=tmpdir):
img_file = os.path.join(tmpdir, 'img.blah') # file name should be irrelevant
img = fits.PrimaryHDU(np.arange(100))
img.header['EXTNAME'] = 'SCI'
hdul = fits.HDUList([img])
hdul.writeto(img_file)
tabimg_file = os.path.join(tmpdir, 'both.fits')
table = fits.BinTableHDU.from_columns([
fits.Column(name='col1', format='I', array=np.array([1, 2, 3])),
fits.Column(name='col2', format='I', array=np.array([4, 5, 6]))
])
hdul = fits.HDUList([img, table])
hdul.writeto(tabimg_file)
self.data_product.data = tabimg_file
self.assertTrue(is_fits_image_file(self.data_product.data.file))
示例3: make_simple_hdulist
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def make_simple_hdulist(self):
"""
Make a`~astropy.io.fits.HDUList` object with just a simple
PrimaryHDU
"""
p = pyfits.PrimaryHDU()
p.header['ID'] = (self.id, 'Object ID')
p.header['RA'] = (self.ra, 'R.A.')
p.header['DEC'] = (self.dec, 'Decl.')
p.header['NINPUT'] = (len(self.beams), 'Number of drizzled beams')
p.header['HASLINES'] = ('', 'Lines in this file')
for i, beam in enumerate(self.beams):
p.header['FILE{0:04d}'.format(i+1)] = (beam.grism.parent_file,
'Parent filename')
p.header['GRIS{0:04d}'.format(i+1)] = (beam.grism.filter,
'Beam grism element')
p.header['PA{0:04d}'.format(i+1)] = (beam.get_dispersion_PA(),
'PA of dispersion axis')
return pyfits.HDUList(p)
示例4: update_wcs_fits_log
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def update_wcs_fits_log(file, wcs_ref, xyscale=[0, 0, 0, 1], initialize=True, replace=('.fits', '.wcslog.fits'), wcsname='SHIFT'):
"""
Make FITS log when updating WCS
"""
new_hdu = wcs_ref.to_fits(relax=True)[0]
new_hdu.header['XSHIFT'] = xyscale[0]
new_hdu.header['YSHIFT'] = xyscale[1]
new_hdu.header['ROT'] = xyscale[2], 'WCS fit rotation, degrees'
new_hdu.header['SCALE'] = xyscale[3], 'WCS fit scale'
new_hdu.header['WCSNAME'] = wcsname
wcs_logfile = file.replace(replace[0], replace[1])
if os.path.exists(wcs_logfile):
if initialize:
os.remove(wcs_logfile)
hdu = pyfits.HDUList([pyfits.PrimaryHDU()])
else:
hdu = pyfits.open(wcs_logfile)
else:
hdu = pyfits.HDUList([pyfits.PrimaryHDU()])
hdu.append(new_hdu)
hdu.writeto(wcs_logfile, overwrite=True, output_verify='fix')
示例5: _make_primary_hdu
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def _make_primary_hdu(self, target_id):
"""Returns the primary extension of a Target Pixel File."""
hdu = fits.PrimaryHDU()
# Copy the default keywords from a template file from the MAST archive
tmpl = self.get_header_template(0)
for kw in tmpl:
hdu.header[kw] = (tmpl[kw], tmpl.comments[kw])
# Override the defaults where necessary
hdu.header['ORIGIN'] = "Unofficial data product"
hdu.header['DATE'] = datetime.datetime.now().strftime("%Y-%m-%d")
hdu.header['CREATOR'] = "kadenza"
hdu.header['PROCVER'] = "{}".format(__version__)
hdu.header['FILEVER'] = "0.0"
hdu.header['OBJECT'] = target_name(target_id)
hdu.header['KEPLERID'] = target_id
hdu.header['CHANNEL'] = self.pixel_mapping.targets[target_id]['channel']
hdu.header['MODULE'] = self.pixel_mapping.targets[target_id]['module']
hdu.header['OUTPUT'] = self.pixel_mapping.targets[target_id]['output']
# Empty a bunch of keywords rather than having incorrect info
for kw in ["TIMVERSN", "CAMPAIGN", "DATA_REL", "TTABLEID",
"RA_OBJ", "DEC_OBJ"]:
hdu.header[kw] = ""
return hdu
示例6: write_res
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits 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)
示例7: write_fits
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def write_fits(data, header, file_name):
"""
Combine data and a fits header to write a fits file.
Parameters
----------
data : numpy.ndarray
The data to be written.
header : astropy.io.fits.hduheader
The header for the fits file.
file_name : string
The file to write
Returns
-------
None
"""
hdu = fits.PrimaryHDU(data)
hdu.header = header
hdulist = fits.HDUList([hdu])
hdulist.writeto(file_name, overwrite=True)
logging.info("Wrote {0}".format(file_name))
return
示例8: pack
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def pack(uncompressed_hdulist: fits.HDUList) -> fits.HDUList:
if uncompressed_hdulist[0].data is None:
primary_hdu = fits.PrimaryHDU(header=uncompressed_hdulist[0].header)
hdulist = [primary_hdu]
else:
primary_hdu = fits.PrimaryHDU()
compressed_hdu = fits.CompImageHDU(data=np.ascontiguousarray(uncompressed_hdulist[0].data),
header=uncompressed_hdulist[0].header, quantize_level=64,
dither_seed=2048, quantize_method=1)
hdulist = [primary_hdu, compressed_hdu]
for hdu in uncompressed_hdulist[1:]:
if isinstance(hdu, fits.ImageHDU):
compressed_hdu = fits.CompImageHDU(data=np.ascontiguousarray(hdu.data), header=hdu.header,
quantize_level=64, quantize_method=1)
hdulist.append(compressed_hdu)
else:
hdulist.append(hdu)
return fits.HDUList(hdulist)
示例9: save_single_fits
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def save_single_fits(image, name, key_dict=None, image2=None, image2type=None):
# Save an array into the first extension of a fits file
h0 = fits.PrimaryHDU()
h1 = fits.ImageHDU(image, name='DATA')
if image2 is not None:
h2 = fits.ImageHDU(image2)
if image2type is not None:
h2.header['EXTNAME'] = image2type
# if a keyword dictionary is provided, put the
# keywords into the 0th and 1st extension headers
if key_dict is not None:
for key in key_dict:
h0.header[key] = key_dict[key]
h1.header[key] = key_dict[key]
if image2 is None:
hdulist = fits.HDUList([h0, h1])
else:
hdulist = fits.HDUList([h0, h1, h2])
hdulist.writeto(name, overwrite=True)
示例10: __init__
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def __init__(self, primary_hdu=None, fits_extensions=None):
hdu_list = []
if primary_hdu is None:
primary_hdu = fits.PrimaryHDU()
else:
assert isinstance(primary_hdu, fits.PrimaryHDU)
hdu_list.append(primary_hdu)
if fits_extensions is not None:
fits_extensions = list(fits_extensions)
hdu_list.extend([x.hdu for x in fits_extensions])
# We embed instead of subclassing because the HDUList class has some weird interaction with the
# __init__ and __new__ methods which makes difficult to do so (we couldn't figure it out)
self._hdu_list = fits.HDUList(hdus=hdu_list)
示例11: saveScrns
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits 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!")
示例12: from_tree
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [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
示例13: test_insert_groupshdu_to_non_empty_list
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def test_insert_groupshdu_to_non_empty_list(self):
"""Tests inserting a Simple GroupsHDU to an empty HDUList."""
hdul = fits.HDUList()
hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
hdul.insert(0, hdu)
hdu = fits.GroupsHDU()
with pytest.raises(ValueError):
hdul.insert(1, hdu)
info = [(0, 'PRIMARY', 1, 'GroupsHDU', 8, (), '',
'1 Groups 0 Parameters'),
(1, '', 1, 'ImageHDU', 6, (100,), 'int32', '')]
hdul.insert(0, hdu)
assert hdul.info(output=False) == info
hdul.writeto(self.temp('test-insert.fits'))
assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例14: save_unwrapped
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def save_unwrapped(self, fname):
imarr = np.array(self.profiles).T
header = fits.Header()
header['CTYPE1'] = 'RA---SIN'
header['CTYPE2'] = 'DEC--SIN'
header['CDELT1'] = 2*np.pi/float(len(self.profiles))
header['CDELT2'] = np.max(self.rs)/float(len(self.rs))
header['BUNIT'] = 'K'
hdu = fits.PrimaryHDU(imarr, header=header)
hdulist = [hdu]
hdulist = fits.HDUList(hdulist)
hdulist.writeto(fname, overwrite=True)
示例15: test_read_cst_write_read_fits_intensity
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import PrimaryHDU [as 别名]
def test_read_cst_write_read_fits_intensity(cst_power_1freq, tmp_path):
# set up power beam
beam_in = cst_power_1freq
beam_out = UVBeam()
write_file = str(tmp_path / "outtest_beam.fits")
write_file2 = str(tmp_path / "outtest_beam2.fits")
beam_in.write_beamfits(write_file, clobber=True)
# now replace 'power' with 'intensity' for btype
fname = fits.open(write_file)
data = fname[0].data
primary_hdr = fname[0].header
primary_hdr["BTYPE"] = "Intensity"
hdunames = uvutils._fits_indexhdus(fname)
bandpass_hdu = fname[hdunames["BANDPARM"]]
prihdu = fits.PrimaryHDU(data=data, header=primary_hdr)
hdulist = fits.HDUList([prihdu, bandpass_hdu])
hdulist.writeto(write_file2, overwrite=True)
hdulist.close()
beam_out.read_beamfits(write_file2)
assert beam_in == beam_out
return