Add keepdim option for maps #1951
Conversation
) | ||
ax_sq = axis.squash() | ||
|
||
assert_allclose(ax_sq.nbin, 1) |
adonath
Nov 26, 2018
Member
Can you add asserts on the edge min and max values here?
Can you add asserts on the edge min and max values here?
AtreyeeS
Nov 26, 2018
Author
Member
Ok. Also added assert on the center.
Ok. Also added assert on the center.
axis = tuple(range(self.data.ndim - 2)) | ||
data = np.nansum(self.data, axis=axis) | ||
data = np.nansum(self.data, axis=axis, keepdims=keepdims) | ||
geom = self.geom.to_image() |
adonath
Nov 26, 2018
Member
Maybe move this line to an else
block below? I think this improves the code structure a bit.
Maybe move this line to an else
block below? I think this improves the code structure a bit.
AtreyeeS
Nov 26, 2018
Author
Member
I think an else
block is not necessary here.
But I have moved the data = np.nansum(self.data, axis=axis, keepdims=keepdims)
to after the if
block, which does make the code clearer.
I think an else
block is not necessary here.
But I have moved the data = np.nansum(self.data, axis=axis, keepdims=keepdims)
to after the if
block, which does make the code clearer.
Returns | ||
------- | ||
axis : `~MapAxis` | ||
Sliced axis objected. |
adonath
Nov 26, 2018
Member
Please adapt the docstring here and fix the typo.
Please adapt the docstring here and fix the typo.
AtreyeeS
Nov 26, 2018
Author
Member
Done. Also fixed typo in preceeding function
Done. Also fixed typo in preceeding function
Thanks @adonath . Made the changes as you said. I dont think there is any special need to put this in v0.9, so if you are ready with the release already, this can wait. |
@AtreyeeS Just one last comment: could you extend the |
And what about #1935? Do you want to implement the option for |
Thanks for this. I had added the option, but missed doing a git add on those files! |
Shouldn't axis.squash preserve the |
@cdeil I've thought about this as well. But apart from #1952, there is also the question where to set the bin center if you sum over the axes. I'm not sure if there is a unique answer. Summing over the axes also mainly applies to integral quantities such as counts or flux, so I'm not sure if there is a use case for differential quantities at all. But I agree we should not silently change the |
I think the main use case (see #1935) is to allow getting a flux map with correct value via the Personally I think only supporting that kind of analysis by running 3D with multiple bins and fixing spectral paramters except for amplitude would be fine, because getting the 2D "right" is a headache. Probably we should use
Or maybe keep as-is to allow using this, and add a comment at the top of the
|
I thought about this while coding, and reached #1952 . But then, I argues that this discrepancy does not matter too much for the purpose of
No, this is definitely not fine. For low flux sources, it is offensive to ask users to make too many bins in
I think this a good idea for the present, and then, once we decide the fix for #1952, we fix the TODO |
The cash / cstat likelihood that is used for map analyses doesn't have this issue, only WSTAT, which is only used for spectra and there we already support it. But no need to argue - if you take care of figuring out the node_type and single bin case and make it work in Gammapy - that's great! There is still the question if special-casing is needed for 2D maps, especially to support ring background estimation. We talked about this in Madrid and even did a bit of prototyping (#1850). Not sure if we reached a conclusion on what to do. If it's possible to support 2D analysis as you like by making it work with one |
This PR adds an option for squashing an axis into a corresponding axis with only one bin