Skip to content

Commit

Permalink
adding per-CCD header keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmejia committed Dec 3, 2024
1 parent 0b699d3 commit 03cdf1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
8 changes: 5 additions & 3 deletions python/lvmdrp/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,10 @@ def convertUnit(self, to, assume="adu", gain_field="GAIN", inplace=False):
return new_image

if current != to:
camera = self.getHdrValue("CCD").upper()
exptime = self.getHdrValue("EXPTIME")
gains = self.getHdrValue(f"AMP? {gain_field}")
sects = self.getHdrValue("AMP? TRIMSEC")
gains = self.getHdrValue(f"{camera} AMP? {gain_field}")
sects = self.getHdrValue(f"{camera} AMP? TRIMSEC")
n_amp = len(gains)
for i in range(n_amp):
if current == "adu" and to == "electron":
Expand Down Expand Up @@ -3373,7 +3374,8 @@ def combineImages(
stack_error[stack_mask] = numpy.nan

if background_subtract:
quad_sections = images[0].getHdrValues("AMP? TRIMSEC")
camera = images[0].getHdrValue("CCD").upper()
quad_sections = images[0].getHdrValues(f"{camera} AMP? TRIMSEC")
stack_image, _, _, _ = _bg_subtraction(
images=stack_image,
quad_sections=quad_sections,
Expand Down
3 changes: 2 additions & 1 deletion python/lvmdrp/core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def plot_detrend(ori_image, det_image, axs, mbias=None, mdark=None, labels=False
"""

# define quadrant sections
sections = ori_image.getHdrValue("AMP? TRIMSEC")
camera = ori_image.getHdrValue("CCD").upper()
sections = ori_image.getHdrValue(f"{camera} AMP? TRIMSEC")

# convert all images to adu
unit = "adu"
Expand Down
35 changes: 18 additions & 17 deletions python/lvmdrp/functions/imageMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2732,15 +2732,15 @@ def extract_spectra(
rss.setHdrValue("NAXIS2", data.shape[0])
rss.setHdrValue("NAXIS1", data.shape[1])
rss.setHdrValue("DISPAXIS", 1, "axis of spectral dispersion")
rss.setHdrValue("HIERARCH FIBER CENT_MIN", numpy.round(bn.nanmin(trace_mask._data),4), "min. fiber centroid")
rss.setHdrValue("HIERARCH FIBER CENT_MAX", numpy.round(bn.nanmax(trace_mask._data),4), "max. fiber centroid")
rss.setHdrValue("HIERARCH FIBER CENT_AVG", numpy.round(bn.nanmean(trace_mask._data),4), "avg. fiber centroid")
rss.setHdrValue("HIERARCH FIBER CENT_STD", numpy.round(bn.nanstd(trace_mask._data),4), "stddev. fiber centroid")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER CENT_MIN", numpy.round(bn.nanmin(trace_mask._data),4), "min. fiber centroid")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER CENT_MAX", numpy.round(bn.nanmax(trace_mask._data),4), "max. fiber centroid")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER CENT_AVG", numpy.round(bn.nanmean(trace_mask._data),4), "avg. fiber centroid")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER CENT_STD", numpy.round(bn.nanstd(trace_mask._data),4), "stddev. fiber centroid")
if method == "optimal":
rss.setHdrValue("HIERARCH FIBER WIDTH_MIN", numpy.round(bn.nanmin(trace_fwhm._data),4), "min. fiber width")
rss.setHdrValue("HIERARCH FIBER WIDTH_MAX", numpy.round(bn.nanmax(trace_fwhm._data),4), "max. fiber width")
rss.setHdrValue("HIERARCH FIBER WIDTH_AVG", numpy.round(bn.nanmean(trace_fwhm._data),4), "avg. fiber width")
rss.setHdrValue("HIERARCH FIBER WIDTH_STD", numpy.round(bn.nanstd(trace_fwhm._data),4), "stddev. fiber width")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER WIDTH_MIN", numpy.round(bn.nanmin(trace_fwhm._data),4), "min. fiber width")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER WIDTH_MAX", numpy.round(bn.nanmax(trace_fwhm._data),4), "max. fiber width")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER WIDTH_AVG", numpy.round(bn.nanmean(trace_fwhm._data),4), "avg. fiber width")
rss.setHdrValue(f"HIERARCH {camera.upper()} FIBER WIDTH_STD", numpy.round(bn.nanstd(trace_fwhm._data),4), "stddev. fiber width")

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}")
Expand Down Expand Up @@ -3281,35 +3281,35 @@ def preproc_raw_frame(
ysize, xsize = sc_quads[i]._dim
x, y = int(QUAD_POSITIONS[i][0]), int(QUAD_POSITIONS[i][1])
proc_img.setHdrValue(
f"HIERARCH AMP{i+1} TRIMSEC",
f"HIERARCH {camera.upper()} AMP{i+1} TRIMSEC",
f"[{x*xsize+1}:{xsize*(x+1)}, {y*ysize+1}:{ysize*(y+1)}]",
f"region of amp. {i+1}",
)
# add gain keywords for the different subimages (CCDs/Amplifiers)
for i in range(NQUADS):
proc_img.setHdrValue(
f"HIERARCH AMP{i+1} {gain_prefix}",
f"HIERARCH {camera.upper()} AMP{i+1} {gain_prefix}",
gain[i],
f"gain value of amp. {i+1} [electron/adu]",
)
# add read-out noise keywords for the different subimages (CCDs/Amplifiers)
for i in range(NQUADS):
proc_img.setHdrValue(
f"HIERARCH AMP{i+1} {rdnoise_prefix}",
f"HIERARCH {camera.upper()} AMP{i+1} {rdnoise_prefix}",
rdnoise[i],
f"read-out noise of amp. {i+1} [electron]",
)
# add bias of overscan region for the different subimages (CCDs/Amplifiers)
for i in range(NQUADS):
proc_img.setHdrValue(
f"HIERARCH AMP{i+1} OVERSCAN_MED",
f"HIERARCH {camera.upper()} AMP{i+1} OVERSCAN_MED",
os_bias_med[i],
f"overscan median of amp. {i+1} [adu]",
)
# add bias std of overscan region for the different subimages (CCDs/Amplifiers)
for i in range(NQUADS):
proc_img.setHdrValue(
f"HIERARCH AMP{i+1} OVERSCAN_STD",
f"HIERARCH {camera.upper()} AMP{i+1} OVERSCAN_STD",
os_bias_std[i],
f"overscan std of amp. {i+1} [adu]",
)
Expand Down Expand Up @@ -3756,13 +3756,13 @@ def detrend_frame(
if convert_to_e:
# calculate Poisson errors
log.info("applying gain correction per quadrant")
for i, quad_sec in enumerate(bcorr_img.getHdrValue("AMP? TRIMSEC").values()):
for i, quad_sec in enumerate(bcorr_img.getHdrValue(f"{camera.upper()} AMP? TRIMSEC").values()):
log.info(f"processing quadrant {i+1}: {quad_sec}")
# extract quadrant image
quad = bcorr_img.getSection(quad_sec)
# extract quadrant gain and rdnoise values
gain = quad.getHdrValue(f"AMP{i+1} GAIN")
rdnoise = quad.getHdrValue(f"AMP{i+1} RDNOISE")
gain = quad.getHdrValue(f"{camera.upper()} AMP{i+1} GAIN")
rdnoise = quad.getHdrValue(f"{camera.upper()} AMP{i+1} RDNOISE")

# non-linearity correction
gain_map = _nonlinearity_correction(ptc_params, gain, quad, iquad=i+1)
Expand Down Expand Up @@ -4155,7 +4155,8 @@ def create_pixelmask(in_short_dark, in_long_dark, out_pixmask, in_flat_a=None, i
ratio_dark = short_dark / long_dark

# define quadrant sections
sections = short_dark.getHdrValue("AMP? TRIMSEC")
camera = short_dark.getHdrValue("CCD")
sections = short_dark.getHdrValue(f"{camera.upper()} AMP? TRIMSEC")

# define pixelmask image
pixmask = Image(data=numpy.zeros_like(short_dark._data), mask=numpy.zeros_like(short_dark._data, dtype="bool"))
Expand Down
8 changes: 4 additions & 4 deletions python/lvmdrp/functions/rssMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ def shift_wave_skylines(in_frame: str, out_frame: str, dwave: float = 8.0, skyli
meanoffset = numpy.nan_to_num(meanoffset)
log.info(f'Applying the offsets [Angstroms] in [1,2,3] spectrographs with means: {meanoffset}')
lvmframe._wave_trace['COEFF'].data[:,0] -= fiber_offset_mod
lvmframe._header[f'HIERARCH WAVE SKYOFF_{channel.upper()}1'] = (meanoffset[0], f'avg. sky line offset in {channel}1 [angstrom]')
lvmframe._header[f'HIERARCH WAVE SKYOFF_{channel.upper()}2'] = (meanoffset[1], f'avg. sky line offset in {channel}2 [angstrom]')
lvmframe._header[f'HIERARCH WAVE SKYOFF_{channel.upper()}3'] = (meanoffset[2], f'avg. sky line offset in {channel}3 [angstrom]')
lvmframe._header[f'HIERARCH {channel.upper()}1 WAVE SKYOFF'] = (meanoffset[0], f'avg. sky line offset in {channel}1 [angstrom]')
lvmframe._header[f'HIERARCH {channel.upper()}2 WAVE SKYOFF'] = (meanoffset[1], f'avg. sky line offset in {channel}2 [angstrom]')
lvmframe._header[f'HIERARCH {channel.upper()}3 WAVE SKYOFF'] = (meanoffset[2], f'avg. sky line offset in {channel}3 [angstrom]')

wave_trace = TraceMask.from_coeff_table(lvmframe._wave_trace)
lvmframe._wave = wave_trace.eval_coeffs()
Expand Down Expand Up @@ -3194,7 +3194,7 @@ def quickQuality(

# compute statistics
quads_avg, quads_std, quads_pct = [], [], []
for section in bias_img._header["AMP? TRIMSEC"]:
for section in bias_img._header[f"{camera.upper()} AMP? TRIMSEC"]:
quad = bias_img.getSection(section)
quads_avg.append(numpy.mean(quad._data))
quads_std.append(numpy.std(quad._data))
Expand Down

0 comments on commit 03cdf1d

Please sign in to comment.