diff --git a/.gitignore b/.gitignore index 9635da1..fc17b81 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ __pycache__ # Setuptools build and distribution folders /.cache /.eggs -/.venv/ +/.gifts/ /build/ /dist/ /data/ diff --git a/gifts/swaDecoder.py b/gifts/swaDecoder.py index d539db7..ed28e0e 100644 --- a/gifts/swaDecoder.py +++ b/gifts/swaDecoder.py @@ -15,7 +15,10 @@ import re import time +import skyfield + from skyfield.api import Loader +from skyfield.toposlib import wgs84 from .common import tpg from .common import xmlConfig as des @@ -109,7 +112,7 @@ def __init__(self): # # Preparing Skyfield try: - load = Loader(os.path.join(os.path.dirname(__file__), '../data'), verbose=False) + load = Loader(os.path.join(skyfield.__path__[0], 'bsp_files'), verbose=False) self._ts = load.timescale() # # Open NAIF/JPL/NASA SPICE Kernel @@ -118,7 +121,7 @@ def __init__(self): self._Helios = planets['sun'] except Exception: - self._Logger.exception('Unable to load/initialize Skyfield Module.') + self._Logger.exception('Unable to load/initialize Skyfield ephemeris file.') raise return super(Decoder, self).__init__() @@ -264,7 +267,7 @@ def daylight(self): # # Determine solar sub-point on Earth at forecast/observed time. fcsttime = self._ts.utc(*self.issueTime[:5]) - subpoint = (self._Helios - self._Gaia).at(fcsttime).subpoint() + subpoint = wgs84.geographic_position_of((self._Helios - self._Gaia).at(fcsttime)) self._affected['daylight'] = '%s %s' % (round(subpoint.latitude.degrees, 2), round(subpoint.longitude.degrees, 2)) diff --git a/setup.py b/setup.py index b908cbe..73cde52 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,32 @@ +import os +import sys import setuptools setuptools.setup() +# +# Find skyfield module location +try: + # + # If skyfield was installed before GIFTs + import skyfield + + bsp_directory = os.path.join(skyfield.__path__[0], 'bsp_files') + if not os.path.exists(bsp_directory): + os.mkdir(bsp_directory) + os.chmod(bsp_directory, 0o777) + +except ModuleNotFoundError: + # + # Newly installed with GIFTs + site_package_dir = os.path.join(sys.prefix, 'lib', 'python{}.{}'.format(sys.version_info.major, + sys.version_info.minor), 'site-packages') + egg_ext = '-py{}.{}.egg'.format(sys.version_info.major, sys.version_info.minor) + + for d in os.listdir(site_package_dir): + if d.startswith('skyfield') and d.endswith(egg_ext): + os.mkdir(os.path.join(site_package_dir, d, 'skyfield', 'bsp_files')) + os.chmod(os.path.join(site_package_dir, d, 'skyfield', 'bsp_files'), 0o777) + break + else: + print("Unable to create bsp_files directory for skyfield module. Please create it manually with user & group " + "write permissions")