From 47c66d19b45147a91fe6026102be541d7ace08ea Mon Sep 17 00:00:00 2001 From: Mark Oberfield Date: Tue, 14 Dec 2021 09:20:36 -0500 Subject: [PATCH 1/2] Update setup.cfg Update the file to be in sync with the latest tag version. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 5c68048..006d7d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,7 @@ description = IWXXM encoders for Annex3 TAC products author = Mark Oberfield - NOAA/NWS/OSTI/MDL/WIAD author_email = Mark.Oberfield@noaa.gov maintainer = Mark Oberfield -version = 1.0.0 +version = 1.3.1 classifiers = Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Operating System :: OS Independent From 99a13e55913beb209bc2b435e202429eb8baa747 Mon Sep 17 00:00:00 2001 From: Mark Oberfield Date: Wed, 15 Dec 2021 19:52:04 +0000 Subject: [PATCH 2/2] Create new directory for ephemeris files where skyfield is installed. --- .gitignore | 2 +- gifts/swaDecoder.py | 9 ++++++--- setup.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) 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")