YusifovKucuk2004¶

class gammapy.astro.population.YusifovKucuk2004(amplitude=1, a=1.64, b=4.01, r_1=0.55, **kwargs)[source]

Radial distribution of the surface density of pulsars in the galaxy - Yusifov & Kucuk 2004.

$f(r) = A \left ( \frac{r + r_1}{r_{\odot} + r_1} \right )^a \exp \left [-b \left( \frac{r - r_{\odot}}{r_{\odot} + r_1} \right ) \right ]$

Used by Faucher-Guigere and Kaspi. Density at r = 0 is nonzero.

Parameters: amplitude : float See model formula a : float See model formula b : float See model formula r_1 : float See model formula

Attributes Summary

 a amplitude b bounding_box A tuple of length n_inputs defining the bounding box limits, or None for no bounding box. bounds A dict mapping parameter names to their upper and lower bounds as (min, max) tuples or [min, max] lists. col_fit_deriv eqcons List of parameter equality constraints. evolved fit_deriv fittable 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. has_user_inverse A flag indicating whether or not a custom inverse model has been assigned to this model by a user, via assignment to model.inverse. 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. inputs inverse Returns a new Model instance which performs the inverse transform, if an analytic inverse is defined for this model. linear meta model_constraints 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 The number of inputs to this model. n_outputs The number of outputs from this model. name User-provided name for this model instance. outputs param_names param_sets Return parameters as a pset. parameter_constraints parameters A flattened array of all parameter values in all parameter sets. r_1 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). separable A flag indicating whether a model is separable. standard_broadcasting tied A dict mapping parameter names to their tied constraint. uses_quantity True if this model has been created with Quantity objects or if there are no parameters.

Methods Summary

 __call__(self, x[, model_set_axis, …]) Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated. copy(self) Return a copy of this model. deepcopy(self) Return a deep copy of this model. evaluate(r, amplitude, a, b, r_1) Evaluate model. n_submodels() Return the number of components in a single model, which is obviously 1. prepare_inputs(self, \*inputs[, …]) This method is used in __call__ to ensure that all the inputs to the model can be broadcast into compatible shapes (if one or both of them are input as arrays), particularly if there are more than one parameter sets. prepare_outputs(self, format_info, …) rename(name) Creates a copy of this model class with a new name. render(self[, out, coords]) Evaluate a model at fixed positions, respecting the bounding_box. strip_units_from_tree(self) sum_of_implicit_terms(self, \*args, \*\*kwargs) Evaluate the sum of any implicit model terms on some input variables. with_units_from_data(self, \*\*kwargs) Return an instance of the model which has units for which the parameter values are compatible with the data units specified. without_units_for_data(self, \*\*kwargs) Return an instance of the model for which the parameter values have been converted to the right units for the data, then the units have been stripped away.

Attributes Documentation

a
amplitude
b
bounding_box

A tuple of length n_inputs defining the bounding box limits, or None for no bounding box.

The default limits are given by a bounding_box property or method defined in the class body of a specific model. If not defined then this property just raises NotImplementedError by default (but may be assigned a custom value by a user). bounding_box can be set manually to an array-like object of shape (model.n_inputs, 2). For further usage, see Efficient Model Rendering with Bounding Boxes

The limits are ordered according to the numpy indexing convention, and are the reverse of the model input order, e.g. for inputs ('x', 'y', 'z'), bounding_box is defined:

• for 1D: (x_low, x_high)
• for 2D: ((y_low, y_high), (x_low, x_high))
• for 3D: ((z_low, z_high), (y_low, y_high), (x_low, x_high))

Examples

Setting the bounding_box limits for a 1D and 2D model:

>>> from astropy.modeling.models import Gaussian1D, Gaussian2D
>>> model_1d = Gaussian1D()
>>> model_2d = Gaussian2D(x_stddev=1, y_stddev=1)
>>> model_1d.bounding_box = (-5, 5)
>>> model_2d.bounding_box = ((-6, 6), (-5, 5))


Setting the bounding_box limits for a user-defined 3D custom_model:

>>> from astropy.modeling.models import custom_model
>>> def const3d(x, y, z, amp=1):
...    return amp
...
>>> Const3D = custom_model(const3d)
>>> model_3d = Const3D()
>>> model_3d.bounding_box = ((-6, 6), (-5, 5), (-4, 4))


To reset bounding_box to its default limits just delete the user-defined value–this will reset it back to the default defined on the class:

>>> del model_1d.bounding_box


To disable the bounding box entirely (including the default), set bounding_box to None:

