LSSTApplications  17.0+103,17.0+11,17.0+61,18.0.0+13,18.0.0+25,18.0.0+5,18.0.0+52,18.0.0-4-g68ffd23,18.1.0-1-g0001055+8,18.1.0-1-g03d53ef+1,18.1.0-1-g1349e88+28,18.1.0-1-g2505f39+22,18.1.0-1-g380d4d4+27,18.1.0-1-g5315e5e+1,18.1.0-1-g5e4b7ea+10,18.1.0-1-g7e8fceb+1,18.1.0-1-g85f8cd4+23,18.1.0-1-g9a6769a+13,18.1.0-1-ga1a4c1a+22,18.1.0-1-gd55f500+17,18.1.0-12-g42eabe8e+10,18.1.0-14-gd04256d+15,18.1.0-16-g430f6a53+1,18.1.0-17-gd2166b6e4,18.1.0-18-gb5d19ff+1,18.1.0-2-gfbf3545+7,18.1.0-2-gfefb8b5+16,18.1.0-3-g52aa583+13,18.1.0-3-g62b5e86+14,18.1.0-3-g8f4a2b1+17,18.1.0-3-g9bc06b8+7,18.1.0-3-gb69f684+9,18.1.0-4-g1ee41a7+1,18.1.0-5-g6dbcb01+13,18.1.0-5-gc286bb7+3,18.1.0-6-g48bdcd3+2,18.1.0-6-gd05e160+9,18.1.0-7-gc4d902b+2,18.1.0-7-gebc0338+8,18.1.0-9-gae7190a+10,w.2019.38
LSSTDataManagementBasePackage
astrometryNetDataConfig.py
Go to the documentation of this file.
1 '''
2 We used to have AstrometryNetDataConfig() use the pex_config
3 mechanism, but we need nested lists, so we do this home-brew version
4 instead.
5 '''
6 __all__ = ["AstrometryNetDataConfig"]
7 
8 
9 def _checkMagMap(magmap):
10  '''
11  Checks the validity of a magnitude column map in AstrometryNetDataConfig.
12  '''
13  if not isinstance(magmap, dict):
14  raise RuntimeError('Mag maps must be dicts')
15  for k, v in magmap.items():
16  if not isinstance(k, str):
17  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad key \"%s\"' % str(k))
18  if not isinstance(v, str):
19  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad value \"%s\"' % str(v))
20  if not (len(k) > 0 and len(v) > 0):
21  raise RuntimeError('Mag maps items must be non-empty: got bad values \"%s\" -> \"%s\"' %
22  (str(k), str(v)))
23 
24 
25 def _checkIndexList(indexList):
26  '''
27  Checks the validity of an index list in AstrometryNetDataConfig.
28  '''
29  if not isinstance(indexList, list):
30  raise RuntimeError('indexList config item must be a list')
31  for k in indexList:
32  if not isinstance(k, str):
33  raise RuntimeError('indexList config items must be strings: got bad one \"%s\"' % (str(k),))
34  if len(k) == 0:
35  raise RuntimeError('indexList config items must be non-empty strings')
36 
37 
38 def _checkMultiIndexList(multiIndexList):
39  '''
40  Checks the validity of a multi_index list in AstrometryNetDataConfig.
41  '''
42  if not isinstance(multiIndexList, list):
43  raise RuntimeError('multiIndexList config item must be a list')
44  for k in multiIndexList:
45  if not isinstance(k, list):
46  raise RuntimeError('multiIndexList config items must be lists: got bad one \"%s\"' % (str(k),))
47  if len(k) == 0:
48  raise RuntimeError('multiIndexList config items must be non-empty lists')
49  for kk in k:
50  if not isinstance(kk, str):
51  raise RuntimeError('multiIndexList config items must be strings: got bad one \"%s\"' %
52  (str(kk),))
53  if len(kk) == 0:
54  raise RuntimeError('multiIndexList config items must be non-empty strings')
55 
56 
58  '''
59  Astrometry.net data config object. This is a plain-python config
60  structure similar to pexConfig.
61 
62  For examples of use, see tests/astrometry_net_data/photocal/andConfig*.py
63 
64  '''
65  fields = [
66  ('idColumn', str, 'id', None,
67  'Column name (in the index files) of the ID number of reference sources'),
68  ('defaultMagColumn', str, 'mag', None,
69  'Default column name (in the index files) of the reference source mag'),
70  ('defaultMagErrorColumn', str, '', None,
71  'Default column name (in the index files) of the reference source mag error'),
72  ('starGalaxyColumn', str, None, None,
73  'Column name of the star/galaxy flag'),
74  ('variableColumn', str, None, None,
75  'Column name of the star variability flag'),
76  ('magErrorColumnMap', dict, {}, _checkMagMap,
77  'Mapping from LSST filter name to mag error column name'),
78  ('magColumnMap', dict, {}, _checkMagMap,
79  'Mapping from LSST filter name to mag column name'),
80  ('indexFiles', list, [], _checkIndexList,
81  'List of Astrometry.net index filenames'),
82  ('multiIndexFiles', list, [], _checkMultiIndexList,
83  'Astrometry.net multi-index filename lists. '
84  'Each item in this list must itself be a list of filenames. '
85  'The first filename is the file that contains the star kd-tree and tag-along tables. '
86  'Subsequent filenames must be files containing just the non-star index parts '
87  '(quads and code kd-tree). Note that this means you may need to repeat the first filename '
88  'if it contains a star kd-tree and the first index.'),
89  ('allowCache', bool, True, None,
90  'Allow use of cache for reading index file regions?'),
91  ]
92 
93  def load(self, fn):
94  # Hold on to your socks!
95  loc = dict(root=self)
96  with open(fn, 'rb') as file:
97  code = compile(file.read(), fn, 'exec')
98  exec(code, globals(), loc)
99 
100  def __init__(self, **kwargs):
101  self.setDefaults()
102  for k, v in kwargs.items():
103  self.set(k, v)
104 
105  def setDefaults(self):
106  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
107  self.set(nm, deef)
108 
109  def set(self, k, v):
110  setattr(self, k, v)
111 
112  def __setattr__(self, k, v):
113  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
114  if k != nm:
115  continue
116  if typ is not None:
117  if v is None:
118  pass
119  elif not isinstance(v, typ):
120  raise RuntimeError(('Attempted to set AstrometryNetDataConfig'
121  ' field \"%s\" to type %s, but need type %s') %
122  (nm, str(typ), str(type(v))))
123  if check is not None:
124  check(v)
125  # Looks ok; set it!
126  object.__setattr__(self, nm, v)
127  return
128 
129  raise RuntimeError('Attempted to set invalid AstrometryNetDataConfig'
130  ' field \"%s\"' % k)
table::Key< int > type
Definition: Detector.cc:167