LSST Applications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-10-gbfb87ad6+3307648ee3,21.0.0-15-gedb9d5423+47cba9fc36,21.0.0-2-g103fe59+fdf0863a2a,21.0.0-2-g1367e85+d38a93257c,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+d38a93257c,21.0.0-2-g7f82c8f+e682ffb718,21.0.0-2-g8dde007+d179fbfa6a,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+e682ffb718,21.0.0-2-ga63a54e+08647d4b1b,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0445ed2f95,21.0.0-2-gfc62afb+d38a93257c,21.0.0-27-gbbd0d29+ae871e0f33,21.0.0-28-g5fc5e037+feb0e9397b,21.0.0-3-g21c7a62+f4b9c0ff5c,21.0.0-3-g357aad2+57b0bddf0b,21.0.0-3-g4be5c26+d38a93257c,21.0.0-3-g65f322c+3f454acf5d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+9e4ef6332c,21.0.0-3-ge02ed75+4b120a55c4,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-g591bb35+4b120a55c4,21.0.0-4-gc004bbf+4911b9cd27,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-ge8fba5a+2b3a696ff9,21.0.0-5-gb155db7+2c5429117a,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g00874e7+c9fd7f7160,21.0.0-6-g4e60332+4b120a55c4,21.0.0-7-gc8ca178+40eb9cf840,21.0.0-8-gfbe0b4b+9e4ef6332c,21.0.0-9-g2fd488a+d83b7cd606,w.2021.05
LSST Data Management Base Package
Public Member Functions | Static Public Attributes | Properties | List of all members
lsst.obs.base.gen2to3.convertRepo.ConvertRepoSkyMapConfig Class Reference
Inheritance diagram for lsst.obs.base.gen2to3.convertRepo.ConvertRepoSkyMapConfig:
lsst.pex.config.config.Config lsst.pex.config.config.ConfigMeta

Public Member Functions

def __iter__ (self)
 
def keys (self)
 
def values (self)
 
def items (self)
 
def iteritems (self)
 
def itervalues (self)
 
def iterkeys (self)
 
def __contains__ (self, name)
 Return True if the specified field exists in this config. More...
 
def __new__ (cls, *args, **kw)
 
def __reduce__ (self)
 
def setDefaults (self)
 
def update (self, **kw)
 
def load (self, filename, root="config")
 
def loadFromStream (self, stream, root="config", filename=None)
 
def save (self, filename, root="config")
 
def saveToStream (self, outfile, root="config", skipImports=False)
 
def freeze (self)
 
def toDict (self)
 
def names (self)
 
def validate (self)
 
def formatHistory (self, name, **kwargs)
 
def __setattr__ (self, attr, value, at=None, label="assignment")
 
def __setattr__ (cls, name, value)
 
def __delattr__ (self, attr, at=None, label="deletion")
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __str__ (self)
 
def __repr__ (self)
 
def compare (self, other, shortcut=True, rtol=1E-8, atol=1E-8, output=None)
 
def __init_subclass__ (cls, **kwargs)
 

Static Public Attributes

 skyMap
 

Properties

 history = property(lambda x: x._history)
 

Detailed Description

Sub-config used to hold the parameters of a SkyMap.

Notes
-----
This config only needs to exist because we can't put a
`~lsst.pex.config.RegistryField` directly inside a
`~lsst.pex.config.ConfigDictField`.

It needs to have its only field named "skyMap" for compatibility with the
configuration of `lsst.pipe.tasks.MakeSkyMapTask`, which we want so we can
use one config file in an obs package to configure both.

This name leads to unfortunate repetition with the field named
"skymap" that holds it - "skyMap[name].skyMap" - but that seems
unavoidable.

Definition at line 213 of file convertRepo.py.

Member Function Documentation

◆ __contains__()

def lsst.pex.config.config.Config.__contains__ (   self,
  name 
)
inherited

Return True if the specified field exists in this config.

    @param[in] name  field name to test for

Definition at line 877 of file config.py.

877  def __contains__(self, name):
878  """!Return True if the specified field exists in this config
879 
880  @param[in] name field name to test for
881  """
882  return self._storage.__contains__(name)
883 

◆ __delattr__()

def lsst.pex.config.config.Config.__delattr__ (   self,
  attr,
  at = None,
  label = "deletion" 
)
inherited

Definition at line 1360 of file config.py.

1360  def __delattr__(self, attr, at=None, label="deletion"):
1361  if attr in self._fields:
1362  if at is None:
1363  at = getCallStack()
1364  self._fields[attr].__delete__(self, at=at, label=label)
1365  else:
1366  object.__delattr__(self, attr)
1367 
def getCallStack(skip=0)
Definition: callStack.py:175

◆ __eq__()

def lsst.pex.config.config.Config.__eq__ (   self,
  other 
)
inherited

Definition at line 1368 of file config.py.

1368  def __eq__(self, other):
1369  if type(other) == type(self):
1370  for name in self._fields:
1371  thisValue = getattr(self, name)
1372  otherValue = getattr(other, name)
1373  if isinstance(thisValue, float) and math.isnan(thisValue):
1374  if not math.isnan(otherValue):
1375  return False
1376  elif thisValue != otherValue:
1377  return False
1378  return True
1379  return False
1380 
table::Key< int > type
Definition: Detector.cc:163

◆ __init_subclass__()

def lsst.pex.config.config.Config.__init_subclass__ (   cls,
**  kwargs 
)
inherited
Run initialization for every subclass.

Specifically registers the subclass with a YAML representer
and YAML constructor (if pyyaml is available)

Definition at line 1438 of file config.py.

1438  def __init_subclass__(cls, **kwargs):
1439  """Run initialization for every subclass.
1440 
1441  Specifically registers the subclass with a YAML representer
1442  and YAML constructor (if pyyaml is available)
1443  """
1444  super().__init_subclass__(**kwargs)
1445 
1446  if not yaml:
1447  return
1448 
1449  yaml.add_representer(cls, _yaml_config_representer)
1450 

◆ __iter__()

def lsst.pex.config.config.Config.__iter__ (   self)
inherited
Iterate over fields.

Definition at line 782 of file config.py.

782  def __iter__(self):
783  """Iterate over fields.
784  """
785  return self._fields.__iter__()
786 

◆ __ne__()

def lsst.pex.config.config.Config.__ne__ (   self,
  other 
)
inherited

Definition at line 1381 of file config.py.

1381  def __ne__(self, other):
1382  return not self.__eq__(other)
1383 

◆ __new__()

def lsst.pex.config.config.Config.__new__ (   cls,
args,
**  kw 
)
inherited
Allocate a new `lsst.pex.config.Config` object.

In order to ensure that all Config object are always in a proper state
when handed to users or to derived `~lsst.pex.config.Config` classes,
some attributes are handled at allocation time rather than at
initialization.

This ensures that even if a derived `~lsst.pex.config.Config` class
implements ``__init__``, its author does not need to be concerned about
when or even the base ``Config.__init__`` should be called.

Definition at line 884 of file config.py.

884  def __new__(cls, *args, **kw):
885  """Allocate a new `lsst.pex.config.Config` object.
886 
887  In order to ensure that all Config object are always in a proper state
888  when handed to users or to derived `~lsst.pex.config.Config` classes,
889  some attributes are handled at allocation time rather than at
890  initialization.
891 
892  This ensures that even if a derived `~lsst.pex.config.Config` class
893  implements ``__init__``, its author does not need to be concerned about
894  when or even the base ``Config.__init__`` should be called.
895  """
896  name = kw.pop("__name", None)
897  at = kw.pop("__at", getCallStack())
898  # remove __label and ignore it
899  kw.pop("__label", "default")
900 
901  instance = object.__new__(cls)
902  instance._frozen = False
903  instance._name = name
904  instance._storage = {}
905  instance._history = {}
906  instance._imports = set()
907  # load up defaults
908  for field in instance._fields.values():
909  instance._history[field.name] = []
910  field.__set__(instance, field.default, at=at + [field.source], label="default")
911  # set custom default-overides
912  instance.setDefaults()
913  # set constructor overides
914  instance.update(__at=at, **kw)
915  return instance
916 
daf::base::PropertySet * set
Definition: fits.cc:912

◆ __reduce__()

def lsst.pex.config.config.Config.__reduce__ (   self)
inherited
Reduction for pickling (function with arguments to reproduce).

We need to condense and reconstitute the `~lsst.pex.config.Config`,
since it may contain lambdas (as the ``check`` elements) that cannot
be pickled.

Definition at line 917 of file config.py.

917  def __reduce__(self):
918  """Reduction for pickling (function with arguments to reproduce).
919 
920  We need to condense and reconstitute the `~lsst.pex.config.Config`,
921  since it may contain lambdas (as the ``check`` elements) that cannot
922  be pickled.
923  """
924  # The stream must be in characters to match the API but pickle
925  # requires bytes
926  stream = io.StringIO()
927  self.saveToStream(stream)
928  return (unreduceConfig, (self.__class__, stream.getvalue().encode()))
929 

◆ __repr__()

def lsst.pex.config.config.Config.__repr__ (   self)
inherited

Definition at line 1387 of file config.py.

1387  def __repr__(self):
1388  return "%s(%s)" % (
1389  _typeStr(self),
1390  ", ".join("%s=%r" % (k, v) for k, v in self.toDict().items() if v is not None)
1391  )
1392 
std::vector< SchemaItem< Flag > > * items

◆ __setattr__() [1/2]

def lsst.pex.config.config.ConfigMeta.__setattr__ (   cls,
  name,
  value 
)
inherited

Definition at line 189 of file config.py.

189  def __setattr__(cls, name, value):
190  if isinstance(value, Field):
191  value.name = name
192  cls._fields[name] = value
193  type.__setattr__(cls, name, value)
194 
195 

◆ __setattr__() [2/2]

def lsst.pex.config.config.Config.__setattr__ (   self,
  attr,
  value,
  at = None,
  label = "assignment" 
)
inherited
Set an attribute (such as a field's value).

Notes
-----
Unlike normal Python objects, `~lsst.pex.config.Config` objects are
locked such that no additional attributes nor properties may be added
to them dynamically.

Although this is not the standard Python behavior, it helps to protect
users from accidentally mispelling a field name, or trying to set a
non-existent field.

Definition at line 1328 of file config.py.

1328  def __setattr__(self, attr, value, at=None, label="assignment"):
1329  """Set an attribute (such as a field's value).
1330 
1331  Notes
1332  -----
1333  Unlike normal Python objects, `~lsst.pex.config.Config` objects are
1334  locked such that no additional attributes nor properties may be added
1335  to them dynamically.
1336 
1337  Although this is not the standard Python behavior, it helps to protect
1338  users from accidentally mispelling a field name, or trying to set a
1339  non-existent field.
1340  """
1341  if attr in self._fields:
1342  if self._fields[attr].deprecated is not None:
1343  fullname = _joinNamePath(self._name, self._fields[attr].name)
1344  warnings.warn(f"Config field {fullname} is deprecated: {self._fields[attr].deprecated}",
1345  FutureWarning, stacklevel=2)
1346  if at is None:
1347  at = getCallStack()
1348  # This allows Field descriptors to work.
1349  self._fields[attr].__set__(self, value, at=at, label=label)
1350  elif hasattr(getattr(self.__class__, attr, None), '__set__'):
1351  # This allows properties and other non-Field descriptors to work.
1352  return object.__setattr__(self, attr, value)
1353  elif attr in self.__dict__ or attr in ("_name", "_history", "_storage", "_frozen", "_imports"):
1354  # This allows specific private attributes to work.
1355  self.__dict__[attr] = value
1356  else:
1357  # We throw everything else.
1358  raise AttributeError("%s has no attribute %s" % (_typeStr(self), attr))
1359 

◆ __str__()

def lsst.pex.config.config.Config.__str__ (   self)
inherited

Definition at line 1384 of file config.py.

1384  def __str__(self):
1385  return str(self.toDict())
1386 

◆ compare()

def lsst.pex.config.config.Config.compare (   self,
  other,
  shortcut = True,
  rtol = 1E-8,
  atol = 1E-8,
  output = None 
)
inherited
Compare this configuration to another `~lsst.pex.config.Config` for
equality.

Parameters
----------
other : `lsst.pex.config.Config`
    Other `~lsst.pex.config.Config` object to compare against this
    config.
shortcut : `bool`, optional
    If `True`, return as soon as an inequality is found. Default is
    `True`.
rtol : `float`, optional
    Relative tolerance for floating point comparisons.
atol : `float`, optional
    Absolute tolerance for floating point comparisons.
output : callable, optional
    A callable that takes a string, used (possibly repeatedly) to
    report inequalities.

Returns
-------
isEqual : `bool`
    `True` when the two `lsst.pex.config.Config` instances are equal.
    `False` if there is an inequality.

See also
--------
lsst.pex.config.compareConfigs

Notes
-----
Unselected targets of `~lsst.pex.config.RegistryField` fields and
unselected choices of `~lsst.pex.config.ConfigChoiceField` fields
are not considered by this method.

Floating point comparisons are performed by `numpy.allclose`.

Definition at line 1393 of file config.py.

1393  def compare(self, other, shortcut=True, rtol=1E-8, atol=1E-8, output=None):
1394  """Compare this configuration to another `~lsst.pex.config.Config` for
1395  equality.
1396 
1397  Parameters
1398  ----------
1399  other : `lsst.pex.config.Config`
1400  Other `~lsst.pex.config.Config` object to compare against this
1401  config.
1402  shortcut : `bool`, optional
1403  If `True`, return as soon as an inequality is found. Default is
1404  `True`.
1405  rtol : `float`, optional
1406  Relative tolerance for floating point comparisons.
1407  atol : `float`, optional
1408  Absolute tolerance for floating point comparisons.
1409  output : callable, optional
1410  A callable that takes a string, used (possibly repeatedly) to
1411  report inequalities.
1412 
1413  Returns
1414  -------
1415  isEqual : `bool`
1416  `True` when the two `lsst.pex.config.Config` instances are equal.
1417  `False` if there is an inequality.
1418 
1419  See also
1420  --------
1421  lsst.pex.config.compareConfigs
1422 
1423  Notes
1424  -----
1425  Unselected targets of `~lsst.pex.config.RegistryField` fields and
1426  unselected choices of `~lsst.pex.config.ConfigChoiceField` fields
1427  are not considered by this method.
1428 
1429  Floating point comparisons are performed by `numpy.allclose`.
1430  """
1431  name1 = self._name if self._name is not None else "config"
1432  name2 = other._name if other._name is not None else "config"
1433  name = getComparisonName(name1, name2)
1434  return compareConfigs(name, self, other, shortcut=shortcut,
1435  rtol=rtol, atol=atol, output=output)
1436 
def compareConfigs(name, c1, c2, shortcut=True, rtol=1E-8, atol=1E-8, output=None)
Definition: comparison.py:111
def getComparisonName(name1, name2)
Definition: comparison.py:40

◆ formatHistory()

def lsst.pex.config.config.Config.formatHistory (   self,
  name,
**  kwargs 
)
inherited
Format a configuration field's history to a human-readable format.

Parameters
----------
name : `str`
    Name of a `~lsst.pex.config.Field` in this config.
kwargs
    Keyword arguments passed to `lsst.pex.config.history.format`.

Returns
-------
history : `str`
    A string containing the formatted history.

See also
--------
lsst.pex.config.history.format

Definition at line 1302 of file config.py.

1302  def formatHistory(self, name, **kwargs):
1303  """Format a configuration field's history to a human-readable format.
1304 
1305  Parameters
1306  ----------
1307  name : `str`
1308  Name of a `~lsst.pex.config.Field` in this config.
1309  kwargs
1310  Keyword arguments passed to `lsst.pex.config.history.format`.
1311 
1312  Returns
1313  -------
1314  history : `str`
1315  A string containing the formatted history.
1316 
1317  See also
1318  --------
1319  lsst.pex.config.history.format
1320  """
1321  import lsst.pex.config.history as pexHist
1322  return pexHist.format(self, name, **kwargs)
1323 

◆ freeze()

def lsst.pex.config.config.Config.freeze (   self)
inherited
Make this config, and all subconfigs, read-only.

Definition at line 1168 of file config.py.

1168  def freeze(self):
1169  """Make this config, and all subconfigs, read-only.
1170  """
1171  self._frozen = True
1172  for field in self._fields.values():
1173  field.freeze(self)
1174 

◆ items()

def lsst.pex.config.config.Config.items (   self)
inherited
Get configurations as ``(field name, field value)`` pairs.

Returns
-------
items : `list`
    List of tuples for each configuration. Tuple items are:

    0. Field name.
    1. Field value.

See also
--------
lsst.pex.config.Config.iteritems

Definition at line 815 of file config.py.

815  def items(self):
816  """Get configurations as ``(field name, field value)`` pairs.
817 
818  Returns
819  -------
820  items : `list`
821  List of tuples for each configuration. Tuple items are:
822 
823  0. Field name.
824  1. Field value.
825 
826  See also
827  --------
828  lsst.pex.config.Config.iteritems
829  """
830  return list(self._storage.items())
831 
daf::base::PropertyList * list
Definition: fits.cc:913

◆ iteritems()

def lsst.pex.config.config.Config.iteritems (   self)
inherited
Iterate over (field name, field value) pairs.

Yields
------
item : `tuple`
    Tuple items are:

    0. Field name.
    1. Field value.

See also
--------
lsst.pex.config.Config.items

Definition at line 832 of file config.py.

832  def iteritems(self):
833  """Iterate over (field name, field value) pairs.
834 
835  Yields
836  ------
837  item : `tuple`
838  Tuple items are:
839 
840  0. Field name.
841  1. Field value.
842 
843  See also
844  --------
845  lsst.pex.config.Config.items
846  """
847  return iter(self._storage.items())
848 

◆ iterkeys()

def lsst.pex.config.config.Config.iterkeys (   self)
inherited
Iterate over field names

Yields
------
key : `str`
    A field's key (attribute name).

See also
--------
lsst.pex.config.Config.values

Definition at line 863 of file config.py.

863  def iterkeys(self):
864  """Iterate over field names
865 
866  Yields
867  ------
868  key : `str`
869  A field's key (attribute name).
870 
871  See also
872  --------
873  lsst.pex.config.Config.values
874  """
875  return iter(self.storage.keys())
876 

◆ itervalues()

def lsst.pex.config.config.Config.itervalues (   self)
inherited
Iterate over field values.

Yields
------
value : obj
    A field value.

See also
--------
lsst.pex.config.Config.values

Definition at line 849 of file config.py.

849  def itervalues(self):
850  """Iterate over field values.
851 
852  Yields
853  ------
854  value : obj
855  A field value.
856 
857  See also
858  --------
859  lsst.pex.config.Config.values
860  """
861  return iter(self.storage.values())
862 

◆ keys()

def lsst.pex.config.config.Config.keys (   self)
inherited
Get field names.

Returns
-------
names : `list`
    List of `lsst.pex.config.Field` names.

See also
--------
lsst.pex.config.Config.iterkeys

Definition at line 787 of file config.py.

787  def keys(self):
788  """Get field names.
789 
790  Returns
791  -------
792  names : `list`
793  List of `lsst.pex.config.Field` names.
794 
795  See also
796  --------
797  lsst.pex.config.Config.iterkeys
798  """
799  return list(self._storage.keys())
800 

◆ load()

def lsst.pex.config.config.Config.load (   self,
  filename,
  root = "config" 
)
inherited
Modify this config in place by executing the Python code in a
configuration file.

Parameters
----------
filename : `str`
    Name of the configuration file. A configuration file is Python
    module.
root : `str`, optional
    Name of the variable in file that refers to the config being
    overridden.

    For example, the value of root is ``"config"`` and the file
    contains::

        config.myField = 5

    Then this config's field ``myField`` is set to ``5``.

    **Deprecated:** For backwards compatibility, older config files
    that use ``root="root"`` instead of ``root="config"`` will be
    loaded with a warning printed to `sys.stderr`. This feature will be
    removed at some point.

See also
--------
lsst.pex.config.Config.loadFromStream
lsst.pex.config.Config.save
lsst.pex.config.Config.saveFromStream

Definition at line 1003 of file config.py.

1003  def load(self, filename, root="config"):
1004  """Modify this config in place by executing the Python code in a
1005  configuration file.
1006 
1007  Parameters
1008  ----------
1009  filename : `str`
1010  Name of the configuration file. A configuration file is Python
1011  module.
1012  root : `str`, optional
1013  Name of the variable in file that refers to the config being
1014  overridden.
1015 
1016  For example, the value of root is ``"config"`` and the file
1017  contains::
1018 
1019  config.myField = 5
1020 
1021  Then this config's field ``myField`` is set to ``5``.
1022 
1023  **Deprecated:** For backwards compatibility, older config files
1024  that use ``root="root"`` instead of ``root="config"`` will be
1025  loaded with a warning printed to `sys.stderr`. This feature will be
1026  removed at some point.
1027 
1028  See also
1029  --------
1030  lsst.pex.config.Config.loadFromStream
1031  lsst.pex.config.Config.save
1032  lsst.pex.config.Config.saveFromStream
1033  """
1034  with open(filename, "r") as f:
1035  code = compile(f.read(), filename=filename, mode="exec")
1036  self.loadFromStream(stream=code, root=root, filename=filename)
1037 

◆ loadFromStream()

def lsst.pex.config.config.Config.loadFromStream (   self,
  stream,
  root = "config",
  filename = None 
)
inherited
Modify this Config in place by executing the Python code in the
provided stream.

Parameters
----------
stream : file-like object, `str`, or compiled string
    Stream containing configuration override code.
root : `str`, optional
    Name of the variable in file that refers to the config being
    overridden.

    For example, the value of root is ``"config"`` and the file
    contains::

        config.myField = 5

    Then this config's field ``myField`` is set to ``5``.

    **Deprecated:** For backwards compatibility, older config files
    that use ``root="root"`` instead of ``root="config"`` will be
    loaded with a warning printed to `sys.stderr`. This feature will be
    removed at some point.
filename : `str`, optional
    Name of the configuration file, or `None` if unknown or contained
    in the stream. Used for error reporting.

See also
--------
lsst.pex.config.Config.load
lsst.pex.config.Config.save
lsst.pex.config.Config.saveFromStream

Definition at line 1038 of file config.py.

1038  def loadFromStream(self, stream, root="config", filename=None):
1039  """Modify this Config in place by executing the Python code in the
1040  provided stream.
1041 
1042  Parameters
1043  ----------
1044  stream : file-like object, `str`, or compiled string
1045  Stream containing configuration override code.
1046  root : `str`, optional
1047  Name of the variable in file that refers to the config being
1048  overridden.
1049 
1050  For example, the value of root is ``"config"`` and the file
1051  contains::
1052 
1053  config.myField = 5
1054 
1055  Then this config's field ``myField`` is set to ``5``.
1056 
1057  **Deprecated:** For backwards compatibility, older config files
1058  that use ``root="root"`` instead of ``root="config"`` will be
1059  loaded with a warning printed to `sys.stderr`. This feature will be
1060  removed at some point.
1061  filename : `str`, optional
1062  Name of the configuration file, or `None` if unknown or contained
1063  in the stream. Used for error reporting.
1064 
1065  See also
1066  --------
1067  lsst.pex.config.Config.load
1068  lsst.pex.config.Config.save
1069  lsst.pex.config.Config.saveFromStream
1070  """
1071  with RecordingImporter() as importer:
1072  globals = {"__file__": filename}
1073  try:
1074  local = {root: self}
1075  exec(stream, globals, local)
1076  except NameError as e:
1077  if root == "config" and "root" in e.args[0]:
1078  if filename is None:
1079  # try to determine the file name; a compiled string
1080  # has attribute "co_filename",
1081  # an open file has attribute "name", else give up
1082  filename = getattr(stream, "co_filename", None)
1083  if filename is None:
1084  filename = getattr(stream, "name", "?")
1085  print(f"Config override file {filename!r}"
1086  " appears to use 'root' instead of 'config'; trying with 'root'", file=sys.stderr)
1087  local = {"root": self}
1088  exec(stream, globals, local)
1089  else:
1090  raise
1091 
1092  self._imports.update(importer.getModules())
1093 

◆ names()

def lsst.pex.config.config.Config.names (   self)
inherited
Get all the field names in the config, recursively.

Returns
-------
names : `list` of `str`
    Field names.

Definition at line 1223 of file config.py.

1223  def names(self):
1224  """Get all the field names in the config, recursively.
1225 
1226  Returns
1227  -------
1228  names : `list` of `str`
1229  Field names.
1230  """
1231  #
1232  # Rather than sort out the recursion all over again use the
1233  # pre-existing saveToStream()
1234  #
1235  with io.StringIO() as strFd:
1236  self.saveToStream(strFd, "config")
1237  contents = strFd.getvalue()
1238  strFd.close()
1239  #
1240  # Pull the names out of the dumped config
1241  #
1242  keys = []
1243  for line in contents.split("\n"):
1244  if re.search(r"^((assert|import)\s+|\s*$|#)", line):
1245  continue
1246 
1247  mat = re.search(r"^(?:config\.)?([^=]+)\s*=\s*.*", line)
1248  if mat:
1249  keys.append(mat.group(1))
1250 
1251  return keys
1252 

◆ save()

def lsst.pex.config.config.Config.save (   self,
  filename,
  root = "config" 
)
inherited
Save a Python script to the named file, which, when loaded,
reproduces this config.

Parameters
----------
filename : `str`
    Desination filename of this configuration.
root : `str`, optional
    Name to use for the root config variable. The same value must be
    used when loading (see `lsst.pex.config.Config.load`).

See also
--------
lsst.pex.config.Config.saveToStream
lsst.pex.config.Config.load
lsst.pex.config.Config.loadFromStream

Definition at line 1094 of file config.py.

1094  def save(self, filename, root="config"):
1095  """Save a Python script to the named file, which, when loaded,
1096  reproduces this config.
1097 
1098  Parameters
1099  ----------
1100  filename : `str`
1101  Desination filename of this configuration.
1102  root : `str`, optional
1103  Name to use for the root config variable. The same value must be
1104  used when loading (see `lsst.pex.config.Config.load`).
1105 
1106  See also
1107  --------
1108  lsst.pex.config.Config.saveToStream
1109  lsst.pex.config.Config.load
1110  lsst.pex.config.Config.loadFromStream
1111  """
1112  d = os.path.dirname(filename)
1113  with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=d) as outfile:
1114  self.saveToStream(outfile, root)
1115  # tempfile is hardcoded to create files with mode '0600'
1116  # for an explantion of these antics see:
1117  # https://stackoverflow.com/questions/10291131/how-to-use-os-umask-in-python
1118  umask = os.umask(0o077)
1119  os.umask(umask)
1120  os.chmod(outfile.name, (~umask & 0o666))
1121  # chmod before the move so we get quasi-atomic behavior if the
1122  # source and dest. are on the same filesystem.
1123  # os.rename may not work across filesystems
1124  shutil.move(outfile.name, filename)
1125 

