-
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 #613
Changes from all commits
d4349c8
0af0a45
89ba28b
75d1d95
f4a663a
d4dfd2d
3ede27a
c47288c
a6de70c
c8ae852
0fea09b
2c59414
f6c8140
f9b44bc
cd10324
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. Likewise, I think my expectation throughout here is that the old code would be fine |
||
|
||
# Combine the science and flat DQ arrays | ||
science.dq = np.bitwise_or(science.dq, flat_dq) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ | |
import pytest | ||
import numpy as np | ||
from astropy.time import Time | ||
from astropy import units as u | ||
|
||
import roman_datamodels.stnode as rds | ||
from roman_datamodels import datamodels as rdm | ||
from roman_datamodels.datamodels import GainRefModel | ||
from roman_datamodels.datamodels import ReadnoiseRefModel | ||
from roman_datamodels.testing import utils as testutil | ||
from roman_datamodels import units as ru | ||
|
||
from romancal.jump import JumpStep | ||
|
||
|
@@ -49,7 +51,7 @@ def generate_wfi_reffiles(tmpdir_factory): | |
gain_ref['meta'] = meta | ||
gain_ref['data'] = np.ones(shape, dtype=np.float32) * ingain | ||
gain_ref['dq'] = np.zeros(shape, dtype=np.uint16) | ||
gain_ref['err'] = (np.random.random(shape) * 0.05).astype(np.float64) | ||
gain_ref['err'] = (np.random.random(shape) * 0.05).astype(np.float32) | ||
|
||
gain_ref_model = GainRefModel(gain_ref) | ||
gain_ref_model.save(gainfile) | ||
|
@@ -72,7 +74,7 @@ def generate_wfi_reffiles(tmpdir_factory): | |
rn_ref['meta'] = meta | ||
rn_ref['data'] = np.ones(shape, dtype=np.float32) | ||
rn_ref['dq'] = np.zeros(shape, dtype=np.uint16) | ||
rn_ref['err'] = (np.random.random(shape) * 0.05).astype(np.float64) | ||
rn_ref['err'] = (np.random.random(shape) * 0.05).astype(np.float32) | ||
|
||
rn_ref_model = ReadnoiseRefModel(rn_ref) | ||
rn_ref_model.save(readnoisefile) | ||
|
@@ -101,10 +103,10 @@ def _setup(ngroups=10, readnoise=10, nrows=20, ncols=20, | |
dm_ramp.meta.instrument.name = 'WFI' | ||
dm_ramp.meta.instrument.optical_element = 'F158' | ||
|
||
dm_ramp.data = data + 6. | ||
dm_ramp.data = u.Quantity(data + 6., ru.DN, dtype=data.dtype) | ||
dm_ramp.pixeldq = pixdq | ||
dm_ramp.groupdq = gdq | ||
dm_ramp.err = err | ||
dm_ramp.err = u.Quantity(err, ru.DN, dtype=err.dtype) | ||
|
||
dm_ramp.meta.exposure.type = 'WFI_IMAGE' | ||
dm_ramp.meta.exposure.group_time = deltatime | ||
|
@@ -142,7 +144,7 @@ def test_one_CR(generate_wfi_reffiles, max_cores, setup_inputs): | |
deltatime=grouptime) | ||
|
||
for i in range(ngroups): | ||
model1.data[i, :, :] = deltaDN * i | ||
model1.data.value[i, :, :] = deltaDN * i | ||
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 would have said it's more idiomatic to change deltaDN -> deltaDN * u.DN that it is to have all the data.values. |
||
first_CR_group_locs = [x for x in range(1, 7) if x % 5 == 0] | ||
|
||
CR_locs = [x for x in range(xsize * ysize) if x % CR_fraction == 0] | ||
|
@@ -153,8 +155,8 @@ def test_one_CR(generate_wfi_reffiles, max_cores, setup_inputs): | |
# Add CRs to the SCI data | ||
for i in range(len(CR_x_locs)): | ||
CR_group = next(CR_pool) | ||
model1.data[CR_group:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data[CR_group:, CR_y_locs[i], CR_x_locs[i]] + 500. | ||
model1.data.value[CR_group:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data.value[CR_group:, CR_y_locs[i], CR_x_locs[i]] + 500. | ||
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. Likewise my default here would have been 500 -> 500 * u.DN rather than working directly with the values. |
||
|
||
out_model = JumpStep.call(model1, override_gain=override_gain, | ||
override_readnoise=override_readnoise, | ||
|
@@ -190,7 +192,7 @@ def test_two_CRs(generate_wfi_reffiles, max_cores, setup_inputs): | |
deltatime=grouptime) | ||
|
||
for i in range(ngroups): | ||
model1.data[i, :, :] = deltaDN * i | ||
model1.data.value[i, :, :] = deltaDN * i | ||
|
||
first_CR_group_locs = [x for x in range(1, 7) if x % 5 == 0] | ||
CR_locs = [x for x in range(xsize * ysize) if x % CR_fraction == 0] | ||
|
@@ -201,10 +203,10 @@ def test_two_CRs(generate_wfi_reffiles, max_cores, setup_inputs): | |
for i in range(len(CR_x_locs)): | ||
CR_group = next(CR_pool) | ||
|
||
model1.data[CR_group:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data[CR_group:, CR_y_locs[i], CR_x_locs[i]] + 500 | ||
model1.data[CR_group + 8:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data[CR_group + 8:, CR_y_locs[i], CR_x_locs[i]] + 700 | ||
model1.data.value[CR_group:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data.value[CR_group:, CR_y_locs[i], CR_x_locs[i]] + 500 | ||
model1.data.value[CR_group + 8:, CR_y_locs[i], CR_x_locs[i]] = \ | ||
model1.data.value[CR_group + 8:, CR_y_locs[i], CR_x_locs[i]] + 700 | ||
|
||
out_model = JumpStep.call(model1, override_gain=override_gain, | ||
override_readnoise=override_readnoise, | ||
|
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.
What units does science.data start with We already forced it to have e/s in the schema? flat_data is probably dimensionless, so I would have guessed that science.data /= flat_data would just work? Am I missing something?