HiSPARC / sapphire

SAPPHiRE, a framework for HiSPARC
https://docs.hisparc.nl/sapphire/
GNU General Public License v3.0
7 stars 9 forks source link

Useless warnings in (direction) reconstruction. #148

Closed tomkooij closed 8 years ago

tomkooij commented 8 years ago

While doing direction reconstructions users encouter many (useless) warnings:

d:\Anaconda2\envs\tom\lib\site-packages\sapphire\analysis\coincidence_queries.py:59: UserWarning: Missing some station groups. This is no problem if those are not in coincidences.
  warnings.warn('Missing some station groups. This is no '
d:\Anaconda2\envs\tom\lib\site-packages\sapphire\analysis\direction_reconstruction.py:1334: RuntimeWarning: invalid value encountered in double_scalars
  sin2 = area / lenvec01 / lenvec12
d:\Anaconda2\envs\tom\lib\site-packages\sapphire\analysis\direction_reconstruction.py:1335: RuntimeWarning: invalid value encountered in double_scalars
  sin3 = area / lenvec02 / lenvec12
d:\Anaconda2\envs\tom\lib\site-packages\sapphire\analysis\direction_reconstruction.py:1333: RuntimeWarning: invalid value encountered in double_scalars
  sin1 = area / lenvec01 / lenvec02
d:\Anaconda2\envs\tom\lib\site-packages\sapphire\utils.py:137: RuntimeWarning: invalid value encountered in double_scalars
  return sqrt(x ** 2 + y ** 2 + z ** 2)

Besides being confusing for newbies, these warnings have an undesirable side effect: real warnings (All NaN axis-encountered) are no longer registered by the user. This is a real problem.

The first warning is from CoincidenceQuery.__init__() about missing stations groups: link I suggest removing this warning and letting the query fail when it is indeed a problem. Perhaps make such a failure verbose. this will make _get_events() throw a verbose warning when events are actually missing.

I suggest turning off warnings about invalid value encountered in double_scalars by numpy.setterr(invalid='ignore').

153957 commented 8 years ago

What values cause these errors? To large/to small/to negative floats?

In core_reconstruction some warnings are suppressed using:

with warnings.catch_warnings(record=True):

Using the numpy warning setter may be more specific. Though, do we know that the other numpy warnings never occur, and if they do, can they also be ignored or not?

tomkooij commented 8 years ago

I'll try to investigate (when time permits...). We need an overview of warnings (with causes) to properly decide which warnings to suppress.

153957 commented 8 years ago

Some warnings are suppressed in the tests, disabling those filters and catches then running the tests might reveal many warnings.

tomkooij commented 8 years ago

The invalid value encountered in double_scalars all seem to be caused by 'area' being very small (smaller than 'eps') in:

        # area triangle is |cross product|
        area = abs(dx1 * dy2 - dx2 * dy1 + dy1 * dz2 - dy2 * dz1 +
                   dz1 * dx2 - dz2 * dx1)

        # sine of angle is area divided by two sides
        sin1 = area / lenvec01 / lenvec02
        sin2 = area / lenvec01 / lenvec12
        sin3 = area / lenvec02 / lenvec12

direction_reconstruction.py

These are easily prevented, so there is no need to suppress them. I'll push a PR.

tomkooij commented 8 years ago

I have tested many reconstructions and (after merging #149) I only encounter RuntimeWarning: All-NaN axis encountered from numpy.nanmin in event_utils.station_arrival_times. This seems to be due to all NaN detector_arrival_times probably caused by (nan, nan, nan, nan) detector offsets, but I have not verified that yet.

There is a similar warning from numpy.nanmean in core reconstruction, which is probably due to the same nan detector offsets.

I'd like to fix these as well (or throw a real verbose warning). But I need to investigate more. (Again when time permits)

tomkooij commented 8 years ago

The warnings are indeed from (nan, nan, nan, nan) detector offsets (see above).

There is no need in throwing a verbose warning, because this is just one of the many cases that can make a reconstruction fail.

I'd like to discard events before the warning is thrown, for example by adding a check here or supress the warnings as suggested by @153957 above.