-
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
Hackday mteodoro sky variance readnoise #1556
base: main
Are you sure you want to change the base?
Hackday mteodoro sky variance readnoise #1556
Conversation
ee3f001
to
2d8b4fe
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1556 +/- ##
==========================================
+ Coverage 78.15% 78.17% +0.01%
==========================================
Files 116 116
Lines 7646 7671 +25
==========================================
+ Hits 5976 5997 +21
- Misses 1670 1674 +4 ☔ View full report in Codecov by Sentry. |
37cf8b1
to
2448932
Compare
60b0642
to
d8dddf9
Compare
I follow the addition of the new weight type but I'm not sure I see the connection between the ticket and resampling each computed If the goal is to save |
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.
I think this looks conceptually right; thanks! Can you put a couple of example files on /grp/roman somewhere, together with an invocation (run strun roman::resample blah.asn --weight_type skyivm ??) so that I can easily poke at some example input and output files?
Yes, that's the idea. |
192c1cb
to
65f7acd
Compare
2064e73
to
af738f3
Compare
f70fc8a
to
48ed0fe
Compare
for more information, see https://pre-commit.ci
48ed0fe
to
fadc18d
Compare
for more information, see https://pre-commit.ci
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.
Thanks for updating this.
I left a few more comments and questions.
Would you open a RAD PR to add var_sky
to the mosaic schema?
def test_resampledata_do_drizzle_default_single_exposure_weight_array( | ||
exposure_1, | ||
weight_type, | ||
): | ||
"""Test that resample methods return non-empty weight arrays.""" | ||
|
||
# adding a few zero flux pixels | ||
for i, model in enumerate(exposure_1): | ||
model.data[10 + i, 40 - i] = 0 |
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.
Would you help me understand how setting pixels offset by the index of the exposure in exposure_1
results in the resampled pixel at [10, 40] being equal to 0? Is each exposure offset by 1 pixel in X and 1 in Y?
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.
I just added a random pixel with zero flux. I was not interested in the position of the pixel, just that we did have a pixel with zero flux.
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.
I'm still confused by this. What's the need for a random zero flux pixel per image? If I comment out this code the test doesn't fail.
] / img.data[ok_data] * np.median(img.data) | ||
img["var_sky"][~ok_data] = img.var_rnoise[~ok_data] | ||
except (AttributeError, KeyError, TypeError, ValueError) as e: | ||
raise ValueError("Input model contains invalid data array.") from e |
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.
Since this raises an exception (if for instance var_rnoise
isn't available won't this stop resample from proceeding if ivsky
is selected and var_rnoise
isn't available? That behavior makes sense to me but is at odds with the documentation (which says thew weight will be 1 for all pixels in this case).
Also I suggest checking for var_rnoise
and var_poisson
instead of using the try/except (since the try/except will also trigger for other reasons.
ref_img = input_models.borrow(index=0) | ||
input_models.shelve(model=ref_img, index=0) |
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.
ref_img = input_models.borrow(index=0) | |
input_models.shelve(model=ref_img, index=0) |
Is ref_img used?
img["var_sky"] = np.empty_like(img.data) | ||
img["var_sky"][ok_data] = img.var_rnoise[ok_data] + img.var_poisson[ | ||
ok_data | ||
] / img.data[ok_data] * np.median(img.data) |
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.
If data
contains a nan
won't this cause every var_sky
pixel (for each index wither data
!= 0) to be nan
?
for i, img in enumerate(input_models): | ||
try: | ||
ok_data = img.data != 0 | ||
img["var_sky"] = np.empty_like(img.data) |
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.
I think this could be simplified by starting with something like:
img["var_sky"] = img.var_rnoise.copy()
since all pixels are either:
- copied from
var_sky
if ~(img.data != 0) - computed below
@@ -86,13 +86,15 @@ def __init__( | |||
) | |||
|
|||
self.input_models = input_models | |||
# add sky variance array | |||
resample_utils.add_var_sky_array(self.input_models) |
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.
This will always re-compute var_sky
(even if the input contains a var_sky
). If that's the goal (always have resample compute var_sky
) what about something like:
- if
weight
isivsky
computevar_sky
for each model - when resampling
var_sky
compute it (if it wasn't computed before)
That way for nonivsky
weighting resample won't need to make a separate pass through all the models here (in add_var_sky_array
).
def test_resampledata_do_drizzle_default_single_exposure_weight_array( | ||
exposure_1, | ||
weight_type, | ||
): | ||
"""Test that resample methods return non-empty weight arrays.""" | ||
|
||
# adding a few zero flux pixels | ||
for i, model in enumerate(exposure_1): | ||
model.data[10 + i, 40 - i] = 0 |
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.
I'm still confused by this. What's the need for a random zero flux pixel per image? If I comment out this code the test doesn't fail.
@@ -712,6 +717,8 @@ def test_resampledata_do_drizzle_default_single_exposure_weight_array( | |||
many_to_one_model = output_models_many_to_one.borrow(0) | |||
assert np.any(many_to_one_model.weight > 0) | |||
assert np.any(many_to_many_model.weight > 0) | |||
assert many_to_one_model.data[10, 40] == 0 |
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.
Resolves RCAL-968
This PR adds a sky variance array to the mosaic file created by resample (i.e.
model.var_sky
). It also enables building a drizzle image weighted by the inverse of the sky variance when running resample withweight_type="ivsky"
.Regression test
var_sky
added to the model.Tasks
24Q4_B15
(use the latest build if not sure)no-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)docs/
pageokify_regtests
to update the truth filesnews fragment change types...
changes/<PR#>.general.rst
: infrastructure or miscellaneous changechanges/<PR#>.docs.rst
changes/<PR#>.stpipe.rst
changes/<PR#>.associations.rst
changes/<PR#>.scripts.rst
changes/<PR#>.mosaic_pipeline.rst
changes/<PR#>.patch_match.rst
steps
changes/<PR#>.dq_init.rst
changes/<PR#>.saturation.rst
changes/<PR#>.refpix.rst
changes/<PR#>.linearity.rst
changes/<PR#>.dark_current.rst
changes/<PR#>.jump_detection.rst
changes/<PR#>.ramp_fitting.rst
changes/<PR#>.assign_wcs.rst
changes/<PR#>.flatfield.rst
changes/<PR#>.photom.rst
changes/<PR#>.flux.rst
changes/<PR#>.source_detection.rst
changes/<PR#>.tweakreg.rst
changes/<PR#>.skymatch.rst
changes/<PR#>.outlier_detection.rst
changes/<PR#>.resample.rst
changes/<PR#>.source_catalog.rst