-
Notifications
You must be signed in to change notification settings - Fork 270
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
Fix HillasReconstructor in case of too few telescopes #994
Fix HillasReconstructor in case of too few telescopes #994
Conversation
Hi. Checking for valid telescopes is indeed a good approach. Crucial parameters can fail for many reasons. I also remember suggesting in some discussion about Hillas parameters that the width should be equal to 0 and not |
I think u refer to #772, right? |
ctapipe/reco/HillasReconstructor.py
Outdated
if len(hillas_dict) < 2: | ||
|
||
# stereoscopy needs at least two telescopes with valid widths | ||
valid_telescopes = sum([1 if not np.isnan(hillas_dict[x]['width'].value) |
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 think you could directly build a new dict here with all the valid telescopes and only use those later.
E.g. valid_hillas = {tel_id: hillas for tel_id, hillas in hillas_dict.items() if np.isfinite(hillas['width'].value}
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 think this would be the cleaner approach for now but it kind of comes back to #772.
Do we still use these images by adjusting the weights or do we not use them at all?
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.
Exactly, thanks for digging it out.
My feeling is that 3 aligned pixels still give information about the direction and should not simply be thrown out - but I have not done a study on that ;-)
I see the problem with weights, however, and have no clear fix to handle this.
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, it's nice to keep track of what telescopes were dropped. Generally, i think a real pipeline would use a CutFlow to select telescopes before Hillas parameterization (e.g. with a minimum width and length or number of surviving pixels), but the code should still do reasonable things without that separate step, so testing for at least NaN is good. It should only skip telescopes if there is a real problem, and leave it up to the user to make any looser cuts for robustness.
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.
and by real problem I mean e.g. a singular matrix. In that case you could still reconstruct a direction if possible, and set the h_max to NaN
Just a question: what happens in case of we have 3 telescopes triggered and one of them has a NaN width? is h_max well reconstructed in this case? |
Codecov Report
@@ Coverage Diff @@
## master #994 +/- ##
=========================================
+ Coverage 84.14% 84.2% +0.05%
=========================================
Files 181 181
Lines 10907 10946 +39
=========================================
+ Hits 9178 9217 +39
Misses 1729 1729
Continue to review full report at Codecov.
|
Im not sure actually. If we only go with the valid telescopes as @maxnoe suggested above we would obviously avoid that (potential) problem |
I agree we should treat those images in a certain way (and we can discuss about this). |
I will try to find some time for this :) |
Reiterating my comments from above, we should avoid putting any "cuts" in the code, other than absolute failure cases (e.g. NaN or Inf preventing a sensible value). The user should explicitly control all cuts before the hillas code is executed (e.g they might replace the telescope dict with a subset after rejecting telescopes for any reason) |
And we must make sure any ignored telescopes are recorded somehow, so we don't get the case of events that are marked as 3 tel in the output that only really used 2 telescopes (which will throw off any benchmarks we do) |
That would mean to fail loudly, if any of the telescopes contain unusable data. So this means, the |
@kpfrang |
Yes, I think that's cleaner. I worry about adding any "hidden" cuts inside classes like Reconstructors, since it will clearly lead to some unexpected behavior later when people forget they are there (e.g. expecting the telescope multiplicity to be what the reconstructor used, when sometimes it is not). |
So this should fail as soon as there any nans in the hillas_dict. Makes sense to me. 👍 |
I would like to solve this PR asap since I just run into this same problem today.
We leave this selection to the user (replace width or apply some cleaning) and decide that in the HillasReconstructor we keep only those telescopes not breaking the reconstruction? Of course if the reconstructor drops a telescope, this should be reported to the user (with explanations). Since my problem is with |
- Hillas Reconstroctur now fails in any of these cases: - len(hillas_dict) < 2 - any width is np.nan - any width is 0
.format(len(hillas_dict))) | ||
|
||
# check for np.nan or 0 width's as these screw up weights | ||
if any([np.isnan(hillas_dict[tel]['width'].value) for tel in hillas_dict]): |
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.
Better in one loop and use a generator expression?
any(np.isnan(h.width.value) or h.width.value == 0 for h in hillas_dict.values())
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.
Fine with me. I wanted to seperate the error messages but we can combine them if you feel like we dont gain anything with it
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 would prefer to print two different messages in case of w=0
or w=NaN
.
Ok to use one generator expression per each case.
What I did was investigating what we gain using weights from lookup tables for the distance of closest approach between the semi-major axis of the image and the true direction projected in the camera. Besides improving the overall reconstruction, it also helped to save those images. For this investigation I always used I did not dig too deep into this, but I didn't find a problem in the reconstruction when I kept those images. |
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.
sorry this has sat around for so long - I hadn't noticed it was ready. Still, it's missing a unit test to check that the exception is thrown. Could you add one? Then it's ready
- there are less than 2 telescopes for the given event - any width is 0 - any width is nan Implementation is mostly copied from the test_reconstruction test.
…tainer: image->waveform)
0572d33
to
8450731
Compare
Hi all, regarding this (still open) discussion, now that the protopipe code is out, you could give a look to event_preparer.py. I couldn't yet elaborate on what Julien left me, but I believe that from line #133 of that file there is code very similar to what you suggest - perhaps it can be possible to get inspired from it. |
@mackaiver , @maxnoe and me faced an issue where the HillasReconstructor would fail even though there were two telescopes left after cleaning. It turned out that you could encounter situations where one of the hillas ellipses had a width of np.NaN because there were only a few pixels remaining which are all aligned.
This would render the weights useless and leave the h_max estimation with a singular matrix.
We decided that the HillasReconstructor should check for valid telescopes (that is telescopes with a defined width of the hillas ellipse) and that we would not even try to reconstruct other events (which should be very few if any).
Is there any reason against this approach?