How to use the sherpa.models.model.RegriddableModel1D function in sherpa

To help you get started, we’ve selected a few sherpa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sherpa / sherpa / sherpa / astro / models / __init__.py View on Github external
from sherpa.utils.err import ModelErr
from sherpa.utils import _guess_ampl_scale, bool_cast, get_fwhm, \
    get_peak, get_position, guess_amplitude, guess_amplitude2d, \
    guess_amplitude_at_ref, guess_fwhm, guess_position, \
    guess_radius, guess_reference, lgam, param_apply_limits

from . import _modelfcts

__all__ = ('Atten', 'BBody', 'BBodyFreq', 'Beta1D', 'BPL1D', 'Dered', 'Edge',
           'LineBroad', 'Lorentz1D', 'NormBeta1D', 'Schechter',
           'Beta2D', 'DeVaucouleurs2D', 'HubbleReynolds', 'Lorentz2D',
           'JDPileup', 'MultiResponseSumModel', 'Sersic2D', 'Disk2D',
           'Shell2D')


class Atten(RegriddableModel1D):
    """Model the attenuation by the Inter-Stellar Medium (ISM).

    This model calculates the transmission of the interstellar medium
    using the description of the ISM absorption of [1]_. It includes
    neutral He autoionization features. Between 1.2398 and 43.655
    Angstroms (i.e. in the 0.28-10 keV range) the model also accounts
    for metals as described in [2]_. It should only be used when the
    independent axis has units of Angstroms.

    Attributes
    ----------
    hcol
        The column density of HI in atoms cm^-2.
    heiRatio
        The ratio of the HeI to HI column densities.
    heiiRatio
github sherpa / sherpa / sherpa / astro / optical / __init__.py View on Github external
ArithmeticModel.__init__(self, name, pars)

    # @modelCacher1d
    def calc(self, p, x, xhi=None, **kwargs):
        x = numpy.asarray(x, dtype=SherpaFloat)
        y = numpy.zeros_like(x)
        xtemp = x - p[6]
        y += p[5]
        for i in [4, 3, 2, 1, 0]:
            y = y * xtemp + p[i]

        return y


# This model computes continuum emission using a power-law.
class Powerlaw(RegriddableModel1D):
    """Power-law model.

    It is for use when the independent axis is in Angstroms.

    Attributes
    ----------
    refer
        The reference point at which the amplitude is defined, with
        units of Angstroms.
    ampl
        The amplitude at the reference point.
    index
        The index for the power law.

    See Also
    --------
github sherpa / sherpa / sherpa / astro / models / __init__.py View on Github external
norm = guess_amplitude(dep, *args)
        modampl = norm['val'] * (numpy.exp(Emax / tMax) - 1) / \
            numpy.square(Emax)
        mod = {'val': modampl,
               'min': modampl / _guess_ampl_scale,
               'max': modampl * _guess_ampl_scale}
        param_apply_limits(mod, self.ampl, **kwargs)

    @modelCacher1d
    def calc(self, *args, **kwargs):
        kwargs['integrate'] = bool_cast(self.integrate)
        return _modelfcts.bbody(*args, **kwargs)


class BBodyFreq(RegriddableModel1D):
    """A one-dimensional Blackbody model (frequency).

    This model can be used when the independent axis is in frequency
    space.

    Attributes
    ----------
    T
        The temperature if the blackbody, in Kelvin.
    ampl
        The amplitude of the blackbody component.

    See Also
    --------
    BBody
github sherpa / sherpa / sherpa / astro / models / __init__.py View on Github external
if fwhm != 10:
            aprime = norm['val'] * self.fwhm.val * numpy.pi / 2.
            ampl = {'val': aprime,
                    'min': aprime / _guess_ampl_scale,
                    'max': aprime * _guess_ampl_scale}
            param_apply_limits(ampl, self.ampl, **kwargs)
        else:
            param_apply_limits(norm, self.ampl, **kwargs)

    @modelCacher1d
    def calc(self, *args, **kwargs):
        kwargs['integrate'] = bool_cast(self.integrate)
        return _modelfcts.lorentz1d(*args, **kwargs)


class NormBeta1D(RegriddableModel1D):
    """One-dimensional normalized beta model function.

    This is the same model as the ``Beta1D`` model but with a
    different slope parameter and normalisation.

    Attributes
    ----------
    pos
        The center of the line.
    w
        The line width.
    alpha
        The slope of the profile at large radii.
    ampl
        The amplitude refers to the integral of the model.
github sherpa / sherpa / sherpa / astro / models / __init__.py View on Github external
http://adsabs.harvard.edu/abs/1978ApJ...224..132B

    """

    def __init__(self, name='dered'):
        self.rv = Parameter(name, 'rv', 10, 1e-10, 1000, tinyval)
        self.nhgal = Parameter(name, 'nhgal', 1e-07, 1e-07, 100000)
        ArithmeticModel.__init__(self, name, (self.rv, self.nhgal))

    @modelCacher1d
    def calc(self, *args, **kwargs):
        kwargs['integrate'] = bool_cast(self.integrate)
        return _modelfcts.dered(*args, **kwargs)


class Edge(RegriddableModel1D):
    """Photoabsorption edge model.

    This model can be used when the independent axis is in energy
    or wavelength space.

    Attributes
    ----------
    space
        Switch to select whether the independent axis is energy or
        wavelength. This parameter is not fit (``alwaysfrozen`` is
        set), and should be set to either 0, when the independent axis
        is energy with units of keV, or 1 when the axis is wavelength
        with units of Angstrom.
    thresh
        The edge position (in energy or wavelength units matching
        the data grid).
