本文整理汇总了Python中astropy.io.fits.writeto方法的典型用法代码示例。如果您正苦于以下问题:Python fits.writeto方法的具体用法?Python fits.writeto怎么用?Python fits.writeto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.io.fits
的用法示例。
在下文中一共展示了fits.writeto方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_wcs_fits_log
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [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')
示例2: test_insert_image_extension_to_primary_in_non_empty_list
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_insert_image_extension_to_primary_in_non_empty_list(self):
"""
Tests inserting a Simple Image ExtensionHDU to a non-empty HDUList
as the primary HDU.
"""
with fits.open(self.data('tb.fits')) as hdul:
hdu = fits.ImageHDU(np.arange(100, dtype=np.int32))
hdul.insert(0, hdu)
info = [(0, 'PRIMARY', 1, 'PrimaryHDU', 5, (100,), 'int32', ''),
(1, '', 1, 'ImageHDU', 12, (), '', ''),
(2, '', 1, 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', '')]
assert hdul.info(output=False) == info
hdul.writeto(self.temp('test-insert.fits'))
assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例3: write_res
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits 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)
示例4: test_insert_groupshdu_to_non_empty_list
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [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
示例5: test_update_filelike
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_update_filelike(self):
"""Test opening a file-like object in update mode and resizing the
HDU.
"""
sf = io.BytesIO()
arr = np.zeros((100, 100))
hdu = fits.PrimaryHDU(data=arr)
hdu.writeto(sf)
sf.seek(0)
arr = np.zeros((200, 200))
hdul = fits.open(sf, mode='update')
hdul[0].data = arr
hdul.flush()
sf.seek(0)
hdul = fits.open(sf)
assert len(hdul) == 1
assert (hdul[0].data == arr).all()
示例6: test_open_file_with_end_padding
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_open_file_with_end_padding(self):
"""Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/106
Open files with end padding bytes.
"""
with fits.open(self.data('test0.fits'),
do_not_scale_image_data=True) as hdul:
info = hdul.info(output=False)
hdul.writeto(self.temp('temp.fits'))
with open(self.temp('temp.fits'), 'ab') as f:
f.seek(0, os.SEEK_END)
f.write(b'\0' * 2880)
with ignore_warnings():
assert info == fits.info(self.temp('temp.fits'), output=False,
do_not_scale_image_data=True)
示例7: test_byteswap
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_byteswap(self):
p = fits.PrimaryHDU()
l = fits.HDUList()
n = np.zeros(3, dtype='i2')
n[0] = 1
n[1] = 60000
n[2] = 2
c = fits.Column(name='foo', format='i2', bscale=1, bzero=32768,
array=n)
t = fits.BinTableHDU.from_columns([c])
l.append(p)
l.append(t)
l.writeto(self.temp('test.fits'), overwrite=True)
with fits.open(self.temp('test.fits')) as p:
assert p[1].data[1]['foo'] == 60000.0
示例8: test_writeto_2
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [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
示例9: test_writeto_append_mode_gzip
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_writeto_append_mode_gzip(self):
"""Regression test for
https://github.com/spacetelescope/PyFITS/issues/33
Check that a new GzipFile opened in append mode can be used to write
out a new FITS file.
"""
# Note: when opening a GzipFile the 'b+' is superfluous, but this was
# still how the original test case looked
# Note: with statement not supported on GzipFile in older Python
# versions
fileobj = gzip.GzipFile(self.temp('test.fits.gz'), 'ab+')
h = fits.PrimaryHDU()
try:
h.writeto(fileobj)
finally:
fileobj.close()
with fits.open(self.temp('test.fits.gz')) as hdul:
assert hdul[0].header == h.header
示例10: test_write_read_gzip_file
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_write_read_gzip_file(self):
"""
Regression test for https://github.com/astropy/astropy/issues/2794
Ensure files written through gzip are readable.
"""
data = np.arange(100)
hdu = fits.PrimaryHDU(data=data)
hdu.writeto(self.temp('test.fits.gz'))
with open(self.temp('test.fits.gz'), 'rb') as f:
assert f.read(3) == GZIP_MAGIC
with fits.open(self.temp('test.fits.gz')) as hdul:
assert np.all(hdul[0].data == data)
示例11: test_updated_file_permissions
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_updated_file_permissions(self):
"""
Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/79
Tests that when a FITS file is modified in update mode, the file
permissions are preserved.
"""
filename = self.temp('test.fits')
hdul = [fits.PrimaryHDU(), fits.ImageHDU()]
hdul = fits.HDUList(hdul)
hdul.writeto(filename)
old_mode = os.stat(filename).st_mode
hdul = fits.open(filename, mode='update')
hdul.insert(1, fits.ImageHDU())
hdul.flush()
hdul.close()
assert old_mode == os.stat(filename).st_mode
示例12: test_write_bytesio_discontiguous
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_write_bytesio_discontiguous(self):
"""
Regression test related to
https://github.com/astropy/astropy/issues/2794#issuecomment-55441539
Demonstrates that writing an HDU containing a discontiguous Numpy array
should work properly.
"""
data = np.arange(100)[::3]
hdu = fits.PrimaryHDU(data=data)
fileobj = io.BytesIO()
hdu.writeto(fileobj)
fileobj.seek(0)
with fits.open(fileobj) as h:
assert np.all(h[0].data == data)
示例13: test_fix_invalid_extname
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_fix_invalid_extname(self, capsys):
phdu = fits.PrimaryHDU()
ihdu = fits.ImageHDU()
ihdu.header['EXTNAME'] = 12345678
hdul = fits.HDUList([phdu, ihdu])
filename = self.temp('temp.fits')
pytest.raises(fits.VerifyError, hdul.writeto, filename,
output_verify='exception')
with pytest.warns(fits.verify.VerifyWarning,
match=r'Verification reported errors'):
hdul.writeto(filename, output_verify='fix')
with fits.open(filename):
assert hdul[1].name == '12345678'
assert hdul[1].header['EXTNAME'] == '12345678'
hdul.close()
示例14: test_binary_table_data
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_binary_table_data(self):
a1 = np.array(['NGC1001', 'NGC1002', 'NGC1003'])
a2 = np.array([11.1, 12.3, 15.2])
col1 = fits.Column(name='target', format='20A', array=a1)
col2 = fits.Column(name='V_mag', format='E', array=a2)
cols = fits.ColDefs([col1, col2])
tbhdu = fits.BinTableHDU.from_columns(cols)
tbhdu.writeto(self.temp('tmp.fits'), overwrite=True, checksum=True)
with fits.open(self.temp('tmp.fits'), checksum=True) as hdul:
assert comparerecords(tbhdu.data, hdul[1].data)
assert 'CHECKSUM' in hdul[0].header
assert hdul[0].header['CHECKSUM'] == 'D8iBD6ZAD6fAD6ZA'
assert 'DATASUM' in hdul[0].header
assert hdul[0].header['DATASUM'] == '0'
assert 'CHECKSUM' in hdul[1].header
assert hdul[1].header['CHECKSUM'] == 'aD1Oa90MaC0Ma90M'
assert 'DATASUM' in hdul[1].header
assert hdul[1].header['DATASUM'] == '1062205743'
示例15: test_variable_length_table_data
# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import writeto [as 别名]
def test_variable_length_table_data(self):
c1 = fits.Column(name='var', format='PJ()',
array=np.array([[45.0, 56], np.array([11, 12, 13])],
'O'))
c2 = fits.Column(name='xyz', format='2I', array=[[11, 3], [12, 4]])
tbhdu = fits.BinTableHDU.from_columns([c1, c2])
tbhdu.writeto(self.temp('tmp.fits'), overwrite=True, checksum=True)
with fits.open(self.temp('tmp.fits'), checksum=True) as hdul:
assert comparerecords(tbhdu.data, hdul[1].data)
assert 'CHECKSUM' in hdul[0].header
assert hdul[0].header['CHECKSUM'] == 'D8iBD6ZAD6fAD6ZA'
assert 'DATASUM' in hdul[0].header
assert hdul[0].header['DATASUM'] == '0'
assert 'CHECKSUM' in hdul[1].header
assert hdul[1].header['CHECKSUM'] == 'YIGoaIEmZIEmaIEm'
assert 'DATASUM' in hdul[1].header
assert hdul[1].header['DATASUM'] == '1507485'