diff --git a/Tools/CMakeLists.txt b/Tools/CMakeLists.txt index c1347108d1d451651bb8a6a593c4acd7c8aab66d..109b6d44abe7794a1f9ee39456ae24d883872e30 100644 --- a/Tools/CMakeLists.txt +++ b/Tools/CMakeLists.txt @@ -1,4 +1,4 @@ -set (TOOLS_FILES plot_tracks.sh plot_crossings.sh) +set (TOOLS_FILES plot_tracks.sh plot_crossings.sh read_hist.py) install ( FILES ${TOOLS_FILES} diff --git a/Tools/read_hist.py b/Tools/read_hist.py new file mode 100755 index 0000000000000000000000000000000000000000..1d3a69490ba6ccea7dde99fc5d3075a35582ed60 --- /dev/null +++ b/Tools/read_hist.py @@ -0,0 +1,27 @@ +import numpy as np +import matplotlib.pyplot as plt +import boost_histogram as bh +import operator +import functools + +def read_hist(filename): + """ + read numpy file produced with CORSIKA 8's save_hist() function into + boost-histogram object. + """ + + d = np.load(filename) + axistypes = d['axistypes'].view('c') + + axes = [] + for i, at in enumerate(axistypes): + if at == b'c': + axes.append(bh.axis.Variable(d[f'binedges_{i}'], overflow=True, underflow=True)) + elif at == b'd': + axes.append(bh.axis.IntCategory(d[f'binedges_{i}'])) + + h = bh.Histogram(*axes) + h.view(flow=True)[:] = d['data'] + + return h +