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:
namepython:str

parameter name

Warning

The fact that Parameter accepts name as 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.

descriptionpython:str

parameter description

defaultpython:float or array

default value to use for this parameter

unitUnit

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.

getterpython:callable()

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)

setterpython:callable()

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

tiedpython:callable() or python:False

if callable is supplied it provides a way to link the value of this parameter to another parameter (or some other arbitrary function)

minpython:float

the lower bound of a parameter

maxpython:float

the upper bound of a parameter

boundspython: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

Attributes Summary

bounds

The minimum and maximum values of a parameter as a tuple

constraints

Types of constraints a parameter can have.

default

Parameter default value

fixed

Boolean indicating if the parameter is kept fixed during fitting.

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

quantity

This parameter, as a Quantity instance.

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.

unit

The unit attached to this parameter, if any.

validator

Used as a decorator to set the validator method for a Parameter.

value

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.

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
quantity

This parameter, as a Quantity instance.

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 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).

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 new Parameter instance with any or all of the attributes overridden, and so returns the equivalent of:

Parameter(self.name, self.description, ...)
validate(value)[source]

Run the validator on this parameter