简体   繁体   中英

fix and edit a FITS header

I have a code to fix a header called "fix_header.py". I have tried to change location of a FITS file and if in the terminal I run python3 fix_header.py I get an error as:

AssertionError: attempted to get a local data file outside of the __main__ tree

But if I open python3 or python2 in the terminal and enter the code line by line, it works. My code is:

from astropy.io import fits
from astropy.utils.data import get_pkg_data_filename

fits_file = get_pkg_data_filename("../test/FITS-Header/IMAGES/STACK/input_file.fits") #path to the test 
fits.info(fits_file)

with fits.open(fits_file, 'update') as f:
    for hdu in f:
        hdu.header['OBJECT'] = "Mao"

fits.info(fits_file)

print(repr(fits.getheader(fits_file, 0)))

My question is whether or not the error refers to a bug? How can I run the code without entering it line by line in the terminal?

In my opinion, it's a bug of your pc and you just can run your code entering line by line every time. Or try with another pc!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM