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

HLA-1312: Numpy 2.0 scalar promotion issues in STWCS #206

Conversation

s-goldman
Copy link
Collaborator

@s-goldman s-goldman commented Aug 29, 2024

Resolves HLA-1312

Closes #199

This PR addresses issues related to scalar promotion in numpy 2.0. The main issues are related to the IDCTAB refpix values being downgraded. More precisely, they are no longer automatically being upgraded from a float32 to a float64.

The important value that is now manually upgraded is the 'PSCALE'. Without this change, the 'PSCALE' is truncated (e.g. for ACS, WFC3, and WFPC2 IDCTABs) with a float32.

Several other values in the IDCTAB ('XREF', 'YREF', and 'THETA') are no longer automatically being upgraded, but these do not affect the results as, while they are technically floats, the values are integers.

Checklist for maintainers

  • added entry in CHANGELOG.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant label(s)

@s-goldman s-goldman marked this pull request as ready for review August 29, 2024 18:24
@s-goldman s-goldman requested a review from a team as a code owner August 29, 2024 18:24
Copy link

@mdlpstsci mdlpstsci left a comment

Choose a reason for hiding this comment

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

Manual promotion looks fine.

@mcara
Copy link
Member

mcara commented Sep 16, 2024

I wonder why are 'PSCALE' numpy.float32 at all?

@mcara
Copy link
Member

mcara commented Sep 16, 2024

I wonder whether it would be better to modify

refpix = {}
refpix['XREF'] = ftab[1].data.field('XREF')[row]
refpix['YREF'] = ftab[1].data.field('YREF')[row]
refpix['XSIZE'] = ftab[1].data.field('XSIZE')[row]
refpix['YSIZE'] = ftab[1].data.field('YSIZE')[row]
refpix['PSCALE'] = round(ftab[1].data.field('SCALE')[row], 8)
refpix['V2REF'] = v2ref
refpix['V3REF'] = v3ref
refpix['THETA'] = theta
refpix['XDELTA'] = 0.0
refpix['YDELTA'] = 0.0
refpix['DEFAULT_SCALE'] = True
refpix['centered'] = False
refpix['skew_coeffs'] = skew_coeffs

to simply store Python float instead of whatever type is in the table.

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 feel it would be better to just convert tab values to floats right away (currently they can be both np.float32 and Python float (0.0) which is a little inconsistent) then to promote to float64 at the end stage but it is not wrong.

@s-goldman
Copy link
Collaborator Author

I feel it would be better to just convert tab values to floats right away (currently they can be both np.float32 and Python float (0.0) which is a little inconsistent) then to promote to float64 at the end stage but it is not wrong.

Thanks for reviewing this. I would prefer to do it the right way. I couldn't find where they were instantiated, so now that you've pointed it out, I will set the type at the beginning of the process.

@s-goldman s-goldman requested a review from mcara September 17, 2024 14:26
stwcs/distortion/mutil.py Outdated Show resolved Hide resolved
@s-goldman s-goldman requested a review from mcara September 17, 2024 17:54
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.

LGTM. Thank you!

@s-goldman s-goldman merged commit 9b8269b into spacetelescope:master Sep 18, 2024
8 checks passed
@s-goldman s-goldman deleted the hla-1312_numpy2_scalar_promotion_08_29_24 branch September 18, 2024 20:45
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.

Accommodating scalar promotion in Numpy 2.0
4 participants