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

46 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-12 03:12 -0800

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 "has_simulated_content": True, 

36 } 

37 _trivial_map = {} 

38 

39 @classmethod 

40 def max_exposure_id(cls): 

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

42 

43 Returns 

44 ------- 

45 max_exposure_id : `int` 

46 The maximum value. 

47 """ 

48 return 9_999_999 

49 

50 @cache_translation 

51 def to_telescope(self): 

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

53 telescope = None 

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

55 telescope = SIMONYI_TELESCOPE 

56 self._used_these_cards("OUTFILE") 

57 elif "LSST_NUM" in self._header: 

58 telescope = SIMONYI_TELESCOPE 

59 self._used_these_cards("LSST_NUM") 

60 return telescope 

61 

62 @cache_translation 

63 def to_location(self): 

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

65 location = None 

66 # In theory simulated files might not be for LSST 

67 tel = self.to_telescope() 

68 if tel == SIMONYI_TELESCOPE: 

69 location = SIMONYI_LOCATION 

70 else: 

71 # Try standard FITS headers 

72 try: 

73 location = super().to_location() 

74 except Exception: 

75 pass 

76 return location 

77 

78 @cache_translation 

79 def to_altaz_begin(self): 

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

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

82 # Derive from RADec in absence of any other information 

83 radec = self.to_tracking_radec() 

84 if radec is not None: 

85 # This can trigger warnings because of the future dates 

86 with warnings.catch_warnings(): 

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

88 altaz = radec.transform_to(AltAz()) 

89 return altaz 

90 return None