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

use doubles for filter values used with fft in refpix #8512

Merged
merged 1 commit into from
May 29, 2024

Conversation

braingram
Copy link
Collaborator

@braingram braingram commented May 28, 2024

The fft filtering (fft_interp_norm) used during the the fill_bad_regions function in the refpix step suffers from loss of precision leading to numerical differences across systems. The aa filter coefficients are defined as float32 (temp_a1 is the start of a number of variables used to construct aa):

temp_a1 = (np.cos(np.arange(elen, dtype=np.float32) *

but are used with a double precision fft result:
for it in range(n_iter_norm):
pp = np.fft.fft(p)
pp *= aa
p[:] = np.fft.ifft(pp).real

For each loop iteration aa is cast to double and as the added 32 bits are not defined by the algorithm used for the other bits in aa each iteration accumulates error in the output.

This PR switches aa to double precision to avoid the loss of precision. It is expected that this will change the regression test output.

To take one example, test_nirspec_irs2_detector1[linearity] currently passes on jenkins but fails on github actions:
https://github.com/spacetelescope/RegressionTests/actions/runs/9261424291/job/25476839480#step:25:297
although this tests the output file for the linearity step the differences stem from the refpix step (run immediately before linearity for this test). Although the failure is only a single pixel the difference is above the tolerance:

E          Relative tolerance: 1e-05, Absolute tolerance: 1e-07
E         
E         Extension HDU 1 (SCI, 1):
E         
E            Data contains differences:
E              Data differs at [634, 1532, 4, 1]:
E                 a> 0.088768005
E                 b> 0.08876419
E              1 different pixels found (0.00% different).

Furthermore this failure matches that seen when running the same test locally with a mac m1 or on a system with RHEL 9 (jenkins is running RHEL 7).

With this PR the above test fails in the same way on jenkins, github actions, RHEL9 and on a mac m1.

E            Data contains differences:
E              Data differs at [44, 87, 3, 1]:
E                 a> -0.42095566
E                 b> -0.42092705
E              Data differs at [634, 1532, 4, 1]:
E                 a> 0.088768005
E                 b> 0.08876419
E              Data differs at [863, 1294, 5, 1]:
E                 a> 1.7601109
E                  ?       ^
E                 b> 1.7601409
E                  ?       ^
E              Data differs at [5, 1649, 5, 1]:
E                 a> 0.46575546
E                 b> 0.4657402
E              4 different pixels found (0.00% different).

See https://github.com/spacetelescope/RegressionTests/actions/runs/9273993994/job/25515454758 for the regression test run on github actions (with this PR) and https://plwishmaster.stsci.edu:8081/blue/organizations/jenkins/RT%2FJWST-Developers-Pull-Requests/detail/JWST-Developers-Pull-Requests/1480/pipeline/200 for the jenkins run (note that several nan vs 0 failures due to #8488 are unrelated).

This addresses one of several RHEL9 issues (which appear the largely overlap with github actions vs jenkins differences) revealed during testing for JP-3312.

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 May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.95%. Comparing base (4179c09) to head (83b41eb).
Report is 2 commits behind head on master.

Current head 83b41eb differs from pull request most recent head 67c779b

Please upload reports for the commit 67c779b to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8512      +/-   ##
==========================================
- Coverage   57.97%   57.95%   -0.03%     
==========================================
  Files         387      387              
  Lines       38830    38810      -20     
==========================================
- Hits        22513    22493      -20     
  Misses      16317    16317              

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

@braingram braingram changed the title use doubles for intermediate values used with fft in refpix use doubles for filter values used with fft in refpix May 28, 2024
@braingram braingram marked this pull request as ready for review May 28, 2024 20:57
@braingram braingram requested a review from a team as a code owner May 28, 2024 20:57
@braingram braingram requested a review from hbushouse May 28, 2024 20:58
@hbushouse hbushouse added this to the Build 11.0 milestone May 29, 2024
Copy link
Collaborator

@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@hbushouse hbushouse merged commit 36728a3 into spacetelescope:master May 29, 2024
24 checks passed
@braingram braingram deleted the refpix_double branch May 29, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants