Commit d318f06c authored by Tobias WEBER's avatar Tobias WEBER
Browse files

a) added function to append polarisation channels, b) bugfixes

parent e64ec1e8
......@@ -31,7 +31,7 @@ real (([0-9]+\.?[0-9]*)|(\.[0-9]+))
return yy::CliParser::make_TOK_STRING(str);
}
[A-Za-z_]+[A-Za-z0-9]* {
[A-Za-z_]+[A-Za-z0-9_]* {
return yy::CliParser::make_TOK_IDENT(yytext);
}
......
......@@ -507,6 +507,47 @@ std::shared_ptr<Symbol> func_append(CliParserContext & ctx, const std::vector<st
/**
* append datasets as the channels of a new dataset
*/
std::shared_ptr<Symbol> func_append_channels(CliParserContext & ctx, const std::vector<std::shared_ptr<Symbol>>& args)
{
if(args.size() == 0)
{
ctx.PrintError("No arguments given.");
return nullptr;
}
// append datasets
if(args[0]->GetType() == SymbolType::DATASET)
{
// first dataset
Dataset datret = dynamic_cast<const SymbolDataset&>(*args[0]).GetValue();
for(std::size_t idx=1; idx<args.size(); ++idx)
{
if(args[idx]->GetType() != SymbolType::DATASET)
{
ctx.PrintError("Mismatching argument types. Expected data sets.");
return nullptr;
}
const auto& dat = dynamic_cast<const SymbolDataset&>(*args[idx]).GetValue();
datret = Dataset::append_channels(datret, dat);
}
return std::make_shared<SymbolDataset>(datret);
}
// otherwise fail
ctx.PrintError("Invalid argument type for append operation: ", Symbol::get_type_name(*args[0]), ".");
return nullptr;
}
/**
* point-wise addition of arrays or datasets
*/
......@@ -703,6 +744,7 @@ std::unordered_map<std::string, std::tuple<std::shared_ptr<Symbol>(*)
(CliParserContext&, const std::vector<std::shared_ptr<Symbol>>&), std::string>> g_funcs_gen_vararg =
{
std::make_pair("append", std::make_tuple(&func_append, "appends two or more data sets")),
std::make_pair("append_channels", std::make_tuple(&func_append_channels, "appends two or more data set as individual channels")),
std::make_pair("add_pointwise", std::make_tuple(&func_add_pointwise, "pointwise addition of two or more data sets")),
};
......
......@@ -228,22 +228,23 @@ Data Data::append(const Data& dat1, const Data& dat2)
Data datret = dat1;
// append x axes
for(std::size_t xidx=0; xidx<dat1.m_x_names.size(); ++xidx)
for(std::size_t xidx=0; xidx<std::min(dat1.m_x_names.size(), dat1.m_x.size()); ++xidx)
{
//std::cout << "Appending column " << dat1.m_x_names[xidx] << std::endl;
// 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())
auto iter2 = std::find(dat2.m_x_names.begin(), dat2.m_x_names.end(), dat1.m_x_names[xidx]);
if(iter2 == 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();
std::size_t xidx2 = iter2 - 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());
......@@ -254,7 +255,6 @@ Data Data::append(const Data& dat1, const Data& dat2)
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;
}
......@@ -498,6 +498,20 @@ Dataset Dataset::append(const Dataset& dat1, const Dataset& dat2)
}
Dataset Dataset::append_channels(const Dataset& dat1, const Dataset& dat2)
{
Dataset dataset = dat1;
for(std::size_t ch2=0; ch2<dat2.GetNumChannels(); ++ch2)
{
const Data& thechannel= dat2.GetChannel(ch2);
dataset.AddChannel(thechannel);
}
return dataset;
}
Dataset operator +(const Dataset& dat1, const Dataset& dat2)
{
return Dataset::add_pointwise(dat1, dat2);
......
......@@ -86,7 +86,7 @@ public:
if(name != "")
m_x_names.push_back(name);
else
else if(m_x_names.size() < m_x.size())
m_x_names.push_back("ax" + std::to_string(GetNumAxes()));
}
void AddAxis(std::vector<t_real_dat> &&dat, const std::string &name="")
......@@ -95,7 +95,7 @@ public:
if(name != "")
m_x_names.push_back(name);
else
else if(m_x_names.size() < m_x.size())
m_x_names.push_back("ax" + std::to_string(GetNumAxes()));
}
......@@ -165,6 +165,7 @@ public:
// different ways of uniting data sets
static Dataset add_pointwise(const Dataset& dat1, const Dataset& dat2);
static Dataset append(const Dataset& dat1, const Dataset& dat2);
static Dataset append_channels(const Dataset& dat1, const Dataset& dat2);
static std::tuple<bool, Dataset> convert_instr_file(const char* pcFile);
};
......
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