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

49 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-02-25 09:36 +0000

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 ( 

23 LsstBaseTranslator, 

24 SIMONYI_LOCATION, 

25 SIMONYI_TELESCOPE, 

26 compute_detector_exposure_id_generic, 

27) 

28 

29log = logging.getLogger(__name__) 

30 

31 

32class LsstSimTranslator(LsstBaseTranslator): 

33 """Shared routines for LSST Simulated Data. 

34 """ 

35 

36 # Reset mappings 

37 _const_map = { 

38 # neither phosim nor imsim report a counter 

39 "observation_counter": 0, 

40 "has_simulated_content": True, 

41 } 

42 _trivial_map = {} 

43 

44 @classmethod 

45 def max_exposure_id(cls): 

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

47 

48 Returns 

49 ------- 

50 max_exposure_id : `int` 

51 The maximum value. 

52 """ 

53 return 9_999_999 

54 

55 @classmethod 

56 def compute_detector_exposure_id(cls, exposure_id, detector_num): 

57 # Docstring inherited from LsstBaseTranslator. 

58 return compute_detector_exposure_id_generic(exposure_id, detector_num, max_num=cls.DETECTOR_MAX) 

59 

60 @cache_translation 

61 def to_telescope(self): 

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

63 telescope = None 

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

65 telescope = SIMONYI_TELESCOPE 

66 self._used_these_cards("OUTFILE") 

67 elif "LSST_NUM" in self._header: 

68 telescope = SIMONYI_TELESCOPE 

69 self._used_these_cards("LSST_NUM") 

70 return telescope 

71 

72 @cache_translation 

73 def to_location(self): 

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

75 location = None 

76 # In theory simulated files might not be for LSST 

77 tel = self.to_telescope() 

78 if tel == SIMONYI_TELESCOPE: 

79 location = SIMONYI_LOCATION 

80 else: 

81 # Try standard FITS headers 

82 try: 

83 location = super().to_location() 

84 except Exception: 

85 pass 

86 return location 

87 

88 @cache_translation 

89 def to_altaz_begin(self): 

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

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

92 # Derive from RADec in absence of any other information 

93 radec = self.to_tracking_radec() 

94 if radec is not None: 

95 # This can trigger warnings because of the future dates 

96 with warnings.catch_warnings(): 

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

98 altaz = radec.transform_to(AltAz()) 

99 return altaz 

100 return None