Created
January 12, 2018 22:26
-
-
Save giacomov/a8608f1baed609111d2c62304fb2f80d to your computer and use it in GitHub Desktop.
A custom model in astromodels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from astromodels.functions.function import Function1D, FunctionMeta | |
class MyCustomModel(Function1D): | |
r""" | |
description : | |
A custom power law model | |
latex : $ 10^{K}~\frac{x}{piv}^{index} $ | |
parameters : | |
K : | |
desc : Normalization (log of differential flux at the pivot value) | |
initial value : 1.0 | |
is_normalization : True | |
transformation : log10 | |
piv : | |
desc : Pivot value | |
initial value : 1 | |
fix : yes | |
index : | |
desc : Photon index | |
initial value : -2 | |
min : -10 | |
max : 10 | |
""" | |
__metaclass__ = FunctionMeta | |
def _set_units(self, x_unit, y_unit): | |
# The index is always dimensionless | |
self.index.unit = astropy_units.dimensionless_unscaled | |
# The pivot energy has always the same dimension as the x variable | |
self.piv.unit = x_unit | |
# The normalization has the same units as the y | |
self.K.unit = y_unit | |
# noinspection PyPep8Naming | |
def evaluate(self, x, K, piv, index): | |
xx = x / piv | |
return 10**K * xx**index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment