Skip to content

Commit

Permalink
Merge pull request #255 from lsst/tickets/DM-26943
Browse files Browse the repository at this point in the history
DM-26943: Use AIRMASS or AMSTART headers for imsim if they exist
  • Loading branch information
timj committed Sep 29, 2020
2 parents 5066a00 + d46bbd0 commit 5865270
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 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 @@ -87,6 +92,9 @@ def to_tracking_radec(self):
@cache_translation
def to_boresight_airmass(self):
# Docstring will be inherited. Property defined in properties.py
for key in ("AIRMASS", "AMSTART"):
if self.is_key_ok(key):
return self._header[key]
altaz = self.to_altaz_begin()
if altaz is not None:
return altaz.secz.to_value()
Expand All @@ -113,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 5865270

Please sign in to comment.