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

Application of mask_safe in MapDataset and SpectrumDataset does not handle nan values well #3064

Closed
lmohrmann opened this issue Oct 13, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@lmohrmann
Copy link
Contributor

Gammapy version
0.17

Bug description
The mask_safe is applied in the MapDataset and SpectrumDataset by multiplying the different maps (counts, background, etc.) with the mask_safe. This method fails when, for instance, there are nan values present in the background model map (which might occur when the background model is interpolated onto the used geometry). This is because nan * False = nan, which results in the corresponding pixels not being properly masked.

Expected behavior
All pixels outside the mask_safe should be properly masked. This could be achieved by using a scheme like dataset.background_model.map[~dataset.mask_safe.data] = 0 instead of the multiplication.

@lmohrmann lmohrmann added the bug label Oct 13, 2020
@adonath adonath added this to the v0.19 milestone Nov 23, 2020
@adonath
Copy link
Member

adonath commented Apr 26, 2021

@lmohrmann I checked once again what the status here is and to apply the mask we consistently use Map.stack( weights=). The weights argument however is meant to be more generic and not strictly for boolean types. So I think we cannot apply the proposed solution and have to fix replace NaN values beforehand instead. A method for this has been added in #3219

@adonath
Copy link
Member

adonath commented May 3, 2021

However one could check the dtype here: https://github.com/gammapy/gammapy/blob/master/gammapy/maps/wcsnd.py#L782

@QRemy
Copy link
Contributor

QRemy commented Jul 7, 2021

PR #3416 adds a method "bkg-clip" to the SafeMaskMaker in order create a mask from aberrant values in the background map (not finite and eventually very large values). It also offers the possibility to clip the aberrant values to zero in the background map. This should solve the issue.

@adonath
Copy link
Member

adonath commented Jul 15, 2021

Solved by #3419.

@adonath adonath closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants