Short-bus / pilomar

RaspberryPi based miniature observatory
https://shortbus.blog/
GNU General Public License v3.0
70 stars 14 forks source link

Comet positions fail in Skyfield timelib.py julian_day() function. #77

Closed Short-bus closed 3 months ago

Short-bus commented 3 months ago

When testing on recent RPi5 build, found that comet positions nolonger calculate. The positions fail in the skyfield timelib.py julian_day() function with the following error.

Traceback (most recent call last):
  File "/home/pi/pilomar/src/pilomar2.py", line 7927, in <module>
    Session.Target = TargetSelection()
                     ^^^^^^^^^^^^^^^^^
  File "/home/pi/pilomar/src/pilomar2.py", line 7893, in TargetSelection
    elif option == "COMET": obstarget = ChooseComet()
                                        ^^^^^^^^^^^^^
  File "/home/pi/pilomar/src/pilomar2.py", line 6801, in ChooseComet
    p = planets['sun'] + mpc.comet_orbit( row, ts, GM_SUN)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/skyfield/data/mpc.py", line 222, in comet_orbit
    t_perihelion = ts.tt(row.perihelion_year, row.perihelion_month,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/skyfield/timelib.py", line 299, in tt
    whole, fraction = self._jd(year, month, day, hour, minute, second)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/skyfield/timelib.py", line 210, in _jd
    whole = julian_day(a(year), a(month), a(day), cutoff) - 0.5
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/skyfield/timelib.py", line 955, in julian_day
    year = year + y
           ~~~~~^~~
numpy.core._exceptions._UFuncNoLoopError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U4'), dtype('float64')) -> None

The mpc comet file is recent and initially looks healthy, however the code fails at the same point for every comet in the mpc list.

The julian_day() function looks like this...

def julian_day(year, month=1, day=1, julian_before=None):
    """Given a calendar date, return a Julian day integer.

    Uses the proleptic Gregorian calendar unless ``julian_before`` is
    set to a specific Julian day, in which case the Julian calendar is
    used for dates older than that.

    """
    # Support months <1 and >12 by overflowing cleanly into adjacent years.
    y, month = divmod(month - 1, 12)
    year = year + y
    month += 1

    # See the Explanatory Supplement to the Astronomical Almanac 15.11.
    janfeb = month <= 2
    g = year + 4716 - janfeb
    f = (month + 9) % 12
    e = 1461 * g // 4 + day - 1402
    J = e + (153 * f + 2) // 5

    mask = 1 if (julian_before is None) else (J >= julian_before)
    J += (38 - (g + 184) // 100 * 3 // 4) * mask
    return J

The error message suggests a type mismatch between 'year' and 'y'. Maybe one is a numpy array, and the other isn't?

Short-bus commented 3 months ago

Refreshing the CometEls.txt file solved the problem. The value on disc appeared to be incompatible in some way.

Solution: Refresh the comet data file on disc.

1) Purge /home/pi/pilomar/data/CometEls.txt 2) Restart the pilomar program