◆ saveToStream()

def lsst.pex.config.config.Config.saveToStream (   self,
  outfile,
  root = "config",
  skipImports = False 
)
inherited
Save a configuration file to a stream, which, when loaded,
reproduces this config.

Parameters
----------
outfile : file-like object
    Destination file object write the config into. Accepts strings not
    bytes.
root
    Name to use for the root config variable. The same value must be
    used when loading (see `lsst.pex.config.Config.load`).
skipImports : `bool`, optional
    If `True` then do not include ``import`` statements in output,
    this is to support human-oriented output from ``pipetask`` where
    additional clutter is not useful.

See also
--------
lsst.pex.config.Config.save
lsst.pex.config.Config.load
lsst.pex.config.Config.loadFromStream

Definition at line 1126 of file config.py.

1126  def saveToStream(self, outfile, root="config", skipImports=False):
1127  """Save a configuration file to a stream, which, when loaded,
1128  reproduces this config.
1129 
1130  Parameters
1131  ----------
1132  outfile : file-like object
1133  Destination file object write the config into. Accepts strings not
1134  bytes.
1135  root
1136  Name to use for the root config variable. The same value must be
1137  used when loading (see `lsst.pex.config.Config.load`).
1138  skipImports : `bool`, optional
1139  If `True` then do not include ``import`` statements in output,
1140  this is to support human-oriented output from ``pipetask`` where
1141  additional clutter is not useful.
1142 
1143  See also
1144  --------
1145  lsst.pex.config.Config.save
1146  lsst.pex.config.Config.load
1147  lsst.pex.config.Config.loadFromStream
1148  """
1149  tmp = self._name
1150  self._rename(root)
1151  try:
1152  if not skipImports:
1153  self._collectImports()
1154  # Remove self from the set, as it is handled explicitly below
1155  self._imports.remove(self.__module__)
1156  configType = type(self)
1157  typeString = _typeStr(configType)
1158  outfile.write(f"import {configType.__module__}\n")
1159  outfile.write(f"assert type({root})=={typeString}, 'config is of type %s.%s instead of "
1160  f"{typeString}' % (type({root}).__module__, type({root}).__name__)\n")
1161  for imp in self._imports:
1162  if imp in sys.modules and sys.modules[imp] is not None:
1163  outfile.write(u"import {}\n".format(imp))
1164  self._save(outfile)
1165  finally:
1166  self._rename(tmp)
1167 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ setDefaults()

def lsst.pex.config.config.Config.setDefaults (   self)
inherited
Subclass hook for computing defaults.

Notes
-----
Derived `~lsst.pex.config.Config` classes that must compute defaults
rather than using the `~lsst.pex.config.Field` instances's defaults
should do so here. To correctly use inherited defaults,
implementations of ``setDefaults`` must call their base class's
``setDefaults``.

Reimplemented in lsst.pipe.tasks.scaleVariance.ScaleVarianceConfig, lsst.pipe.tasks.mocks.mockCoadd.MockCoaddConfig, lsst.pipe.tasks.ingestCuratedCalibs.IngestCuratedCalibsConfig, lsst.pipe.drivers.multiBandDriver.MultiBandDriverConfig, lsst.pipe.drivers.constructCalibs.FringeConfig, lsst.pipe.drivers.constructCalibs.DarkConfig, lsst.pipe.drivers.constructCalibs.CalibConfig, lsst.pipe.drivers.coaddDriver.CoaddDriverConfig, lsst.pipe.drivers.background.MaskObjectsConfig, lsst.obs.base.gen2to3.convertRepo.ConvertRepoConfig, lsst.meas.modelfit.psf.psfContinued.GeneralShapeletPsfApproxForcedConfig, lsst.meas.modelfit.psf.psfContinued.GeneralShapeletPsfApproxSingleFrameConfig, lsst.meas.modelfit.cmodel.cmodelContinued.CModelForcedConfig, lsst.meas.modelfit.cmodel.cmodelContinued.CModelSingleFrameConfig, lsst.meas.base.forcedMeasurement.ForcedMeasurementConfig, and lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementConfig.

Definition at line 930 of file config.py.

930  def setDefaults(self):
931  """Subclass hook for computing defaults.
932 
933  Notes
934  -----
935  Derived `~lsst.pex.config.Config` classes that must compute defaults
936  rather than using the `~lsst.pex.config.Field` instances's defaults
937  should do so here. To correctly use inherited defaults,
938  implementations of ``setDefaults`` must call their base class's
939  ``setDefaults``.
940  """
941  pass
942 

◆ toDict()

def lsst.pex.config.config.Config.toDict (   self)
inherited
Make a dictionary of field names and their values.

Returns
-------
dict_ : `dict`
    Dictionary with keys that are `~lsst.pex.config.Field` names.
    Values are `~lsst.pex.config.Field` values.

See also
--------
lsst.pex.config.Field.toDict

Notes
-----
This method uses the `~lsst.pex.config.Field.toDict` method of
individual fields. Subclasses of `~lsst.pex.config.Field` may need to
implement a ``toDict`` method for *this* method to work.

Definition at line 1199 of file config.py.

1199  def toDict(self):
1200  """Make a dictionary of field names and their values.
1201 
1202  Returns
1203  -------
1204  dict_ : `dict`
1205  Dictionary with keys that are `~lsst.pex.config.Field` names.
1206  Values are `~lsst.pex.config.Field` values.
1207 
1208  See also
1209  --------
1210  lsst.pex.config.Field.toDict
1211 
1212  Notes
1213  -----
1214  This method uses the `~lsst.pex.config.Field.toDict` method of
1215  individual fields. Subclasses of `~lsst.pex.config.Field` may need to
1216  implement a ``toDict`` method for *this* method to work.
1217  """
1218  dict_ = {}
1219  for name, field in self._fields.items():
1220  dict_[name] = field.toDict(self)
1221  return dict_
1222 

