-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add tag on DM Annihilation spectral model #4071
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4071 +/- ##
==========================================
- Coverage 94.04% 94.00% -0.05%
==========================================
Files 162 162
Lines 21444 21447 +3
==========================================
- Hits 20167 20161 -6
- Misses 1277 1286 +9
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks @registerrier! My main question is whether adding the tag really solves the problem? The |
This is a good point. Technically, some of these quantities could be |
@registerrier Yes, maybe let's just raise a meaningful error for now? |
Signed-off-by: Terrier <rterrier@apc.in2p3.fr>
Signed-off-by: Terrier <rterrier@apc.in2p3.fr>
I have included additional attributes in the out dictionary. It actually works and allows exporting DMmodels to yaml. Obviously we will need to look at what should be a Opinions @adonath ? |
Thanks @registerrier, great to see it works with limited effort. I'll make a more thorough review later... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @registerrier, I have left one minor comment and one inline suggestion...
gammapy/astro/darkmatter/spectra.py
Outdated
def from_dict(cls, data): | ||
data = data["spectral"] | ||
|
||
channel = data["channel"] | ||
mass = u.Quantity(data["mass"]) | ||
jfactor = u.Quantity(data["jfactor"]) | ||
z = data["z"] | ||
k = data["k"] | ||
|
||
scale = [p["value"] for p in data["parameters"] if p["name"] == "scale"][0] | ||
return cls(mass, channel, scale=scale, jfactor=jfactor, z=z, k=k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def from_dict(cls, data): | |
data = data["spectral"] | |
channel = data["channel"] | |
mass = u.Quantity(data["mass"]) | |
jfactor = u.Quantity(data["jfactor"]) | |
z = data["z"] | |
k = data["k"] | |
scale = [p["value"] for p in data["parameters"] if p["name"] == "scale"][0] | |
return cls(mass, channel, scale=scale, jfactor=jfactor, z=z, k=k) | |
def from_dict(cls, data): | |
"""Create spectral model from dict | |
Parameters | |
---------- | |
data : dict | |
DIct with model data | |
Returns | |
------- | |
model : `DarkMatterAnnihilationSpectralModel` | |
Dark matter annihilation spectral model | |
""" | |
data = data["spectral"] | |
scale = [p["value"] for p in data.pop("parameters") if p["name"] == "scale"][0] | |
return cls(scale=scale, **data) |
|
||
def __init__(self, mass, channel, scale=scale.quantity, jfactor=1, z=0, k=2): | ||
self.k = k | ||
self.z = z | ||
self.mass = mass | ||
self.mass = u.Quantity(mass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a unit test to establish the quantity here...
What is the status here @registerrier ? |
Signed-off-by: Terrier <rterrier@apc.in2p3.fr>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @registerrier, no further comments from my side.
Description
This pull request solves #4056 by simply adding a
tag
onDarkMatterAnnihilationSpectralModel
with short namedm-annihilation
.Note that DM spatial models are not usable in
SkyModel
as they are not regularSpatialModel
.Dear reviewer