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

Cleanup FluxMaps a little bit #3275

Merged
merged 8 commits into from
Mar 24, 2021
Merged

Conversation

adonath
Copy link
Member

@adonath adonath commented Mar 17, 2021

Description

This pull request cleans up the FluxMaps object a little bit.

Dear reviewer
@registerrier Previously the code allowed any arbitrary extra maps for I/O. I wasn't sure whether this is a good idea or not. In this PR I'm introducing a COMMON_MAPS variable that declare the allowed extra quantities. In general this possibly includes a few other such as is_ul or niter.

@adonath adonath added this to the v0.19 milestone Mar 17, 2021
@adonath adonath added this to In progress in gammapy.estimators via automation Mar 17, 2021
@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #3275 (f0c29b8) into master (569215f) will decrease coverage by 0.06%.
The diff coverage is 87.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3275      +/-   ##
==========================================
- Coverage   93.81%   93.74%   -0.07%     
==========================================
  Files         144      144              
  Lines       17754    17738      -16     
==========================================
- Hits        16656    16629      -27     
- Misses       1098     1109      +11     
Impacted Files Coverage Δ
gammapy/estimators/core.py 92.93% <81.25%> (-4.35%) ⬇️
gammapy/estimators/flux_map.py 92.08% <90.27%> (-1.80%) ⬇️
gammapy/modeling/models/spectral.py 96.74% <100.00%> (+0.02%) ⬆️
gammapy/modeling/iminuit.py 92.39% <0.00%> (-3.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 569215f...f0c29b8. Read the comment docs.

@adonath adonath self-assigned this Mar 18, 2021
Copy link
Contributor

@registerrier registerrier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adonath.

My main concern is the decision to remove the flexibility to support other maps than some specified ones.
This means each time we adapt some estimator or introduce some functionality we have to add the new maps in the list of supported maps. We will introduce some for incompatibility with that. If there is no strong gain to introduce this limited list of supported map, I would not do that.

return self.energy_axis.edges[1:]

@property
def ts(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a check for the existence of the ts entry in self.data or can we assume it will always be there?

Note that if we use this for FluxPoints as well this will no longer be a Map object.


@property
def ts(self):
if not "ts" in self.data:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there is a test.

str_ += "\n\t"+"\n\t".join(str(self.norm.geom).split("\n")[2:])
str_ += "-" * len(self.__class__.__name__)
str_ += "\n\n"
str_ += "\t" + "\t\n".join(str(self.norm.geom).split("\n")[:1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use self.geom if it exists now.


rows = []
for idx, energy in enumerate(self.energy_ref):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove this, you won't have the various energy columns in the final Table, right?

factor = reference_model.spectral_model.energy_flux(e_edges[:-1], e_edges[1:])
elif sed_type == "e2dnde":
factor = e_ref ** 2 * ref_dnde
with np.errstate(invalid="ignore", divide="ignore"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference_flux method is an elegant solution.

BTW, should we protect the class to make sure that no model is passed which carries the flux on the spatial_model. It shouldn't be the case most of the time, but who knows...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess the alternative solution is to evaluate the reference flux on the SkyModel and integrate over the spatial part, but that's probably too much trouble for almost no benefit....I agree that using a cube template as reference model could be just forbidden.


# We add the remaining maps
for key in maps.keys() - (REQUIRED_MAPS[sed_type] + OPTIONAL_MAPS[sed_type]):
data[key] = maps[key]
for key in COMMON_MAPS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with this is that you can get a different dict in output.

Also we don't support other possible entries.

}

COMMON_MAPS = ["ts", "sqrt_ts"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about other maps: counts, background, excess.
ExcessMapEstimator could be adapted to return flux maps as well but we would need other diagnostics maps in that case.
Shouldn't we leave the flexibility of using any other map?

Copy link
Member Author

@adonath adonath Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the main question I had as well. In general I would prefer to declare somehow which other maps are allowed as well, but this requires to define first which those are. I think defining and documenting the additional quantities e.g. a ExcessMapEstiamtor returns is a good thing. And this requires also clarifying the terms we use. E.g. especially in the context of the ExcessMapEstimator this is not 100% clear to me yet. E.g. currently we return counts and excess and background, while in the context of an Estimator I would rather refer to npred, npred_signal and npred_background, even if it is the same by definition in the Li&Ma case.

As a first start I could open an PR extending the documentation here https://docs.gammapy.org/dev/estimators/index.html, for quantities we are currently missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following #3278 , I added npred, npred_excess and npred_null to the maps. However it might still be incomplete. I think the next step is to check the result quantities of the current estimators and make a PR to unify it and extend for missing quantities. I'm completely open to allow for any other additional quantity, however for this PR I propose to just stick with the defined and documented ones.

@adonath
Copy link
Member Author

adonath commented Mar 24, 2021

@registerrier I'll go ahead and merge this PR. Then we can prepare a second one to unify and add missing quantities to the current Estimators...

@adonath adonath merged commit a82da1d into gammapy:master Mar 24, 2021
gammapy.estimators automation moved this from In progress to Done Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants