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