◆ update()

def lsst.pex.config.config.Config.update (   self,
**  kw 
)
inherited
Update values of fields specified by the keyword arguments.

Parameters
----------
kw
    Keywords are configuration field names. Values are configuration
    field values.

Notes
-----
The ``__at`` and ``__label`` keyword arguments are special internal
keywords. They are used to strip out any internal steps from the
history tracebacks of the config. Do not modify these keywords to
subvert a `~lsst.pex.config.Config` instance's history.

Examples
--------
This is a config with three fields:

>>> from lsst.pex.config import Config, Field
>>> class DemoConfig(Config):
...     fieldA = Field(doc='Field A', dtype=int, default=42)
...     fieldB = Field(doc='Field B', dtype=bool, default=True)
...     fieldC = Field(doc='Field C', dtype=str, default='Hello world')
...
>>> config = DemoConfig()

These are the default values of each field:

>>> for name, value in config.iteritems():
...     print(f"{name}: {value}")
...
fieldA: 42
fieldB: True
fieldC: 'Hello world'

Using this method to update ``fieldA`` and ``fieldC``:

>>> config.update(fieldA=13, fieldC='Updated!')

Now the values of each field are:

>>> for name, value in config.iteritems():
...     print(f"{name}: {value}")
...
fieldA: 13
fieldB: True
fieldC: 'Updated!'

Definition at line 943 of file config.py.

