Created
May 31, 2018 11:42
-
-
Save bsipocz/386f527be22583c5c322befc1aa0f5ef to your computer and use it in GitHub Desktop.
Standalone example to add new extension fits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from astropy.io import fits | |
from astropy.table import Table, Column | |
# Generating dummy file | |
import numpy as np | |
data = np.array(list(zip([1, 2, 3, 4], | |
['a', 'b', 'c', 'd'], | |
[2.3, 4.5, 6.7, 8.9])), | |
dtype=[('a', int), ('b', 'S1'), ('c', float)]) | |
hdul = fits.HDUList([fits.PrimaryHDU(), fits.BinTableHDU(data=data)]) | |
hdul.writeto('tb.fits') | |
# ###### | |
hdu = fits.open('tb.fits') | |
new_extension = Table.read('tb.fits', hdu=1) | |
new_extension['new column'] = Column([11, 22, 33, 44]) | |
hdu.append(fits.table_to_hdu(new_extension)) | |
hdu.writeto('tb.fits', overwrite=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment