From e5e7bc68065a662255c2d808f4e7de3fe73138c2 Mon Sep 17 00:00:00 2001 From: Jonathan Eisenhamer Date: Fri, 12 Apr 2024 17:10:36 -0400 Subject: [PATCH] Error out completely if units are not as expected --- romancal/flux/flux_step.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/romancal/flux/flux_step.py b/romancal/flux/flux_step.py index 1a3a05995..13e601b86 100644 --- a/romancal/flux/flux_step.py +++ b/romancal/flux/flux_step.py @@ -70,11 +70,8 @@ def process(self, input): ) for model in input_models: - try: - apply_flux_correction(model) - model.meta.cal_step.flux = "COMPLETE" - except ValueError: - model.meta.cal_step.flux = "SKIPPED" + apply_flux_correction(model) + model.meta.cal_step.flux = "COMPLETE" if single_model: return input_models[0] @@ -102,18 +99,27 @@ def apply_flux_correction(model): DATA = ("data", "err") VARIANCES = ("var_rnoise", "var_poisson", "var_flat") - # Check for units. Must be election/second. Otherwise, it is unknown how to - # convert. + if model.data.unit == model.meta.photometry.conversion_megajanskys.unit: + message = ( + f"Input data is already in flux units of {model.meta.photometry.conversion_megajanskys.unit}." + "\nFlux correction already applied." + ) + log.info(message) + return + if model.data.unit != LV2_UNITS: - message = f"Input data units {model.data.unit} is not the expected units of %s. Flux correction will not be done." - log.debug(message) + message = ( + f"Input data units {model.data.unit} are not in the expected units of {LV2_UNITS}" + "\nAborting flux correction" + ) + log.error(message) raise ValueError(message) - # Apply the correction + # Apply the correction. # The end goal in units is to have MJy/sr. The scale is in MJy/sr also. # Hence the extra factor of s/DN must be applied to cancel DN/s. log.debug("Flux correction being applied") - c_mj = model.meta.photometry.conversion_megajanskys / LV2_UNITS + c_mj = model.meta.photometry.conversion_megajanskys / model.data.unit for data in DATA: model[data] = model[data] * c_mj for variance in VARIANCES: