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
Background estimation map #1198
Comments
Note that a few modifications have been made to the |
Thanks for the info. I produced the bkg map with 8bfae5c and it has no grid. The grid seems to be centered on the ref_image defined by SkyImage.empty. So the effect seems not FoV related but rather SkyImage related. |
Is this using FFT convolution? These artifacts look like something FFT convolution could introduce, no? Probably writing a few tests to check if Here's what we have for Line 1175 in c421ba9
Note that in Astropy a lot of time was spent over the past year to get the same output from direct and FFT convolution. Initially it was very buggy (i.e. different behaviour for NaN values, edges, kernel normalisation, ...), but I think by now it's really a common and nice / well-tested uniform interface for both FFT and direct convolve: http://astropy.readthedocs.io/en/stable/convolution/index.html I was against using it in Gammapy before, because it was buggy, and because we didn't really need FFT convolution and scipy.ndimage.convolve was simple / correct / fast.
So does anyone have time to tackly the convolve and then ring bg estimate situation and bring us towards a good, well-understood and well-tested situation? @adonath - I think for someone that knows about the methods it should be a day or two of work, and for someone new to Gammapy development / writing tests or even convolution it's a week of work? |
Just one more thing I forgot to mention: one concern I would have with switching to |
This doesn't seem related to FFT. The examples above were generated with Concerning the FFT, one interessting thing is that when keeping the code as is ( For speed for 5 observations and an image of 200x200 pixels, fftconvolve runs in 3.7 sec and convolve in 8.4sec on my laptop. |
@facero Now, I realize what the problem is. Could you increase the size of the reference sky image, so that the FoV is fully contained (and maybe include an extra margin of 0.5 deg) and see if that fixes the problem? Actually the boundary handling of the convolution should not influence the result, because the code implicitly requires that the image is much larger than the FoV, so the part of the image, that is affected by the boundary handling is always outside the FoV. This is no the case in your example and we have to think about how to handle this. We could simply require a minimum size of the reference image. But it is probably best to adapt the algorithm and pad the image by half the kernel size prior to the ring convolution and crop it afterwards again. Does that make sense? |
I will try that. I know that astropy.fftconvolve does padding (I don't remember if it is by default). |
Why is padding needed? We want to have the ring be a counting kernel. So https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.convolve.html with If we can avoid padding, it'll avoid having to introduce special code for handling different cases of where the background is in the image and different kernel / image sizes. |
@cdeil The problem here is a different one: the FoV is not fully contained in the reference image and instead of using the full information for the background computation (i.e. the data in the FoV that is outside the reference image) the zero padding is used for the convolution, which causes the artefacts. There are now different ways to handle this problem:
|
@adonath - I don't think we should pad anywhere. So I read the gammapy/gammapy/background/ring.py Line 331 in 0d475fc
You're convolving exposure_on with mode='reflect' , but you should do the same thing on on_exposure and you do to counts, i.e. mode='constant' , no?
Another suggestion: change the test case so that the run isn't fully contained in the image:
and then add asserts on a pixel at the edge to establish what the algorithm does. To debug it, probably a notebook showing images would be better than just running pytest and printout. @facero or @adonath - Does one of you have time to start a pull request soon? Or should I do it? |
Here is another bug in the image computation (not really related to the feature discussed here, but could be fixed in the same PR if someone starts one with the goal to get correct images): gammapy/gammapy/image/basic.py Line 223 in 0d475fc
Instead I think one has to process counts like this, to make sure the FOV offset cut is 100% consistent between exposure and counts, and the lines at the FOV edge with counts / exposure mismatch are gone for sure: |
The problem @cdeil mentioned with @cdeil Note that the data outside the FoV of the counts image is handled here: gammapy/gammapy/image/basic.py Line 293 in 0d475fc
But I agree this is better handled inside _counts() using data[offset >= offset_max] = 0 but the result will be the same...
|
I think you are right! I just quickly read the code and thought you had a "select_cone" call on the events, but actually there is only a "select_energy" call: gammapy/gammapy/image/basic.py Line 233 in e167145
|
This is what I don't understand: yes, usually the caller should compute images so that all data is fully contained. But if there are runs at the edge of the image, then counts / exposure / background computations should still work, just loose some data. You know the code better than me, maybe indeed there is another bug in the background computation code. But the solution would be to fix that without introducing padding. Suggest to first fix the obvious bug "reflect" -> "constant" and then look at an example image. |
I talked to @adonath about this offline:
Keeping this issue open for now. |
@registerrier has started to work on new code to make maps that should resolve the issues discussed here. Regis - assigning this issue to you. |
I'm closing this old issue. I think it has been resolved in the old image estimator a few months ago, and anyways that code will be deleted very soon. Please use gammapy.maps and the new MapMaker (see tutorial), and do report any issue you find there! |
Hi,
While preparing my notebooks for the DC1 gammapy/ctools comparison, I reran my notebook that I used for the PHYS meeting in Sept 2017.
The background map with the latest gammapy version (0.7.dev5223) produces a background map with higher (more diffuse/smoothed) background values than the map that I produced in september with 0.7.dev5025.
I reverted my current version to 0.7.dev5025 (67babf6) and the background map is similar to the one obtained in september.
There has been quite some modifications since september. Has any of you noticed this change ?
I'm not sure which background image is the more realistic but the change is quite significant and I was wondering whether someone had checked this.
In particular there is some kind of square grid pattern that is visible.
@bkhelifi when you implemented changes during the last coding sprint did you see changes in the background maps ?
0.7.dev5223
0.7.dev5025 (67babf6)
For a minimal example, you can use the notebook here:
#1143
and use this command:
images['background'].smooth(radius=0.1).plot(cmap='viridis',add_cbar=True)
The text was updated successfully, but these errors were encountered: