Skip to content

Another MEF FITS issue with copying data #322

Answered by olebole
mgregg128 asked this question in Q&A
Discussion options

You must be logged in to vote

Why are you using IRAF here at all? IMO Astropy should easily do the job. Like:

from astropy.io import fits

hdul = fits.open("image.fits")
hdul[1].write("sci01.fits") # extract the first extension to a separate file
# ... do lacosmic...
sci = fits.open("sci01.fits") # or whatever the result file is
hdul[1].data = sci[0].data # Replace the data, assuming the same shape
hdul[1].header.update(sci[0].header) # Update/add header values if needed
hdul.write("image.fits", overwrite=True) # Replace the original file, or write a new one
sci.close()
hdul.close()

I would really take any chance to move away from IRAF and to use modern tools instead of a lengthy search how this could be done there.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@olebole
Comment options

Answer selected by mgregg128
@mgregg128
Comment options

@olebole
Comment options

@mgregg128
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants