LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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.