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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

''' 

We used to have AstrometryNetDataConfig() use the pex_config 

mechanism, but we need nested lists, so we do this home-brew version 

instead. 

''' 

from __future__ import absolute_import, division, print_function 

 

__all__ = ["AstrometryNetDataConfig"] 

 

from builtins import object 

 

 

def _checkMagMap(magmap): 

''' 

Checks the validity of a magnitude column map in AstrometryNetDataConfig. 

''' 

17 ↛ 18line 17 didn't jump to line 18, because the condition on line 17 was never true if not isinstance(magmap, dict): 

raise RuntimeError('Mag maps must be dicts') 

for k, v in magmap.items(): 

20 ↛ 21line 20 didn't jump to line 21, because the condition on line 20 was never true if not isinstance(k, str): 

raise RuntimeError('Mag maps must be dicts mapping str->str: got bad key \"%s\"' % str(k)) 

22 ↛ 23line 22 didn't jump to line 23, because the condition on line 22 was never true if not isinstance(v, str): 

raise RuntimeError('Mag maps must be dicts mapping str->str: got bad value \"%s\"' % str(v)) 

24 ↛ 25line 24 didn't jump to line 25, because the condition on line 24 was never true if not (len(k) > 0 and len(v) > 0): 

raise RuntimeError('Mag maps items must be non-empty: got bad values \"%s\" -> \"%s\"' % 

(str(k), str(v))) 

 

 

def _checkIndexList(indexList): 

''' 

Checks the validity of an index list in AstrometryNetDataConfig. 

''' 

33 ↛ 34line 33 didn't jump to line 34, because the condition on line 33 was never true if not isinstance(indexList, list): 

raise RuntimeError('indexList config item must be a list') 

for k in indexList: 

36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true if not isinstance(k, str): 

raise RuntimeError('indexList config items must be strings: got bad one \"%s\"' % (str(k),)) 

38 ↛ 39line 38 didn't jump to line 39, because the condition on line 38 was never true if len(k) == 0: 

raise RuntimeError('indexList config items must be non-empty strings') 

 

 

def _checkMultiIndexList(multiIndexList): 

''' 

Checks the validity of a multi_index list in AstrometryNetDataConfig. 

''' 

46 ↛ 47line 46 didn't jump to line 47, because the condition on line 46 was never true if not isinstance(multiIndexList, list): 

raise RuntimeError('multiIndexList config item must be a list') 

for k in multiIndexList: 

49 ↛ 50line 49 didn't jump to line 50, because the condition on line 49 was never true if not isinstance(k, list): 

raise RuntimeError('multiIndexList config items must be lists: got bad one \"%s\"' % (str(k),)) 

51 ↛ 52line 51 didn't jump to line 52, because the condition on line 51 was never true if len(k) == 0: 

raise RuntimeError('multiIndexList config items must be non-empty lists') 

for kk in k: 

54 ↛ 55line 54 didn't jump to line 55, because the condition on line 54 was never true if not isinstance(kk, str): 

raise RuntimeError('multiIndexList config items must be strings: got bad one \"%s\"' % 

(str(kk),)) 

57 ↛ 58line 57 didn't jump to line 58, because the condition on line 57 was never true if len(kk) == 0: 

raise RuntimeError('multiIndexList config items must be non-empty strings') 

 

 

class AstrometryNetDataConfig(object): 

''' 

Astrometry.net data config object. This is a plain-python config 

structure similar to pexConfig. 

 

For examples of use, see tests/astrometry_net_data/photocal/andConfig*.py 

 

''' 

fields = [ 

('idColumn', str, 'id', None, 

'Column name (in the index files) of the ID number of reference sources'), 

('defaultMagColumn', str, 'mag', None, 

'Default column name (in the index files) of the reference source mag'), 

('defaultMagErrorColumn', str, '', None, 

'Default column name (in the index files) of the reference source mag error'), 

('starGalaxyColumn', str, None, None, 

'Column name of the star/galaxy flag'), 

('variableColumn', str, None, None, 

'Column name of the star variability flag'), 

('magErrorColumnMap', dict, {}, _checkMagMap, 

'Mapping from LSST filter name to mag error column name'), 

('magColumnMap', dict, {}, _checkMagMap, 

'Mapping from LSST filter name to mag column name'), 

('indexFiles', list, [], _checkIndexList, 

'List of Astrometry.net index filenames'), 

('multiIndexFiles', list, [], _checkMultiIndexList, 

'Astrometry.net multi-index filename lists. ' 

'Each item in this list must itself be a list of filenames. ' 

'The first filename is the file that contains the star kd-tree and tag-along tables. ' 

'Subsequent filenames must be files containing just the non-star index parts ' 

'(quads and code kd-tree). Note that this means you may need to repeat the first filename ' 

'if it contains a star kd-tree and the first index.'), 

('allowCache', bool, True, None, 

'Allow use of cache for reading index file regions?'), 

] 

 

def load(self, fn): 

# Hold on to your socks! 

loc = dict(root=self) 

with open(fn, 'rb') as file: 

code = compile(file.read(), fn, 'exec') 

exec(code, globals(), loc) 

 

def __init__(self, **kwargs): 

self.setDefaults() 

106 ↛ 107line 106 didn't jump to line 107, because the loop on line 106 never started for k, v in kwargs.items(): 

self.set(k, v) 

 

def setDefaults(self): 

for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields: 

self.set(nm, deef) 

 

def set(self, k, v): 

setattr(self, k, v) 

 

def __setattr__(self, k, v): 

117 ↛ 133line 117 didn't jump to line 133, because the loop on line 117 didn't complete for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields: 

if k != nm: 

continue 

120 ↛ 127line 120 didn't jump to line 127, because the condition on line 120 was never false if typ is not None: 

if v is None: 

pass 

123 ↛ 124line 123 didn't jump to line 124, because the condition on line 123 was never true elif not isinstance(v, typ): 

raise RuntimeError(('Attempted to set AstrometryNetDataConfig' 

' field \"%s\" to type %s, but need type %s') % 

(nm, str(typ), str(type(v)))) 

if check is not None: 

check(v) 

# Looks ok; set it! 

object.__setattr__(self, nm, v) 

return 

 

raise RuntimeError('Attempted to set invalid AstrometryNetDataConfig' 

' field \"%s\"' % k)