24 Sio::NumpyFrameSaver::~NumpyFrameSaver()
35 cfg[
"digitize"] =
false;
39 cfg[
"baseline"] = 0.0;
50 cfg[
"frame_tags"] = Json::arrayValue;
60 cfg[
"filename"] =
"wct-frame.npz";
75 l->debug(
"NumpyFrameSaver: EOS");
84 const float baseline = m_cfg[
"baseline"].asFloat();
85 const float scale = m_cfg[
"scale"].asFloat();
86 const float offset = m_cfg[
"offset"].asFloat();
87 const bool digitize = m_cfg[
"digitize"].asBool();
96 if (m_cfg[
"frame_tags"].isNull() or m_cfg[
"frame_tags"].
empty()) {
97 m_cfg[
"frame_tags"][0] =
"";
101 std::stringstream ss;
102 ss <<
"NumpyFrameSaver: see frame #" << inframe->ident()
103 <<
" with " << inframe->traces()->size() <<
" traces with frame tags:";
104 for (
auto t : inframe->frame_tags()) {
105 ss <<
" \"" <<
t <<
"\"";
107 ss <<
" and trace tags:";
108 for (
auto t : inframe->trace_tags()) {
109 ss <<
" \"" <<
t <<
"\"";
111 ss <<
" looking for tags:";
112 for (
auto jt: m_cfg[
"frame_tags"]) {
113 ss <<
" \"" << jt.asString() <<
"\"";
118 for (
auto jtag : m_cfg[
"frame_tags"]) {
121 l->debug(
"NumpyFrameSaver: save {} tagged as {}", traces.size(), tag);
122 if (traces.empty()) {
123 l->warn(
"NumpyFrameSaver: no traces for tag: \"{}\"", tag);
129 auto chend = std::unique(chbeg,
channels.end());
133 const size_t ncols = tbinmm.second-tbinmm.first;
135 l->debug(
"NumpyFrameSaver: saving ncols={} nrows={}", ncols, nrows);
139 arr = arr * scale + offset;
145 const short* sdata = sarr.data();
151 l->debug(
"NumpyFrameSaver: saved {} with {} channels {} ticks @t={} ms qtot={}",
152 aname, nrows, ncols, inframe->time() /
units::ms, arr.sum());
162 const std::vector<double> tickinfo{inframe->time(), inframe->tick(), (double)tbinmm.first};
std::shared_ptr< const IFrame > pointer
void npz_save(std::string zipname, std::string fname, const T *data, const std::vector< size_t > &shape, std::string mode="w")
WIRECELL_FACTORY(NumpyFrameSaver, WireCell::Sio::NumpyFrameSaver, WireCell::IFrameFilter, WireCell::IConfigurable) using namespace WireCell
static ITrace::vector tagged_traces(IFrame::pointer frame, IFrame::tag_t tag)
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
logptr_t logger(std::string name)
Eigen::Array< short, Eigen::Dynamic, Eigen::Dynamic > array_xxs
A 16 bit short integer 2D array.
Json::Value Configuration
unsigned nrows(sqlite3 *db, std::string const &tablename)
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Eigen::ArrayXXf array_xxf
A real, 2D array.