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 2b518e8 commit d46bbd0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion 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 @@ -116,3 +121,25 @@ def to_physical_filter(self):
self.to_observation_id(), self._header["FILTER"])
return self._header["FILTER"]
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 d46bbd0

Please sign in to comment.