spacetelescope / stdatamodels

https://stdatamodels.readthedocs.io
Other
5 stars 24 forks source link

fix numpy scalar handling in RefractionIndexFromPrism #210

Closed braingram closed 11 months ago

braingram commented 11 months ago

As shown in jwst tests fixing numpy 2.0 deprecations there are a few deprecations from numpy 1.25 that are not yet addressed: https://github.com/spacetelescope/jwst/actions/runs/6198454984/job/16828931603#step:10:459

A few of these are from code in stdatamodels file RefractionIndexFromPrism. ~These warnings are not seen in the stdatamodels CI as not all jwst tests are currently run.~ These warnings can also be seen in our test_downstream runs: https://github.com/spacetelescope/stdatamodels/actions/runs/6175840080/job/16763536280#step:10:1995

This PR updates RefractionIndexFromPrism to convert single element ndarrays to scalars before computing sin cos to avoid deprecation warning:

DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

Checklist

codecov[bot] commented 11 months ago

Codecov Report

Patch has no changes to coverable lines.

Files Changed Coverage
src/stdatamodels/jwst/transforms/models.py 0.00%

:loudspeaker: Thoughts on this report? Let us know!.

braingram commented 11 months ago

The jwst-xdist-devdeps job is failing here and not in jwst because we're not installing a dev version of photutils (which has not yet released fixes for numpy 2.0).

braingram commented 11 months ago

Regression tests passed with no errors: https://plwishmaster.stsci.edu:8081/blue/organizations/jenkins/RT%2FJWST-Developers-Pull-Requests/detail/JWST-Developers-Pull-Requests/954/pipeline/202

braingram commented 11 months ago

There are a few remaining warnings in the regtest output that are due to code in stdatamodels. These warnings are not new:

jwst/datamodels/tests/test_model_container.py::test_all_datamodels_init[DrizProductModel]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/datamodels/drizproduct.py:10: DeprecationWarning: DrizProduct is deprecated and will be removed.  Use ImageModel.
    warnings.warn(message="DrizProduct is deprecated and will be removed.  "
jwst/datamodels/tests/test_model_container.py::test_all_datamodels_init[MultiProductModel]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/datamodels/multiprod.py:11: DeprecationWarning: MultiProductModel is deprecated and will be removed.  Use MultiSlitModel.
    warnings.warn(message="MultiProductModel is deprecated and will be removed.  "
jwst/datamodels/tests/test_model_container.py::test_all_datamodels_init[MIRIRampModel]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/library/basic_utils.py:23: DeprecationWarning: "MIRIRampModel" is deprecated and will be removed. Use RampModel
    warnings.warn(message.format(old_class=old_class.__name__, new_class=new_class.__name__),

These are all due to use of deprecated model classes that are removed in https://github.com/spacetelescope/stdatamodels/pull/171 Opening and merging that PR should remove the warnings. Alternatively the jwst test above test_all_datamodels_init could be updated to not use the deprecated models.

jwst/regtest/test_fgs_guider.py::test_fgs_guider[exptype_fgs_acq1-cal]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/datamodels/util.py:247: NoTypeWarning: model_type not found. Opening /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/clone/test_outputs/popen-gw3/test_fgs_guider_run_guider_pipelines0/exptype_fgs_acq1_uncal.fits as a RampModel
    warnings.warn(f"model_type not found. Opening {file_name} as a {class_name}",
jwst/regtest/test_fgs_guider.py::test_fgs_guider[exptype_fgs_fineguide-cal]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/datamodels/util.py:247: NoTypeWarning: model_type not found. Opening /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/clone/test_outputs/popen-gw3/test_fgs_guider_run_guider_pipelines0/exptype_fgs_fineguide_uncal.fits as a RampModel
    warnings.warn(f"model_type not found. Opening {file_name} as a {class_name}",
jwst/regtest/test_fgs_guider.py::test_fgs_guider[exptype_fgs_id_image-cal]
  /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/miniconda/envs/tmp_env0/lib/python3.11/site-packages/stdatamodels/jwst/datamodels/util.py:247: NoTypeWarning: model_type not found. Opening /data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/clone/test_outputs/popen-gw3/test_fgs_guider_run_guider_pipelines0/exptype_fgs_id_image_uncal.fits as a RampModel
    warnings.warn(f"model_type not found. Opening {file_name} as a {class_name}",

These might indicate an issue with the exptype_fgs_id_image_uncal.fits exptype_fgs_fineguide_uncal.fits and exptype_fgs_acq1_uncal.fits test files. I'm not sure if they should have a model type defined within the file. If not, perhaps an ignore can be added for these warnings in the test_fgs_guider test.

braingram commented 11 months ago

@zacharyburnett Would you take a look at the CI for this PR? I added the "run devdeps tests" label yet I'm not seeing the devdeps jobs.

zacharyburnett commented 11 months ago

hmm that's odd. The label is correct and the trigger was working in the original PR... I'll make another dummy PR to test this

braingram commented 11 months ago

Not sure what happened with RTD. The log says 'Build Succeeded' but the docs were not posted. Closing and reopening to re-trigger docs (hopefully).