brandon-rhodes / python-jplephem

Python version of NASA DE4xx ephemerides, the basis for the Astronomical Alamanac
MIT License
111 stars 29 forks source link

Version 2.12 doesn't appear to be on conda-forge #37

Closed richard-timpson closed 4 years ago

richard-timpson commented 4 years ago

When using skyfield to get the sunrise and sunset times for a given datetime, I'm getting an import error regarding the jplephem package.

The following is python code for getting sunrise and sunset.

import datetime
from skyfield import almanac
from skyfield import api
from pytz import timezone
from pytz import utc

ts = api.load.timescale()
e = api.load('de421.bsp')

dt = datetime.datetime.now()
lat = "36.994076 N"
long = "112.974030 W"

sunrise, sunset = get_sunrise_sunset_from_datetime(dt, lat, long)
print(sunrise)
print(sunset)

def get_sunrise_sunset_from_datetime(dt, lat, long):

    bluffton = api.Topos(lat, long)

    start_of_day = dt.replace(hour=0, minute=0, second=1)
    start_of_day = start_of_day.astimezone(timezone('UTC'))
    end_of_day = dt.replace(hour=23, minute=59, second=59)
    end_of_day = end_of_day.astimezone(timezone('UTC'))

    t0 = ts.utc(start_of_day)
    t1 = ts.utc(end_of_day)
    t, y = almanac.find_discrete(t0, t1, almanac.sunrise_sunset(e, bluffton))

    first, first_type = t[0], "Sunset" if y[0] == False else "Sunrise"
    second, second_type = t[1], "Sunset" if y[1] == False else "Sunrise"
    first = first.astimezone(timezone('US/Arizona'))
    second = second.astimezone(timezone('US/Arizona'))

    return (first, second) if first_type == "Sunrise" else (second, first)

I'm getting the following error when I try to run the script

Traceback (most recent call last):
  File "skyfieldtest.py", line 3, in <module>
    from skyfield import api
  File "/Users/richardtimpson/opt/anaconda3/lib/python3.7/site-packages/skyfield/api.py", line 14, in <module>
    from .planetarylib import PlanetaryConstants
  File "/Users/richardtimpson/opt/anaconda3/lib/python3.7/site-packages/skyfield/planetarylib.py", line 5, in <module>
    from jplephem.pck import DAF, PCK
ModuleNotFoundError: No module named 'jplephem.pck'

After investigating the jplephem package in my conda installation, I noticed that the pck.py file didn't exist as it does in version 2.12. The version installed in my conda installation is 2.9, and when trying to update the conda package, it didn't do anything.

Running a conda search reveals that only 2.9 is available on conda-forge.

(base) Richards-MacBook-Pro:jplephem richardtimpson$ conda search -c conda-forge plephem
Loading channels: done
No match found for: plephem. Search: *plephem*
# Name                       Version           Build  Channel             
jplephem                         2.5          py27_0  conda-forge         
jplephem                         2.5          py27_1  conda-forge         
jplephem                         2.5          py34_0  conda-forge         
jplephem                         2.5          py35_0  conda-forge         
jplephem                         2.5          py35_1  conda-forge         
jplephem                         2.5          py36_1  conda-forge         
jplephem                         2.6          py27_0  conda-forge         
jplephem                         2.6          py35_0  conda-forge         
jplephem                         2.6          py36_0  conda-forge         
jplephem                         2.7          py27_0  conda-forge         
jplephem                         2.7          py35_0  conda-forge         
jplephem                         2.7          py36_0  conda-forge         
jplephem                         2.7    pyh24bf2e0_1  conda-forge         
jplephem                         2.7    pyh24bf2e0_2  conda-forge         
jplephem                         2.8    pyh11f86e8_0  conda-forge         
jplephem                         2.9    pyh11f86e8_0  conda-forge  

I'm not certain how conda-forge and the packages work, but the latest version isn't there.

Workaround was to copy and paste the pck.py from github to my local copy of jplephem, but it would be nice if the jplephem dependency would automatically update when updating skyfield using conda update.

brandon-rhodes commented 4 years ago

I am not very familiar with how the conda third-party packaging efforts work. As Skyfield itself requires a more recent jplephem than 2.9 in its setup.py, I am going to close this issue for now — if we find later that I made a mistake in setup.py or somewhere else, please re-open this immediately and let me know what code I can adjust in this repository to fix the problem!

In the meantime, I suspect you will need to file issues with one or both of these projects:

https://github.com/conda-forge/skyfield-feedstock https://github.com/conda-forge/jplephem-feedstock

Good luck, and I hope you will be able to figure out what is going on with conda's ecosystem!