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

Modified get_atmosphere and get_density when single float is input fo… #37

Closed fschlueter closed 4 years ago

fschlueter commented 4 years ago

…r speed.

The present functions utilizing np.where (which works for single floats and arrays) are quite inefficient in case of an float. Since these function are in the 'inner loop' of most calculations and mostly getting floats there is a benefit in having this duplicated code pieces. For get_distance_xmax_geometrical I got a boost of an factor of 3 in computing time.

This commit somewhat increases complexity but I gives you a speed boost of a factor of ~3 (for the numerical calculations). I changed the np.shape(ele) == () to not hasattr(ele, "len"). Not sure if both are completely equivalent and if that matters here. The latter one is a bit faster.

fschlueter commented 4 years ago

I know it increases the complexity and is somewhat duplicated code. However there is a benefit once you aim for numerical integration over a curved atmosphere. One can write the functions for floats such that they can take arrays as well but I realized that takes away most of the speed advantage..

cg-laser commented 4 years ago

@fschlueter I think these changes can be merged?

fschlueter commented 4 years ago

Uh seems I did not catch your approval..