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