Commit c1a01d69 authored by Jan Burle's avatar Jan Burle
Browse files

This is release 2.0.2a

parent 630cd39f
ver. 2.0.2a (hotfix), released 2016.08.29
--------------------------------
Bug fixes:
* vanadium correction re-enabled for diffractograms
* fixed labels in diffractogram output
ver. 2.0.2, released 2016.08.23
-------------------------------
......
......@@ -29,7 +29,8 @@ LensBase::LensBase(core::Session::rc session, data::Datasets::rc datasets,
typ::ImageTransform::rc imageTransform, typ::ImageCut::rc imageCut)
: session_(session), datasets_(datasets)
, trans_(trans), cut_(cut)
, imageTransform_(imageTransform), imageCut_(imageCut) {
, imageTransform_(imageTransform), imageCut_(imageCut)
, intensCorr_(session.intensCorr()) {
}
LensBase::~LensBase() {
......@@ -48,13 +49,11 @@ size2d LensBase::transCutSize(size2d size) const {
//------------------------------------------------------------------------------
ImageLens::ImageLens(core::Session::rc session,
Image::rc image, Image const* corrImage,
Datasets::rc datasets, bool trans, bool cut,
ImageCut::rc imageCut, ImageTransform::rc imageTransform)
: super(session, datasets, trans, cut, imageTransform, imageCut)
, image_(image), corrImage_(corrImage)
Image::rc image, Datasets::rc datasets,
bool trans, bool cut)
: super(session, datasets, trans, cut, session.imageTransform(), session.imageCut())
, image_(image)
{
calcSensCorr();
}
size2d ImageLens::size() const {
......@@ -66,8 +65,8 @@ inten_t ImageLens::imageInten(uint i, uint j) const {
if (cut_) doCut(i, j);
inten_t inten = image_.inten(i, j);
if (corrImage_)
inten *= intensCorr_.at(i, j);
if (intensCorr_)
inten *= intensCorr_->at(i, j);
return inten;
}
......@@ -122,41 +121,8 @@ void ImageLens::doTrans(uint& x, uint& y) const {
}
}
void ImageLens::calcSensCorr() {
hasNaNs_ = false;
if (!corrImage_)
return;
ENSURE(image_.size() == corrImage_->size())
size2d size = corrImage_->size() - imageCut_.marginSize();
ENSURE(!size.isEmpty())
qreal sum = 0;
uint w = size.w, h = size.h, di = imageCut_.left,
dj = imageCut_.top;
for_ij (w, h)
sum += corrImage_->inten(i + di, j + dj);
qreal avg = sum / (w * h);
intensCorr_.fill(1, image_.size());
for_ij (w, h) {
auto inten = corrImage_->inten(i + di, j + dj);
qreal fact;
if (inten > 0) {
fact = avg / inten;
} else {
fact = qQNaN();
hasNaNs_ = true;
}
intensCorr_.setAt(i + di, j + dj, inten_t(fact));
}
void ImageLens::doCut(uint& i, uint& j) const {
i += imageCut_.left; j += imageCut_.top;
}
//------------------------------------------------------------------------------
......@@ -193,7 +159,7 @@ Curve DatasetLens::makeCurve() const {
}
Curve DatasetLens::makeCurve(gma_rge::rc rgeGma) const {
inten_vec intens = dataset_.collectIntens(session_, rgeGma);
inten_vec intens = dataset_.collectIntens(session_, intensCorr_, rgeGma);
Curve res;
uint count = intens.count();
......
......@@ -54,6 +54,7 @@ protected:
bool trans_, cut_;
typ::ImageTransform imageTransform_;
typ::ImageCut imageCut_;
typ::Image const* intensCorr_;
};
//------------------------------------------------------------------------------
......@@ -61,9 +62,8 @@ protected:
class ImageLens final : public LensBase {
CLS(ImageLens) SUPER(LensBase)
public:
ImageLens(core::Session const&, typ::Image::rc, typ::Image const* corrImage,
data::Datasets::rc,
bool trans, bool cut, typ::ImageCut::rc, typ::ImageTransform::rc);
ImageLens(core::Session const&, typ::Image::rc, data::Datasets::rc,
bool trans, bool cut);
typ::size2d size() const;
......@@ -73,20 +73,11 @@ public:
private:
void doTrans(uint& i, uint& j) const;
void doCut(uint& i, uint& j) const;
void doCut(uint& i, uint& j) const {
i += imageCut_.left; j += imageCut_.top;
}
typ::Image const& image_;
void calcSensCorr(); // detector sensitivity correction
typ::Image const& image_;
typ::Image const* corrImage_;
typ::Array2D<inten_t> intensCorr_;
bool hasNaNs_;
mutable inten_rge rgeInten_;
mutable inten_rge rgeInten_;
};
typedef QSharedPointer<ImageLens> shp_ImageLens;
......
......@@ -183,7 +183,7 @@ size2d OneDataset::imageSize() const {
return image_.size();
}
void OneDataset::collectIntens(core::Session::rc session,
void OneDataset::collectIntens(core::Session::rc session, typ::Image const* intensCorr,
inten_vec& intens, uint_vec& counts,gma_rge::rc rgeGma,
tth_t minTth, tth_t deltaTth) const {
auto angleMap = session.angleMap(*this);
......@@ -206,8 +206,14 @@ void OneDataset::collectIntens(core::Session::rc session,
if (qIsNaN(inten))
continue;
inten_t corr = intensCorr ? intensCorr->at(i) : 1;
if (qIsNaN(corr))
continue;
inten *= corr;
uint count = intens.count();
tth_t tth = map.at(ind).tth;
tth_t tth = map.at(ind).tth;
EXPECT(minTth <= tth && tth <= minTth + count*deltaTth)
uint ti = qMin(to_u(qFloor((tth - minTth) / deltaTth)), count-1); // bin index
intens[ti] += inten;
......@@ -340,7 +346,9 @@ qreal Dataset::avgDeltaTime() const {
AVG_ONES(deltaTime)
}
inten_vec Dataset::collectIntens(core::Session::rc session, gma_rge::rc rgeGma) const {
inten_vec Dataset::collectIntens(
core::Session::rc session, typ::Image const* intensCorr, gma_rge::rc rgeGma) const
{
tth_rge tthRge = rgeTth(session);
tth_t tthWdt = tthRge.width();
......@@ -348,7 +356,7 @@ inten_vec Dataset::collectIntens(core::Session::rc session, gma_rge::rc rgeGma)
uint pixWidth = session.imageSize().w - cut.left - cut.right;
uint numBins;
if (1 < count()) { // combined
if (1 < count()) { // combined datasets
auto one = first();
tth_t delta = one->rgeTth(session).width() / pixWidth;
numBins = to_u(qCeil(tthWdt / delta / 2));
......@@ -362,7 +370,7 @@ inten_vec Dataset::collectIntens(core::Session::rc session, gma_rge::rc rgeGma)
tth_t minTth = tthRge.min, deltaTth = tthWdt / numBins;
for (auto& one : *this)
one->collectIntens(session, intens, counts, rgeGma, minTth, deltaTth);
one->collectIntens(session, intensCorr, intens, counts, rgeGma, minTth, deltaTth);
for_i (numBins) {
auto cnt = counts.at(i);
......@@ -449,6 +457,7 @@ inten_rge::rc Datasets::rgeFixedInten(core::Session::rc session, bool trans, boo
Curve Datasets::avgCurve(core::Session::rc session) const {
if (avgCurve_.isEmpty()) {
// TODO invalidate when combinedDgram is unchecked
TakesLongTime __;
......@@ -458,6 +467,13 @@ Curve Datasets::avgCurve(core::Session::rc session) const {
return avgCurve_;
}
void Datasets::invalidateAvgMutables() const {
avgMonitorCount_ = avgDeltaMonitorCount_ = avgDeltaTime_ = qQNaN();
rgeFixedInten_.invalidate();
rgeGma_.invalidate();
avgCurve_.clear();
}
shp_Dataset Datasets::combineAll() const {
shp_Dataset d(new Dataset);
......@@ -468,13 +484,6 @@ shp_Dataset Datasets::combineAll() const {
return d;
}
void Datasets::invalidateAvgMutables() {
avgMonitorCount_ = avgDeltaMonitorCount_ = avgDeltaTime_ = qQNaN();
rgeFixedInten_.invalidate();
rgeGma_.invalidate();
avgCurve_.clear();
}
qreal Datasets::calcAvgMutable(qreal (Dataset::*avgMth)() const) const {
qreal avg = 0;
......
......@@ -113,7 +113,7 @@ public:
typ::Image::rc image() const { return image_; }
typ::size2d imageSize() const;
void collectIntens(core::Session const&,
void collectIntens(core::Session const&, typ::Image const* intensCorr,
inten_vec&, uint_vec&, gma_rge::rc,
tth_t minTth, tth_t deltaTth) const;
private:
......@@ -155,7 +155,8 @@ public:
qreal avgDeltaMonitorCount() const;
qreal avgDeltaTime() const;
inten_vec collectIntens(core::Session const&, gma_rge::rc) const;
inten_vec collectIntens(core::Session const&, typ::Image const* intensCorr,
gma_rge::rc) const;
private:
// all dataset(s) must have the same image size
......@@ -185,9 +186,10 @@ public:
typ::Curve avgCurve(core::Session const&) const;
void invalidateAvgMutables() const;
private:
shp_Dataset combineAll() const;
void invalidateAvgMutables();
qreal calcAvgMutable(qreal (Dataset::*avgMth)() const) const;
// computed on demand (NaNs or emptiness indicate yet unknown values)
......
......@@ -35,7 +35,7 @@ void Session::clear() {
remFile(0);
remCorrFile();
corrEnabled_ = false;
corrEnabled_ = corrHasNaNs_ = false;
bgPolyDegree_ = 0;
bgRanges_.clear();
......@@ -70,6 +70,48 @@ void Session::remFile(uint i) {
updateImageSize();
}
void Session::calcIntensCorr() const {
corrHasNaNs_ = false;
size2d size = corrImage_.size() - imageCut_.marginSize();
ENSURE(!size.isEmpty())
uint w = size.w, h = size.h, di = imageCut_.left,
dj = imageCut_.top;
qreal sum = 0;
for_ij (w, h)
sum += corrImage_.inten(i + di, j + dj);
qreal avg = sum / (w * h);
intensCorr_.fill(1, corrImage_.size());
for_ij (w, h) {
auto inten = corrImage_.inten(i + di, j + dj);
qreal fact;
if (inten > 0) {
fact = avg / inten;
} else {
fact = qQNaN();
corrHasNaNs_ = true;
}
intensCorr_.setAt(i + di, j + dj, inten_t(fact));
}
}
Image const* Session::intensCorr() const {
if (!isCorrEnabled())
return nullptr;
if (intensCorr_.isEmpty())
calcIntensCorr();
return &intensCorr_;
}
void Session::setCorrFile(shp_File file) THROWS {
if (file.isNull()) {
remCorrFile();
......@@ -78,6 +120,7 @@ void Session::setCorrFile(shp_File file) THROWS {
setImageSize(datasets.imageSize());
corrImage_ = datasets.foldedImage();
intensCorr_.clear(); // will be calculated lazily
// all ok
corrFile_ = file;
......@@ -87,7 +130,7 @@ void Session::setCorrFile(shp_File file) THROWS {
void Session::remCorrFile() {
corrFile_.clear();
corrImage_.clear();
corrImage_.clear(); intensCorr_.clear();
corrEnabled_ = false;
updateImageSize();
}
......@@ -194,6 +237,8 @@ void Session::setImageCut(bool topLeftFirst, bool linked, ImageCut::rc cut) {
imageCut_ = ImageCut(left, top, right, bottom);
}
intensCorr_.clear(); // lazy
}
void Session::setGeometry(preal detectorDistance, preal pixSize,
......@@ -231,10 +276,9 @@ shp_AngleMap Session::angleMap(Session::rc session, OneDataset::rc one) {
}
shp_ImageLens Session::imageLens(
Image::rc image, Datasets::rc datasets, bool trans, bool cut) const {
return shp_ImageLens(
new ImageLens(*this, image, corrEnabled_ ? &corrImage_ : nullptr,
datasets, trans, cut, imageCut_, imageTransform_));
Image::rc image, Datasets::rc datasets, bool trans, bool cut) const
{
return shp_ImageLens(new ImageLens(*this, image, datasets, trans, cut));
}
shp_DatasetLens Session::datasetLens(Dataset::rc dataset, Datasets::rc datasets, eNorm norm,
......
......@@ -50,12 +50,18 @@ public:
void addFile(data::shp_File) THROWS;
void remFile(uint i);
// correction file
private:
// correction file
data::shp_File corrFile_;
typ::Image corrImage_;
bool corrEnabled_;
mutable typ::Image intensCorr_;
mutable bool corrHasNaNs_;
void calcIntensCorr() const;
// datasets
uint_vec collectedFromFiles_; // from these files
data::Datasets collectedDatasets_; // datasets collected ...
str_lst collectedDatasetsTags_;
......@@ -73,6 +79,8 @@ public:
return corrImage_;
}
typ::Image const* intensCorr() const;
void setCorrFile(data::shp_File) THROWS; // Load or remove a correction file.
void remCorrFile();
......
......@@ -223,7 +223,11 @@ Actions::Actions(TheHub& hub): super(hub) {
deselect();
});
onSigDatasetsChanged([this,deselect]() {
onSigDatasetsChanged([deselect]() {
deselect();
});
onSigCorrEnabled([deselect]() {
deselect();
});
}
......
......@@ -142,16 +142,19 @@ OutputData DiffractogramsFrame::outputCurrDiffractogram() {
auto writeMetaData = [](OutputData outputData, QTextStream& stream, str separator) {
if (outputData.picNum_ > 0)
stream << "Picture Nr:" << separator << outputData.picNum_ << '\n';
stream << "Picture Nr: " << outputData.picNum_ << '\n';
stream << "Comment:" << separator << outputData.dataset_.metadata()->comment << '\n';
stream << "Date:" << separator << outputData.dataset_.metadata()->date << '\n';
stream << "Gamma Range max:" << separator << outputData.gmaStripe_.min << '\n';
stream << "Gamma Range max:" << separator << outputData.gmaStripe_.max << '\n';
auto &md = *outputData.dataset_.metadata();
auto &rgeGma = outputData.gmaStripe_;
stream << "Comment: " << md.comment << '\n';
stream << "Date: " << md.date << '\n';
stream << "Gamma range min: " << rgeGma.min << '\n';
stream << "Gamma range max: " << rgeGma.max << '\n';
for_i (data::Metadata::numAttributes(true)) {
stream << data::Metadata::attributeTag(i) << ": " <<
outputData.dataset_.metadata()->attributeValue(i).toDouble() << '\n';
md.attributeValue(i).toDouble() << '\n';
}
};
......@@ -164,10 +167,12 @@ bool DiffractogramsFrame::writeCurrDiffractogramToFile(rcstr filePath, rcstr sep
QTextStream stream(&file);
writeMetaData(outputData, stream, separator);
stream << "Intensity" << separator << "Tth" << '\n';
for_i(outputData.curve_.xs().count())
stream << outputData.curve_.x(i) << separator << outputData.curve_.y(i)
<< '\n';
stream << "Tth" << separator << "Intensity" << '\n';
auto &curve = outputData.curve_;
for_i (curve.xs().count())
stream << curve.x(i) << separator << curve.y(i) << '\n';
return true;
}
......@@ -189,7 +194,7 @@ bool DiffractogramsFrame::writeAllDiffractogramsToFiles(rcstr filePath, rcstr se
for (auto outputData : outputCollection) {
writeMetaData(outputData,stream,separator);
stream << "Intensity" << separator << "Tth" << '\n';
stream << "Tth" << separator << "Intensity" << '\n';
for_i (outputData.curve_.xs().count()) {
stream << outputData.curve_.x(i) << separator << outputData.curve_.y(i) << '\n';
}
......@@ -200,7 +205,7 @@ bool DiffractogramsFrame::writeAllDiffractogramsToFiles(rcstr filePath, rcstr se
for (auto outputCollection : outputCollections) {
for (auto outputData : outputCollection) {
writeMetaData(outputData,stream,separator);
stream << "Intensity" << separator << "Tth" << '\n';
stream << "Tth" << separator << "Intensity" << '\n';
for_i (outputData.curve_.xs().count()) {
stream << outputData.curve_.x(i) << separator << outputData.curve_.y(i) << '\n';
}
......@@ -208,9 +213,9 @@ bool DiffractogramsFrame::writeAllDiffractogramsToFiles(rcstr filePath, rcstr se
++fileNumber;
}
}
return true;
}
return true;
}
bool DiffractogramsFrame::saveDiffractogramOutput() {
str path = tabSave_->filePath(true);
......
......@@ -73,6 +73,11 @@ public:
Array2D(): size_(0,0) {
}
// is empty?
bool isEmpty() const {
return 0 == count();
}
// 2D image size
size2d::rc size() const {
return size_;
......
......@@ -3,7 +3,7 @@
PRO=STeCa2.pro
echo -e '# generated project\n' > $PRO
APP=Steca2_`date +%y%m%d_%H%M`
APP=STeCa2-`date +%y%m%d_%H%M`
cat >> $PRO <<EOT
TARGET = $APP
......
......@@ -2,7 +2,7 @@
#define MANIFEST_H
#define APPLICATION_NAME "STeCa2"
#define APPLICATION_VERSION "2.0.2"
#define APPLICATION_VERSION "2.0.2a"
#define ORGANIZATION_NAME "Scientific Computing at MLZ"
#define ORGANIZATION_DOMAIN "apps.jcns.fz-juelich.de"
......
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