LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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 past.builtins import execfile
7 from builtins import object
8 
9 
10 def _checkMagMap(magmap):
11  '''
12  Checks the validity of a magnitude column map in AstrometryNetDataConfig.
13  '''
14  if not isinstance(magmap, dict):
15  raise RuntimeError('Mag maps must be dicts')
16  for k, v in magmap.items():
17  if not isinstance(k, str):
18  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad key \"%s\"' % str(k))
19  if not isinstance(v, str):
20  raise RuntimeError('Mag maps must be dicts mapping str->str: got bad value \"%s\"' % str(v))
21  if not (len(k) > 0 and len(v) > 0):
22  raise RuntimeError('Mag maps items must be non-empty: got bad values \"%s\" -> \"%s\"' %
23  (str(k), str(v)))
24 
25 
26 def _checkIndexList(indexList):
27  '''
28  Checks the validity of an index list in AstrometryNetDataConfig.
29  '''
30  if not isinstance(indexList, list):
31  raise RuntimeError('indexList config item must be a list')
32  for k in indexList:
33  if not isinstance(k, str):
34  raise RuntimeError('indexList config items must be strings: got bad one \"%s\"' % (str(k),))
35  if len(k) == 0:
36  raise RuntimeError('indexList config items must be non-empty strings')
37 
38 
39 def _checkMultiIndexList(multiIndexList):
40  '''
41  Checks the validity of a multi_index list in AstrometryNetDataConfig.
42  '''
43  if not isinstance(multiIndexList, list):
44  raise RuntimeError('multiIndexList config item must be a list')
45  for k in multiIndexList:
46  if not isinstance(k, list):
47  raise RuntimeError('multiIndexList config items must be lists: got bad one \"%s\"' % (str(k),))
48  if len(k) == 0:
49  raise RuntimeError('multiIndexList config items must be non-empty lists')
50  for kk in k:
51  if not isinstance(kk, str):
52  raise RuntimeError('multiIndexList config items must be strings: got bad one \"%s\"' %
53  (str(kk),))
54  if len(kk) == 0:
55  raise RuntimeError('multiIndexList config items must be non-empty strings')
56 
57 
59  '''
60  Astrometry.net data config object. This is a plain-python config
61  structure similar to pexConfig.
62 
63  For examples of use, see tests/astrometry_net_data/photocal/andConfig*.py
64 
65  '''
66  fields = [
67  ('idColumn', str, 'id', None,
68  'Column name (in the index files) of the ID number of reference sources'),
69  ('defaultMagColumn', str, 'mag', None,
70  'Default column name (in the index files) of the reference source mag'),
71  ('defaultMagErrorColumn', str, '', None,
72  'Default column name (in the index files) of the reference source mag error'),
73  ('starGalaxyColumn', str, None, None,
74  'Column name of the star/galaxy flag'),
75  ('variableColumn', str, None, None,
76  'Column name of the star variability flag'),
77  ('magErrorColumnMap', dict, {}, _checkMagMap,
78  'Mapping from LSST filter name to mag error column name'),
79  ('magColumnMap', dict, {}, _checkMagMap,
80  'Mapping from LSST filter name to mag column name'),
81  ('indexFiles', list, [], _checkIndexList,
82  'List of Astrometry.net index filenames'),
83  ('multiIndexFiles', list, [], _checkMultiIndexList,
84  'Astrometry.net multi-index filename lists. '
85  'Each item in this list must itself be a list of filenames. '
86  'The first filename is the file that contains the star kd-tree and tag-along tables. '
87  'Subsequent filenames must be files containing just the non-star index parts '
88  '(quads and code kd-tree). Note that this means you may need to repeat the first filename '
89  'if it contains a star kd-tree and the first index.'),
90  ('allowCache', bool, True, None,
91  'Allow use of cache for reading index file regions?'),
92  ]
93 
94  def load(self, fn):
95  # Hold on to your socks!
96  loc = dict(root=self)
97  execfile(fn, globals(), loc)
98 
99  def __init__(self, **kwargs):
100  self.setDefaults()
101  for k, v in kwargs.items():
102  self.set(k, v)
103 
104  def setDefaults(self):
105  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
106  self.set(nm, deef)
107 
108  def set(self, k, v):
109  setattr(self, k, v)
110 
111  def __setattr__(self, k, v):
112  for nm, typ, deef, check, doc in AstrometryNetDataConfig.fields:
113  if k != nm:
114  continue
115  if typ is not None:
116  if v is None:
117  pass
118  elif not isinstance(v, typ):
119  raise RuntimeError(('Attempted to set AstrometryNetDataConfig'
120  ' field \"%s\" to type %s, but need type %s') %
121  (nm, str(typ), str(type(v))))
122  if check is not None:
123  check(v)
124  # Looks ok; set it!
125  object.__setattr__(self, nm, v)
126  return
127 
128  raise RuntimeError('Attempted to set invalid AstrometryNetDataConfig'
129  ' field \"%s\"' % k)