IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ccd7e6e8 authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan: Committed by Maximilian Reininghaus
Browse files

removed append option from save_hist()

parent c731622e
No related branches found
No related tags found
No related merge requests found
...@@ -23,12 +23,9 @@ namespace corsika { ...@@ -23,12 +23,9 @@ namespace corsika {
template <class Axes, class Storage> template <class Axes, class Storage>
inline void save_hist(boost::histogram::histogram<Axes, Storage> const& h, inline void save_hist(boost::histogram::histogram<Axes, Storage> const& h,
std::string const& filename, SaveMode mode) { std::string const& filename) {
unsigned const rank = h.rank(); unsigned const rank = h.rank();
// append vs. overwrite
const std::string mode_str = (mode == SaveMode::append ? "a" : "w");
std::vector<size_t> axes_dims; std::vector<size_t> axes_dims;
axes_dims.reserve(rank); axes_dims.reserve(rank);
...@@ -58,7 +55,7 @@ namespace corsika { ...@@ -58,7 +55,7 @@ namespace corsika {
ax_edges.push_back(ax.bin(ax.size() - 1).upper()); ax_edges.push_back(ax.bin(ax.size() - 1).upper());
cnpy::npz_save(filename, std::string{"binedges_"} + std::to_string(i), cnpy::npz_save(filename, std::string{"binedges_"} + std::to_string(i),
ax_edges.data(), {ax_edges.size()}, mode_str); ax_edges.data(), {ax_edges.size()}, "a");
} else { } else {
axis_types.push_back('d'); axis_types.push_back('d');
std::vector<int64_t> bins; // we assume that discrete axes have integer bins std::vector<int64_t> bins; // we assume that discrete axes have integer bins
...@@ -67,14 +64,13 @@ namespace corsika { ...@@ -67,14 +64,13 @@ namespace corsika {
for (int j = 0; j < ax.size(); ++j) { bins.push_back(ax.bin(j).lower()); } for (int j = 0; j < ax.size(); ++j) { bins.push_back(ax.bin(j).lower()); }
cnpy::npz_save(filename, std::string{"bins_"} + std::to_string(i), bins.data(), cnpy::npz_save(filename, std::string{"bins_"} + std::to_string(i), bins.data(),
{bins.size()}, mode_str); {bins.size()}, "a");
} }
} }
cnpy::npz_save(filename, std::string{"axistypes"}, axis_types.data(), {rank}, cnpy::npz_save(filename, std::string{"axistypes"}, axis_types.data(), {rank}, "a");
mode_str); cnpy::npz_save(filename, std::string{"overflow"}, overflow.get(), {rank}, "a");
cnpy::npz_save(filename, std::string{"overflow"}, overflow.get(), {rank}, mode_str); cnpy::npz_save(filename, std::string{"underflow"}, underflow.get(), {rank}, "a");
cnpy::npz_save(filename, std::string{"underflow"}, underflow.get(), {rank}, mode_str);
auto const prod_axis_size = std::accumulate(axes_dims.cbegin(), axes_dims.cend(), auto const prod_axis_size = std::accumulate(axes_dims.cbegin(), axes_dims.cend(),
unsigned{1}, std::multiplies<>()); unsigned{1}, std::multiplies<>());
...@@ -98,9 +94,9 @@ namespace corsika { ...@@ -98,9 +94,9 @@ namespace corsika {
temp[p] = *x; temp[p] = *x;
} }
cnpy::npz_save(filename, "data", temp.get(), axes_dims, mode_str); cnpy::npz_save(filename, "data", temp.get(), axes_dims, "a");
// In Python this array can directly be assigned to a histogram view if that // In Python this array can directly be assigned to a histogram view if that
// histogram has its axes correspondingly: hist.view(flow=True)[:] = file['data'] // histogram has its axes correspondingly: hist.view(flow=True)[:] = file['data']
} // namespace corsika } // namespace corsika
} // namespace corsika } // namespace corsika
\ No newline at end of file
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
namespace corsika { namespace corsika {
enum class SaveMode { overwrite, append };
/** /**
* This functions saves a boost::histogram into a numpy file. Only rather basic axis * This functions saves a boost::histogram into a numpy file. Only rather basic axis
* types are supported: regular, variable, integer, category<int>. Only "ordinary" bin * types are supported: regular, variable, integer, category<int>. Only "ordinary" bin
...@@ -24,7 +22,7 @@ namespace corsika { ...@@ -24,7 +22,7 @@ namespace corsika {
*/ */
template <class Axes, class Storage> template <class Axes, class Storage>
inline void save_hist(boost::histogram::histogram<Axes, Storage> const& h, inline void save_hist(boost::histogram::histogram<Axes, Storage> const& h,
std::string const& filename, SaveMode mode = SaveMode::append); std::string const& filename);
} // namespace corsika } // namespace corsika
#include <corsika/detail/framework/utility/SaveBoostHistogram.inl> #include <corsika/detail/framework/utility/SaveBoostHistogram.inl>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment