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
setConfigFromEups.py
Go to the documentation of this file.
1 from eups import Eups
2 from fnmatch import fnmatch
3 
4 from lsst.pipe.base.argumentParser import setDottedAttr
5 
6 __all__ = ["getAndVersion", "setAstrometryConfigFromEups", "setPhotocalConfigFromEups", "setConfigFromEups",]
7 
8 def getEups():
9  """Return a cached eups instance"""
10  try:
11  return getEups._eups
12  except AttributeError:
13  getEups._eups = Eups()
14  return getEups._eups
15 
16 
18  """Return the version of astrometry_net_data in use"""
19  return getEups().findSetupVersion("astrometry_net_data")[0]
20 
21 
22 def setAstrometryConfigFromEups(config, menu):
23  """Set the astrometry configuration according to the astrometry_net_data being used
24 
25  The menu is a dict mapping the astrometry_net_data version to a dict of configuration
26  values to apply. The menu key may also be a glob. For example:
27  menu = { "ps1*": {}, # No changes
28  "ps1-without-y": { "solver.filterMap": {"y": "z"} }, # No y-band in this specific version
29  "sdss*": { "solver.filterMap": {"y": "z"} }, # No y-band, use z instead
30  "2mass*": { "solver.filterMap": {"y": "J"} }, # No y-band, use J instead
31  }
32  """
33  version = getAndVersion()
34 
35  if version in menu:
36  selected = menu[version]
37  else:
38  # Treat keys in menu as glob; see if any match
39  matchList = [key for key in menu if fnmatch(version, key)]
40  if len(matchList) > 1:
41  raise RuntimeError("Multiple menu keys match astrometry_net_data version %s: %s" %
42  (version, matchList))
43  if len(matchList) == 0:
44  raise RuntimeError("No menu key matches astrometry_net_data version %s" % version)
45  selected = menu[matchList.pop()]
46  for name, value in selected.iteritems():
47  setDottedAttr(config, name, value)
48 
49 
51  """Set the photocal configuration according to the astrometry_net_data being used"""
52  config.photoCatName = getAndVersion()
53 
54 
55 def setConfigFromEups(photocalConfig=None, astrometryConfig=None, astrometryMenu=None):
56  """Set the astrometry and photocal configuration according to the astrometry_net_data being used
57 
58  The 'astrometryMenu' is as defined for the 'menu' parameter for 'setAstrometryConfigFromEups'.
59  """
60  if photocalConfig:
61  setPhotocalConfigFromEups(photocalConfig)
62  if astrometryConfig:
63  if astrometryMenu is None:
64  raise RuntimeError("No astrometryMenu provided for astrometryConfig")
65  setAstrometryConfigFromEups(astrometryConfig, astrometryMenu)
def setDottedAttr
Like setattr, but accepts hierarchical names, e.g.