Mantid
Loading...
Searching...
No Matches
MaxentTransformMultiFourier.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <gsl/gsl_fft_complex.h>
9
10#include <iterator>
11#include <stdexcept>
12#include <utility>
13
14namespace Mantid::Algorithms {
15
18 MaxentSpace_sptr imageSpace, size_t numSpec)
19 : MaxentTransformFourier(dataSpace, std::move(imageSpace)), m_numSpec(numSpec), m_linearAdjustments(),
20 m_constAdjustments() {}
21
36std::vector<double> MaxentTransformMultiFourier::imageToData(const std::vector<double> &image) {
37
38 std::vector<double> dataOneSpec = MaxentTransformFourier::imageToData(image);
39
40 // Create concatenated copies of transformed data (one for each spectrum)
41 std::vector<double> data;
42 data.reserve(m_numSpec * dataOneSpec.size());
43 for (size_t s = 0; s < m_numSpec; s++) {
44 std::copy(dataOneSpec.begin(), dataOneSpec.end(), std::back_inserter(data));
45 }
46
47 // Apply adjustments (we assume there are sufficient adjustments supplied)
48 double dataR = 0.123456789;
49 double dataI = 0.987654321;
50 if (!m_linearAdjustments.empty() && !m_constAdjustments.empty()) {
51 for (size_t i = 0; i < data.size(); i++) {
52 if (i % 2 == 0) { // Real part
53 dataR = data[i];
54 dataI = data[i + 1];
55 data[i] = m_linearAdjustments[i] * dataR - m_linearAdjustments[i + 1] * dataI + m_constAdjustments[i];
56 } else { // Imaginary part
57 data[i] = m_linearAdjustments[i] * dataR + m_linearAdjustments[i - 1] * dataI + m_constAdjustments[i];
58 }
59 }
60 } else if (!m_linearAdjustments.empty() && m_constAdjustments.empty()) {
61 for (size_t i = 0; i < data.size(); i++) {
62 if (i % 2 == 0) { // Real part
63 dataR = data[i];
64 dataI = data[i + 1];
65 data[i] = m_linearAdjustments[i] * dataR - m_linearAdjustments[i + 1] * dataI;
66 } else { // Imaginary part
67 data[i] = m_linearAdjustments[i] * dataR + m_linearAdjustments[i - 1] * dataI;
68 }
69 }
70 } else if (m_linearAdjustments.empty() && !m_constAdjustments.empty()) {
71 for (size_t i = 0; i < data.size(); i++) {
72 data[i] = data[i] + m_constAdjustments[i];
73 }
74 }
75
76 return data;
77}
78
91std::vector<double> MaxentTransformMultiFourier::dataToImage(const std::vector<double> &data) {
92
93 if (data.size() % m_numSpec)
94 throw std::invalid_argument("Size of data vector must be a multiple of number of spectra.");
95
96 // Sum the concatenated spectra in data
97 size_t nData = data.size() / (m_numSpec);
98 std::vector<double> dataSum(nData, 0.0);
99 for (size_t s = 0; s < m_numSpec; s++) {
100 for (size_t i = 0; i < nData; i++) {
101 dataSum[i] += data[s * nData + i];
102 }
103 }
104 // Then apply forward fourier transform to sum
105 std::vector<double> image = MaxentTransformFourier::dataToImage(dataSum);
106
107 return image;
108}
109
117void MaxentTransformMultiFourier::setAdjustments(const std::vector<double> &linAdj,
118 const std::vector<double> &constAdj) {
119 m_linearAdjustments = linAdj;
120 m_constAdjustments = constAdj;
121}
122
123} // namespace Mantid::Algorithms
MaxentTransformFourier : Defines a transformation from data space to image space (and vice-versa) whe...
std::vector< double > imageToData(const std::vector< double > &image) override
Transforms a 1D signal from image space to data space, performing an inverse Fast Fourier Transform.
std::vector< double > dataToImage(const std::vector< double > &data) override
Transforms a 1D signal from data space to image space, performing a forward Fast Fourier Transform.
std::vector< double > imageToData(const std::vector< double > &image) override
Transforms a 1D signal from image space to data space, performing an a backward MaxentTransformFourie...
std::vector< double > dataToImage(const std::vector< double > &data) override
Transforms a 1D signal from data space to image space, performing a forward Fast MexentTransformFouri...
void setAdjustments(const std::vector< double > &linAdj, const std::vector< double > &constAdj)
Sets the adjustments to be applied to the data when converted from image.
std::shared_ptr< Mantid::Algorithms::MaxentSpaceComplex > MaxentSpaceComplex_sptr
std::shared_ptr< MaxentSpace > MaxentSpace_sptr
Definition: MaxentSpace.h:33
STL namespace.