Skip to content

Commit

Permalink
Use ERFA to get AZEL from Hour Angle
Browse files Browse the repository at this point in the history
This is faster and more reliable than trying to derive it
from the RA/Dec in the future (which also requires assumptions
on leap seconds).
  • Loading branch information
timj committed Sep 28, 2020
1 parent 157298e commit b2f4c50
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions python/lsst/obs/lsst/translators/imsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

import logging
import astropy.units as u
from astropy.coordinates import Angle
from astropy.coordinates import Angle, AltAz

try:
import erfa
except ImportError:
import astropy._erfa as erfa

from astro_metadata_translator import cache_translation
from astro_metadata_translator.translators.helpers import tracking_from_degree_headers
Expand Down Expand Up @@ -114,5 +119,28 @@ def to_physical_filter(self):
if throughputs_version is None:
log.warning("%s: throughputs version not found. Using FILTER keyword value '%s'.",
self.to_observation_id(), self._header["FILTER"])
return self._header["FILTER"]
# return self._header["FILTER"]
throughputs_version = "1.4"
return "_".join((self._header["FILTER"], "sim", throughputs_version))

@cache_translation
def to_altaz_begin(self):
# Calculate from the hour angle if available
if self.to_observation_type() != "science":
return None

if not self.are_keys_ok(["HASTART", "DECTEL"]):
# Fallback to slow method
return super().to_altaz_begin()

location = self.to_location()
ha = Angle(self._header["HASTART"], unit=u.deg)

# For speed over accuracy, assume this is apparent Dec not ICRS
dec = Angle(self._header["DECTEL"], unit=u.deg)

# Use erfa directly
az, el = erfa.hd2ae(ha.radian, dec.radian, location.lat.radian)

return AltAz(az*u.radian, el*u.radian,
obstime=self.to_datetime_begin(), location=location)

0 comments on commit b2f4c50

Please sign in to comment.