Add Astronoby::Moon#current_phase_fraction#115
Merged
rhannequin merged 1 commit intomainfrom Dec 10, 2024
Merged
Conversation
While `#illuminated_fraction` already provides a valid information on how much the Moon seems illuminated as observed from the Earth, it doesn't help deduce the current phase name. When the Moon is 45% illuminated, it can be either the First Quarter or the Last Quarter, there is no way of knowing without calculating when is was the previous Full Moon and when is the next one. To help with this, we introduce `#current_phase_fraction`, based on the mean elongation, which is a number from 0 to 1 which always increase while we're getting closer to the next New Moon. As it is using `#mean_elongation`, the result is not extremely precise, however it is precise enough to deduce the current phase name for a given day. For a user wanting to get accurate phase times, it is preferred to use `::monthly_phase_events`. ```rb # ~ time of first quarter in December 2024 time = Time.utc(2024, 12, 8, 15, 26) Astronoby::Moon.new(time: time) .illuminated_fraction .round(2) # => 0.5 Astronoby::Moon.new(time: time) .current_phase_fraction .round(2) # => 0.26 # ~ time of last quarter in December 2024 time = Time.utc(2024, 12, 22, 22, 18) Astronoby::Moon.new(time: time) .illuminated_fraction .round(2) # => 0.5 Astronoby::Moon.new(time: time) .current_phase_fraction . round(2) # => 0.74 ``` Fixes #101
|
🥳 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While
#illuminated_fractionalready provides a valid information on how much the Moon seems illuminated as observed from the Earth, it doesn't help deduce the current phase name. When the Moon is 45% illuminated, it can be either the First Quarter or the Last Quarter, there is no way of knowing without calculating when is was the previous Full Moon and when is the next one.To help with this, we introduce
#current_phase_fraction, based on the mean elongation, which is a number from 0 to 1 which always increase while we're getting closer to the next New Moon.As it is using
#mean_elongation, the result is not extremely precise, however it is precise enough to deduce the current phase name for a given day.For a user wanting to get accurate phase times, it is preferred to use
::monthly_phase_events.Fixes #101