943  def update(self, **kw):
944  """Update values of fields specified by the keyword arguments.
945 
946  Parameters
947  ----------
948  kw
949  Keywords are configuration field names. Values are configuration
950  field values.
951 
952  Notes
953  -----
954  The ``__at`` and ``__label`` keyword arguments are special internal
955  keywords. They are used to strip out any internal steps from the
956  history tracebacks of the config. Do not modify these keywords to
957  subvert a `~lsst.pex.config.Config` instance's history.
958 
959  Examples
960  --------
961  This is a config with three fields:
962 
963  >>> from lsst.pex.config import Config, Field
964  >>> class DemoConfig(Config):
965  ... fieldA = Field(doc='Field A', dtype=int, default=42)
966  ... fieldB = Field(doc='Field B', dtype=bool, default=True)
967  ... fieldC = Field(doc='Field C', dtype=str, default='Hello world')
968  ...
969  >>> config = DemoConfig()
970 
971  These are the default values of each field:
972 
973  >>> for name, value in config.iteritems():
974  ... print(f"{name}: {value}")
975  ...
976  fieldA: 42
977  fieldB: True
978  fieldC: 'Hello world'
979 
980  Using this method to update ``fieldA`` and ``fieldC``:
981 
982  >>> config.update(fieldA=13, fieldC='Updated!')
983 
984  Now the values of each field are:
985 
986  >>> for name, value in config.iteritems():
987  ... print(f"{name}: {value}")
988  ...
989  fieldA: 13
990  fieldB: True
991  fieldC: 'Updated!'
992  """
993  at = kw.pop("__at", getCallStack())
994  label = kw.pop("__label", "update")
995 
996  for name, value in kw.items():
997  try:
998  field = self._fields[name]
999  field.__set__(self, value, at=at, label=label)
1000  except KeyError:
1001  raise KeyError("No field of name %s exists in config type %s" % (name, _typeStr(self)))
1002 

◆ validate()

def lsst.pex.config.config.Config.validate (   self)
inherited
Validate the Config, raising an exception if invalid.

Raises
------
lsst.pex.config.FieldValidationError
    Raised if verification fails.

Notes
-----
The base class implementation performs type checks on all fields by
calling their `~lsst.pex.config.Field.validate` methods.

Complex single-field validation can be defined by deriving new Field
types. For convenience, some derived `lsst.pex.config.Field`-types
(`~lsst.pex.config.ConfigField` and
`~lsst.pex.config.ConfigChoiceField`) are defined in `lsst.pex.config`
that handle recursing into subconfigs.

Inter-field relationships should only be checked in derived
`~lsst.pex.config.Config` classes after calling this method, and base
validation is complete.

Reimplemented in lsst.pipe.drivers.multiBandDriver.MultiBandDriverConfig, lsst.pipe.drivers.coaddDriver.CoaddDriverConfig, lsst.pipe.drivers.background.MaskObjectsConfig, lsst.meas.base.baseMeasurement.BaseMeasurementConfig, lsst.meas.algorithms.measureApCorr.MeasureApCorrConfig, lsst.meas.algorithms.gaussianPsfFactory.GaussianPsfFactory, lsst.fgcmcal.sedterms.Sedterm, and lsst.afw.geom.transformConfig.RadialTransformConfig.

Definition at line 1276 of file config.py.

1276  def validate(self):
1277  """Validate the Config, raising an exception if invalid.
1278 
1279  Raises
1280  ------
1281  lsst.pex.config.FieldValidationError
1282  Raised if verification fails.
1283 
1284  Notes
1285  -----
1286  The base class implementation performs type checks on all fields by
1287  calling their `~lsst.pex.config.Field.validate` methods.
1288 
1289  Complex single-field validation can be defined by deriving new Field
1290  types. For convenience, some derived `lsst.pex.config.Field`-types
1291  (`~lsst.pex.config.ConfigField` and
1292  `~lsst.pex.config.ConfigChoiceField`) are defined in `lsst.pex.config`
1293  that handle recursing into subconfigs.
1294 
1295  Inter-field relationships should only be checked in derived
1296  `~lsst.pex.config.Config` classes after calling this method, and base
1297  validation is complete.
1298  """
1299  for field in self._fields.values():
1300  field.validate(self)
1301 

◆ values()

def lsst.pex.config.config.Config.values (   self)
inherited
Get field values.

Returns
-------
values : `list`
    List of field values.

See also
--------
lsst.pex.config.Config.itervalues

Definition at line 801 of file config.py.

801  def values(self):
802  """Get field values.
803 
804  Returns
805  -------
806  values : `list`
807  List of field values.
808 
809  See also
810  --------
811  lsst.pex.config.Config.itervalues
812  """
813  return list(self._storage.values())
814 

Member Data Documentation

◆ skyMap

lsst.obs.base.gen2to3.convertRepo.ConvertRepoSkyMapConfig.skyMap
static
Initial value:
= skyMapRegistry.makeField(
doc="Type and parameters for the SkyMap itself.",
default="dodeca",
)

Definition at line 230 of file convertRepo.py.

Property Documentation

◆ history

lsst.pex.config.config.Config.history = property(lambda x: x._history)
staticinherited

Definition at line 1324 of file config.py.


The documentation for this class was generated from the following file: