CompoundModel

class astropy.modeling.CompoundModel(op, left, right, name=None, inverse=None)[source]

Bases: astropy.modeling.Model

Base class for compound models.

While it can be used directly, the recommended way to combine models is through the model operators.

Attributes Summary

bounds A dict mapping parameter names to their upper and lower bounds as (min, max) tuples or [min, max] lists.
eqcons List of parameter equality constraints.
fittable bool(x) -> bool
fixed A dict mapping parameter names to their fixed constraint.
has_user_bounding_box A flag indicating whether or not a custom bounding_box has been assigned to this model by a user, via assignment to model.bounding_box.
ineqcons List of parameter inequality constraints.
input_units This property is used to indicate what units or sets of units the evaluate method expects, and returns a dictionary mapping inputs to units (or None if any units are accepted).
input_units_allow_dimensionless Allow dimensionless input (and corresponding output).
input_units_equivalencies
input_units_strict Enforce strict units on inputs to evaluate.
inverse Returns a new Model instance which performs the inverse transform, if an analytic inverse is defined for this model.
isleaf
model_set_axis The index of the model set axis–that is the axis of a parameter array that pertains to which model a parameter value pertains to–as specified when the model was initialized.
n_inputs
n_outputs
n_submodels Return the number of components in a single model, which is obviously 1.
param_names tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable’s items
parameters A flattened array of all parameter values in all parameter sets.
return_units This property is used to indicate what units or sets of units the output of evaluate should be in, and returns a dictionary mapping outputs to units (or None if any units are accepted).
submodel_names
tied A dict mapping parameter names to their tied constraint.

Methods Summary

__call__(self, \*args, \*\*kw) Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated.
both_inverses_exist(self) if both members of this compound model have inverses return True
evaluate(self, \*args, \*\*kwargs) Evaluate the model on some input variables.
has_inverse(self)
inputs_map(self) Map the names of the inputs to this ExpressionTree to the inputs to the leaf models.
outputs_map(self) Map the names of the outputs to this ExpressionTree to the outputs to the leaf models.
rename(self, name) Creates a copy of this model class with a new name, inputs or outputs.
render(self[, out, coords]) Evaluate a model at fixed positions, respecting the bounding_box.
traverse_postorder(self[, include_operator])

Attributes Documentation

bounds

A dict mapping parameter names to their upper and lower bounds as (min, max) tuples or [min, max] lists.

eqcons

List of parameter equality constraints.

fittable

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

fixed

A dict mapping parameter names to their fixed constraint.

has_user_bounding_box

A flag indicating whether or not a custom bounding_box has been assigned to this model by a user, via assignment to model.bounding_box.

ineqcons

List of parameter inequality constraints.

input_units

This property is used to indicate what units or sets of units the evaluate method expects, and returns a dictionary mapping inputs to units (or None if any units are accepted).

Model sub-classes can also use function annotations in evaluate to indicate valid input units, in which case this property should not be overridden since it will return the input units based on the annotations.

input_units_allow_dimensionless

Allow dimensionless input (and corresponding output). If this is True, input values to evaluate will gain the units specified in input_units. If this is a dictionary then it should map input name to a bool to allow dimensionless numbers for that input. Only has an effect if input_units is defined.

input_units_equivalencies
input_units_strict

Enforce strict units on inputs to evaluate. If this is set to True, input values to evaluate will be in the exact units specified by input_units. If the input quantities are convertible to input_units, they are converted. If this is a dictionary then it should map input name to a bool to set strict input units for that parameter.

inverse

Returns a new Model instance which performs the inverse transform, if an analytic inverse is defined for this model.

Even on models that don’t have an inverse defined, this property can be set with a manually-defined inverse, such a pre-computed or experimentally determined inverse (often given as a PolynomialModel, but not by requirement).

A custom inverse can be deleted with del model.inverse. In this case the model’s inverse is reset to its default, if a default exists (otherwise the default is to raise NotImplementedError).

Note to authors of Model subclasses: To define an inverse for a model simply override this property to return the appropriate model representing the inverse. The machinery that will make the inverse manually-overridable is added automatically by the base class.

isleaf
model_set_axis

The index of the model set axis–that is the axis of a parameter array that pertains to which model a parameter value pertains to–as specified when the model was initialized.

See the documentation on Model Sets for more details.

n_inputs
n_outputs
n_submodels

Return the number of components in a single model, which is obviously 1.

param_names

tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable’s items

If the argument is a tuple, the return value is the same object.

parameters

A flattened array of all parameter values in all parameter sets.

Fittable parameters maintain this list and fitters modify it.

return_units

This property is used to indicate what units or sets of units the output of evaluate should be in, and returns a dictionary mapping outputs to units (or None if any units are accepted).

Model sub-classes can also use function annotations in evaluate to indicate valid output units, in which case this property should not be overridden since it will return the return units based on the annotations.

submodel_names
tied

A dict mapping parameter names to their tied constraint.

Methods Documentation

__call__(self, *args, **kw)[source]

Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated.

both_inverses_exist(self)[source]

if both members of this compound model have inverses return True

evaluate(self, *args, **kwargs)[source]

Evaluate the model on some input variables.

has_inverse(self)[source]
inputs_map(self)[source]

Map the names of the inputs to this ExpressionTree to the inputs to the leaf models.

outputs_map(self)[source]

Map the names of the outputs to this ExpressionTree to the outputs to the leaf models.

rename(self, name)[source]

Creates a copy of this model class with a new name, inputs or outputs.

The new class is technically a subclass of the original class, so that instance and type checks will still work. For example:

>>> from astropy.modeling.models import Rotation2D
>>> SkyRotation = Rotation2D.rename('SkyRotation')
>>> SkyRotation
<class 'astropy.modeling.core.SkyRotation'>
Name: SkyRotation (Rotation2D)
N_inputs: 2
N_outputs: 2
Fittable parameters: ('angle',)
>>> issubclass(SkyRotation, Rotation2D)
True
>>> r = SkyRotation(90)
>>> isinstance(r, Rotation2D)
True
render(self, out=None, coords=None)[source]

Evaluate a model at fixed positions, respecting the bounding_box.

The key difference relative to evaluating the model directly is that this method is limited to a bounding box if the Model.bounding_box attribute is set.

Parameters:
out : numpy.ndarray, optional

An array that the evaluated model will be added to. If this is not given (or given as None), a new array will be created.

coords : array_like, optional

An array to be used to translate from the model’s input coordinates to the out array. It should have the property that self(coords) yields the same shape as out. If out is not specified, coords will be used to determine the shape of the returned array. If this is not provided (or None), the model will be evaluated on a grid determined by Model.bounding_box.

Returns:
out : numpy.ndarray

The model added to out if out is not None, or else a new array from evaluating the model over coords. If out and coords are both None, the returned array is limited to the Model.bounding_box limits. If Model.bounding_box is None, arr or coords must be passed.

Raises:
ValueError

If coords are not given and the the Model.bounding_box of this model is not set.

Examples

Efficient Model Rendering with Bounding Boxes

traverse_postorder(self, include_operator=False)[source]