diff --git a/src/km3irf/utils.py b/src/km3irf/utils.py index 2b082925fa829bd60ef1cc839c0472a29144f338..dcfcc8771a5f0bbb32048d06d34795d5832dc411 100644 --- a/src/km3irf/utils.py +++ b/src/km3irf/utils.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from .calc import Calculator +from calc import Calculator from astropy.io import fits from os import path data_dir = path.join(path.dirname(__file__), 'data') @@ -27,22 +27,53 @@ def merge_fits(aeff_fits=path.join(data_dir, "aeff.fits"), hdu_list = [] hdu_list.append(fits.PrimaryHDU()) - with fits.open(aeff_fits) as file_aeff: - hdu_list.append(file_aeff[1]) + # with fits.open(aeff_fits) as file_aeff: + # hdu_list.append(file_aeff[1]) + # hdu_list[1].name = 'EFFECTIVE AREA' + + # with fits.open(psf_fits) as file_psf: + # hdu_list.append(file_psf[1]) + # hdu_list[2].name = 'POINT SPREAD FUNCTION' + + # with fits.open(edisp_fits) as file_edisp: + # hdu_list.append(file_edisp[1]) + # hdu_list[3].name = 'ENERGY DISPERSION' + + # with fits.open(bkg_fits) as file_bkg: + # hdu_list.append(file_bkg[1]) + # hdu_list[4].name = 'BACKGROUND' + + file_aeff = fits.open(aeff_fits) + hdu_list.append(file_aeff[1]) hdu_list[1].name = 'EFFECTIVE AREA' - with fits.open(psf_fits) as file_psf: - hdu_list.append(file_psf[1]) + file_psf = fits.open(psf_fits) + hdu_list.append(file_psf[1]) hdu_list[2].name = 'POINT SPREAD FUNCTION' - with fits.open(edisp_fits) as file_edisp: - hdu_list.append(file_edisp[1]) + file_edisp = fits.open(edisp_fits) + hdu_list.append(file_edisp[1]) hdu_list[3].name = 'ENERGY DISPERSION' - with fits.open(bkg_fits) as file_bkg: - hdu_list.append(file_bkg[1]) + file_bkg = fits.open(bkg_fits) + hdu_list.append(file_bkg[1]) hdu_list[4].name = 'BACKGROUND' - new_fits_file = fits.HDUList(hdu) - new_fits_file.writeto(f'./data/{output_file}', overwrite=True) + + new_fits_file = fits.HDUList(hdu_list) + # new_fits_file.writeto(f'.data/{output_file}', overwrite=True) + # new_fits_file.writeto(output_file, overwrite=True) + new_fits_file.writeto(path.join(data_dir, output_file), overwrite=True) + # new_fits_file.writeto(f'.data/{output_file}', overwrite=True) + # new_fits_file.close() + + # with fits.open(path.join(data_dir, output_file), mode='update') as new_fits_file: + # new_fits_file = fits.HDUList(hdu_list) + # new_fits_file.writeto(path.join(data_dir, output_file), overwrite=True) + + file_aeff.close() + file_psf.close() + file_edisp.close() + file_bkg.close() +# merge_fits() \ No newline at end of file