-
Notifications
You must be signed in to change notification settings - Fork 28
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 406 science array quantities #616
Changes from 18 commits
d4349c8
0af0a45
89ba28b
75d1d95
f4a663a
d4dfd2d
3ede27a
c47288c
a6de70c
c8ae852
0fea09b
2c59414
f6c8140
f9b44bc
cd10324
9744fc5
b6d8d64
a80a56e
8d6a135
0b53ad8
6be7840
e6f9747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
import logging | ||
import numpy as np | ||
from astropy import units as u | ||
from roman_datamodels import units as ru | ||
|
||
from romancal.lib import dqflags | ||
|
||
|
@@ -109,21 +111,21 @@ def apply_flat_field(science, flat): | |
flat_data[np.where(flat_bad)] = 1.0 | ||
# Now let's apply the correction to science data and error arrays. Rely | ||
# on array broadcasting to handle the cubes | ||
science.data /= flat_data | ||
science.data = u.Quantity((science.data.value / flat_data), ru.electron / u.s, dtype=science.data.dtype) | ||
|
||
# Update the variances using BASELINE algorithm. For guider data, it has | ||
# not gone through ramp fitting so there is no Poisson noise or readnoise | ||
flat_data_squared = flat_data**2 | ||
science.var_poisson /= flat_data_squared | ||
science.var_rnoise /= flat_data_squared | ||
try: | ||
science.var_flat = science.data**2 / flat_data_squared * flat_err**2 | ||
except AttributeError: | ||
science['var_flat'] = np.zeros(shape=science.data.shape, | ||
dtype=np.float32) | ||
science.var_flat = science.data**2 / flat_data_squared * flat_err**2 | ||
science.err = np.sqrt(science.var_poisson + | ||
science.var_rnoise + science.var_flat) | ||
science.var_poisson = u.Quantity((science.var_poisson.value / flat_data_squared), ru.electron**2 / u.s**2, | ||
dtype = science.var_poisson.dtype) | ||
science.var_rnoise = u.Quantity((science.var_rnoise / flat_data_squared), ru.electron**2 / u.s**2, | ||
dtype = science.var_rnoise.dtype) | ||
|
||
science['var_flat'] = u.Quantity((science.data.value ** 2 / flat_data_squared * flat_err ** 2), | ||
ru.electron ** 2 / u.s ** 2, dtype=science.data.value.dtype) | ||
|
||
err_sqrt = np.sqrt(science.var_poisson.value + science.var_rnoise.value + science.var_flat) | ||
science.err = u.Quantity(err_sqrt, ru.electron / u.s, dtype=err_sqrt.dtype) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like we don't need to touch most of this section, since flat_data is unitless so things like science.data /= flat_data should do the right thing? What am I missing? One would only need to touch the except: AttributeError stanza, which was deleted here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted |
||
|
||
# Combine the science and flat DQ arrays | ||
science.dq = np.bitwise_or(science.dq, flat_dq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Staring at this; does it make more sense to add these units onto out_data in process(...) following the do_correction call? Harping on my usual imagination that our ideal model should be: units everywhere, except around the calls to stcal, where there's a step beforehand removing units and afterward adding them back?