RCAL-1342: Source Injection Nan Pixel Support#2368
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2368 +/- ##
==========================================
+ Coverage 80.87% 81.54% +0.67%
==========================================
Files 159 157 -2
Lines 9531 9406 -125
==========================================
- Hits 7708 7670 -38
+ Misses 1823 1736 -87 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
schlafly
left a comment
There was a problem hiding this comment.
Thanks. I identified some of the same code duplication in the testing that you did. I agree that it makes sense to clean this up; I don't think we want this PR to introduce more duplication in preparation for a later PR that removes it?
I left a few other in line comments about the tests.
More importantly, I'm not sure I really get what the purpose of the new block in _multiband_catalog is. If the PR were only the deletion of 302-306 in _injection, what would go wrong?
| # Ensure all objects matched | ||
| assert len(matched_grid) == len(results["NoNan"].source_injection_catalog) | ||
|
|
||
| # Test that all matched objects have similar magnitudes |
There was a problem hiding this comment.
Does this test depend on the fact that the NaNs are far from the sources? Broadly I think it's fine if the magnitudes are wrong if you NaN out the center of a source; I don't think we want this test to depend on how the fake sources are located relative to the NaNs.
There was a problem hiding this comment.
The NaNs are only at the center of the injected sources.
There was a problem hiding this comment.
Thanks. What is the typical dispersion here? If I understand right, this is matching the recovered magnitude of the source on a partially NaNed image to the recovered magnitude of the same source, on an image without NaNs. Conceptually I expect the recovered magnitude to depend on whether the the image has NaNs. For stars, I expect it to depend a lot because the stars are small and NaNing their centers makes a big impact on the flux estimate you would get. For galaxies, it depends on how big the galaxy is and things are less clear to me. 2 mmag is a very tight tolerance and I worry that this is a sign that something is not working right. What am I missing?
…spacetelescope#2360) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…etelescope#2352) Co-authored-by: Eddie Schlafly <eschlafly@gmail.com>
Co-authored-by: William Jamieson <william+github@jamieson.phd>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…telescope#2367) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…escope#2324) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eddie Schlafly <eschlafly@gmail.com>
…y, with a checklist for the procedure (spacetelescope#2374)
…pacetelescope#2355) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
|
Regression tests pass: https://github.com/spacetelescope/RegressionTests/actions/runs/29050165165 |
|
|
||
| # Temporarily set NaNs to zero for injections | ||
| si_model.data[y_pos_idx[nanmask], x_pos_idx[nanmask]] = 0 | ||
| si_model.var_poisson[y_pos_idx[nanmask], x_pos_idx[nanmask]] = 0 |
There was a problem hiding this comment.
Per our discussion Wednesday, the ratio here is used to determine the exposure time, so we should fill with nanmedian or something rather than just zeros (I don't know what exposure time 0/0 would correspond to).
There was a problem hiding this comment.
When data and var_poisson is zero, exposure time is 0/1 - the method changes any 0 var_poisson to 1. I was going for the least bespoke change, but I am happy to switch to nanmedian.
https://github.com/spacetelescope/romanisim/blob/main/romanisim/l3.py#L172C1-L177C27
There was a problem hiding this comment.
Let's fill with the nanmedians of the whole image so that these sources have sane exposure times.
| # Ensure all objects matched | ||
| assert len(matched_grid) == len(results["NoNan"].source_injection_catalog) | ||
|
|
||
| # Test that all matched objects have similar magnitudes |
There was a problem hiding this comment.
Thanks. What is the typical dispersion here? If I understand right, this is matching the recovered magnitude of the source on a partially NaNed image to the recovered magnitude of the same source, on an image without NaNs. Conceptually I expect the recovered magnitude to depend on whether the the image has NaNs. For stars, I expect it to depend a lot because the stars are small and NaNing their centers makes a big impact on the flux estimate you would get. For galaxies, it depends on how big the galaxy is and things are less clear to me. 2 mmag is a very tight tolerance and I worry that this is a sign that something is not working right. What am I missing?
| ) | ||
| assert np.allclose( | ||
| matched_block["kron_f184_abmag"], matched_si_bl["kron_f184_abmag"], rtol=3e-2 | ||
| ) |
There was a problem hiding this comment.
Similarly to the comment above... this is for the case where large chunks of the image are NaN. So we expect some sources to not be recovered at all. I guess in this section there's no assertion that the lengths are identical, reflecting that. But the requirement that the kron mags match at 0.03 mag means that no sources are allowed to be injected near the edge?
There was a problem hiding this comment.
Your suspicions are well founded - during PR revisions, the NANPOINTS drifted. I am rewriting that section (and tests) to be less brittle.
Co-authored-by: Eddie Schlafly <eschlafly@gmail.com>


Resolves RCAL-1342
Closes #2022
This PR adds support for injecting sources onto NaN pixels. Previously, if an object was to be injected at the location of a NaN pixel, it would be skipped. This PR will inject the source at a location with a single NaN at the grid point, using an interpolated pixel value for injection. If a source is to be injected in a NaN region, it is skipped.
NOTES:
Tasks
24Q4_B15(use the latest build if not sure)no-changelog-entry-needed)changes/:echo "changed something" > changes/<PR#>.<changetype>.rst(see changelog readme for instructions)changes/<PR#>.breaking.rstnews fragmentdocs/pageokify_regteststo update the truth files