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

1from builtins import object 

2from collections import OrderedDict 

3import numpy as np 

4from .cloudModelConfig import CloudModelConfig 

5from lsst.sims.cloudModel import version 

6 

7 

8__all__ = ["CloudModel"] 

9 

10 

11class CloudModel(object): 

12 """LSST cloud calculations for cloud extinction. 

13 Currently this actually only returns the cloud coverage of the sky, exactly as reported in the 

14 cloud database (thus the sky coverage, in fractions of 8ths). 

15 

16 

17 Parameters 

18 ---------- 

19 config: CloudModelConfig, opt 

20 A configuration class for the cloud model. 

21 This can be None, in which case the default CloudModelConfig is used. 

22 The user should set any non-default values for CloudModelConfig before 

23 configuration of the actual CloudModel. 

24 

25 self.efd_requirements and self.map_requirements are also set. 

26 efd_requirements is a tuple: (list of str, float). 

27 This corresponds to the data columns required from the EFD and the amount of time history required. 

28 target_requirements is a list of str. 

29 This corresponds to the data columns required in the target map dictionary passed when calculating the 

30 processed telemetry values. 

31 """ 

32 def __init__(self, config=None): 

33 self._config = None 

34 self.configure(config=config) 

35 self.efd_requirements = (self._config.efd_columns, self._config.efd_delta_time) 

36 self.target_requirements = self._config.target_columns 

37 self.altcol = self.target_requirements[0] 

38 self.azcol = self.target_requirements[1] 

39 self.efd_cloud = self._config.efd_columns[0] 

40 

41 def configure(self, config=None): 

42 """Configure the model. After 'configure' the model config will be frozen. 

43 

44 Parameters 

45 ---------- 

46 config: CloudModelConfig, opt 

47 A configuration class for the cloud model. 

48 This can be None, in which case the default values are used. 

49 """ 

50 if config is None: 

51 self._config = CloudModelConfig() 

52 elif isinstance(config, dict): 

53 self._config = CloudModelConfig() 

54 for key in config: 

55 setattr(self._config, key, config[key]) 

56 elif isinstance(config, CloudModelConfig): 

57 self._config = config 

58 else: 

59 raise RuntimeError(f'Expecting `None`, dictionary or `CloudModelConfig`, ' 

60 f'got {type(config)}: {config!r}.') 

61 

62 self._config.validate() 

63 self._config.freeze() 

64 

65 def config_info(self): 

66 """Report configuration parameters and version information. 

67 

68 Returns 

69 ------- 

70 OrderedDict 

71 """ 

72 config_info = OrderedDict() 

73 config_info['CloudModel_version'] = '%s' % version.__version__ 

74 config_info['CloudModel_sha'] = '%s' % version.__fingerprint__ 

75 for k, v in self._config.iteritems(): 

76 config_info[k] = v 

77 return config_info 

78 

79 def __call__(self, cloud_value, altitude): 

80 """Calculate the sky coverage due to clouds. 

81 

82 This is where we'd plug in Peter's cloud transparency maps and predictions. 

83 We could also try translating cloud transparency into a cloud extinction. 

84 For now, we're simply returning the cloud coverage that we already got from the database, 

85 but multiplied over the whole sky to provide a map. 

86 

87 Parameters 

88 ---------- 

89 cloud_value: float or efdData dict 

90 The value to give the clouds (XXX-units?). 

91 altitude: float, np.array, or targetDict 

92 Altitude of the output (arbitrary). 

93 

94 Returns 

95 ------- 

96 dict of np.ndarray 

97 Cloud transparency map values. 

98 """ 

99 if isinstance(cloud_value, dict): 

100 cloud_value = cloud_value[self.efd_cloud] 

101 if isinstance(altitude, dict): 

102 altitude = altitude[self.altcol] 

103 

104 model_cloud = np.zeros(len(altitude), float) + cloud_value 

105 return {'cloud': model_cloud}