>>> model_1d.bounding_box = None
>>> model_1d.bounding_box  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "astropy\modeling\core.py", line 980, in bounding_box
"No bounding box is defined for this model (note: the "
NotImplementedError: No bounding box is defined for this model (note:
the bounding box was explicitly disabled for this model; use del
model.bounding_box to restore the default bounding box, if one is
defined for this model).

bounds

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

col_fit_deriv = True
eqcons

List of parameter equality constraints.

evolved = True
fit_deriv = None
fittable = True
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.

has_user_inverse

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

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 = None
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.

inputs = ('x',)
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.

linear = False
meta
model_constraints = ('eqcons', 'ineqcons')
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

The number of inputs to this model.

Equivalent to len(model.inputs).

n_outputs

The number of outputs from this model.

Equivalent to len(model.outputs).

name

User-provided name for this model instance.

outputs = ('y',)
param_names = ('amplitude', 'a', 'b', 'r_1')
param_sets

Return parameters as a pset.

This is a list with one item per parameter set, which is an array of that parameter’s values across all parameter sets, with the last axis associated with the parameter set.

parameter_constraints = ('fixed', 'tied', 'bounds', 'prior', 'posterior')
parameters

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

Fittable parameters maintain this list and fitters modify it.

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

separable

A flag indicating whether a model is separable.

standard_broadcasting = True
tied

A dict mapping parameter names to their tied constraint.

uses_quantity

True if this model has been created with Quantity objects or if there are no parameters.

This can be used to determine if this model should be evaluated with Quantity or regular floats.

Methods Documentation

__call__(self, x, model_set_axis=None, with_bounding_box=False, fill_value=nan, equivalencies=None)

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

copy(self)

Return a copy of this model.

Uses a deep copy so that all model attributes, including parameter values, are copied as well.

deepcopy(self)

Return a deep copy of this model.

static evaluate(r, amplitude, a, b, r_1)[source]

Evaluate model.

classmethod n_submodels()

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

prepare_inputs(self, *inputs, model_set_axis=None, equivalencies=None, **kwargs)

This method is used in __call__ to ensure that all the inputs to the model can be broadcast into compatible shapes (if one or both of them are input as arrays), particularly if there are more than one parameter sets. This also makes sure that (if applicable) the units of the input will be compatible with the evaluate method.

prepare_outputs(self, format_info, *outputs, **kwargs)
classmethod rename(name)

Creates a copy of this model class with a new name.

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 '__main__.SkyRotation'>
Name: SkyRotation (Rotation2D)
Inputs: ('x', 'y')
Outputs: ('x', 'y')
Fittable parameters: ('angle',)
>>> issubclass(SkyRotation, Rotation2D)
True
>>> r = SkyRotation(90)
>>> isinstance(r, Rotation2D)
True

render(self, out=None, coords=None)

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

strip_units_from_tree(self)
sum_of_implicit_terms(self, *args, **kwargs)

Evaluate the sum of any implicit model terms on some input variables. This includes any fixed terms used in evaluating a linear model that do not have corresponding parameters exposed to the user. The prototypical case is astropy.modeling.functional_models.Shift, which corresponds to a function y = a + bx, where b=1 is intrinsically fixed by the type of model, such that sum_of_implicit_terms(x) == x. This method is needed by linear fitters to correct the dependent variable for the implicit term(s) when solving for the remaining terms (ie. a = y - bx).

with_units_from_data(self, **kwargs)

Return an instance of the model which has units for which the parameter values are compatible with the data units specified.

The input and output Quantity objects should be given as keyword arguments.

Notes

This method is needed in order to be able to fit models with units in the parameters, since we need to temporarily strip away the units from the model during the fitting (which might be done by e.g. scipy functions).

The units that the parameters will gain are not necessarily the units of the input data, but are derived from them. Model subclasses that want fitting to work in the presence of quantities need to define a _parameter_units_for_data_units method that takes the input and output units (as two dictionaries) and returns a dictionary giving the target units for each parameter.

without_units_for_data(self, **kwargs)

Return an instance of the model for which the parameter values have been converted to the right units for the data, then the units have been stripped away.

The input and output Quantity objects should be given as keyword arguments.

Notes

This method is needed in order to be able to fit models with units in the parameters, since we need to temporarily strip away the units from the model during the fitting (which might be done by e.g. scipy functions).

The units that the parameters should be converted to are not necessarily the units of the input data, but are derived from them. Model subclasses that want fitting to work in the presence of quantities need to define a _parameter_units_for_data_units method that takes the input and output units (as two dictionaries) and returns a dictionary giving the target units for each parameter.