LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 from __future__ import absolute_import, division, print_function
7 
8 __all__ = ["AstrometryNetDataConfig"]
9 
10 from builtins import object
11 
12 
13 def _checkMagMap(magmap):
14  '''
15  Checks the validity of a magnitude column map in AstrometryNetDataConfig.
16  '''
17  if not isinstance(magmap, dict):
18  raise RuntimeError('Mag maps must be dicts')
19  for k, v in magmap.items():
20  if not isinstance(k, str):
21  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad key \"%s\"' % str(k))
22  if not isinstance(v, str):
23  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad value \"%s\"' % str(v))
24  if not (len(k) > 0 and len(v) > 0):
25  raise RuntimeError('Mag maps items must be non-empty: got bad values \"%s\" -> \"%s\"' %
26  (str(k), str(v)))
27 
28 
29 def _checkIndexList(indexList):
30  '''
31  Checks the validity of an index list in AstrometryNetDataConfig.
32  '''
33  if not isinstance(indexList, list):
34  raise RuntimeError('indexList config item must be a list')
35  for k in indexList:
36  if not isinstance(k, str):
37  raise RuntimeError('indexList config items must be strings: got bad one \"%s\"' % (str(k),))
38  if len(k) == 0:
39  raise RuntimeError('indexList config items must be non-empty strings')
40 
41 
42 def _checkMultiIndexList(multiIndexList):
43  '''
44  Checks the validity of a multi_index list in AstrometryNetDataConfig.
45  '''
46  if not isinstance(multiIndexList, list):
47  raise RuntimeError('multiIndexList config item must be a list')
48  for k in multiIndexList:
49  if not isinstance(k, list):
50  raise RuntimeError('multiIndexList config items must be lists: got bad one \"%s\"' % (str(k),))
51  if len(k) == 0:
52  raise RuntimeError('multiIndexList config items must be non-empty lists')
53  for kk in k:
54  if not isinstance(kk, str):
55  raise RuntimeError('multiIndexList config items must be strings: got bad one \"%s\"' %
56  (str(kk),))
57  if len(kk) == 0:
58  raise RuntimeError('multiIndexList config items must be non-empty strings')
59 
60 
62  '''
63  Astrometry.net data config object. This is a plain-python config
64  structure similar to pexConfig.
65 
66  For examples of use, see tests/astrometry_net_data/photocal/andConfig*.py
67 
68  '''
69  fields = [
70  ('idColumn', str, 'id', None,
71  'Column name (in the index files) of the ID number of reference sources'),
72  ('defaultMagColumn', str, 'mag', None,
73  'Default column name (in the index files) of the reference source mag'),
74  ('defaultMagErrorColumn', str, '', None,
75  'Default column name (in the index files) of the reference source mag error'),
76  ('starGalaxyColumn', str, None, None,
77  'Column name of the star/galaxy flag'),
78  ('variableColumn', str, None, None,
79  'Column name of the star variability flag'),
80  ('magErrorColumnMap', dict, {}, _checkMagMap,
81  'Mapping from LSST filter name to mag error column name'),
82  ('magColumnMap', dict, {}, _checkMagMap,
83  'Mapping from LSST filter name to mag column name'),
84  ('indexFiles', list, [], _checkIndexList,
85  'List of Astrometry.net index filenames'),
86  ('multiIndexFiles', list, [], _checkMultiIndexList,
87  'Astrometry.net multi-index filename lists. '
88  'Each item in this list must itself be a list of filenames. '
89  'The first filename is the file that contains the star kd-tree and tag-along tables. '
90  'Subsequent filenames must be files containing just the non-star index parts '
91  '(quads and code kd-tree). Note that this means you may need to repeat the first filename '
92  'if it contains a star kd-tree and the first index.'),
93  ('allowCache', bool, True, None,
94  'Allow use of cache for reading index file regions?'),
95  ]
96 
97  def load(self, fn):
98  # Hold on to your socks!
99  loc = dict(root=self)
100  with open(fn, 'rb') as file:
101  code = compile(file.read(), fn, 'exec')
102  exec(code, globals(), loc)
103 
104  def __init__(self, **kwargs):
105  self.setDefaults()
106  for k, v in kwargs.items():
107  self.set(k, v)
108 
109  def setDefaults(self):
110  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
111  self.set(nm, deef)
112 
113  def set(self, k, v):
114  setattr(self, k, v)
115 
116  def __setattr__(self, k, v):
117  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
118  if k != nm:
119  continue
120  if typ is not None:
121  if v is None:
122  pass
123  elif not isinstance(v, typ):
124  raise RuntimeError(('Attempted to set AstrometryNetDataConfig'
125  ' field \"%s\" to type %s, but need type %s') %
126  (nm, str(typ), str(type(v))))
127  if check is not None:
128  check(v)
129  # Looks ok; set it!
130  object.__setattr__(self, nm, v)
131  return
132 
133  raise RuntimeError('Attempted to set invalid AstrometryNetDataConfig'
134  ' field \"%s\"' % k)
table::Key< int > type
Definition: Detector.cc:167