Skip to content

Commit

Permalink
adding calibrations to header as COMMENT and fixing header combination
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmejia committed Oct 1, 2024
1 parent e94be25 commit d0be900
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/lvmdrp/core/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from lvmdrp.core.cube import Cube
from lvmdrp.core.fiberrows import FiberRows
from lvmdrp.core.tracemask import TraceMask
from lvmdrp.core.header import Header, combineHdr
from lvmdrp.core.header import Header
from lvmdrp.core.positionTable import PositionTable
from lvmdrp.core.spectrum1d import Spectrum1D, find_continuum, wave_little_interpol
from lvmdrp.core import dataproducts as dp
Expand Down Expand Up @@ -295,8 +295,10 @@ def from_spectrographs(cls, rss_sp1, rss_sp2, rss_sp3):

# update header
if len(hdrs) > 0:
hdr_out = combineHdr(hdrs)
hdr_out._header["CCD"] = hdr_out._header["CCD"][0]
hdr_out = hdrs[0]._header.copy()
for hdr in hdrs[1:]:
hdr_out.update(hdr._header)
hdr_out["CCD"] = hdr_out["CCD"][0]
else:
hdr_out = None

Expand All @@ -316,7 +318,7 @@ def from_spectrographs(cls, rss_sp1, rss_sp2, rss_sp3):
sky_error=sky_error_out,
supersky=supersky_out,
supersky_error=supersky_error_out,
header=hdr_out._header,
header=hdr_out,
slitmap=slitmap_out,
fluxcal_std=fluxcal_std_out,
fluxcal_sci=fluxcal_sci_out
Expand Down
13 changes: 13 additions & 0 deletions python/lvmdrp/functions/imageMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,10 @@ def extract_spectra(
rss.setHdrValue("NAXIS2", data.shape[0])
rss.setHdrValue("NAXIS1", data.shape[1])
rss.setHdrValue("DISPAXIS", 1)
rss.add_header_comment(f"{in_trace}, fiber centroids used for {camera}")
rss.add_header_comment(f"{in_fwhm}, fiber width (FWHM) used for {camera}")
rss.add_header_comment(f"{in_model}, fiber model used for {camera}")
rss.add_header_comment(f"{in_acorr}, fiber aperture correction used for {camera}")
rss.setHdrValue(
"HIERARCH FIBER CENT MIN",
bn.nanmin(trace_mask._data),
Expand Down Expand Up @@ -3367,6 +3371,8 @@ def preproc_raw_frame(
proc_img.setHdrValue("DRPVER", DRPVER, comment='data reduction pipeline software tag')
# set drp commit SHA
proc_img.setHdrValue("COMMIT", DRP_COMMIT, comment="data reduction pipeline commit HASH")
# add calibrations used to header
proc_img.add_header_comment(f"{in_mask}, pixel mask used for {camera}")

# write out FITS file
log.info(f"writing preprocessed image to {os.path.basename(out_image)}")
Expand Down Expand Up @@ -3694,6 +3700,7 @@ def detrend_frame(
# TODO: Confirm that dark is not being flat fielded in current logic
# TODO: What is the difference between "flat" and "flatfield"? Pixel flats should not be pixel flatted but regular flats (dome and twilight) yes.
org_img = loadImage(in_image)
camera = org_img._header["CCD"]
exptime = org_img._header["EXPTIME"]
img_type = org_img._header["IMAGETYP"].lower()
log.info(
Expand Down Expand Up @@ -3831,6 +3838,12 @@ def detrend_frame(
log.warning("no slitmap information to be added")
detrended_img.add_header_comment("no slitmap information to be added")

# add calibrations used to header
detrended_img.add_header_comment(f"{in_bias}, bias used for {camera}")
detrended_img.add_header_comment(f"{in_dark}, dark used for {camera}")
detrended_img.add_header_comment(f"{in_pixelflat}, pixel flat used for {camera}")
detrended_img.add_header_comment(f"{in_nonlinearity}, non-linearity correction used for {camera}")

# save detrended image
log.info(f"writing detrended image to '{os.path.basename(out_image)}'")
detrended_img.writeFitsData(out_image)
Expand Down
8 changes: 8 additions & 0 deletions python/lvmdrp/functions/rssMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,14 @@ def create_pixel_table(in_rss: str, out_rss: str, in_waves: str, in_lsfs: str, c
rss.set_lsf_trace(lsf_trace)
rss.set_lsf_array()

# add calibrations used to header
for wave_trace, in_wave in zip(wave_traces, in_waves):
camera = wave_trace._header["CCD"]
rss.add_header_comment(f"{in_wave}, wavelength used for {camera}")
for lsf_trace, in_lsf in zip(lsf_traces, in_lsfs):
camera = lsf_trace._header["CCD"]
rss.add_header_comment(f"{in_lsf}, LSF used for {camera}")

# set header keywords for heliocentric velocity corrections
log.info("calculating heliocentric velocity corrections")
helio_rvs = rss.get_helio_rv(apply_heliorv)
Expand Down

0 comments on commit d0be900

Please sign in to comment.