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

AL-852: GWCS inverse transform should respect its bounding box #8554

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

nden
Copy link
Collaborator

@nden nden commented Jun 12, 2024

GWCS has a bug where the inverse transform does not respect the bounding_box. This leads to unexpected results that affect other applications. The GWCS bud is fixed in spacetelescope/gwcs#498
This PR fixes problems in jwst which surfaced when the bug was fixed.

Checklist for PR authors (skip items if you don't have permissions or they are not applicable)

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • All comments are resolved
  • Make sure the JIRA ticket is resolved properly

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.84%. Comparing base (e3d263f) to head (588187d).
Report is 2 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (e3d263f) and HEAD (588187d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (e3d263f) HEAD (588187d)
2 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8554      +/-   ##
==========================================
- Coverage   76.81%   66.84%   -9.98%     
==========================================
  Files         496      376     -120     
  Lines       45610    37998    -7612     
==========================================
- Hits        35034    25398    -9636     
- Misses      10576    12600    +2024     
Flag Coverage Δ
nightly ?

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@melanieclarke melanieclarke added this to the Build 11.2 milestone Dec 16, 2024
@emolter
Copy link
Collaborator

emolter commented Dec 16, 2024

The failing oldestdeps tests appear to show that asdf needs a minimum of at least 3.3 now since that's what GWCS needs

@nden nden marked this pull request as ready for review December 18, 2024 14:37
Copy link
Collaborator

@emolter emolter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASDF still needs a bump to >=3.3.0

It looks like your auto-formatter touched CHANGES.rst, which is making the CI unhappy

Needs a changelog fragment

I forgot to remove two imports that are no longer used in test_outlier_detection.py, namely create_fitswcs() and compute_s_region_imaging()

Other than those small things that are needed to make our CI pass, this looks good to me.

@nden
Copy link
Collaborator Author

nden commented Dec 18, 2024

Regression test run: https://github.com/spacetelescope/RegressionTests/actions/runs/12395581275/job/34601785739

MIRI LRS differences are expected, since the bounding_box has changed.
NRS differences are: 1 px in one case and 4 px in the other.
NRS moving target differences are bigger, worth looking into ths.

@emolter
Copy link
Collaborator

emolter commented Dec 18, 2024

NRS moving target differences are bigger, worth looking into ths.

Without doing too deep a dive, just plotting some of the outputs, it looks to me like as we guessed in stand-up there are just a few more flagged pixels in the data which are then propagating to the output spectra and it's not much to worry about. But I'll let Melanie have the final word on this one

Copy link
Collaborator

@WilliamJamieson WilliamJamieson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good for me other than the comments made by @emolter which look relatively trivial.

Does this warrant a change log fragment?

@melanieclarke
Copy link
Collaborator

melanieclarke commented Dec 18, 2024

Thanks Ned. Specifically, it is these pixels at the upper edge of the second SCI extension image (top: branch test output crf file, bottom: truth):

jw1245-o002_s1_crf

The border pixels used to be marked as outliers, and now are not. I suspect it's just that the edge of the array shifted a little due to the changes, and these pixels were on a threshold. It also appears to be architecture dependent - on my Mac, the regtest outputs show no difference from truth for this test, on this branch.

I agree it's not a cause for concern. There is no impact on the output spectra.

… Bump min version of asdf. Fix tweakreg step test.
@github-actions github-actions bot added the MIRI label Dec 18, 2024
forward_transform = wcs1.pixel_to_world_values
backward_transform = wcs2.world_to_pixel_values
wcs_no_bbox = deepcopy(wcs2)
Copy link
Member

@mcara mcara Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought deepcopying a WCS is cpu-intense. Wouldn't it be better to you try-finally to turn it off/on? Still, I think @emolter 's comment about turning this off may be hiding some other issue is relevant. That is, if we do not disable bbox on the inverse, will the custom WCS test (as modified here) still work?

@pytest.mark.parametrize('shape', [(1205, 1100)])
@pytest.mark.parametrize('crpix', [(100, 101), (101, 101)])
@pytest.mark.parametrize('crval', [(22.01, 12), (22.15, 12.01)])
@pytest.mark.parametrize('shape', [(10205, 10100)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way, way too large for a test. I think it is an indication that crval is wrong if you need to make output shape this large in order to get data within the output.

Copy link
Member

@mcara mcara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most changes are reasonable except for the custom wcs test where output shape is increased to 10k pixels. I believe the original test does not work because of innacurate crval and that issue about the bbox calculation in stcal.

Copy link
Member

@mcara mcara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test_custom_wcs_resample_imaging needs better parameters that do not require these large output shapes. I also think that we need to investigate why it is necessary to disable bounding box for pixmap computations. However, this should prevent merging this PR as it allows the pipeline to work as before the major GWCS change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants