Skip to content

Commit

Permalink
Merge pull request #180 from sdss/fixeph
Browse files Browse the repository at this point in the history
Setting single source of ephemeris at lvmcore
  • Loading branch information
ajmejia authored Dec 3, 2024
2 parents cca8807 + 0b7db46 commit 4d81c4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions python/lvmdrp/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@
# ESO skycorr configuration file
SKYCORR_CONFIG_PATH = os.path.join(CONFIG_PATH, "third_configs", "skycorr_config.yml")

# data paths
DATA_PATH = os.path.join(ROOT_PATH, "data")
EPHEMERIS_PATH = os.path.join(DATA_PATH, "de421.bsp")
# ephemeris path
EPHEMERIS_DIR = os.path.join(os.getenv("LVMCORE_DIR"), "etc")

# fiducial calibrations directory
MASTERS_DIR = os.getenv("LVM_MASTER_DIR")
Expand Down
9 changes: 5 additions & 4 deletions python/lvmdrp/core/sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
from skycalc_cli.skycalc_cli import fixObservatory
from skyfield import almanac
from skyfield.positionlib import ICRS
from skyfield.api import Star, load, wgs84
from skyfield.api import Loader, Star, load, wgs84
from skyfield.framelib import ecliptic_frame

from lvmdrp.external import shadow_height_lib as sh

from lvmdrp.core.constants import (
ALMANAC_CONFIG_PATH,
EPHEMERIS_PATH,
EPHEMERIS_DIR,
SKYCALC_CONFIG_PATH,
SKYCORR_CONFIG_PATH,
SKYCORR_INST_PATH,
Expand Down Expand Up @@ -256,7 +256,8 @@ def skymodel_pars_header(header):
obstime = Time(header["OBSTIME"], scale="tai")

# define ephemeris object
astros = load(os.path.basename(EPHEMERIS_PATH))
ephemeris_loader = Loader(EPHEMERIS_DIR)
astros = ephemeris_loader("de421.bsp")
sun, earth, moon = astros["sun"], astros["earth"], astros["moon"]
# define location
obs_topos = wgs84.latlon(
Expand All @@ -266,7 +267,7 @@ def skymodel_pars_header(header):
)
obs = earth + obs_topos
# define observation datetime
ts = load.timescale()
ts = ephemeris_loader.timescale()
obs_time = ts.from_astropy(obstime)
# define observatory object
obs = obs.at(obs_time)
Expand Down
9 changes: 4 additions & 5 deletions python/lvmdrp/external/shadow_height_lib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/python3
import numpy as np
import os
import sys
from astropy import units as u
from skyfield.api import Loader
from skyfield.api import Topos

from lvmdrp.core.constants import EPHEMERIS_DIR

class shadow_calc(object):
def __init__(self, observatory_name="LCO",
observatory_elevation=2380.0*u.m,
Expand All @@ -21,9 +22,8 @@ def __init__(self, observatory_name="LCO",
super().__init__()

# Load the ephemeral datat for the earth and sun.
load = Loader(EPHEMERIS_DIR)
if eph is None:
redux = os.getenv("LVM_SPECTRO_REDUX")
load = Loader(redux)
self.eph = load('de421.bsp')

# Get functions for the earth, sun and observatory
Expand Down Expand Up @@ -343,8 +343,7 @@ def test_shadow_calc():

compare_old = True
if compare_old:
redux = os.getenv("LVM_SPECTRO_REDUX")
load = Loader(redux)
load = Loader(EPHEMERIS_DIR)
eph = load('de421.bsp')
import lvmsurveysim.utils.iterative_shadow_height_lib as iterative_shadow_height_lib
iter_calc = iterative_shadow_height_lib.shadow_calc(observatory_name='LCO',
Expand Down

0 comments on commit 4d81c4f

Please sign in to comment.