Commit 2cec0ef0 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Merge branch 'develop'

parents 104b7593 9d96a230
......@@ -71,6 +71,8 @@ message(STATUS
find_package(Cerf MODULE REQUIRED)
message(STATUS "libcerf: FOUND=${Cerf_FOUND}, VERSION=${Cerf_VERSION}, LIB=${Cerf_LIBRARIES}, "
"IS_CPP=${Cerf_IS_CPP}")
find_package(QCR MODULE REQUIRED)
message(STATUS "libcerf: FOUND=${QCR_FOUND}, VERSION=${QCR_VERSION}, LIB=${QCR_LIBRARIES}")
# how to build 3rd party libraries:
set(LIB_MAN OFF)
......@@ -86,7 +88,7 @@ message(STATUS "3rdparty libraries all found or configured")
configure_file("manifest.h.in" "${CMAKE_BINARY_DIR}/manifest.h")
add_subdirectory(qcr)
add_subdirectory(devtools)
add_subdirectory(core)
add_subdirectory(gui)
add_subdirectory(main)
......
# Find libQCR
#
# Usage:
# find_package(QCR [REQUIRED] [QUIET])
#
# Sets the following variables:
# - QCR_FOUND .. true if library is found
# - QCR_LIBRARIES .. full path to library
# - QCR_INCLUDE_DIR .. full path to include directory
#
# Copyright 2019 Joachim Wuttke, Forschungszentrum Jülich.
# Redistribution permitted.
find_path(QCR_INCLUDE_DIR QCR/widgets/mainwindow.h)
find_library(QCR_LIBRARIES NAMES QCR QCR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QCR DEFAULT_MSG QCR_LIBRARIES QCR_INCLUDE_DIR)
mark_as_advanced(QCR_INCLUDE_DIR QCR_LIBRARIES)
......@@ -16,7 +16,8 @@ message(STATUS "core to be linked with yaml: ${yaml_LIBRARIES}")
target_link_libraries(${lib}
PUBLIC
qcr
QCR
Qt5::Widgets # depends on Qt5::Gui which depends on Qt5::Core
PRIVATE
LevMar
caress_loader
......
......@@ -13,7 +13,7 @@
// ***********************************************************************************************
#include "core/base/async.h"
#include "qcr/base/debug.h"
#include "QCR/base/debug.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QProgressBar>
......
......@@ -17,7 +17,7 @@
#include "core/base/async.h"
#include "core/data/lens.h"
#include "core/session.h"
//#include "qcr/base/debug.h"
//#include "QCR/base/debug.h"
namespace {
......
......@@ -20,7 +20,7 @@
#include "core/peakfit/peak_function.h"
#include "core/typ/mapped.h"
#include "core/session.h"
#include "qcr/base/debug.h" // ASSERT
#include "QCR/base/debug.h" // ASSERT
namespace {
......@@ -49,7 +49,7 @@ Mapped getPeak(int jP, const Cluster& cluster, int iGamma)
const PeakFunction*const peakFit = dynamic_cast<const PeakFunction*>(pFct.fitFunction());
ASSERT(peakFit);
const Mapped& po = peakFit->outcome(pFct);
if (po.has("center") && fitrange.contains(po.get<double>("center")))
if (po.has("center") && fitrange.contains(po.get<deg>("center")))
out = po;
}
out.set("alpha", alpha);
......
......@@ -13,7 +13,7 @@
// ***********************************************************************************************
#include "export.h"
#include "qcr/base/debug.h"
#include "QCR/base/debug.h"
#include "core/base/async.h"
#include "core/calc/onepeak_allinfos.h"
#include "core/data/cluster.h"
......@@ -109,9 +109,14 @@ void data_export::writeCurve(
stream << "#Gamma range min: " << rgeGma.min << '\n';
stream << "#Gamma range max: " << rgeGma.max << '\n';
for (int i=0; i<meta::numAttributes(false); ++i)
stream << "#" << meta::asciiTag(i) << ": "
<< md.attributeValue(i).toDouble() << '\n';
for (int i=0; i<meta::numAttributes(false); ++i) {
stream << "#" << meta::asciiTag(i) << ": ";
QVariant attr = md.attributeValue(i);
if (attr.canConvert<deg>())
stream << attr.value<deg>() << '\n';
else
stream << attr.value<double>() << '\n';
}
stream << "#Tth" << separator << "Intensity" << '\n';
for (int i=0; i<curve.xs().size(); ++i)
......
......@@ -15,7 +15,7 @@
#include "core/calc/interpolate_polefig.h"
#include "core/session.h"
#include "core/base/async.h"
#include "qcr/base/debug.h" // ASSERT
#include "QCR/base/debug.h" // ASSERT
#include <qmath.h>
// ***********************************************************************************************
......@@ -24,24 +24,6 @@
namespace {
struct itf_t {
itf_t() : itf_t(Q_QNAN, deg(Q_QNAN), Q_QNAN) {}
itf_t(double _inten, deg _tth, double _fwhm) : inten(_inten), tth(_tth), fwhm(_fwhm) {}
void operator+=(const itf_t&); // used once to compute average
double inten;
deg tth;
double fwhm;
};
void itf_t::operator+=(const itf_t& that)
{
inten += that.inten;
tth += that.tth;
fwhm += that.fwhm;
}
//! Calculates the difference of two angles. Parameters should be in [0, 360].
deg calculateDeltaBeta(deg beta1, deg beta2)
{
......@@ -117,16 +99,20 @@ bool inRadius(deg alpha, deg beta, deg centerAlpha, deg centerBeta, deg radius)
//! Adds data from peak infos within radius from alpha and beta to the peak parameter lists.
void searchPoints(deg alpha, deg beta, deg radius, const OnePeakAllInfos& infos,
std::vector<itf_t>& itfs)
std::vector<Mapped>& itfs)
{
// TODO REVIEW Use value trees to improve performance.
// qDebug() << "DEB searchPts " << alpha << beta;
for (const Mapped& info : infos.peakInfos()) {
// qDebug() << " candidate " << info.alpha() << info.beta();
if (inRadius(info.get<deg>("alpha"), info.get<deg>("beta"), alpha, beta, radius)) {
if (info.has("intensity"))
itfs.push_back(itf_t(info.get<double>("intensity"), info.get<double>("center"),
info.get<double>("fwhm")));
if (info.has("intensity")) {
Mapped m;
m.set("intensity", info.at("intensity"));
m.set("center", info.at("center"));
m.set("fwhm", info.at("fwhm"));
itfs.push_back(m);
}
}
}
}
......@@ -168,7 +154,7 @@ void searchInQuadrants(
}
}
itf_t inverseDistanceWeighing(
Mapped inverseDistanceWeighing(
const std::vector<double>& distances, const std::vector<const Mapped*>& infos)
{
int N = NUM_QUADRANTS;
......@@ -182,10 +168,15 @@ itf_t inverseDistanceWeighing(
if (distances.at(i) == .0) {
// Points coincide; no need to interpolate.
const Mapped* m = infos.at(i);
if (m->has("intensity"))
return itf_t{m->get<double>("intensity"), m->get<double>("center"), m->get<double>("fwhm")};
if (m->has("intensity")) {
Mapped itf;
itf.set("intensity", m->at("intensity"));
itf.set("center", m->at("center"));
itf.set("fwhm", m->at("fwhm"));
return itf;
}
qFatal("inverseDistanceWeighing: no intensity given (#1)");
return { Q_QNAN, Q_QNAN, Q_QNAN };
return {};
}
inverseDistances[i] = 1 / distances.at(i);
inverseDistanceSum += inverseDistances.at(i);
......@@ -199,18 +190,20 @@ itf_t inverseDistanceWeighing(
if (!m->has("intensity"))
qFatal("inverseDistanceWeighing: no intensity given (#2)");
double d = inverseDistances.at(i);
offset += m->get<double>("center") * d;
offset += double(m->get<deg>("center")) * d;
height += m->get<double>("intensity") * d;
fwhm += m->get<double>("fwhm") * d;
}
return { double(height/inverseDistanceSum),
deg(offset/inverseDistanceSum),
double(fwhm/inverseDistanceSum) };
Mapped itf;
itf.set("intensity", double(height/inverseDistanceSum));
itf.set("center", deg{offset/inverseDistanceSum});
itf.set("fwhm", double(fwhm/inverseDistanceSum));
return itf;
}
//! Interpolates peak infos to a single point using idw.
itf_t interpolateValues(deg searchRadius, const OnePeakAllInfos& infos, deg alpha, deg beta)
Mapped interpolateValues(deg searchRadius, const OnePeakAllInfos& infos, deg alpha, deg beta)
{
std::vector<const Mapped*> interpolationInfos;
std::vector<double> distances;
......@@ -245,8 +238,13 @@ itf_t interpolateValues(deg searchRadius, const OnePeakAllInfos& infos, deg alph
// Use inverse distance weighing if everything is alright.
if (numQuadrantsOk == NUM_QUADRANTS)
return inverseDistanceWeighing(distances, interpolationInfos);
else
return {};
else {
Mapped itf;
itf.set("intensity", Q_QNAN);
itf.set("fwhm", Q_QNAN);
itf.set("center", deg{Q_QNAN});
return itf;
}
}
} // namespace
......@@ -304,31 +302,37 @@ OnePeakAllInfos algo::interpolateInfos(const OnePeakAllInfos& direct)
if (alpha <= avgAlphaMax) {
// Use averaging.
std::vector<itf_t> itfs;
std::vector<Mapped> itfs;
searchPoints(alpha, beta, avgRadius, direct, itfs);
if (!itfs.empty()) {
// If treshold < 1, we'll only use a fraction of largest peak parameter values.
std::sort(itfs.begin(), itfs.end(), [](const itf_t& i1, const itf_t& i2) {
return i1.inten < i2.inten; });
std::sort(itfs.begin(), itfs.end(), [](const Mapped& i1, const Mapped& i2) {
return i1.get<double>("intensity") < i2.get<double>("intensity"); });
itf_t avg(0, 0, 0);
double inten =0;
deg tth=0;
double fwhm=0;
int iEnd = itfs.size();
int iBegin = qMax(0, qMin(qRound(itfs.size() * (1. - threshold)), iEnd - 1));
ASSERT(iBegin < iEnd);
int n = iEnd - iBegin;
for (int i=iBegin; i<iEnd; ++i)
avg += itfs.at(i);
for (int i=iBegin; i<iEnd; ++i) {
inten += itfs.at(i).get<double>("intensity");
tth += itfs.at(i).get<deg>("center");
fwhm += itfs.at(i).get<double>("fwhm");
}
Mapped m = direct.peakInfos().front();
ASSERT(m.has("gamma_min"));
m.set("alpha", alpha);
m.set("beta", beta);
m.set("center", avg.tth / n);
m.set("intensity", avg.inten / n);
m.set("fwhm", avg.fwhm / n);
m.set("center", tth / n);
m.set("intensity", inten / n);
m.set("fwhm", fwhm / n);
ret.appendPeak(std::move(m));
continue;
}
......@@ -344,14 +348,14 @@ OnePeakAllInfos algo::interpolateInfos(const OnePeakAllInfos& direct)
}
// Use idw, if alpha > avgAlphaMax OR averaging failed (too small avgRadius?).
itf_t itf = interpolateValues(idwRadius, direct, alpha, beta);
Mapped itf = interpolateValues(idwRadius, direct, alpha, beta);
Mapped m = direct.peakInfos().front();
ASSERT(m.has("gamma_min"));
m.set("alpha", alpha);
m.set("beta", beta);
m.set("center", itf.tth);
m.set("intensity", itf.inten);
m.set("fwhm", itf.fwhm);
m.set("center", itf.at("center"));
m.set("intensity", itf.at("intensity"));
m.set("fwhm", itf.at("fwhm"));
ret.appendPeak(std::move(m));
}
}
......
......@@ -14,7 +14,7 @@
#include "core/calc/onepeak_allinfos.h"
#include "core/session.h"
#include "qcr/base/debug.h" // ASSERT
#include "QCR/base/debug.h" // ASSERT
namespace {
......@@ -55,10 +55,11 @@ std::vector<QVariant> peakData(const Mapped& m)
std::vector<QVariant> ret;
for (const QString& key: {"alpha", "beta", "gamma_min", "gamma_max"})
ret.push_back( m.at(key));
for (const QString& key: {"intensity", "center", "fwhm", "gammaOverSigma"}) {
for (const QString& key: {"intensity", "center", "fwhm", "gaussianity"}) {
if (m.has(key)) {
ret.push_back( m.at(key) );
ret.push_back( m.at("sigma_"+key) );
if (m.has("sigma_"+key))
ret.push_back( m.at("sigma_"+key) );
}
}
auto values_to_append = meta::metaValues(m);
......@@ -122,8 +123,14 @@ void OnePeakAllInfos::getValuesAndSigma(const size_t indexX, const size_t indexY
for (size_t i=0; i<n; ++i) {
const Mapped& peakInfo = peakInfos_.at(i);
const std::vector<QVariant> row = peakData(peakInfo);
xs[i] = row.at(indexX).toDouble();
ys[i] = row.at(indexY).toDouble();
if (row.at(indexX).canConvert<deg>())
xs[i] = row.at(indexX).value<deg>();
else
xs[i] = row.at(indexX).toDouble();
if (row.at(indexY).canConvert<deg>())
ys[i] = row.at(indexY).value<deg>();
else
ys[i] = row.at(indexY).toDouble();
}
std::vector<int> is;
......@@ -136,7 +143,10 @@ void OnePeakAllInfos::getValuesAndSigma(const size_t indexX, const size_t indexY
for (auto i : is) {
const Mapped& peakInfo = peakInfos_.at(is.at(i));
const std::vector<QVariant> row = peakData(peakInfo);
ysSigma[i] = row.at(indexY+1).toDouble(); // SIGMA_X has tag position of X plus 1
if (row.at(indexY+1).canConvert<deg>())
ysSigma[i] = row.at(indexY+1).value<deg>();
else
ysSigma[i] = row.at(indexY+1).toDouble(); // SIGMA_X has tag position of X plus 1
}
} else {
ysSigma.resize(0);
......
......@@ -13,7 +13,7 @@
// ***********************************************************************************************
#include "core/base/angles.h"
#include "qcr/base/debug.h" // ASSERT
#include "QCR/base/debug.h" // ASSERT
#include <vector>
namespace {
......
......@@ -15,7 +15,7 @@
#include "core/data/cluster.h"
#include "core/session.h"
#include "core/data/collect_intensities.h"
#include "qcr/base/debug.h" // warning
#include "QCR/base/debug.h" // warning
// ***********************************************************************************************
//! @class Sequence
......
......@@ -14,7 +14,7 @@
#include "core/data/collect_intensities.h"
#include "core/session.h"
#include "qcr/base/debug.h"
#include "QCR/base/debug.h"
#include <qmath.h>
namespace {
......
......@@ -15,8 +15,8 @@
#include "core/data/corrset.h"
#include "core/loaders/loaders.h"
#include "core/session.h"
#include "qcr/engine/mixin.h" // remakeAll
#include "qcr/base/debug.h"
#include "QCR/engine/mixin.h" // remakeAll
#include "QCR/base/debug.h"
namespace {
......
......@@ -17,7 +17,7 @@
#include "core/raw/image.h"
#include "core/raw/rawfile.h"
#include "qcr/engine/cell.h"
#include "QCR/engine/cell.h"
#include "core/typ/lazy_data.h"
#include <memory>
......
......@@ -15,8 +15,8 @@
#include "core/data/cluster.h"
#include "core/loaders/loaders.h"
#include "core/session.h"
#include "qcr/engine/mixin.h" // remakeAll
#include "qcr/base/debug.h" // ASSERT
#include "QCR/engine/mixin.h" // remakeAll
#include "QCR/base/debug.h" // ASSERT
#include <algorithm>
// ***********************************************************************************************
......@@ -168,6 +168,7 @@ void Dataset::onFileChanged()
cnt += file.numMeasurements();
}
updateClusters();
updateMetaModes();
}
void Dataset::onClusteringChanged()
......@@ -180,8 +181,12 @@ void Dataset::updateClusters()
{
allClusters.clear();
hasIncomplete_ = false;
int measureNum = 1;
double measureTime =0;
int clusterOffset = 0;
for (Datafile& file : files_) {
file.clusters_.clear();
file.clusterOffset_ = clusterOffset;
for (int i=0; i<file.numMeasurements(); i+=binning.val()) {
if (i+binning.val()>file.numMeasurements()) {
hasIncomplete_ = true;
......@@ -189,11 +194,17 @@ void Dataset::updateClusters()
break;
}
std::vector<const Measurement*> group;
for (int ii=i; ii<file.numMeasurements() && ii<i+binning.val(); ii++)
for (int ii=i; ii<file.numMeasurements() && ii<i+binning.val(); ii++) {
file.raw_.setMeasurementNum(ii, measureNum);
file.raw_.setMeasurementTime(ii, measureTime);
measureTime += file.raw_.measurements().at(ii)->deltaTime();
group.push_back(file.raw_.measurements().at(ii));
measureNum++;
}
std::unique_ptr<Cluster> cluster(new Cluster(group, file, allClusters.size(), i));
file.clusters_.push_back(cluster.get());
allClusters.push_back(std::move(cluster));
clusterOffset++;
}
}
gSession->activeClusters.invalidate();
......@@ -241,3 +252,32 @@ bool Dataset::hasFile(const QString& fileName) const
return true;
return false;
}
void Dataset::updateMetaModes() const
{
meta::clearMetaModes();
int metasize = meta::numAttributes(false);
for (int f=0; f<files_.size(); f++) {
const Datafile& file = files_.at(f);
for (int m=0; m<metasize; m++) {
if (meta::getMetaMode(m) == metaMode::MEASUREMENT_DEPENDENT)
continue;
std::vector<const Measurement*> measurements = file.raw_.measurements();
for (int i=0; i<file.raw_.numMeasurements()-1; i++) {
if (measurements.at(i)->metadata().attributeValue(m) ==
measurements.at(i+1)->metadata().attributeValue(m))
continue;
meta::setMetaMode(m, metaMode::MEASUREMENT_DEPENDENT);
}
if (meta::getMetaMode(m) == metaMode::FILE_DEPENDENT)
continue;
if (f>=files_.size()-1)
continue;
if (files_.at(f).raw_.measurements().at(0)->metadata().attributeValue(m) ==
files_.at(f+1).raw_.measurements().at(0)->metadata().attributeValue(m))
continue;
if (meta::getMetaMode(m) != metaMode::MEASUREMENT_DEPENDENT)
meta::setMetaMode(m, metaMode::FILE_DEPENDENT);
}
}
}
......@@ -16,7 +16,7 @@
#define DATASET_H
#include "core/data/cluster.h"
#include "qcr/engine/cell.h"
#include "QCR/engine/cell.h"
#include "core/raw/rawfile.h"
#include <memory>
......@@ -40,6 +40,8 @@ public:
bool activated() const { return activated_; }
int offset_; //!< first index in total list of `Measurement`s
int clusterOffset_; //!< first index in list of all `Cluster`s
//!< set by Dataset::updateClusters
private:
friend class Dataset;
......@@ -118,6 +120,7 @@ private:
void onClusteringChanged();
void updateClusters();
void updateActiveClusters();
void updateMetaModes() const;
bool hasFile(const QString& fileName) const;
};
......
......@@ -16,7 +16,7 @@
#include "core/peakfit/peak_function.h"
#include "core/peakfit/polynom.h"
#include "core/session.h"
//#include "qcr/base/debug.h"
//#include "QCR/base/debug.h"
namespace {
......
......@@ -14,7 +14,7 @@
#include "core/data/cluster.h"
#include "core/session.h"
//#include "qcr/base/debug.h"
//#include "QCR/base/debug.h"
GammaSelection::GammaSelection()
{
......
......@@ -16,7 +16,7 @@
#define GAMMA_SELECTION_H
#include "core/typ/range.h"
#include "qcr/engine/cell.h"
#include "QCR/engine/cell.h"
#include <QJsonArray>
//! Supports different ways of setting a gamma range.
......
......@@ -15,7 +15,7 @@
#include "core/data/collect_intensities.h"
#include "core/data/cluster.h"
#include "core/session.h"
#include "qcr/base/debug.h"
#include "QCR/base/debug.h"
QJsonObject ThetaSelection::toJson() const
{
......
Supports Markdown
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