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

JWST issues with numpy 2.0 #8580

Open
stscijgbot-jp opened this issue Jun 20, 2024 · 10 comments · Fixed by spacetelescope/stcal#282 · May be fixed by #8718
Open

JWST issues with numpy 2.0 #8580

stscijgbot-jp opened this issue Jun 20, 2024 · 10 comments · Fixed by spacetelescope/stcal#282 · May be fixed by #8718

Comments

@stscijgbot-jp
Copy link
Collaborator

stscijgbot-jp commented Jun 20, 2024

Issue JP-3664 was created on JIRA by Brett Graham:

Using numpy 2.0 results in failures in:

Regression tests here: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1664/#showFailuresLink

More recent regression test results here: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1737/#showFailuresLink](https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1737/#showFailuresLink)

These were built with PRs to jwst, stdatamodels and stcal:
jwst: #8718
stcal: tapastro/stcal@1bb106f

EDIT: updated commit hash to
stdatamodels: tapastro/stdatamodels@e3b53d6

Hashes provided for stcal/stdatamodels to specify custom installation procedure for future regression test runs, as needed.

The regression tests show many failures, most of which on cursory inspection show small numerical differences. We'll need to check them off one by one to ensure there aren't any unreasonable changes as part of this migration.

Helpful link to numpy 2.0 migration guide: https://numpy.org/devdocs/numpy_2_0_migration_guide.html

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Kenneth MacDonald on JIRA:

There doesn't appear to be any problems in STCAL with numpy 2.0. !ruff_checks_numpy_20.png!

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Kenneth MacDonald on JIRA:

There doesn't appear to be a problem in JWST ramp fitting for numpy 2.0.

 

!Screenshot 2024-08-29 at 1.08.36 PM.png!

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Kenneth MacDonald on JIRA:

Tyler Pauly has an STCAL PR open to handle numpy 2.0, which necessitates a change in the calling of a byte order method:

 

spacetelescope/stcal#282

@tapastro
Copy link
Contributor

tapastro commented Sep 9, 2024

Still regression test differences that need to be investigated; the stcal PR partially addressed this issue.

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Robert Jedrzejewski on JIRA:

I checked all the steps in the miri detector1 pipeline.  The only ones that gave non-zero differences between numpy 1.26 and numpy 21.1 were emicorr and ramp_fit.  The differences were all below 1 part in 10^6, except for 8 pixels in the ramp_fit step that were still closer to 1 part in 10^5.

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Robert Jedrzejewski on JIRA:

I also checked the refpix irs2 step.  I ran the step starting with the same _superbias.fits input file, and then using numpy 1.26 and numpy 2.1.1.  The distribution of #discrepant pixels vs. threshold looks like this:

rtol           #pixels
1.0e-1                     13
1.0e-2                  135
1.0e-3                1245
1.0e-4              12381
1.0e-5           123644
1.0e-6         1225356
1.0e-7       14343640
all              27792406

these differences propagated down to the rate file:

rtol          #pixels
1.0e-1                    8
1.0e-2                  75
1.0e-3                811
1.0e-4              7811
1.0e-5           78980
1.0e-6         714332
1.0e-7       2913580
all             3392633

There were a few statements that behave differently under numpy 2.1.1 compared to 1.26; I tried forcing the same behaviour by casting variables in arithmetic expressions, but was unable to reconcile the differences.  More time would be needed to determine whether the numpy 2 behaviour is preferable to the numpy 1 behaviour

@stscijgbot-jp
Copy link
Collaborator Author

Comment by Robert Jedrzejewski on JIRA:

I checked all the files that were reported as discrepant in the regression test run and made a note of the largest percentage of discrepant pixels in the comparison (there will be more than 1 value for multi-extension products).  In some cases the failures were because the data in the extension was of a different size between result and truth. some files had a different number of extensions or table rows in an extension.  The last dozen or so tests with very large number of discrepant pixels also had the RSCD and FIRSTFRAME steps performed in the test, while these steps were skipped in the truth files.

There are about 4000 file comparisons done in the regression tests.  A few are skipped, a few are XFAILed.  These 112 failed 
their comparisons:

jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-nsclean]                    0.71%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-extract_2d]                 0.52%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-wavecorr]                   0.52%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-srctype]                    0.52%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-cal]                        0.75%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-s2d]                        1.14%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw02072-o002_20221206t143745_spec2_00001_asn.json-x1d]                        0.14%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw01309-o022_20230113t025924_spec2_00001_asn.json-s2d]                        1.14%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2[jw01309-o022_20230113t025924_spec2_00001_asn.json-x1d]                        0.00%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2_pixel_replace[jw013090_prtest_04102_00004_nrs2_pixel_replace.fits]            2.55%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2_pixel_replace[jw013090_prtest_04102_00004_nrs2_s2d.fits]                     12.14%
jwst.regtest.test_nirspec_fs_spec2.[stable-deps] test_nirspec_fs_spec2_pixel_replace[jw013090_prtest_04102_00004_nrs2_x1d.fits]                     10.34%
jwst.regtest.test_nircam_image.[stable-deps] test_nircam_image_stages12[i2d]                                                                         0.00%
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[extract_2d]                                                     Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[srctype]                                                        Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[master_background_mos]                                          Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[wavecorr]                                                       Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[flat_field]                                                     Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[pathloss]                                                       Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[barshadow]                                                      Data size differs  68x18 vs 370x24
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[cal]                                                            Data size differs  68x18 vs 370x24, also 52.36%
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[s2d]                                                            Data sizes differ, also 72.56%
jwst.regtest.test_nirspec_mos_fs_spec2.[stable-deps] test_nirspec_mos_fs_spec2[x1d]                                                            Table rows differ, also 17.62%
jwst.regtest.test_miri_lrs_slit_spec2.[stable-deps] test_miri_lrs_slit_spec2[pixel_replace]                                                          0.01%
jwst.regtest.test_miri_lrs_slit_spec2.[stable-deps] test_miri_lrs_slit_spec2[s2d]                                                                    1.50%
jwst.regtest.test_miri_lrs_slit_spec2.[stable-deps] test_miri_lrs_slit_spec2[x1d]                                                                    2.45%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg[masterbg2d]                                                     Data size differs
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg[cal]                                                            Data size differs, also 0.25%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg[s2d]                                                            Data size differs, also 0.64%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg[x1d]                                                            Data size differs, also 0.16%
jwst.regtest.test_niriss_wfss.[stable-deps] test_nis_wfss_spec2[cal]                                                                                 0.21%
jwst.regtest.test_niriss_wfss.[stable-deps] test_nis_wfss_spec2[photom]                                                                              0.21%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[nsclean]                                                                   74.12%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[bsub]                                                                      74.12%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[extract_2d]                                                           Data sizes differ, also 94.44%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[wavecorr]                                                             Data sizes differ, also 94.44%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[flat_field]                                                           Different #HDUs, data sizes differ
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[srctype]                                                              Different #HDUs, data sizes differ, also 94.44%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[pathloss]                                                             Different #HDUs, data sizes differ
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[barshadow]                                                            Different #HDUs, data sizes differ
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[cal]                                                                  Data sizes differ, also 52.36%
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[s2d]                                                                  Different #HDUs, data sizes differ
jwst.regtest.test_nirspec_mos_spec2.[stable-deps] test_nirspec_mos_spec2[x1d]                                                                  Different #HDUs, table rows differ
jwst.regtest.test_niriss_wfss.[stable-deps] test_nis_wfss_spec3[s000000015-cal]                                                                      0.37%
jwst.regtest.test_niriss_wfss.[stable-deps] test_nis_wfss_spec3[s000000104-cal]                                                                      0.03%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg_user[cal]                                                       Data sizes differ, also 0.01%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg_user[s2d]                                                       Data sizes differ, also 0.01%
jwst.regtest.test_nirspec_masterbackground.[stable-deps] test_nirspec_mos_mbkg_user[x1d]                                                       Data sizes differ
jwst.regtest.test_nircam_coron3.[stable-deps] test_nircam_coron3_sci_exp[002-psfalign]                                                               5.04%
jwst.regtest.test_nircam_coron3.[stable-deps] test_nircam_coron3_sci_exp[002-psfsub]                                                                17.81%
jwst.regtest.test_nircam_coron3.[stable-deps] test_nircam_coron3_sci_exp[003-psfalign]                                                              12.39%
jwst.regtest.test_nircam_coron3.[stable-deps] test_nircam_coron3_sci_exp[003-psfsub]                                                                26.98%
jwst.regtest.test_nircam_coron3.[stable-deps] test_nircam_coron3_product[i2d]                                                                        5.78%
jwst.regtest.test_niriss_soss.[stable-deps] test_niriss_soss_stage3_x1dints                                                                          3.74%
jwst.regtest.test_niriss_soss.[stable-deps] test_niriss_soss_stage3_whtlt                                                                           66.7 %
jwst.regtest.test_nirspec_verify.[stable-deps] test_verify_detector1[rate]                                                                           0.00%
jwst.regtest.test_nirspec_verify.[stable-deps] test_verify_image2[assign_wcs]                                                                        0.00%
jwst.regtest.test_nirspec_verify.[stable-deps] test_verify_image2[flat_field]                                                                        0.00%
jwst.regtest.test_nirspec_verify.[stable-deps] test_verify_image2[cal]                                                                               0.00%
jwst.coron.tests.test_coron.[stable-deps] test_shift_subtract         
jwst.coron.tests.test_coron.[stable-deps] test_align_fourierLSQ
jwst.coron.tests.test_coron.[stable-deps] test_align_array
jwst.regtest.test_miri_coron3.[stable-deps] test_miri_coron3_sci_exp[4-psfalign]                                                                    36.87%
jwst.regtest.test_miri_coron3.[stable-deps] test_miri_coron3_sci_exp[4-psfsub]                                                                      84.19%
jwst.regtest.test_miri_coron3.[stable-deps] test_miri_coron3_sci_exp[5-psfalign]                                                                    61.82%
jwst.regtest.test_miri_coron3.[stable-deps] test_miri_coron3_sci_exp[5-psfsub]                                                                      90.09%
jwst.regtest.test_miri_coron3.[stable-deps] test_miri_coron3_product[i2d]                                                                           55.45%
jwst.regtest.test_nircam_wfss_spec2.[stable-deps] test_nircam_wfss_spec2[cal]                                                                        0.43%
jwst.regtest.test_nirspec_ifu_spec2.[stable-deps] test_spec2[cal]                                                                                    0.17%
jwst.regtest.test_nirspec_ifu_spec2.[stable-deps] test_spec2[nsclean]                                                                                0.00%
jwst.regtest.test_nirspec_ifu_spec2.[stable-deps] test_spec2[s3d]                                                                                    0.11%
jwst.regtest.test_nirspec_ifu_spec2.[stable-deps] test_spec2[srctype]                                                                                0.00%
jwst.regtest.test_nirspec_ifu_spec2.[stable-deps] test_spec2[x1d]                                                                                    0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[refpix]                                                           0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[linearity]                                                        0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[dark_current]                                                     0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[jump]                                                             0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[0_ramp_fit]                                                       0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[gain_scale]                                                       0.00%
jwst.regtest.test_nirspec_irs2_detector1.[stable-deps] test_nirspec_irs2_detector1[rate]                                                             0.00%
jwst.regtest.test_niriss_ami3.[stable-deps] test_niriss_ami3_cal[amilg]                                                                              0.34%
jwst.regtest.test_nirspec_lamp_ifu_spec2.[stable-deps] test_nirspec_lamp_ifu_spec2[s3d]                                                             87.27%
jwst.regtest.test_nirspec_lamp_ifu_spec2.[stable-deps] test_nirspec_lamp_ifu_spec2[x1d]                                                             21.25%
jwst.regtest.test_nircam_mtimage.[stable-deps] test_nircam_image_moving_target_i2d                                                                   0.00%
jwst.regtest.test_miri_residual_fringe.[stable-deps] test_residual_fringe_cal                                                                       64.63%
jwst.regtest.test_nirspec_ifu_internal_cal.[stable-deps] test_cube_build_nirspec_internal_cal                                                       44.92%
jwst.regtest.test_niriss_soss.[stable-deps] test_niriss_soss_extras[x1dints]                                                                         4.78%
jwst.regtest.test_niriss_soss.[stable-deps] test_niriss_soss_extras[AtocaSpectra]                                                                    5.56%
jwst.regtest.test_niriss_soss.[stable-deps] test_niriss_soss_extras[SossExtractModel]                                                               27.29%
jwst.regtest.test_niriss_soss.[stable-deps] test_extract1d_null_order2                                                                               3.65%
jwst.regtest.test_nircam_image.[stable-deps] test_image3_closedfile                                                                                  0.02%
jwst.regtest.test_nircam_mtimage.[stable-deps] test_nircam_image_moving_target_kwds[midpt_not_in_mt_table_range]                              Column names don't match schema
jwst.regtest.test_nircam_mtimage.[stable-deps] test_nircam_image_moving_target_kwds[midpt_not_in_mt_table_range]                                  TypeError
jwst.regtest.test_nircam_mtimage.[stable-deps] test_nircam_image_moving_target_kwds[with_mt_table]                                            Column names don't match schema
jwst.regtest.test_nircam_mtimage.[stable-deps] test_nircam_image_moving_target_kwds[with_mt_table]                                                TypeError
jwst.regtest.test_miri_image.[stable-deps] test_miri_image_detector1[refpix]                                                                  Error opening file
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[lastframe]                                                             0.65%
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[reset]                                                                 0.65%
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[linearity]                                                             0.65%
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[dark_current]                                                         93.29%                RSCD, FIRSTFRAME run
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[ramp]                                                           Error opening file                  |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[rate]                                                                 92.94%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso1[rateints]                                                             92.80%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[assign_wcs]                                                      92.80%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[srctype]                                                         92.80%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[flat_field]                                                      92.78%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[pixel_replace]                                                   81.70%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[calints]                                                         81.09%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso_spec2[x1dints]                                                         39.33%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso3[outlier_detection]                                                    81.09%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso3[crfints]                                                              81.09%                        |
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso3_x1dints                                                               42.24%                      \ | /
jwst.regtest.test_miri_lrs_slitless.[stable-deps] test_miri_lrs_slitless_tso3_whtlt                                                                100%                          |/

