Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCAL-800: Set flux step status for each input #1160

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ dq_init
- Allow ``dq_init`` to pass through keys not defined in ``RampModel``
schema [#1151]

flux
----

- Set flux step status for each input. [#1160]

resample
--------

Expand Down
25 changes: 16 additions & 9 deletions romancal/flux/flux_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

for model in input_models:
apply_flux_correction(model)
model.meta.cal_step.flux = "COMPLETE"

if single_model:
return input_models[0]
Expand Down Expand Up @@ -98,21 +99,27 @@
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 != LV2_UNITS:
log.debug(
"Input data is not in units of %s. Flux correction will not be done.",
LV2_UNITS,
if model.data.unit == model.meta.photometry.conversion_megajanskys.unit:
message = (

Check warning on line 103 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L103

Added line #L103 was not covered by tests
f"Input data is already in flux units of {model.meta.photometry.conversion_megajanskys.unit}."
"\nFlux correction already applied."
)
log.debug("Input data units are %s", model.data.unit)
log.info(message)

Check warning on line 107 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L107

Added line #L107 was not covered by tests
return

# Apply the correction
if model.data.unit != LV2_UNITS:
message = (

Check warning on line 111 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L111

Added line #L111 was not covered by tests
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)

Check warning on line 116 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L115-L116

Added lines #L115 - L116 were not covered by tests

# 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
Loading