Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# 

2# LSST Data Management System 

3# Copyright 2016 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import astropy.units 

23 

24from lsst.afw.image import VisitInfo, RotType 

25from lsst.afw.coord import Observatory, Weather 

26from lsst.afw.coord.refraction import defaultWeather 

27from lsst.geom import degrees, SpherePoint 

28from lsst.obs.base import MakeRawVisitInfo 

29 

30__all__ = ["MakeLsstSimRawVisitInfo"] 

31 

32 

33class MakeLsstSimRawVisitInfo(MakeRawVisitInfo): 

34 """Make a VisitInfo from the FITS header of a raw LSST simulated image 

35 

36 The convention for ROTANG is as follows: 

37 at 0 degrees E = +Y CCD = -X Focal Plane, N = +X CCD = +Y Focal Plane: 0 boresightRotAng 

38 at 90 degrees E = -X CCD = -Y Focal Plane, N = +Y CCD = -X Focal Plane: 270 boresightRotAng 

39 

40 So boresightRotAng = -ROTANG 

41 """ 

42 observatory = Observatory(-70.749417*degrees, -30.244633*degrees, 2663) # long, lat, elev 

43 

44 def setArgDict(self, md, argDict): 

45 """Set an argument dict for VisitInfo and pop associated metadata 

46 

47 @param[in,out] md metadata, as an lsst.daf.base.PropertyList or PropertySet 

48 @param[in,out] argdict a dict of arguments 

49 """ 

50 MakeRawVisitInfo.setArgDict(self, md, argDict) 

51 argDict["darkTime"] = self.popFloat(md, "DARKTIME") 

52 argDict["boresightAzAlt"] = SpherePoint( 

53 self.popAngle(md, "AZIMUTH"), 

54 self.altitudeFromZenithDistance(self.popAngle(md, "ZENITH")), 

55 ) 

56 argDict["boresightRaDec"] = SpherePoint( 

57 self.popAngle(md, "RA_DEG"), 

58 self.popAngle(md, "DEC_DEG"), 

59 ) 

60 argDict["boresightAirmass"] = self.popFloat(md, "AIRMASS") 

61 argDict["boresightRotAngle"] = -self.popAngle(md, "ROTANG") 

62 argDict["rotType"] = RotType.SKY 

63 argDict["observatory"] = self.observatory 

64 weather = defaultWeather(self.observatory.getElevation()) 

65 temperature = self.defaultMetadata(self.popFloat(md, "TEMPERA"), weather.getAirTemperature(), 

66 minimum=-10, maximum=40.) 

67 pressure = self.defaultMetadata(self.pascalFromMmHg(self.popFloat(md, "PRESS")), 

68 weather.getAirPressure(), minimum=50000., maximum=90000.) 

69 humidity = 40. # Not currently supplied by phosim, so set to a typical value. 

70 argDict["weather"] = Weather(temperature, pressure, humidity) 

71 longitude = argDict["observatory"].getLongitude() 

72 RA = argDict["boresightRaDec"][0] 

73 # phosim doesn't supply LST, HA, or UT1, and the alt/az/ra/dec/time can be inconsistent. 

74 # We will leave ERA as NaN until a better answer is available. 

75 try: 

76 # Other simulation tools don't have the same problem, and need hour angle if it is available. 

77 HA = self.popAngle(md, "HA", units=astropy.units.h) 

78 argDict['era'] = HA + RA - longitude 

79 except Exception: 

80 self.log.warn("Hour angle missing from metadata, will be NAN") 

81 return VisitInfo(**argDict) 

82 

83 def getDateAvg(self, md, exposureTime): 

84 """Return date at the middle of the exposure 

85 

86 @param[in,out] md FITS metadata; changed in place 

87 @param[in] exposureTime exposure time in sec 

88 """ 

89 startDate = self.popMjdDate(md, "TAI", timesys="TAI") 

90 return self.offsetDate(startDate, 0.5*exposureTime)