nu-radio / radiotools

A tool package for cosmic-ray and neutrino radio detectors
GNU General Public License v3.0
8 stars 5 forks source link

fix catching overflow in get_angle function #31

Closed cg-laser closed 4 years ago

christophwelling commented 4 years ago

Is this check even a good idea? By definition arccos should not be larger than 1, so if it is, something must have gone seriously wrong. Wouldn't we want to throw an error then?

fschlueter commented 4 years ago

Hi fix looks okay to me. But I would have a few questions. It is correct that in case of if (type(mask) == np.bool_): which should be the normal case with two 1d-arrays we would just set the result to +1 regardless what happened. Is this function suppose to be used with something else than 1d arrays? If not we would always expect an np.bool_ and should require this.

cg-laser commented 4 years ago

because of rounding errors in the scalar products and norms, the value can be just slightly above 1. E.g. 1.00000000000001. Therefore we need to catch it.

The if (type(mask) == np.bool_): is required to distinguish between the first variable being a vector or a list of vectors. I fixed the else branch to

else:
        if (mask1):
            arccos = 1
        if (mask2):
            arccos = -1

I also added more documentation.

christophwelling commented 4 years ago

Ah, that makes sense. Looks good