astromodels.functions.function module

class astromodels.functions.function.CompositeFunction(operation, function_or_scalar_1, function_or_scalar_2=None)[source]

Bases: Function

evaluate()[source]
property expression
fast_call(x)

Call self as a function.

property functions

A list containing the function used to build this composite function

set_units(x_unit, y_unit, relaxed=False)[source]
to_dict(minimal=False)[source]
exception astromodels.functions.function.DesignViolation[source]

Bases: Exception

exception astromodels.functions.function.DocstringIsNotRaw[source]

Bases: ValueError

class astromodels.functions.function.Function(name: str | None = None, function_definition: str | None = None, parameters: Dict[str, Parameter] | None = None, properties: Dict[str, FunctionProperty] | None = None)[source]

Bases: Node

Generic Function class. Will be subclassed in Function1D, Function2D and Function3D.

property description: str

Returns a description for this function

duplicate()[source]

Create a copy of the current function with all the parameters equal to the current value

Returns:

a new copy of the function

evaluate_at(*args, **parameter_specification)[source]

Evaluate the function at the given x(,y,z) for the provided parameters, explicitly provided as part of the parameter_specification keywords.

Parameters:
  • *args

  • **parameter_specification

Returns:

property external_functions
fast_call(*args)[source]
property fixed_units

Returns the fixed units if has_fixed_units is True (see has_fixed_units)

Returns:

None, or a tuple (x_unit, y_unit)

property free_parameters: Dict[str, Parameter]

Returns a dictionary of free parameters for this function

Returns:

dictionary of free parameters

get_boundaries()[source]

Returns the boundaries of this function. By default there is no boundary, but subclasses can override this.

Returns:

a tuple of tuples containing the boundaries for each coordinate (ra_min, ra_max), (dec_min, dec_max)

get_total_spatial_integral(z)[source]

Returns the total integral (for 2D functions) or the integral over the spatial components (for 3D functions). needs to be implemented in subclasses.

Returns:

an array of values of the integral (same dimension as z).

has_fixed_units() bool[source]

Returns True if this function cannot change units, which is the case only for very specific functions (like models from foreign libraries like Xspec)

Returns:

True or False

property has_free_parameters: bool

Returns True or False depending on if any parameters are free

property has_properties: bool
property is_prior: bool

Returns False by default and must be overrided in the prior functions.

Returns:

True or False

property latex

Returns the LaTEX formula for this function

link and external function to this function for use in its evaluate method. the function can be from another source

the linked function can be accessed via self.external_functions[internal_name]

Parameters:
  • function ("Function") – the function to link.

  • internal_name (str) – the internal name used to access this in the external_functions dict

Returns:

property n_dim: int

number of dimensions for this function (1, 2 or 3)

Type:

return

of(another_function)[source]

Compose this function with another as in this_function(another_function(x)) :param another_function: another function to compose with the current one :return: a composite function instance

property parameters: Dict[str, Parameter]

Returns a dictionary of parameters

property properties: Dict[str, FunctionProperty] | None

return the properties of the function

Returns:

to_dict(minimal: bool = False)[source]

unlinks all external functions from this function

Returns:

unlink an external function

Parameters:

internal_name (str)

Returns:

property uuid

Returns the ID of the current function. The ID is used by the CompositeFunction class to keep track of the unique instances of each function. It should not be used by the user for any specific purpose.

Returns:

(none)

class astromodels.functions.function.Function1D(name: str | None = None, function_definition: str | None = None, parameters: Dict[str, Parameter] | None = None, properties: Dict[str, FunctionProperty] | None = None)[source]

Bases: Function

evaluate(x, *args, **kwargs)[source]
fast_call(x) ndarray[source]
get_boundaries()[source]

Returns the boundaries of this function. By default there is no boundary, but subclasses can override this.

Returns:

a tuple of tuples containing the boundaries for each coordinate (ra_min, ra_max), (dec_min, dec_max)

local_spectral_index(x, epsilon=1e-05)[source]

compute the local spectral index of the model at a given set of energies

Parameters:
  • x

  • epsilon

Returns:

set_units(in_x_unit, in_y_unit)[source]
property x_unit

The unit of the independent variable :return: a astropy.Unit instance

property y_unit: Unit

The unit of the dependent variable :return: a astropy.Unit instance

class astromodels.functions.function.Function2D(name: str | None = None, function_definition: str | None = None, parameters: Dict[str, Parameter] | None = None, properties: Dict[str, FunctionProperty] | None = None)[source]

Bases: Function

evaluate(x, y, *args)[source]
set_units(in_x_unit, in_y_unit, in_z_unit)[source]
property x_unit
property y_unit
property z_unit
class astromodels.functions.function.Function3D(name: str | None = None, function_definition: str | None = None, parameters: Dict[str, Parameter] | None = None, properties: Dict[str, FunctionProperty] | None = None)[source]

Bases: Function

evaluate(x, y, z, *args, **kwargs)[source]
set_units(in_x_unit, in_y_unit, in_z_unit, in_w_unit)[source]
property w_unit
property x_unit
property y_unit
property z_unit
exception astromodels.functions.function.FunctionDefinitionError[source]

Bases: Exception

exception astromodels.functions.function.FunctionInstanceError[source]

Bases: Exception

class astromodels.functions.function.FunctionMeta(name, bases, dct)[source]

Bases: type

A metaclass for the models, which takes care of setting up the parameters and the other attributes according to the definition given in the documentation of the function class.

static check_calling_sequence(name, function_name, function, possible_variables)[source]

Check the calling sequence for the function looking for the variables specified. One or more of the variables can be in the calling sequence. Note that the order of the variables will be enforced. It will also enforce that the first parameter in the calling sequence is called ‘self’.

Parameters:
  • function – the function to check

  • possible_variables – a list of variables to check, The order is important, and will be enforced

Returns:

a tuple containing the list of found variables, and the name of the other parameters in the calling

sequence

static class_init(instance, **kwargs)[source]
static parse_parameter_definition(func_name, par_name, definition) Parameter[source]
static parse_property_definition(func_name, prop_name, definition) FunctionProperty[source]
exception astromodels.functions.function.ModelAssertionViolation[source]

Bases: Exception

exception astromodels.functions.function.TestFailed[source]

Bases: Exception

exception astromodels.functions.function.TestSpecificationError[source]

Bases: Exception

exception astromodels.functions.function.UnknownFunction[source]

Bases: ValueError

exception astromodels.functions.function.UnknownParameter[source]

Bases: ValueError

exception astromodels.functions.function.WarningNoTests[source]

Bases: ImportWarning

exception astromodels.functions.function.WrongDimensionality[source]

Bases: Exception

astromodels.functions.function.get_function(function_name, composite_function_expression=None)[source]

Returns the function “name”, which must be among the known functions or a composite function.

Parameters:
  • function_name – the name of the function (use ‘composite’ if the function is a composite function)

  • composite_function_expression – composite function specification such as

((((powerlaw{1} + (sin{2} * 3)) + (sin{2} * 25)) - (powerlaw{1} * 16)) + (sin{2} ** 3.0)) :return: the an instance of the requested class

astromodels.functions.function.get_function_class(function_name)[source]

Return the type for the requested function

Parameters:

function_name – the function to return

Returns:

the type for that function (i.e., this is a class, not an instance)

astromodels.functions.function.list_functions()[source]