From ac8656d5f6ecba9c20fd75d4f5920d48103d5d76 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Thu, 1 Oct 2020 14:27:46 +0200
Subject: [PATCH] even better flow bin handling

---
 tools/read_hist.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 tools/read_hist.py

diff --git a/tools/read_hist.py b/tools/read_hist.py
new file mode 100755
index 000000000..4348e118b
--- /dev/null
+++ b/tools/read_hist.py
@@ -0,0 +1,29 @@
+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')
+    overflow = d['overflow']
+    underflow = d['underflow']
+    
+    axes = []
+    for i, (at, has_overflow, has_underflow) in enumerate(zip(axistypes, overflow, underflow)):
+        if at == b'c':
+            axes.append(bh.axis.Variable(d[f'binedges_{i}'], overflow=has_overflow, underflow=has_underflow))
+        elif at == b'd':
+            axes.append(bh.axis.IntCategory(d[f'bins_{i}'], growth=(not has_overflow)))
+        
+    h = bh.Histogram(*axes)
+    h.view(flow=True)[:] = d['data']
+    
+    return h
+
-- 
GitLab