Skip to content

Ensure that always abs(time.jd2)<=0.5. - #8763

Merged
mhvk merged 3 commits into
astropy:masterfrom
mhvk:time-small-day-frac-bug
May 28, 2019
Merged

mhvk merged 3 commits into
astropy:masterfrom
mhvk:time-small-day-frac-bug

Conversation

@mhvk

@mhvk mhvk commented May 26, 2019

Copy link
Copy Markdown
Contributor

Not sure this is strictly a bug, since we do not guarantee a particular implementation of jd1 and jd2, but this is more consistent and will make the precision very slightly better.

Found while implementing a double-precision Phase class where I did want to ensure that the fractional phase in cycles was strictly in the range -0.5<=fraction<=0.5 (mhvk/baseband-tasks#77)

@mhvk mhvk added this to the v3.2.1 milestone May 26, 2019
@mhvk
mhvk requested a review from taldcroft May 26, 2019 16:03
@mhvk
mhvk force-pushed the time-small-day-frac-bug branch from bd27213 to 3f4921c Compare May 27, 2019 15:04
@codecov

codecov Bot commented May 27, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #8763 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8763      +/-   ##
==========================================
+ Coverage   86.96%   86.96%   +<.01%     
==========================================
  Files         400      400              
  Lines       59448    59454       +6     
  Branches     1100     1100              
==========================================
+ Hits        51697    51703       +6     
  Misses       7110     7110              
  Partials      641      641
Impacted Files Coverage Δ
astropy/time/utils.py 100% <100%> (ø) ⬆️
astropy/time/core.py 94.97% <0%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 660d73b...e5aed05. Read the comment docs.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Just a question about whether the testing is complete and a request to update the docstring.

Comment thread astropy/time/tests/test_precision.py Outdated
"""Make jd2 approach +/-0.5, and check that it doesn't go over."""
t1 = Time(2400000.5, [-2**-52, +2**-52], format='jd')
assert np.all(abs(t1.jd2) < 0.5)
t2 = Time(2400000., [0.5-2**-52, 0.5+2**-52], format='jd')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this also need a check for the -0.5 case [-0.5-2**-52, -0.5+2**-52]? I'm not sure if this ends up being a different case or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is the same, but, hey, doesn't cost anything to add it, so consider it done!

Comment thread astropy/time/utils.py
day = np.round(sum12)
extra, frac = two_sum(sum12, -day)
frac += extra + err12
# Our fraction can now have gotten >0.5 or <-0.5, which means we would

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to include something in the docstring for day_frac that specifies the range -0.5 <= frac <= 0.5 instead of just saying "fractional remainder".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I adjusted the docstring (well, more like a rewrite...)

mhvk added 2 commits May 28, 2019 15:01
We used to sometimes have jd1 end in 0.5, but this was fixed
quite a while ago.  Now jd1 is guaranteed to be integer.
@mhvk

mhvk commented May 28, 2019

Copy link
Copy Markdown
Contributor Author

While looking at the tests, I realized one was from an older time where some initializations did not go through day_frac and jd1 could end in 0.5. But that no longer is the case, so I made the test stricter.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM once tests pass.

@mhvk

mhvk commented May 28, 2019

Copy link
Copy Markdown
Contributor Author

Tests passed so merging.

@mhvk
mhvk merged commit 1658b5a into astropy:master May 28, 2019
@mhvk
mhvk deleted the time-small-day-frac-bug branch May 28, 2019 21:24
@bsipocz bsipocz modified the milestones: v3.2.1, v3.2 May 29, 2019
bsipocz pushed a commit that referenced this pull request May 30, 2019
Ensure that always abs(time.jd2)<=0.5.
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.

3 participants