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

Add theta2 distribution plot to EventList class #1207

Closed
wants to merge 5 commits into from

Conversation

@vuillaut
Copy link
Contributor

@vuillaut vuillaut commented Nov 11, 2017

I added this simple plot that is used to check the distribution of the direction of the reconstructed events.
It also computes the 68% containment radius that I just print in the title.

@@ -52,6 +52,9 @@ def test_region(self):
def test_peek(self):
self.events.peek()

def test_plot_theta2_distribution(self):
self.plot_theta2_disitribution()

This comment has been minimized.

@Bultako

Bultako Nov 15, 2017
Member

tests do not pass in travis because this typing error
plot_theta2_disitribution -> plot_theta2_distribution

This comment has been minimized.

@cdeil

cdeil Nov 15, 2017
Member

Also, I think you have to call self.events.plot_theta2_distribution here.
To run the test locally you can use:

python setup.py test -V -t gammapy/data/tests/test_event_list.py

This comment has been minimized.

@vuillaut

vuillaut Nov 15, 2017
Author Contributor

Thanks I didn't have the right command line.

@cdeil cdeil self-assigned this Nov 15, 2017
@cdeil cdeil added the feature label Nov 15, 2017
@cdeil cdeil added this to the 0.7 milestone Nov 15, 2017
Copy link
Member

@cdeil cdeil left a comment

@vuillaut - Thanks for the pull request! I left some inline comments.

Maybe the biggest question here is whether to allow the caller to choose different reference positions for the offset computation. There's two possible positions in the event file header that you could access, namely pointing and "object" position. The "object", i.e. target of observation is sometimes listed in the header and sometimes not.

One option is no center option and to use pointing position (what you do now). Another is to have e.g.

center = {'pointing', 'object'} or SkyCoord

i.e. use the pointing position by default, but give the caller the option to choose something else.

Anything here is fine with me, please choose what you find best, and make the docstring and implementation consistent.

@@ -52,6 +52,9 @@ def test_region(self):
def test_peek(self):
self.events.peek()

def test_plot_theta2_distribution(self):
self.plot_theta2_disitribution()

This comment has been minimized.

@cdeil

cdeil Nov 15, 2017
Member

Also, I think you have to call self.events.plot_theta2_distribution here.
To run the test locally you can use:

python setup.py test -V -t gammapy/data/tests/test_event_list.py
pointing_ra = self.pointing_radec.ra.value
pointing_dec = self.pointing_radec.dec.value

theta2 = (events_ra - pointing_ra)**2 + (events_dec - pointing_dec)**2

This comment has been minimized.

@cdeil

cdeil Nov 15, 2017
Member

There's a few issues with how you compute theta2: I think table[:] makes a copy, so is very inefficient. Since you don't need a copy, just use self.table['RA'] etc. More importantly, I think we should use separation on the sphere, the formula you have doesn't give accurate results, especially if the run is pointing near the poles (i.e. dec = +90 or =90 deg).

So instead I would suggest that you use http://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord.separation. Actually, this is already available via http://docs.gammapy.org/en/latest/api/gammapy.data.EventList.html#gammapy.data.EventList.offset, i.e. you can just access that property.

Note that your docstring currently lists pointing_radec as an argument, but you don't really take that as input. So either remove that from the docstring, or keep a dist_center=None argument to let the caller choose the center to use, and default to self.pointing_radec.

def plot_theta2_distribution(self, ax=None, number_bins=50):
"""Plot the theta2 distribution of the events.
A pointing direction can be given in the same units as the event list as (ra,dec).
If None is given, the average of incoming directions of the events is taken.

This comment has been minimized.

@cdeil

cdeil Nov 15, 2017
Member

Docstring is incorrect. You currently don't take a pointing direction argument.

This comment has been minimized.

@vuillaut

vuillaut Nov 15, 2017
Author Contributor

Thank you so much for taking the time to comment in details and for your suggestions to improve this function!


theta2 = (events_ra - pointing_ra)**2 + (events_dec - pointing_dec)**2

count_theta2, x_edges, y_edges = ax.hist(theta2, bins=number_bins)

This comment has been minimized.

@cdeil

cdeil Nov 15, 2017
Member

How about taking **kwargs as argument in this function, and passing it on to ax.hist?
Then the caller has full control over binning and other hist plotting options.

vuillaut and others added 2 commits Nov 15, 2017
… method. Add optional center position as argument to be passed. Updated docstring and test accordingly
@cdeil
Copy link
Member

@cdeil cdeil commented Nov 16, 2017

@vuillaut - I've made a pull request against your pull request with one follow-up commit: vuillaut#1

This would be my suggestion. Note that I took out the R68 computation and instead explained in the docstring how to do it to the user. The problem with always computing and showing R68 is that it's often not what users want. E.g. I think this method can be used nicely to make theta^2 distributions wrt. the target position. But there computing R68 of all events in the FOV (2 deg in this case) is meaningless. So I would prefer to just add that via documentation to show users how to do it with 2 lines. Docstring now looks like this:
screen shot 2017-11-16 at 11 48 40

Thoughts?

@vuillaut
Copy link
Contributor Author

@vuillaut vuillaut commented Nov 16, 2017

Hi Christophe.
Yes I agree with you on the R68 computation, it might not be always required by the user.
The r68 computation could also be added as a function of the event list.

Improve event list offset2 plot method a bit
@cdeil
cdeil approved these changes Nov 16, 2017
@cdeil cdeil changed the title Adding theta2 distribution plot to EventList class Add theta2 distribution plot to EventList class Nov 16, 2017
@cdeil
Copy link
Member

@cdeil cdeil commented Nov 16, 2017

I added one more commit f8cf94f and then merged this locally 1740a13

Usually I add commits to pull requests and merge via the Github web interface. But @vuillaut - it looks like you disallowed "edits from maintainers", which makes it harder to collaborate and integrate your pull requests. Would you mind to change to "allow edits from maintainers"?
https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/

@cdeil cdeil closed this Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants