Skip to content

Commit

Permalink
Merge pull request #31 from NOAA-MDL/issue#30
Browse files Browse the repository at this point in the history
Create new directory for ephemeris files where skyfield is installed.
  • Loading branch information
mgoberfield authored Dec 15, 2021
2 parents 47c66d1 + 99a13e5 commit fe5b667
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __pycache__
# Setuptools build and distribution folders
/.cache
/.eggs
/.venv/
/.gifts/
/build/
/dist/
/data/
Expand Down
9 changes: 6 additions & 3 deletions gifts/swaDecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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__()
Expand Down Expand Up @@ -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))

Expand Down
29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit fe5b667

Please sign in to comment.