github sherpa / sherpa / sherpa / astro / optical / __init__.py View on Github external
y = numpy.where(x >= p[1],
                        p[2] * numpy.power((x / p[1]), -alpha),
                        p[2] * numpy.power((x / p[1]), alpha))

        return numpy.exp(-y)


# This model computes emission using a Gaussian function expressed
# in optical depth, and using the log of the FWHM.
#
# DOC NOTE: the specview docs and ahelp file claim that fmax
#           requires c but the code uses the pos parameter.
#           WHAT IS CORRECT? See
#           https://github.com/sherpa/sherpa/issues/220
#
class LogEmission(RegriddableModel1D):
    """Gaussian function for modeling emission (log of fwhm).

    It is for use when the independent axis is in Angstroms.

    Attributes
    ----------
    fwhm
        The full-width half-maximum of the model in km/s.
    pos
        The center of the gaussian, in Angstroms.
    flux
        The normalisation of the gaussian.
    skew
        The skew of the gaussian.
    limit
        This is a hidden parameter and is unused by the model.
github sherpa / sherpa / sherpa / astro / optical / __init__.py View on Github external
# intervals. There is a mismatch of 0.009 mag/ebmv at nu=2.7
# (lambda=3704 Angstrom). Seaton's tabulated value of 1.44 mag at
# 1/lambda = 1.1 may be in error; 1.64 seems more consistent with
# his other values.
#
# Wavelength range allowed is 0.1 to 1.0 microns; outside this
# range, the class extrapolates the function.
#
# References:
#
# lambda < 1000		same as lambda = 1000.
# 1000 < lambda < 3704	Seaton (1979) MNRAS 187,73p.
# 3704 < lambda < 10,000	Nandy (1975) A+A 44, 195. (corrected to R=3.2)
# 10000 < lambda		    extrapolate linearly in 1/lambda

class Seaton(RegriddableModel1D):
    """Galactic extinction: the Seaton model from Synphot.

    The interstellar extinction is calculated using the formula
    from [1]_ as implemented in STSCI's Synphot program [2]_.
    The supported wavelength range is 1000 to 10000 Angstroms, and
    the Notes section describes the changes from [1]_. This model is
    intended to be used to modify another model (e.g. by multiplying
    the two together). It is for use when the independent axis is in
    Angstrom.

    Attributes
    ----------
    ebv
        E(B-V)

    See Also
github sherpa / sherpa / sherpa / astro / optical / __init__.py View on Github external
# @modelCacher1d
    def calc(self, p, x, xhi=None, **kwargs):
        if 0.0 == p[0]:
            raise ValueError('model evaluation failed, ' +
                             '%s refer cannot be zero' % self.name)

        x = numpy.asarray(x, dtype=SherpaFloat)
        arg = x / p[0]
        arg = p[1] * numpy.power(arg, p[2])

        return arg


# This model computes the continuum with an optically thin
# recombination function.
class Recombination(RegriddableModel1D):
    """Optically-thin recombination continuum model.

    It is for use when the independent axis is in Angstroms.

    Attributes
    ----------
    refer
        The reference point, in Angstroms.
    ampl
        The amplitude of the emission; it is defined at the reference
        point but its numerical value there also depends on the
        temperature.
    temperature
        The temperature in Kelvin.
    fwhm
        The full-width half-maximum of the model in km/s.
github sherpa / sherpa / sherpa / astro / optical / __init__.py View on Github external
# Formula from paper with zero point moved to (x = 0)
        ext = ((0.011 * x - 0.198) * x + 1.509) * x

        # Normalize the result according to Kailash Sahu's calculations
        ext *= 2.43

        return numpy.power(10.0, (-0.4 * p[0] * ext))


# This model computes the extinction curve for wavelengths for UV
# spectra below 3200 A.  Fitzpatrick and Massa 1988 extinction curve
# with Drude UV bump.
# See Fitzpatrick and Massa (ApJ, 1988, vol. 328, p. 734)

class FM(RegriddableModel1D):
    """UV extinction curve: Fitzpatrick and Massa 1988.

    The UV extinction is calculated using [1]_. This model is
    intended to be used to modify another model (e.g. by multiplying
    the two together). It is for use when the independent axis is in
    Angstrom.

    Attributes
    ----------
    ebv
        E(B-V)
    x0
        Position of the Drude bump.
    width
        Width of the Drude bump.
    c1
github sherpa / sherpa / sherpa / astro / models / __init__.py View on Github external
h_erg = 6.6260693e-27
        factor = numpy.exp(2.82) * numpy.square(c_cm) / h_erg / 2.
        modampl = norm['val'] * factor / numpy.power(vmax, 3.)
        mod = {'val': modampl,
               'min': modampl / _guess_ampl_scale,
               'max': modampl * _guess_ampl_scale}
        param_apply_limits(mod, self.ampl, **kwargs)
        param_apply_limits(t, self.t, **kwargs)

    @modelCacher1d
    def calc(self, *args, **kwargs):
        kwargs['integrate'] = bool_cast(self.integrate)
        return _modelfcts.bbodyfreq(*args, **kwargs)


class Beta1D(RegriddableModel1D):
    """One-dimensional beta model function.

    The beta model is a Lorentz model with a varying power law.

    Attributes
    ----------
    r0
        The core radius.
    beta
        This parameter controls the slope of the profile at large
        radii.
    xpos
        The reference point of the profile. This is frozen by default.
    ampl
        The amplitude refers to the maximum value of the model, at
        x = xpos.