Skip to content

Commit

Permalink
Switch to astro_metadata_translator for VisitInfo calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Oct 19, 2018
1 parent aec0f8b commit 6c8863a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 61 deletions.
58 changes: 5 additions & 53 deletions python/lsst/obs/cfht/makeMegacamRawVisitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,16 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import astropy.units

from lsst.afw.coord import Observatory, Weather
from lsst.afw.geom import SpherePoint
from lsst.obs.base import MakeRawVisitInfo
from lsst.obs.base import MakeRawVisitInfoViaObsInfo
from astro_metadata_translator import MegaPrimeTranslator

__all__ = ["MakeMegacamRawVisitInfo"]


class MakeMegacamRawVisitInfo(MakeRawVisitInfo):
class MakeMegacamRawVisitInfo(MakeRawVisitInfoViaObsInfo):

"""Make a VisitInfo from the FITS header of a raw Megacam image
"""

def setArgDict(self, md, argDict):
"""Set an argument dict for VisitInfo and pop associated metadata
Parameters
----------
md : `lsst.daf.base.PropertyList` or `lsst.daf.base.PropertySet`
Metadata to extract from. Extracted values are removed.
argdict : `dict`
A dict of arguments to add to values to.
"""
MakeRawVisitInfo.setArgDict(self, md, argDict)
argDict["darkTime"] = self.popFloat(md, "DARKTIME")
argDict["boresightAzAlt"] = SpherePoint(
self.popAngle(md, "TELAZ"),
self.popAngle(md, "TELALT"),
)
argDict["boresightRaDec"] = SpherePoint(
self.popAngle(md, "RA_DEG",),
self.popAngle(md, "DEC_DEG"),
)
argDict["boresightAirmass"] = self.popFloat(md, "AIRMASS")
argDict["observatory"] = Observatory(
self.popAngle(md, "LONGITUD"),
self.popAngle(md, "LATITUDE"),
4204, # from Wikipedia
)
argDict["weather"] = Weather(
self.popFloat(md, "TEMPERAT"),
self.popFloat(md, "PRESSURE")*100.0, # 100 Pascal per millibar
self.popFloat(md, "RELHUMID"),
)
# Using LST to compute ERA until we get UT1 (see: DM-8053)
LST = self.popAngle(md, "LST-OBS", units=astropy.units.h)
argDict['era'] = self.eraFromLstAndLongitude(LST, argDict["observatory"].getLongitude())

def getDateAvg(self, md, exposureTime):
"""Return date at the middle of the exposure
Parameters
----------
md : `lsst.daf.base.PropertyList` or `lsst.daf.base.PropertySet`
FITS metadata; changed in place
exposureTime : `float`
exposure time in sec
"""
dateObs = self.popMjdDate(md, "MJD-OBS")
return self.offsetDate(dateObs, 0.5*exposureTime)
# Force MegaPrime translator
metadataTranslator = MegaPrimeTranslator
14 changes: 6 additions & 8 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import lsst.pex.exceptions as pexExcept
from lsst.daf.base import DateTime
from lsst.afw.image import RotType
from lsst.afw.geom import degrees, SpherePoint
from lsst.geom import degrees, radians, SpherePoint

try:
type(display)
Expand All @@ -58,21 +58,19 @@ def setUp(self):
self.filter = "i2"
self.exposureTime = 615.037
self.darkTime = 615.0
dateObs = DateTime(54771.6066250, DateTime.MJD, DateTime.UTC)
self.dateAvg = DateTime(dateObs.nsecs(DateTime.TAI) + int(0.5e9*self.exposureTime), DateTime.TAI)
self.boresightRaDec = SpherePoint(135.409417, -2.400000, degrees)
self.dateAvg = DateTime(54771.610881712964, DateTime.MJD, DateTime.TAI)
self.boresightRaDec = SpherePoint(135.40941055, -2.39999432, degrees)
self.boresightAzAlt = SpherePoint(122.34, 52.02, degrees)
self.boresightAirmass = 1.269
self.rotType = RotType.UNKNOWN
self.obs_longitude = -155.468876*degrees
self.obs_latitude = 19.825252*degrees
self.obs_elevation = 4204
self.obs_elevation = 4215
self.weath_airTemperature = 0.90
self.weath_airPressure = 617.65*100 # 100 Pascal/millibar
self.weath_humidity = 39.77
# NOTE: if we deal with DM-8053 and get UT1 implemented, ERA will change slightly.
lst = 104.16591666666666*degrees
self.era = lst - self.obs_longitude
self.era = 4.55388*radians

def tearDown(self):
del self.butler
Expand Down Expand Up @@ -123,7 +121,7 @@ def testRaw(self):

visitInfo = raw.getInfo().getVisitInfo()
self.assertAlmostEqual(visitInfo.getDate().get(), self.dateAvg.get())
self.assertEqual(visitInfo.getEra(), self.era)
self.assertAnglesAlmostEqual(visitInfo.getEra(), self.era, maxDiff=0.1*degrees)
self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposureTime)
self.assertAlmostEqual(visitInfo.getDarkTime(), self.darkTime)
self.assertSpherePointsAlmostEqual(visitInfo.getBoresightRaDec(), self.boresightRaDec)
Expand Down
1 change: 1 addition & 0 deletions ups/obs_cfht.table
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ setupRequired(obs_base)
setupRequired(meas_algorithms)
setupRequired(pipe_tasks)
setupRequired(astropy)
setupRequired(astro_metadata_translator)

setupOptional(testdata_cfht)

Expand Down

0 comments on commit 6c8863a

Please sign in to comment.