Skip to content

Commit

Permalink
Error out completely if units are not as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
stscieisenhamer committed Apr 12, 2024
1 parent ae26ddd commit e5e7bc6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions romancal/flux/flux_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e5e7bc6

Please sign in to comment.