mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-03-29 03:43:34 -04:00
PY SearchMoonPhase: allow searching backward in time.
Enhanced the Python function SearchMoonPhase to allow searching forward in time when the `limitDays` argument is positive, or backward in time when `limitDays` is negative. Added unit test "moon_reverse" to verify this new feature.
This commit is contained in:
@@ -2952,7 +2952,7 @@ This function is useful for finding general phase angles outside those four quar
|
||||
| --- | --- | --- |
|
||||
| `float` | `targetLon` | The difference in geocentric longitude between the Sun and Moon that specifies the lunar phase being sought. This can be any value in the range [0, 360). Certain values have conventional names: 0 = new moon, 90 = first quarter, 180 = full moon, 270 = third quarter. |
|
||||
| [`Time`](#Time) | `startTime` | The beginning of the time window in which to search for the Moon reaching the specified phase. |
|
||||
| `float` | `limitDays` | The number of days after `startTime` that limits the time window for the search. |
|
||||
| `float` | `limitDays` | The number of days away from `startTime` that limits the time window for the search. If the value is negative, the search is performed into the past from `startTime`. Otherwise, the search is performed into the future from `startTime`. |
|
||||
|
||||
**Returns**: [`Time`](#Time) or `None`
|
||||
|
||||
|
||||
@@ -5893,7 +5893,9 @@ def SearchMoonPhase(targetLon, startTime, limitDays):
|
||||
startTime : Time
|
||||
The beginning of the time window in which to search for the Moon reaching the specified phase.
|
||||
limitDays : float
|
||||
The number of days after `startTime` that limits the time window for the search.
|
||||
The number of days away from `startTime` that limits the time window for the search.
|
||||
If the value is negative, the search is performed into the past from `startTime`.
|
||||
Otherwise, the search is performed into the future from `startTime`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -5911,16 +5913,27 @@ def SearchMoonPhase(targetLon, startTime, limitDays):
|
||||
# But we must return None if the final result goes beyond limitDays after startTime.
|
||||
uncertainty = 1.5
|
||||
ya = _moon_offset(targetLon, startTime)
|
||||
if ya > 0.0:
|
||||
ya -= 360.0 # force searching forward in time, not backward
|
||||
est_dt = -(_MEAN_SYNODIC_MONTH * ya) / 360.0
|
||||
dt1 = est_dt - uncertainty
|
||||
if dt1 > limitDays:
|
||||
return None # not possible for moon phase to occur within the specified window
|
||||
dt2 = min(limitDays, est_dt + uncertainty)
|
||||
if limitDays < 0.0:
|
||||
# Search backward in time.
|
||||
if ya < 0.0:
|
||||
ya += 360.0 # force searching forward in time, not backward
|
||||
est_dt = -(_MEAN_SYNODIC_MONTH * ya) / 360.0
|
||||
dt2 = est_dt + uncertainty
|
||||
if dt2 < limitDays:
|
||||
return None # not possible for moon phase to occur within the specified window
|
||||
dt1 = max(limitDays, est_dt - uncertainty)
|
||||
else:
|
||||
# Search forward in time.
|
||||
if ya > 0.0:
|
||||
ya -= 360.0 # force searching forward in time, not backward
|
||||
est_dt = -(_MEAN_SYNODIC_MONTH * ya) / 360.0
|
||||
dt1 = est_dt - uncertainty
|
||||
if dt1 > limitDays:
|
||||
return None # not possible for moon phase to occur within the specified window
|
||||
dt2 = min(limitDays, est_dt + uncertainty)
|
||||
t1 = startTime.AddDays(dt1)
|
||||
t2 = startTime.AddDays(dt2)
|
||||
return Search(_moon_offset, targetLon, t1, t2, 1.0)
|
||||
return Search(_moon_offset, targetLon, t1, t2, 0.1)
|
||||
|
||||
class MoonQuarter:
|
||||
"""A lunar quarter event along with its date and time.
|
||||
|
||||
Reference in New Issue
Block a user