LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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:164