Parameter#
- class astropy.modeling.Parameter(name='', description='', default=None, unit=None, getter=None, setter=None, fixed=False, tied=False, min=None, max=None, bounds=None, prior=None, posterior=None, mag=False)[source]#
Bases:
object
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:
- name
str
parameter name
- description
str
parameter description
- default
float
orarray
default value to use for this parameter
- unit
Unit
if specified, the parameter will be in these units, and when the parameter is updated in future, it should be set to a
Quantity
that has equivalent units.- getter
callable()
orNone
, optional A function that wraps the raw (internal) value of the parameter when returning the value through the parameter proxy (e.g., a parameter may be stored internally as radians but returned to the user as degrees). The internal value is what is used for computations while the proxy value is what users will interact with (passing and viewing). If
getter
is notNone
, then asetter
must also be input.- setter
callable()
orNone
, optional A function that wraps any values assigned to this parameter; should be the inverse of
getter
. Ifsetter
is notNone
, then agetter
must also be input.- fixedbool
if True the parameter is not varied during fitting
- tied
callable()
orFalse
if callable is supplied it provides a way to link the value of this parameter to another parameter (or some other arbitrary function)
- min
float
the lower bound of a parameter
- max
float
the upper bound of a parameter
- bounds
tuple
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
- name
Attributes Summary
The minimum and maximum values of a parameter as a tuple.
Types of constraints a parameter can have.
Parameter default value.
Boolean indicating if the parameter is kept fixed during fitting.
Unit for the input value.
Return the internal unit the parameter uses for the internal value stored.
A value used as an upper bound when fitting a parameter.
A value used as a lower bound when fitting a parameter.
Return the model this parameter is associated with.
Parameter name.
This parameter, as a
Quantity
instance.The shape of this parameter's value array.
The size of this parameter's value array.
Standard deviation, if available from fit.
Indicates that this parameter is linked to another one.
The unit attached to this parameter, if any.
Used as a decorator to set the validator method for a
Parameter
.The unadorned value proxied by this parameter.
Methods Summary
copy
([name, description, default, unit, ...])Make a copy of this
Parameter
, overriding any of its core attributes in the process (or an exact copy).validate
(value)Run the validator on this parameter.
Attributes Documentation
- bounds#
The minimum and maximum values of a parameter as a tuple.
- 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.
- default#
Parameter default value.
- fixed#
Boolean indicating if the parameter is kept fixed during fitting.
- input_unit#
Unit for the input value.
- internal_unit#
Return the internal unit the parameter uses for the internal value stored.
- max#
A value used as an upper bound when fitting a parameter.
- min#
A value used as a lower bound when fitting a parameter.
- model#
Return the model this parameter is associated with.
- name#
Parameter name.
- posterior#
- prior#
- shape#
The shape of this parameter’s value array.
- size#
The size of this parameter’s value array.
- std#
Standard deviation, if available from fit.
- tied#
Indicates that this parameter is linked to another one.
A callable which provides the relationship of the two parameters.
- unit#
The unit attached to this parameter, if any.
On unbound parameters (i.e. parameters accessed through the model class, rather than a model instance) this is the required/ default unit for the parameter.
- 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 theModel
instance (remember, this is a method defined on aModel
), 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 anInputParameterError
should be raised, though this is not currently a requirement).Note: Using this method as a decorator will cause problems with pickling the model. An alternative is to assign the actual validator function to
Parameter._validator
(see examples in modeling).
- value#
The unadorned value proxied by this parameter.
Methods Documentation
- copy(name=None, description=None, default=None, unit=None, getter=None, setter=None, fixed=False, tied=False, min=None, max=None, bounds=None, prior=None, posterior=None)[source]#
Make a copy of this
Parameter
, overriding any of its core attributes in the process (or an exact copy).The arguments to this method are the same as those for the
Parameter
initializer. This simply returns a newParameter
instance with any or all of the attributes overridden, and so returns the equivalent of:Parameter(self.name, self.description, ...)