- class craftutils.wrap.psfex.Parameter
Wraps individual parameters.
Since 4.0 Parameters are no longer descriptors and are based on a new implementation of the Parameter class. Parameters now (as of 4.0) store values locally (as instead previously in the associated model)
This class represents a model’s parameter (in a somewhat broad sense). It serves a number of purposes:
1) A type to be recognized by models and treated specially at class initialization (i.e., if it is found that there is a class definition of a Parameter, the model initializer makes a copy at the instance level).
2) Managing the handling of allowable parameter values and once defined, ensuring updates are consistent with the Parameter definition. This includes the optional use of units and quantities as well as transforming values to an internally consistent representation (e.g., from degrees to radians through the use of getters and setters).
3) Holding attributes of parameters relevant to fitting, such as whether the parameter may be varied in fitting, or whether there are constraints that must be satisfied.
See Parameters for more details.
Parameters¶
- namestr
parameter name
Warning
The fact that Parameter accepts
nameas an argument is an implementation detail, and should not be used directly. When defining a new Model class, parameter names are always automatically defined by the class attribute they’re assigned to.- descriptionstr
parameter description
- defaultfloat or array
default value to use for this parameter
- unit~astropy.units.Unit
if specified, the parameter will be in these units, and when the parameter is updated in future, it should be set to a
Quantitythat has equivalent units.- gettercallable
a function that wraps the raw (internal) value of the parameter when returning the value through the parameter proxy (eg. a parameter may be stored internally as radians but returned to the user as degrees)
- settercallable
a function that wraps any values assigned to this parameter; should be the inverse of getter
- fixedbool
if True the parameter is not varied during fitting
- tiedcallable or False
if callable is supplied it provides a way to link the value of this parameter to another parameter (or some other arbitrary function)
- minfloat
the lower bound of a parameter
- maxfloat
the upper bound of a parameter
- boundstuple
specify min and max as a single tuple–bounds may not be specified simultaneously with min or max
- magbool
Specify if the unit of the parameter can be a Magnitude unit or not
Public members¶
-
constraints =
('fixed', 'tied', 'bounds') Types of constraints a parameter can have. Excludes ‘min’ and ‘max’ which are just aliases for the first and second elements of the ‘bounds’ constraint (which is represented as a 2-tuple). ‘prior’ and ‘posterior’ are available for use by user fitters but are not used by any built-in fitters as of this writing.
-
Parameter(name=
'', description='', default=None, unit=None, ...) Initialize self. See help(type(self)) for accurate signature.
- __getitem__(key)
- __setitem__(key, value)
- __repr__()
Return repr(self).
- validate(value)
Run the validator on this parameter
-
copy(name=
None, description=None, default=None, unit=None, ...) Make a copy of this Parameter, overriding any of its core attributes in the process (or an exact copy).
- __add__(b, /)
Same as a + b.
- __radd__(b, /)
Same as a + b.
- __sub__(b, /)
Same as a - b.
- __rsub__(b, /)
Same as a - b.
- __mul__(b, /)
Same as a * b.
- __rmul__(b, /)
Same as a * b.
- __pow__(b, /)
Same as a ** b.
- __rpow__(b, /)
Same as a ** b.
- __truediv__(b, /)
Same as a / b.
- __rtruediv__(b, /)
Same as a / b.
- __eq__(b, /)
Same as a == b.
- __ne__(b, /)
Same as a != b.
- __lt__(b, /)
Same as a < b.
- __gt__(b, /)
Same as a > b.
- __le__(b, /)
Same as a <= b.
- __ge__(b, /)
Same as a >= b.
- __neg__()
Same as -a.
- __abs__()
Same as abs(a).
Properties¶
- property name
Parameter name
- property default
Parameter default value
- property value
The unadorned value proxied by this parameter.
- property unit
The unit attached to this parameter, if any.
- property internal_unit
Return the internal unit the parameter uses for the internal value stored
- property shape
The shape of this parameter’s value array.
- property size
The size of this parameter’s value array.
- property std
Standard deviation, if available from fit.
- property prior
- property posterior
- property fixed
Boolean indicating if the parameter is kept fixed during fitting.
- property tied
Indicates that this parameter is linked to another one.
- property bounds
The minimum and maximum values of a parameter as a tuple
- property min
A value used as a lower bound when fitting a parameter
- property max
A value used as an upper bound when fitting a parameter
- property validator
Used as a decorator to set the validator method for a Parameter. The validator method validates any value set for that parameter. It takes two arguments–
self, which refers to the Model instance (remember, this is a method defined on a Model), and the value being set for this parameter. The validator method’s return value is ignored, but it may raise an exception if the value set on the parameter is invalid (typically an InputParameterError should be raised, though this is not currently a requirement).
- property model
Return the model this parameter is associated with.