Skip to content

Commit

Permalink
logic corrected in absorber fits file if no absorbers found
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi0395 committed Aug 7, 2024
1 parent 7dffcd4 commit 9c54d8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions qsoabsfind/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ def save_results_to_fits(results, input_file, output_file, headers, absorber):
for key, header in headers.items():
hdr[key] = (header["value"], header["comment"])

# only save metadata if there at least one absorber is detected
if len(results['index_spec'])>0:
# load the QSO METADATA

_, _, _, metadata = read_fits_file(input_file, index=np.array(results['index_spec']))
qso_hdu = fits.BinTableHDU(metadata, name='METADATA')
hdul = fits.HDUList([fits.PrimaryHDU(header=hdr), hdu, qso_hdu])
_, _, _, metadata = read_fits_file(input_file, index=np.array(results['index_spec']))
qso_hdu = fits.BinTableHDU(metadata, name='METADATA')
hdul = fits.HDUList([fits.PrimaryHDU(header=hdr), hdu, qso_hdu])
else:
hdul = fits.HDUList([fits.PrimaryHDU(header=hdr), hdu])
hdul.writeto(output_file, overwrite=True)
print(f'INFO: ouptut file {output_file} written.')
2 changes: 1 addition & 1 deletion qsoabsfind/parallel_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def main():
args.input_fits_file, spec_indices, absorber=args.absorber,
n_jobs=args.n_tasks * args.ncpus, **constants.search_parameters[args.absorber]
)

# Save the results to a FITS file
save_results_to_fits(results, args.input_fits_file, args.output, headers, args.absorber)

Expand Down
2 changes: 1 addition & 1 deletion qsoabsfind/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class QSOSpecRead:
"""
A class to read and handle QSO spectra from a FITS file containing FLUX, ERROR, WAVELENGTH, and METADATA extensions."""

def __init__(self, fits_file, index=None, verbose=False):
def __init__(self, fits_file, index, verbose=False):
"""
Initializes the QSOSpecRead class.
Expand Down

0 comments on commit 9c54d8f

Please sign in to comment.