Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+aa97b6e50c,g1ec0fe41b4+f536777771,g1fd858c14a+a9301854fb,g35bb328faa+fcb1d3bbc8,g4af146b050+a5c07d5b1d,g4d2262a081+78f4f01b60,g53246c7159+fcb1d3bbc8,g56a49b3a55+9c12191793,g5a012ec0e7+3632fc3ff3,g60b5630c4e+ded28b650d,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8352419a5c+fcb1d3bbc8,g87b7deb4dc+7b42cf88bf,g8852436030+e5453db6e6,g89139ef638+ed4b5058f4,g8e3bb8577d+d38d73bdbd,g9125e01d80+fcb1d3bbc8,g94187f82dc+ded28b650d,g989de1cb63+ed4b5058f4,g9d31334357+ded28b650d,g9f33ca652e+50a8019d8c,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+d9fb1f8026,gb58c049af0+f03b321e39,gb89ab40317+ed4b5058f4,gcf25f946ba+e5453db6e6,gcf6002c91b+2a0c9e9e84,gd6cbbdb0b4+bb83cc51f8,gdd1046aedd+ded28b650d,gde0f65d7ad+66b3a48cb7,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf23fb2af72+b7cae620c0,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.16
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lsst.pex.config.comparison Namespace Reference

Functions

 getComparisonName (name1, name2)
 
 compareScalars (name, v1, v2, output, rtol=1e-8, atol=1e-8, dtype=None)
 
 compareConfigs (name, c1, c2, shortcut=True, rtol=1e-8, atol=1e-8, output=None)
 

Detailed Description

Helper functions for comparing `lsst.pex.config.Config` instancess.

Theses function should be use for any comparison in a `lsst.pex.Config.compare`
or `lsst.pex.config.Field._compare` implementation, as they take care of
writing messages as well as floating-point comparisons and shortcuts.

Function Documentation

◆ compareConfigs()

lsst.pex.config.comparison.compareConfigs ( name,
c1,
c2,
shortcut = True,
rtol = 1e-8,
atol = 1e-8,
output = None )
Compare two `lsst.pex.config.Config` instances for equality.

This function is a helper for `lsst.pex.config.Config.compare`.

Parameters
----------
name : `str`
    Name to use when reporting differences, typically created by
    `getComparisonName`.  This will always appear as the beginning of any
    messages reported via ``output``.
c1 : `lsst.pex.config.Config`
    Left-hand side config to compare.
c2 : `lsst.pex.config.Config`
    Right-hand side config to compare.
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. For example: `print`.

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

See Also
--------
lsst.pex.config.compareScalars

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

If ``c1`` or ``c2`` contain `~lsst.pex.config.RegistryField` or
`~lsst.pex.config.ConfigChoiceField` instances, *unselected*
`~lsst.pex.config.Config` instances will not be compared.

Definition at line 112 of file comparison.py.

112def compareConfigs(name, c1, c2, shortcut=True, rtol=1e-8, atol=1e-8, output=None):
113 """Compare two `lsst.pex.config.Config` instances for equality.
114
115 This function is a helper for `lsst.pex.config.Config.compare`.
116
117 Parameters
118 ----------
119 name : `str`
120 Name to use when reporting differences, typically created by
121 `getComparisonName`. This will always appear as the beginning of any
122 messages reported via ``output``.
123 c1 : `lsst.pex.config.Config`
124 Left-hand side config to compare.
125 c2 : `lsst.pex.config.Config`
126 Right-hand side config to compare.
127 shortcut : `bool`, optional
128 If `True`, return as soon as an inequality is found. Default is `True`.
129 rtol : `float`, optional
130 Relative tolerance for floating point comparisons.
131 atol : `float`, optional
132 Absolute tolerance for floating point comparisons.
133 output : callable, optional
134 A callable that takes a string, used (possibly repeatedly) to report
135 inequalities. For example: `print`.
136
137 Returns
138 -------
139 areEqual : `bool`
140 `True` when the two `lsst.pex.config.Config` instances are equal.
141 `False` if there is an inequality.
142
143 See Also
144 --------
145 lsst.pex.config.compareScalars
146
147 Notes
148 -----
149 Floating point comparisons are performed by `numpy.allclose`.
150
151 If ``c1`` or ``c2`` contain `~lsst.pex.config.RegistryField` or
152 `~lsst.pex.config.ConfigChoiceField` instances, *unselected*
153 `~lsst.pex.config.Config` instances will not be compared.
154 """
155 from .config import _typeStr
156
157 assert name is not None
158 if c1 is None:
159 if c2 is None:
160 return True
161 else:
162 if output is not None:
163 output(f"{name}: None != {c2!r}.")
164 return False
165 else:
166 if c2 is None:
167 if output is not None:
168 output(f"{name}: {c1!r} != None.")
169 return False
170 if type(c1) is not type(c2):
171 if output is not None:
172 output(f"{name}: config types do not match; {_typeStr(c1)} != {_typeStr(c2)}.")
173 return False
174 equal = True
175 for field in c1._fields.values():
176 result = field._compare(c1, c2, shortcut=shortcut, rtol=rtol, atol=atol, output=output)
177 if not result and shortcut:
178 return False
179 equal = equal and result
180 return equal

◆ compareScalars()

lsst.pex.config.comparison.compareScalars ( name,
v1,
v2,
output,
rtol = 1e-8,
atol = 1e-8,
dtype = None )
Compare two scalar values for equality.

This function is a helper for `lsst.pex.config.Config.compare`.

Parameters
----------
name : `str`
    Name to use when reporting differences, typically created by
    `getComparisonName`.  This will always appear as the beginning of any
    messages reported via ``output``.
v1 : object
    Left-hand side value to compare.
v2 : object
    Right-hand side value to compare.
output : callable or `None`
    A callable that takes a string, used (possibly repeatedly) to report
    inequalities (for example, `print`). Set to `None` to disable output.
rtol : `float`, optional
    Relative tolerance for floating point comparisons.
atol : `float`, optional
    Absolute tolerance for floating point comparisons.
dtype : class, optional
    Data type of values for comparison. May be `None` if values are not
    floating-point.

Returns
-------
areEqual : `bool`
    `True` if the values are equal, `False` if they are not.

See Also
--------
lsst.pex.config.compareConfigs

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

Definition at line 62 of file comparison.py.

62def compareScalars(name, v1, v2, output, rtol=1e-8, atol=1e-8, dtype=None):
63 """Compare two scalar values for equality.
64
65 This function is a helper for `lsst.pex.config.Config.compare`.
66
67 Parameters
68 ----------
69 name : `str`
70 Name to use when reporting differences, typically created by
71 `getComparisonName`. This will always appear as the beginning of any
72 messages reported via ``output``.
73 v1 : object
74 Left-hand side value to compare.
75 v2 : object
76 Right-hand side value to compare.
77 output : callable or `None`
78 A callable that takes a string, used (possibly repeatedly) to report
79 inequalities (for example, `print`). Set to `None` to disable output.
80 rtol : `float`, optional
81 Relative tolerance for floating point comparisons.
82 atol : `float`, optional
83 Absolute tolerance for floating point comparisons.
84 dtype : class, optional
85 Data type of values for comparison. May be `None` if values are not
86 floating-point.
87
88 Returns
89 -------
90 areEqual : `bool`
91 `True` if the values are equal, `False` if they are not.
92
93 See Also
94 --------
95 lsst.pex.config.compareConfigs
96
97 Notes
98 -----
99 Floating point comparisons are performed by `numpy.allclose`.
100 """
101 if v1 is None or v2 is None:
102 result = v1 == v2
103 elif dtype in (float, complex):
104 result = numpy.allclose(v1, v2, rtol=rtol, atol=atol) or (numpy.isnan(v1) and numpy.isnan(v2))
105 else:
106 result = v1 == v2
107 if not result and output is not None:
108 output(f"{name}: {v1!r} != {v2!r}")
109 return result
110
111

◆ getComparisonName()

lsst.pex.config.comparison.getComparisonName ( name1,
name2 )
Create a comparison name that is used for printed output of comparisons.

Parameters
----------
name1 : `str`
    Name of the first configuration.
name2 : `str`
    Name of the second configuration.

Returns
-------
name : `str`
    When ``name1`` and ``name2`` are equal, the returned name is
    simply one of the names. When they are different the returned name is
    formatted as ``"{name1} / {name2}"``.

Definition at line 40 of file comparison.py.

40def getComparisonName(name1, name2):
41 """Create a comparison name that is used for printed output of comparisons.
42
43 Parameters
44 ----------
45 name1 : `str`
46 Name of the first configuration.
47 name2 : `str`
48 Name of the second configuration.
49
50 Returns
51 -------
52 name : `str`
53 When ``name1`` and ``name2`` are equal, the returned name is
54 simply one of the names. When they are different the returned name is
55 formatted as ``"{name1} / {name2}"``.
56 """
57 if name1 != name2:
58 return f"{name1} / {name2}"
59 return name1
60
61