Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve output units of spectral models #1979

Merged
merged 2 commits into from Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion gammapy/spectrum/models.py
Expand Up @@ -42,7 +42,10 @@ def __call__(self, energy):
"""Call evaluate method of derived classes"""
kwargs = dict()
for par in self.parameters.parameters:
kwargs[par.name] = par.quantity
quantity = par.quantity
if quantity.unit.physical_type == "energy":
quantity = quantity.to(energy.unit)
kwargs[par.name] = quantity

return self.evaluate(energy, **kwargs)

Expand Down
6 changes: 6 additions & 0 deletions gammapy/spectrum/tests/test_models.py
Expand Up @@ -229,6 +229,12 @@ def test_models(spectrum):
assert_quantity_allclose(val[0], spectrum["val_at_2TeV"])


def test_model_unit():
pwl = PowerLaw()
value = pwl(500 * u.MeV)
assert value.unit == "cm-2 s-1 TeV-1"


@requires_dependency("matplotlib")
@requires_data("gammapy-extra")
def test_table_model_from_file():
Expand Down