astromodels.core.parameter module

exception astromodels.core.parameter.CannotConvertValueToNewUnits[source]

Bases: RuntimeError

exception astromodels.core.parameter.CannotUnderstandUnit[source]

Bases: RuntimeError

class astromodels.core.parameter.IndependentVariable(name, value, unit, min_value=None, max_value=None, desc=None)[source]

Bases: ParameterBase

An independent variable like time or energy.

exception astromodels.core.parameter.IndependentVariableCannotBeLinked[source]

Bases: RuntimeError

exception astromodels.core.parameter.NotCallableOrErrorInCall[source]

Bases: RuntimeError

class astromodels.core.parameter.Parameter(name: str | None = None, value: float | None = None, min_value: float | None = None, max_value: float | None = None, delta: float | None = None, desc: str | None = None, free: bool = True, unit='', prior=None, is_normalization: bool = False, transformation: ParameterTransformation | None = None)[source]

Bases: ParameterBase

Implements a numerical parameter. Optionally the parameter can vary according to an auxiliary law (see below).

  • name – Name for the parameter

  • value – Initial value

  • min_value – minimum allowed value for the parameter (default: None)

  • max_value – maximum allowed value for the parameter (default: None)

  • delta – initial step used by some fitting engines (default: 0.1 * value)

  • desc – description of parameter (default: ‘’)

  • free – whether the parameter is free or not (default: True)

  • unit – the parameter units (default: dimensionless)

  • prior – the parameter’s prior (default: None)

  • is_normalization – True or False, wether the parameter is a normalization or not (default: False)

  • transformation – a transformation to be used between external value (the value the user interacts with) and the value the fitting/sampling engine interacts with (internal value). It is an instance of a class implementing a forward(external_value) and a backward(internal_value) method returning respectively the transformation of the external value in the internal value and viceversa. This is useful because for example the logarithm of a parameter with a large range of possible values (say from 1e-12 to 1e20) is handled much better by fitting engines than the raw value. The log transformation indeed makes the gradient much easier to compute.

add_auxiliary_variable(variable, law) None[source]

TODO describe function

  • variable

  • law


property auxiliary_variable: Tuple

Returns a tuple with the auxiliary variable and the law


tuple (variable, law)

property delta

Gets or sets the delta for the parameter

property fix

‘p.fix = True’ or ‘p.fix = False’.


Gets or sets whether the parameter is fixed or not. Use booleans, like

property free

‘ = True’ or ‘ = False’.


Gets or sets whether the parameter is free or not. Use booleans, like

property has_auxiliary_variable: bool

Returns whether the parameter is linked to an auxiliary variable


Check whether the current parameter has a defined prior


True or False

property is_normalization: bool
property prior

Gets or sets the current prior for this parameter. The prior must be a callable function accepting the current value of the parameter as input and returning the probability density as output. Set to None to remove prior.


Remove an existing auxiliary variable



Sets the prior for the parameter to a uniform prior between the current minimum and maximum, or a log-uniform prior between the current minimum and maximum.

NOTE: if the current minimum and maximum are not defined, the default bounds for the prior class will be used.

:param prior_class : the class to be used as prior (either Log_uniform_prior or Uniform_prior, or a class which provide a lower_bound and an upper_bound properties) :return: (none)


Returns the representation for serialization

class astromodels.core.parameter.ParameterBase(name: str, value: float, min_value: float | None = None, max_value: float | None = None, desc: str | None = None, unit: Unit = Unit(dimensionless), transformation: ParameterTransformation | None = None)[source]

Bases: Node

  • name – name for parameter

  • value – initial value

  • min_value – minimum

  • max_value – maximum

  • desc – description

  • unit – units (string or astropy.Unit)

  • transformation – a class which implements a .forward and a .backward method to transform forth and back from face value (the value exposed to the user) to the internal value (the value exposed to the fitting engine)

add_callback(callback) None[source]

Add a callback to the list of functions which are called immediately after the value of the parameter is changed. The callback must be a function accepting the current parameter as input. The return value of the callback is ignored. More than one callback can be specified. In that case, the callbacks will be called in the same order they have been entered.

property as_quantity: Quantity

Return the current value with its units (as an astropy.Quantity instance)


an instance of astropy.Quantity)

property bounds: Tuple[float]

Gets or sets the boundaries (minimum and maximum) for this parameter

property description: str | None

Return a description of this parameter


a string cointaining a description of the meaning of this parameter

duplicate() Parameter[source]

Returns an exact copy of the current parameter

empty_callbacks() None[source]

Remove all callbacks for this parameter


Returns the list of callbacks currently defined


property has_auxiliary_variable: bool
has_transformation() bool[source]
in_unit_of(unit, as_quantity=False) Quantity[source]

Return the current value transformed to the new units

  • unit – either an astropy.Unit instance, or a string which can be converted to an astropy.Unit instance, like “1 / (erg cm**2 s)”

  • as_quantity – if True, the method return an astropy.Quantity, if False just a floating point number. Default is False


either a floating point or a astropy.Quantity depending on the value of “as_quantity”

internal_to_external_delta(internal_value, internal_delta)[source]

Transform an interval from the internal to the external reference (through the transformation). It is useful if you have for example a confidence interval in internal reference and you want to transform it to the external reference

  • interval_value – value in internal reference

  • internal_delta – delta in internal reference


value and delta in external reference

property max_value: float

Gets or sets the maximum allowed value for the parameter

property min_value

Gets or sets the minimum allowed value for the parameter

remove_maximum() None[source]

Remove the maximum from this parameter (i.e., it becomes boundless in the positive direction)

remove_minimum() None[source]

Remove the minimum from this parameter (i.e., it becomes boundless in the negative direction)

remove_transformation() None[source]

remove any transform on the parameter

useful in bayesian fits where we do not care about transformations but want speed


restore_transformation() None[source]

restore the original transformation if it had been removed


property static_name: str

Returns a name which will never change, even if the name of the parameter does (for example in composite functions)

:return : the static name :type : str

to_dict(minimal=False) Dict[str, Any][source]

Returns the representation for serialization

property transformation: ParameterTransformation | None
property unit

Gets or sets the unit for the parameter

property value: float

Get and sets the current value for the parameter, with or without units

exception astromodels.core.parameter.ParameterMustHaveBounds[source]

Bases: RuntimeError

exception astromodels.core.parameter.SettingOutOfBounds[source]

Bases: RuntimeError

exception astromodels.core.parameter.WarningUnitsAreSlow[source]

Bases: Warning

astromodels.core.parameter.accept_quantity(input_type=<class 'float'>, allow_none=False)[source]

A class-method decorator which allow a given method (typically the set_value method) to receive both a astropy.Quantity or a simple float, but to be coded like it’s always receiving a pure float in the right units. This is to give a way to avoid the huge bottleneck that are astropy.units


input_type – the expected type for the input (float, int)

:param allow_none : whether to allow or not the passage of None as argument (default: False) :return: a decorator for the particular type

astromodels.core.parameter.turn_off_parameter_transforms() None[source]

deactivate parameter transforms temporarily :return: None