-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add n-dim data base class for gammapy.irf #527
Conversation
@@ -0,0 +1,187 @@ | |||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this:
from astropy.tests.helper import pytest
I've done a superficial review and left some comments inline. Do you want to apply it to AEFF or some other IRF in this PR, or add some simple dummy IRF in the test or as an example? (I'm not sure what is best ... either way this will be a large PR, bit it'll still be OK to review.) |
Thanks for you comments. I added an minimal aeff example file. Next thing is to test if the NDDataArray FITS I/O works for the test datastore cc @JouvinLea Since you're also working on IRF stuff maybe you want to have a look, too? If it comes to the worst you will have to use this class at some point 😉 |
Sorry I really didn't follow this PR... What is the purpose exactly? |
I'll answer via email |
@cdeil I added an example |
class EffectiveArea2D(NDDataArray): | ||
"""2D effective area table | ||
|
||
Axes: ``THETA``, ``ENERG`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The axis names are currently just the column names in the Fits file, we might want to map this to energy
and offset
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, probably a mechanism to map FITS axis names to something else would be nice, for cases where the FITS names are cryptic.
value.name = key | ||
self.add_axis(value) | ||
|
||
if data is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at this for 10 minutes, but I would need at least an hour to read through your implementation and make good suggestions. I can do this later if you want, but not this week. Naively I would have expected some scheme where a given IRF is a subclass and has class-level attributes to declare which axes are present and maybe some other things. The axes are class-specific and not instance-specific in your implementation, right? (The alternative would be that there is a factory function to create specific IRFs or a single class that is configurable on construction.) Does this comment make any sense? Or should I give a code example how I would have expected the AEFF class implementation to look like? |
This is an example of a single class that is configurable on construction: For our IRFs I don't know if one configurable class or a sub-class zoo would work better. |
@cdeil thanks. you already helped a lot. Did I understand you correctly that you would have expected something like
This is how I had it in mind originally. I changed to the 'weird' scheme because I have a I will change this, and then add the plotting methods etc. to make the review easier, ok? UPDATE: The
|
@joleroi - To be honest I don't know what I want / expect here. The goal should be that the class is nice to use that that each individual IRF class is small, basically declarative which axes and binning are present, the boilerplate code should be in the base class. Something like this:
There the parameters (axes in your case) are class-level attributed (see here) and then some dark magic is generating I now see that in Sherpa the parameters are constructed in I'll try to think about this and read up on class-level attributes in Python over the weekend. But yes ... adding tests or examples that show how your current class is used and that it works would be very helpful for review. |
@cdeil Otherwise I will continue with the 'construction on initialization' scheme. If we encounter severe problems later, we have to find a way to switch to the other scheme. |
I worked in this with @adonath and we think the subclassing API is sufficiently elegant for now (not as fancy as astropy.models but it does the job, if someone has time it can always be improved). Axes are class level attributes defined in each subclass now. The drawback is that |
@cdeil I will merge this now. The example class |
This PR introduces
gammapy.utils.nddata
This module contains a base class for an NDData array. It is supposed to be subclassed by all classes in `gammapy.irf`` and maybe in other places.
An scratch EffectiveArea2D class is also part of this PR for the sake of illustration.