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

Modify acceptance stacking behavior #5270

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

registerrier
Copy link
Contributor

Description

This pull request tries to solve #5245 by modifying the way acceptance is stacked for MapDatasetOnOff.
Now, instead of assuming the total acceptance to be equal to one, the acceptance is properly stacked. Because alpha
is unchanged acceptance_off is therefore different now.

The PR also corrects an inconsistency noted in #5261 . MapDataset.stack does not apply the mask of self when stacking. This avoids recomupting empty stacks all the time where in practice the first dataset is always empty.
The MapDataset.OnOff had a different assumption. This is now made consistent.

The docstrings where previously incorrect and have been modified. The formula are probably still incorrect.

Dear reviewer

This is ready, but docstrings need to be checked. Also the tutorial for Ring Background should be updated.

Signed-off-by: Régis Terrier <rterrier@apc.in2p3.fr>
Signed-off-by: Régis Terrier <rterrier@apc.in2p3.fr>
Signed-off-by: Régis Terrier <rterrier@apc.in2p3.fr>
…ng and needs to be masked first

Signed-off-by: Régis Terrier <rterrier@apc.in2p3.fr>
Signed-off-by: Régis Terrier <rterrier@apc.in2p3.fr>
Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.46%. Comparing base (a048535) to head (3e840ad).
Report is 105 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5270      +/-   ##
==========================================
+ Coverage   94.25%   94.46%   +0.20%     
==========================================
  Files         234      235       +1     
  Lines       35226    35496     +270     
==========================================
+ Hits        33204    33531     +327     
+ Misses       2022     1965      -57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@samanthalwong samanthalwong left a comment

Choose a reason for hiding this comment

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

Works well in resolving #5245 for RBM analysis

Copy link
Member

@bkhelifi bkhelifi left a comment

Choose a reason for hiding this comment

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

Thanks a lot. I have just few suggestions for the docstrings

Counts outside the safe mask are lost.

The ``acceptance`` of the stacked dataset is obtained by stacking the acceptance weighted
by the other mask_safe onto the current unwieghted acceptance.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
by the other mask_safe onto the current unwieghted acceptance.
by the other mask_safe onto the current unweighted acceptance.

Note that the masking is not applied to the current dataset. If masking needs
to be applied to it, use `~gammapy.MapDataset.to_masked()` first.

The stacked ``acceptance_off`` is scaled so that:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe one can put below the formulae for both acceptance, adding the use of the masks (in the `MapDataset.stack' docstring, one uses \epsilon for the mask

Copy link
Member

Choose a reason for hiding this comment

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

We could instead put that information here https://docs.gammapy.org/1.2/user-guide/makers/ring.html ?
But, no strong opinion on if it should also be in the docstring

Choose a reason for hiding this comment

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

As a user, I think it would definitely be helpful to have the formulae in the user guide (and maybe linked in the docs). Having it in the docstring might be nice too.

Copy link
Member

Choose a reason for hiding this comment

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

We have all the formulas involved in stacking mentioned here, https://docs.gammapy.org/1.2/user-guide/datasets/index.html#stacking-multiple-datasets
So, maybe updating this and linking to this from the docstring would be useful

The ``acceptance`` of the stacked dataset is normalized to 1,
and the stacked ``acceptance_off`` is scaled so that:
Safe mask is applied to the other dataset to compute the stacked counts data.
Counts outside the safe mask are lost.
Copy link
Member

Choose a reason for hiding this comment

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

I propose to add the formula, as in `MapDataset.stack'

Copy link
Member

@AtreyeeS AtreyeeS left a comment

Choose a reason for hiding this comment

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

Thanks @registerrier ! I think the tutorial can be adapted in a separate PR

Note that the masking is not applied to the current dataset. If masking needs
to be applied to it, use `~gammapy.MapDataset.to_masked()` first.

The stacked ``acceptance_off`` is scaled so that:
Copy link
Member

Choose a reason for hiding this comment

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

We have all the formulas involved in stacking mentioned here, https://docs.gammapy.org/1.2/user-guide/datasets/index.html#stacking-multiple-datasets
So, maybe updating this and linking to this from the docstring would be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v1.0.x on-merge: backport to v1.0.x backport-v1.2.x on-merge: backport to v1.2.x bug cleanup
Projects
None yet
5 participants