Constant#

class sunkit_spex.models.scaling.Constant(constant=<Quantity 1.>)[source]#

Bases: FittableModel

A model which returns an array with dimensions n-1 of the input dimension populated with a constant value, of whichever units specified by the user.

Parameters:
  • energy_edges – Energy edges associated with input spectrum

  • constant – A constant value which populates the output array

Examples

import astropy.units as u
import numpy as np
import matplotlib.pyplot as plt

from sunkit_spex.models.scaling import Constant
from sunkit_spex.models.models import StraightLineModel

y_units = u.ph*u.keV**-1*u.s**-1
x_units = u.keV

ph_energies = np.arange(4, 100, 0.5)*x_units
ph_energies_centers = ph_energies[:-1] + 0.5*np.diff(ph_energies)

sim_cont = {"slope": -2*y_units/x_units, "intercept": 100*y_units}
source = StraightLineModel(**sim_cont)


plt.figure()
for i, c in enumerate([0.25,0.5,1,2,4]):
    constant =  Constant(constant=c)
    observed = source * constant
    plt.plot(ph_energies_centers ,  observed(ph_energies), label='Const = '+str(c))
plt.loglog()
plt.legend()
plt.show()

(Source code, png, hires.png, pdf)

../_images/sunkit_spex-models-scaling-Constant-1.png

Attributes Summary

constant

n_inputs

n_outputs

name

param_names

Names of the parameters that describe models of this type.

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

Methods Summary

__call__(*inputs[, model_set_axis, ...])

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

evaluate(x, constant)

Evaluate the model on some input variables.

Attributes Documentation

constant = Parameter('constant', value=1.0, fixed=True)#
n_inputs = 1#
n_outputs = 1#
name = 'Constant'#
param_names = ('constant',)#

Names of the parameters that describe models of this type.

The parameters in this tuple are in the same order they should be passed in when initializing a model of a specific type. Some types of models, such as polynomial models, have a different number of parameters depending on some other property of the model, such as the degree.

When defining a custom model class the value of this attribute is automatically set by the Parameter attributes defined in the class body.

return_units#

Methods Documentation

__call__(
*inputs,
model_set_axis=None,
with_bounding_box=False,
fill_value=nan,
equivalencies=None,
inputs_map=None,
**new_inputs,
)#

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

evaluate(x, constant)[source]#

Evaluate the model on some input variables.