Commit 863fdc57 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

handling of datasets

parent 8d456219
......@@ -214,12 +214,12 @@ void FileBrowserWidget::SetFile(QListWidgetItem* pCur)
copy_interleave(data[x_idx].begin(), data[x_idx].end(), std::back_inserter(x_data), numpolstates, graphidx);
copy_interleave(data[y_idx].begin(), data[y_idx].end(), std::back_inserter(y_data), numpolstates, graphidx);
std::transform(data[y_idx].begin(), data[y_idx].end(), std::back_inserter(y_err),
[](t_real y) -> t_real
{
if(tl::float_equal<t_real>(y, 0))
return 1;
return std::sqrt(y);
});
[](t_real y) -> t_real
{
if(tl::float_equal<t_real>(y, 0))
return 1;
return std::sqrt(y);
});
// graph
......
......@@ -11,12 +11,14 @@
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QFileDialog>
#include <algorithm>
#include <boost/filesystem.hpp>
#include "libs/algos.h"
#include "tlibs/file/loadinstr.h"
using t_real = double;
using t_real = t_real_dat;
// ----------------------------------------------------------------------------
......@@ -77,51 +79,140 @@ void WorkSpaceWidget::ReceiveFiles(const std::vector<std::string> &files)
{
for(const auto& file : files)
{
boost::filesystem::path filepath(file);
if(!boost::filesystem::exists(filepath))
continue;
// load instrument data file
std::unique_ptr<tl::FileInstrBase<t_real>> pInstr(tl::FileInstrBase<t_real>::LoadInstr(file.c_str()));
std::unique_ptr<tl::FileInstrBase<t_real>> pInstr(tl::FileInstrBase<t_real>::LoadInstr(filepath.string().c_str()));
const auto &colnames = pInstr->GetColNames();
const auto &filedata = pInstr->GetData();
if(!pInstr || !colnames.size()) // only valid files with a non-zero column count
continue;
// process polarisation data
pInstr->SetPolNames("p1", "p2", "i11", "i10");
pInstr->ParsePolData();
// get scan axis indices
std::vector<std::size_t> scan_idx;
for(const auto& scanvar : pInstr->GetScannedVars())
{
std::size_t idx = 0;
pInstr->GetCol(scanvar, &idx);
if(idx < colnames.size())
scan_idx.push_back(idx);
}
// try first axis if none found
if(scan_idx.size() == 0) scan_idx.push_back(0);
// get counter column index
std::vector<std::size_t> ctr_idx;
{
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetCountVar(), &idx);
if(idx < colnames.size())
ctr_idx.push_back(idx);
}
// try second axis if none found
if(ctr_idx.size() == 0) ctr_idx.push_back(1);
if(pInstr && colnames.size()) // only valid files with a non-zero column count
// get monitor column index
std::vector<std::size_t> mon_idx;
{
// process polarisation data
pInstr->SetPolNames("p1", "p2", "i11", "i10");
pInstr->ParsePolData();
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetMonVar(), &idx);
if(idx < colnames.size())
mon_idx.push_back(idx);
}
std::size_t numpolstates = pInstr->NumPolChannels();
if(numpolstates == 0) numpolstates = 1;
// get scan axis indices
std::vector<std::size_t> scan_idx;
for(const auto& scanvar : pInstr->GetScannedVars())
Dataset dataset;
// iterate through all (polarisation) subplots
for(std::size_t polstate=0; polstate<numpolstates; ++polstate)
{
Data data;
// get scan axes
for(std::size_t idx : scan_idx)
{
std::size_t idx = 0;
pInstr->GetCol(scanvar, &idx);
if(idx < colnames.size())
scan_idx.push_back(idx);
std::vector<t_real> thedat;
copy_interleave(filedata[idx].begin(), filedata[idx].end(), std::back_inserter(thedat), numpolstates, polstate);
data.AddAxis(thedat, colnames[idx]);
}
// try first axis if none found
if(scan_idx.size() == 0) scan_idx.push_back(0);
// get counter column index
std::vector<std::size_t> ctr_idx;
// get counters
for(std::size_t idx : ctr_idx)
{
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetCountVar(), &idx);
if(idx < colnames.size())
ctr_idx.push_back(idx);
std::vector<t_real> thedat, theerr;
copy_interleave(filedata[idx].begin(), filedata[idx].end(), std::back_inserter(thedat), numpolstates, polstate);
std::transform(filedata[idx].begin(), filedata[idx].end(), std::back_inserter(theerr),
[](t_real y) -> t_real
{
if(tl::float_equal<t_real>(y, 0))
return 1;
return std::sqrt(y);
});
data.AddCounter(thedat, theerr);
}
// try second axis if none found
if(ctr_idx.size() == 0) ctr_idx.push_back(1);
// get monitor column index
std::vector<std::size_t> mon_idx;
// get monitors
for(std::size_t idx : mon_idx)
{
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetMonVar(), &idx);
if(idx < colnames.size())
mon_idx.push_back(idx);
std::vector<t_real> thedat, theerr;
copy_interleave(filedata[idx].begin(), filedata[idx].end(), std::back_inserter(thedat), numpolstates, polstate);
std::transform(filedata[idx].begin(), filedata[idx].end(), std::back_inserter(theerr),
[](t_real y) -> t_real
{
if(tl::float_equal<t_real>(y, 0))
return 1;
return std::sqrt(y);
});
data.AddMonitor(thedat, theerr);
}
dataset.AddChannel(std::move(data));
}
// insert the dataset into the workspace
std::string fileident = "data" + filepath.stem().string();
const auto [iter, insert_ok] = m_workspace.emplace(std::make_pair(fileident, std::move(dataset)));
}
UpdateList();
}
/**
* sync the list widget with the workspace map
*/
void WorkSpaceWidget::UpdateList()
{
for(const auto& [ident, dataset] : m_workspace)
{
QString qident(ident.c_str());
// dataset with this identifier already in list?
if(m_pListFiles->findItems(qident, Qt::MatchCaseSensitive|Qt::MatchExactly).size())
continue;
auto *pItem = new QListWidgetItem(m_pListFiles);
pItem->setText(qident);
pItem->setData(Qt::UserRole, qident);
}
}
// ----------------------------------------------------------------------------
......
......@@ -16,6 +16,7 @@
#include "qcp/qcustomplot.h"
#include <memory>
#include <map>
#include "data.h"
......@@ -31,6 +32,9 @@ private:
QListWidget *m_pListFiles = new QListWidget(this);
QCustomPlot *m_pPlotter = new QCustomPlot(this);
// maps an identifier to a dataset
std::map<std::string, Dataset> m_workspace;
public:
WorkSpaceWidget(QWidget *pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~WorkSpaceWidget();
......@@ -39,6 +43,8 @@ protected:
void ItemSelected(QListWidgetItem* pCur);
void ItemDoubleClicked(QListWidgetItem* pCur);
void UpdateList();
public:
void ReceiveFiles(const std::vector<std::string>&);
};
......@@ -57,7 +63,7 @@ public:
WorkSpace(QWidget* pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~WorkSpace();
const WorkSpaceWidget *GetWidget() const { return m_pWS.get(); }
const WorkSpaceWidget* GetWidget() const { return m_pWS.get(); }
};
#endif
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