Coverage for python/lsst/obs/lsst/translators/lsstsim.py: 38%

Shortcuts 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

46 statements  

1# This file is currently part of obs_lsst but is written to allow it 

2# to be migrated to the astro_metadata_translator package at a later date. 

3# 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the LICENSE file in this directory for details of code ownership. 

7# 

8# Use of this source code is governed by a 3-clause BSD-style 

9# license that can be found in the LICENSE file. 

10 

11"""Metadata translation code for LSST simulations""" 

12 

13__all__ = ("LsstSimTranslator", ) 

14 

15import warnings 

16import logging 

17 

18import astropy.utils.exceptions 

19from astropy.coordinates import AltAz 

20from astro_metadata_translator import cache_translation 

21 

22from .lsst import LsstBaseTranslator, SIMONYI_LOCATION, SIMONYI_TELESCOPE 

23 

24log = logging.getLogger(__name__) 

25 

26 

27class LsstSimTranslator(LsstBaseTranslator): 

28 """Shared routines for LSST Simulated Data. 

29 """ 

30 

31 # Reset mappings 

32 _const_map = { 

33 # neither phosim nor imsim report a counter 

34 "observation_counter": 0, 

35 } 

36 _trivial_map = {} 

37 

38 @classmethod 

39 def max_exposure_id(cls): 

40 """The maximum exposure ID expected from this instrument. 

41 

42 Returns 

43 ------- 

44 max_exposure_id : `int` 

45 The maximum value. 

46 """ 

47 return 9_999_999 

48 

49 @cache_translation 

50 def to_telescope(self): 

51 # Docstring will be inherited. Property defined in properties.py 

52 telescope = None 

53 if self.is_key_ok("OUTFILE") and self._header["OUTFILE"].startswith("lsst"): 

54 telescope = SIMONYI_TELESCOPE 

55 self._used_these_cards("OUTFILE") 

56 elif "LSST_NUM" in self._header: 

57 telescope = SIMONYI_TELESCOPE 

58 self._used_these_cards("LSST_NUM") 

59 return telescope 

60 

61 @cache_translation 

62 def to_location(self): 

63 # Docstring will be inherited. Property defined in properties.py 

64 location = None 

65 # In theory simulated files might not be for LSST 

66 tel = self.to_telescope() 

67 if tel == SIMONYI_TELESCOPE: 

68 location = SIMONYI_LOCATION 

69 else: 

70 # Try standard FITS headers 

71 try: 

72 location = super().to_location() 

73 except Exception: 

74 pass 

75 return location 

76 

77 @cache_translation 

78 def to_altaz_begin(self): 

79 # Docstring will be inherited. Property defined in properties.py 

80 if self.to_observation_type() == "science": 

81 # Derive from RADec in absence of any other information 

82 radec = self.to_tracking_radec() 

83 if radec is not None: 

84 # This can trigger warnings because of the future dates 

85 with warnings.catch_warnings(): 

86 warnings.simplefilter("ignore", category=astropy.utils.exceptions.AstropyWarning) 

87 altaz = radec.transform_to(AltAz()) 

88 return altaz 

89 return None