2 We used to have AstrometryNetDataConfig() use the pex_config 3 mechanism, but we need nested lists, so we do this home-brew version 6 from __future__
import absolute_import, division, print_function
8 __all__ = [
"AstrometryNetDataConfig"]
10 from builtins
import object
13 def _checkMagMap(magmap):
15 Checks the validity of a magnitude column map in AstrometryNetDataConfig. 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\"' %
29 def _checkIndexList(indexList):
31 Checks the validity of an index list in AstrometryNetDataConfig. 33 if not isinstance(indexList, list):
34 raise RuntimeError(
'indexList config item must be a list')
36 if not isinstance(k, str):
37 raise RuntimeError(
'indexList config items must be strings: got bad one \"%s\"' % (
str(k),))
39 raise RuntimeError(
'indexList config items must be non-empty strings')
42 def _checkMultiIndexList(multiIndexList):
44 Checks the validity of a multi_index list in AstrometryNetDataConfig. 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),))
52 raise RuntimeError(
'multiIndexList config items must be non-empty lists')
54 if not isinstance(kk, str):
55 raise RuntimeError(
'multiIndexList config items must be strings: got bad one \"%s\"' %
58 raise RuntimeError(
'multiIndexList config items must be non-empty strings')
63 Astrometry.net data config object. This is a plain-python config 64 structure similar to pexConfig. 66 For examples of use, see tests/astrometry_net_data/photocal/andConfig*.py 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?'),
100 with open(fn,
'rb')
as file:
101 code = compile(file.read(), fn,
'exec')
102 exec(code, globals(), loc)
106 for k, v
in kwargs.items():
110 for nm, typ, deef, check, doc
in AstrometryNetDataConfig.fields:
117 for nm, typ, deef, check, doc
in AstrometryNetDataConfig.fields:
123 elif not isinstance(v, typ):
124 raise RuntimeError((
'Attempted to set AstrometryNetDataConfig' 125 ' field \"%s\" to type %s, but need type %s') %
127 if check
is not None:
130 object.__setattr__(self, nm, v)
133 raise RuntimeError(
'Attempted to set invalid AstrometryNetDataConfig'
def __setattr__(self, k, v)
def __init__(self, kwargs)