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

Add option to write uvw_array as double precision in UVFITS when data_array is single precision #1508

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

bhazelton
Copy link
Member

@bhazelton bhazelton commented Dec 5, 2024

Description

Motivation and Context

This adds the option write the uvw_array as double precision in UVFITS even when the data_array is single precision (they are always written as double precision when the data array are double precision). This is done using the same mechanism as is used for the time_array in UVFITS files, namely creating two identically named group parameters that are intended to be added together. This happens automatically in astropy's FITS reader, but it is possible this could mess up other UVFITS readers, so I added an option to allow it to be turned on or off and defaulted it to on because I think most users would prefer not to lose precision on their uvws.

This problem was noted as far back as #154 and it has come up occasionally since then.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change (documentation changes only)
  • Version change
  • Build or continuous integration change

Checklist:

New feature checklist:

  • I have added or updated the docstrings associated with my feature using the numpy docstring format.
  • I have updated the tutorial to highlight my new feature (if appropriate).
  • I have added tests to cover my new feature.
  • All new and existing tests pass.
  • I have updated the CHANGELOG.

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.93%. Comparing base (e903e5a) to head (240ff1c).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1508   +/-   ##
=======================================
  Coverage   99.93%   99.93%           
=======================================
  Files          63       63           
  Lines       21834    21849   +15     
=======================================
+ Hits        21819    21834   +15     
  Misses         15       15           

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

Copy link
Contributor

@kartographer kartographer left a comment

Choose a reason for hiding this comment

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

Overall I think this is looking good -- just had a small comment regarding the test for the new feature.

if uvw_double:
np.testing.assert_allclose(uvd.uvw_array, uvd2.uvw_array, rtol=0, atol=1e-13)
else:
assert not np.allclose(uvd.uvw_array, uvd2.uvw_array, rtol=0, atol=1e-13)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to additionally check here that the values are consistent with single precision (in addition to checking that they'd not "double-ish" precision). And any reason not to use rtol here instead of atol (given that it's floating-point precision we're working with)?

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

if uvw_double:
np.testing.assert_allclose(uvd.uvw_array, uvd2.uvw_array, rtol=1e-13)
else:
np.testing.assert_allclose(uvd.uvw_array, uvd2.uvw_array, rtol=1e-7)
Copy link
Contributor

@kartographer kartographer Dec 10, 2024

Choose a reason for hiding this comment

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

@bhazelton -- I think actually holding on to both checks when uvw_double=False would be good (both that it fails if rtol=1e-13 and passes when rtol=1e-7), since that's a pretty strong indicator that double-precision isn't being used. Or otherwise, adding a check that the UU2/VV2/WW2 entries aren't in there (although I'm not sure if there's a straight-forward way to do that w/ the astropy FITS interface).

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, added that one back.

Copy link
Contributor

@kartographer kartographer 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, thanks @bhazelton!

@kartographer kartographer merged commit 3fa6a4e into main Dec 11, 2024
50 of 54 checks passed
@kartographer kartographer deleted the uvfits_double_uvws branch December 11, 2024 11:36
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.

2 participants