The test modules that product failures are:

test_nirspec_fs_spec2.py
test_nircam_image.py
test_nirspec_mos_fs_spec2.py
test_miri_lrs_slit_spec2.py
test_nirspec_masterbackground.py
test_niriss_wfss.py
test_nirspec_mos_spec2.py
test_nircam_coron3.py
test_niriss_soss.py
test_nirspec_verify.py
test_miri_coron3.py
test_nircam_wfss_spec2.py
test_nirspec_ifu_spec2.py
test_nirspec_irs2_detector1.py
test_niriss_ami3.py
test_nirspec_lamp_ifu_spec2.py
test_nircam_mtimage.py
test_miri_residual_fringe.py
test_nirspec_ifu_internal_cal.py
test_miri_lrs_slitless.py

20/69 test modules.  That means 49/69 are passing.

Some of these are very small differences and can safely be disregarded, but some are more significant.
There wasn't time to go into depth on whether the differences are scientifically significant, or which of
the versions of numpy is behaving "correctly".  

@stscijgbot-jp
Copy link
Collaborator Author

stscijgbot-jp commented Sep 20, 2024

Comment by Melanie Clarke on JIRA:

Looking at the NIRSpec spec2 differences for MOS, FS, and IFU, they appear to be at least partly because the FFT fit in NSClean is a little different at the edges for full frame data.  I attached an example from the jw02072-o002_20221206t143745_spec2_00001_asn.json-nsclean test.  For this one, the edge effects look a little worse with numpy 2; for the MOS test, they look a little better with numpy 2 than with numpy 1. 

I don't think there's any reason to hold up transitioning to numpy 2 for this, but we should consider fixing edge effects more robustly while refactoring NSClean for full frame arrays in JP-3740.

@stscijgbot-jp
Copy link
Collaborator Author

stscijgbot-jp commented Sep 23, 2024

Comment by Maria Pena-Guerrero on JIRA:

I did a run with numpy 2.0 and numpy 1.26.4 on MIRI data that I had locally to test the emicorr, dark, and saturation steps. I used file jw01386007001_04101_00006_mirimage_uncal.fits. I find that the differences are negligible,  attaching the plots.

!dark_current_np2vs126.png|thumbnail! !emicorr_np2_vs126.png|thumbnail! !saturation_np2_vs126.png|thumbnail!

I obtained similar results for jw05594035001_02101_00005_nrcb1_uncal.fits

@braingram
Copy link
Collaborator

test_engdb_mast.py also fails with numpy 2:

assert str(values) == str(expected)

compares string converted numbers (which changed for numpy 2):
https://github.com/spacetelescope/stdatamodels/actions/runs/11921284593/job/33225085285#step:10:308

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