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# -*- coding: utf-8 -*- 

2import logging 

3 

4rootLogger = logging.getLogger("starry") 

5rootLogger.addHandler(logging.StreamHandler()) 

6rootLogger.setLevel(logging.INFO) 

7 

8 

9class ConfigType(type): 

10 """Global config container.""" 

11 

12 @property 

13 def rootLogger(cls): 

14 return rootLogger 

15 

16 @property 

17 def rootHandler(cls): 

18 return rootLogger.handlers[0] 

19 

20 @property 

21 def lazy(cls): 

22 """Indicates whether or not the map evaluates things lazily. 

23 

24 If True, all attributes and method return values are unevaluated 

25 ``theano`` nodes. This is particularly useful for model building and 

26 integration with ``pymc3``. In lazy mode, call the ``.eval()`` method 

27 on any ``theano`` node to compute and return its numerical value. 

28 

29 If False, ``starry`` will automatically compile methods called by the 

30 user, and all methods will return numerical values as in the previous 

31 version of the code. 

32 """ 

33 return cls._lazy 

34 

35 @property 

36 def quiet(cls): 

37 """Indicates whether or not to suppress informational messages.""" 

38 return cls._quiet 

39 

40 @property 

41 def profile(cls): 

42 """Enable function profiling in lazy mode.""" 

43 return cls._profile 

44 

45 @quiet.setter 

46 def quiet(cls, value): 

47 cls._quiet = value 

48 if cls._quiet: 

49 cls.rootLogger.setLevel(logging.ERROR) 

50 else: 

51 cls.rootLogger.setLevel(logging.INFO) 

52 

53 @lazy.setter 

54 def lazy(cls, value): 

55 if (cls._allow_changes) or (cls._lazy == value): 

56 cls._lazy = value 

57 else: 

58 raise Exception( 

59 "Cannot change the `starry` config at this time. " 

60 "Config options should be set before instantiating any `starry` maps." 

61 ) 

62 

63 @profile.setter 

64 def profile(cls, value): 

65 if (cls._allow_changes) or (cls._profile == value): 

66 cls._profile = value 

67 else: 

68 raise Exception( 

69 "Cannot change the `starry` config at this time. " 

70 "Config options should be set before instantiating any `starry` maps." 

71 ) 

72 

73 def freeze(cls): 

74 cls._allow_changes = False 

75 

76 

77class config(metaclass=ConfigType): 

78 _allow_changes = True 

79 _lazy = True 

80 _quiet = False 

81 _profile = False