Commit 7e46acbf authored by Tobias WEBER's avatar Tobias WEBER
Browse files

started with data merging

parent ce98e6c2
......@@ -217,7 +217,7 @@ std::shared_ptr<Symbol> func_help(CliParserContext & ctx)
std::ostringstream ostr;
ostr << "<hr>IN20 data treatment tool version " << PROGRAM_VERSION << ".<br>\n";
ostr << "Written by Tobias Weber, tweber@ill.fr, 2018.<hr><br>\n";
ostr << "Written by Tobias Weber &lt;tweber@ill.fr&gt;, 2018.<hr><br>\n";
ostr << "Type funcs() or vars() to list available functions or variables.<br>\n";
......
......@@ -9,6 +9,7 @@
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLineEdit>
#include "tlibs/time/chrono.h"
// ----------------------------------------------------------------------------
......@@ -61,7 +62,9 @@ void CommandLineWidget::CommandEntered()
m_pEditCLI->clearEditText();
if(!cmd.length()) return;
m_pEditHistory->insertHtml("<font color=\"#0000ff\">" + cmd + "</font><br>");
std::string timestamp = tl::epoch_to_str(tl::epoch());
m_pEditHistory->insertHtml("<b><font color=\"#008800\">" + QString(timestamp.c_str()) + "&gt;</font> " +
"<font color=\"#0000ff\">" + cmd + "</font></b><br>");
// parse command
......
......@@ -6,7 +6,9 @@
*/
#include "data.h"
#include "globals.h"
#include "tlibs/file/loadinstr.h"
#include "tlibs/math/linalg.h"
#include "libs/algos.h"
......@@ -140,15 +142,34 @@ std::tuple<bool, Dataset> Dataset::convert_instr_file(const char* pcFile)
// data operators
// ----------------------------------------------------------------------------
const Data& operator +(const Data& dat)
Data Data::add_pointwise(const Data& dat1, const Data& dat2)
{
return dat;
}
// check if x axes and dimensions are equal
constexpr const t_real_dat eps = 0.01;
bool compatible = true;
compatible = compatible && (dat1.m_x_names == dat2.m_x_names);
compatible = compatible && (dat1.m_x.size() == dat2.m_x.size());
if(compatible)
{
for(std::size_t i=0; i<dat2.m_x.size(); ++i)
{
if(!tl::vec_equal(dat1.m_x[i], dat2.m_x[i], eps))
{
compatible = false;
break;
}
}
}
Data operator -(const Data& dat)
{
Data datret = dat;
if(!compatible)
{
print_err("Cannot add incompatible data sets: x axes do not match.");
return Data();
}
Data datret = dat1;
// detectors
for(std::size_t detidx=0; detidx<datret.m_counts.size(); ++detidx)
......@@ -158,7 +179,11 @@ Data operator -(const Data& dat)
for(std::size_t cntidx=0; cntidx<det.size(); ++cntidx)
{
auto& cnt = det[cntidx];
cnt = -cnt;
cnt += dat2.m_counts[detidx][cntidx];
datret.m_counts_err[detidx][cntidx] =
std::sqrt(dat1.m_counts_err[detidx][cntidx]*dat1.m_counts_err[detidx][cntidx]
+ dat2.m_counts_err[detidx][cntidx]*dat2.m_counts_err[detidx][cntidx]);
}
}
......@@ -170,7 +195,11 @@ Data operator -(const Data& dat)
for(std::size_t cntidx=0; cntidx<det.size(); ++cntidx)
{
auto& cnt = det[cntidx];
cnt = -cnt;
cnt += dat2.m_monitors[detidx][cntidx];
datret.m_monitors_err[detidx][cntidx] =
std::sqrt(dat1.m_monitors_err[detidx][cntidx]*dat1.m_monitors_err[detidx][cntidx]
+ dat2.m_monitors_err[detidx][cntidx]*dat2.m_monitors_err[detidx][cntidx]);
}
}
......@@ -178,12 +207,68 @@ Data operator -(const Data& dat)
}
Data operator +(const Data& dat1, const Data& dat2)
/**
* append dat2 to the end of dat1
*/
Data Data::append(const Data& dat1, const Data& dat2)
{
// TODO: check if x axes and dimensions are equal!
if(dat1.m_counts.size() != dat2.m_counts.size())
{
print_err("Mismatch in number of detector counters.");
return Data();
}
if(dat1.m_monitors.size() != dat2.m_monitors.size())
{
print_err("Mismatch in number of monitor counters.");
return Data();
}
Data datret = dat1;
// append x axes
for(std::size_t xidx=0; xidx<dat1.m_x_names.size(); ++xidx)
{
// find matching axis
auto iter = std::find(dat2.m_x_names.begin(), dat2.m_x_names.end(), dat1.m_x_names[xidx]);
if(iter == dat2.m_x_names.end())
{
print_err("Column \"", dat1.m_x_names[xidx], "\" was not found in all data sets. Ignoring.");
continue;
}
// insert data
std::size_t xidx2 = iter - dat2.m_x_names.begin();
datret.m_x[xidx].insert(datret.m_x[xidx].end(), dat2.m_x[xidx2].begin(), dat2.m_x[xidx2].end());
}
// append counters, monitors, and their errors
for(std::size_t yidx=0; yidx<dat1.m_counts.size(); ++yidx)
datret.m_counts[yidx].insert(datret.m_counts[yidx].end(), dat2.m_counts[yidx].begin(), dat2.m_counts[yidx].end());
for(std::size_t yidx=0; yidx<dat1.m_counts_err.size(); ++yidx)
datret.m_counts_err[yidx].insert(datret.m_counts_err[yidx].end(), dat2.m_counts_err[yidx].begin(), dat2.m_counts_err[yidx].end());
for(std::size_t yidx=0; yidx<dat1.m_monitors.size(); ++yidx)
datret.m_monitors[yidx].insert(datret.m_monitors[yidx].end(), dat2.m_monitors[yidx].begin(), dat2.m_monitors[yidx].end());
for(std::size_t yidx=0; yidx<dat1.m_counts_err.size(); ++yidx)
datret.m_monitors_err[yidx].insert(datret.m_monitors_err[yidx].end(), dat2.m_monitors_err[yidx].begin(), dat2.m_monitors_err[yidx].end());
return datret;
}
const Data& operator +(const Data& dat)
{
return dat;
}
Data operator -(const Data& dat)
{
Data datret = dat;
// detectors
for(std::size_t detidx=0; detidx<datret.m_counts.size(); ++detidx)
{
......@@ -192,11 +277,7 @@ Data operator +(const Data& dat1, const Data& dat2)
for(std::size_t cntidx=0; cntidx<det.size(); ++cntidx)
{
auto& cnt = det[cntidx];
cnt += dat2.m_counts[detidx][cntidx];
datret.m_counts_err[detidx][cntidx] =
std::sqrt(dat1.m_counts_err[detidx][cntidx]*dat1.m_counts_err[detidx][cntidx]
+ dat2.m_counts_err[detidx][cntidx]*dat2.m_counts_err[detidx][cntidx]);
cnt = -cnt;
}
}
......@@ -208,11 +289,7 @@ Data operator +(const Data& dat1, const Data& dat2)
for(std::size_t cntidx=0; cntidx<det.size(); ++cntidx)
{
auto& cnt = det[cntidx];
cnt += dat2.m_monitors[detidx][cntidx];
datret.m_monitors_err[detidx][cntidx] =
std::sqrt(dat1.m_monitors_err[detidx][cntidx]*dat1.m_monitors_err[detidx][cntidx]
+ dat2.m_monitors_err[detidx][cntidx]*dat2.m_monitors_err[detidx][cntidx]);
cnt = -cnt;
}
}
......@@ -220,6 +297,12 @@ Data operator +(const Data& dat1, const Data& dat2)
}
Data operator +(const Data& dat1, const Data& dat2)
{
return Data::add_pointwise(dat1, dat2);
}
Data operator +(const Data& dat, t_real_dat d)
{
Data datret = dat;
......
......@@ -110,6 +110,10 @@ public:
// unary operators
friend const Data& operator +(const Data& dat);
friend Data operator -(const Data& dat);
// different ways of uniting data containers
static Data add_pointwise(const Data& dat1, const Data& dat2);
static Data append(const Data& dat1, const Data& dat2);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment