diff --git a/CMakeLists.txt b/CMakeLists.txt index 964b2f2cf396162fd8b9a841cf1d2db19707ac22..f43819bad7d5b79976810fe0c33ebd6c72258ba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,6 @@ else() set(EISGEN_LINK_FLAG ${PROJECT_NAME}) endif(WIN32) - configure_file(pkgconfig/libeisgenerator.pc.in pkgconfig/libeisgenerator.pc @ONLY) install(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/basicmath.cpp b/basicmath.cpp index f08bff27de033ef25e368490a1521980b9fe673b..53cab7387043f31a482acb0cf13433df206c1fca 100644 --- a/basicmath.cpp +++ b/basicmath.cpp @@ -150,8 +150,16 @@ std::vector<eis::DataPoint> eis::rescale(const std::vector<eis::DataPoint>& data fvalue sourcePosF = (data.size()-1)*position; size_t sourcePos = (data.size()-1)*position; fvalue frac = sourcePosF - sourcePos; - output[i].im = data[sourcePos].im*(1-frac) + data[sourcePos+1].im*frac; - output[i].omega = data[sourcePos].omega*(1-frac) + data[sourcePos+1].omega*frac; + if(sourcePos >= data.size()-1) + { + output[i].im = data[data.size()-1].im; + output[i].omega = data[data.size()-1].omega; + } + else + { + output[i].im = data[sourcePos].im*(1-frac) + data[sourcePos+1].im*frac; + output[i].omega = data[sourcePos].omega*(1-frac) + data[sourcePos+1].omega*frac; + } } return output; } @@ -418,3 +426,51 @@ void eis::difference(std::vector<eis::DataPoint>& a, const std::vector<eis::Data for(size_t i = 0; i < a.size(); ++i) a[i] = a[i] - b[i]; } + + +//Compute simmuliarity on a bode plot +fvalue eis::eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b) +{ + assert(a.size() == b.size()); + + double accum = 0; + for(size_t i = 0; i < a.size(); ++i) + { + double diffRe = std::pow(b[i].im.real() - a[i].im.real(), 2); + double diffIm = std::pow(b[i].im.imag() - a[i].im.imag(), 2); + accum += diffRe+diffIm; + } + return sqrt(accum/a.size()); +} + +//Compute simmuliarity on a nyquist plot +fvalue eis::eisNyquistDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b) +{ + assert(a.size() > 2 && b.size() > 3); + double accum = 0; + for(size_t i = 0; i < a.size(); ++i) + { + std::vector<std::pair<double, const eis::DataPoint*>> distances; + for(size_t j = 0; j < b.size(); ++j) + { + double diffRe = std::pow(b[j].im.real() - a[i].im.real(), 2); + double diffIm = std::pow(b[j].im.imag() - a[i].im.imag(), 2); + std::pair<double, const eis::DataPoint*> dp; + dp.first = sqrt(diffRe+diffIm); + dp.second = &b[j]; + distances.push_back(dp); + } + std::sort(distances.begin(), distances.end(), + [](const std::pair<double, const eis::DataPoint*>& a, const std::pair<double, const eis::DataPoint*>& b) -> bool + {return a.first < b.first;}); + + eis::DataPoint base = (*distances[0].second)-(*distances[1].second); + base = base/base.complexVectorLength(); + eis::DataPoint diff = (*distances[0].second)-a[i]; + diff = diff/diff.complexVectorLength(); + fvalue dprod = base.im.real()*diff.im.real() + base.im.imag()*diff.im.imag(); + fvalue dist = diff.complexVectorLength()*(1-dprod); + accum += std::pow(dist, 2); + } + return std::sqrt(accum/a.size()); +} diff --git a/eisgenerator/basicmath.h b/eisgenerator/basicmath.h index 4d9d7ffa2c9c596e401d0a698f837407f4e181d2..a05377ac78a503c28bea5d8c9ea295fca5dec667 100644 --- a/eisgenerator/basicmath.h +++ b/eisgenerator/basicmath.h @@ -178,6 +178,31 @@ namespace eis const std::vector<eis::DataPoint>& data, bool linearExtrapolation = false); + /** + * @brief Returns the mean l2 element wise distance of the given spectra. + * + * This function will be moved to the math API in the future. + * + * @param a The first set of points. + * @param b The second set of points, must contain the same number of elements as a + * @return The mean l2 distance. + */ + fvalue eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b); + + + /** + * @brief Returns the mean distance of the points in a to the linearly interpolated nyquist curve of b. + * + * This function will be moved to the math API in the future. + * + * This implementation is quite slow. + * + * @param a The first set of points. + * @param b The second set of points. + * @return The mean nyquist distance. + */ + fvalue eisNyquistDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b); + /** @} */ } diff --git a/eisgenerator/eistype.h b/eisgenerator/eistype.h index d1511629f2278c4048fd3bc104ecb98470d0c915..970b4e157bf39acb37e5d86b168c3790e395cdad 100644 --- a/eisgenerator/eistype.h +++ b/eisgenerator/eistype.h @@ -450,31 +450,6 @@ public: */ std::pair<std::valarray<fvalue>, std::valarray<fvalue>> eisToValarrays(const std::vector<eis::DataPoint>& data); -/** -* @brief Returns the mean l2 element wise distance of the given spectra. -* -* This function will be moved to the math API in the future. -* -* @param a The first set of points. -* @param b The second set of points, must contain the same number of elements as a -* @return The mean l2 distance. -*/ -fvalue eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b); - - -/** -* @brief Returns the mean distance of the points in a to the linearly interpolated nyquist curve of b. -* -* This function will be moved to the math API in the future. -* -* This implementation is quite slow. -* -* @param a The first set of points. -* @param b The second set of points. -* @return The mean nyquist distance. -*/ -fvalue eisNyquistDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b); - /** @} */ } diff --git a/eistype.cpp b/eistype.cpp index 5d499f800b7eea780702aa96e67f4dd9b8417188..349688b63014da58b4644e841fdd6e5e87c578d0 100644 --- a/eistype.cpp +++ b/eistype.cpp @@ -22,7 +22,6 @@ #include "eistype.h" #include <fstream> #include <sstream> -#include <algorithm> #include <string> #include <vector> @@ -156,54 +155,6 @@ std::ostream &operator<<(std::ostream &s, Range const& range) return s; } -//Compute simmuliarity on a bode plot -fvalue eis::eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b) -{ - assert(a.size() == b.size()); - - double accum = 0; - for(size_t i = 0; i < a.size(); ++i) - { - double diffRe = std::pow(b[i].im.real() - a[i].im.real(), 2); - double diffIm = std::pow(b[i].im.imag() - a[i].im.imag(), 2); - accum += diffRe+diffIm; - } - return sqrt(accum/a.size()); -} - -//Compute simmuliarity on a nyquist plot -fvalue eis::eisNyquistDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b) -{ - assert(a.size() > 2 && b.size() > 3); - double accum = 0; - for(size_t i = 0; i < a.size(); ++i) - { - std::vector<std::pair<double, const eis::DataPoint*>> distances; - for(size_t j = 0; j < b.size(); ++j) - { - double diffRe = std::pow(b[j].im.real() - a[i].im.real(), 2); - double diffIm = std::pow(b[j].im.imag() - a[i].im.imag(), 2); - std::pair<double, const eis::DataPoint*> dp; - dp.first = sqrt(diffRe+diffIm); - dp.second = &b[j]; - distances.push_back(dp); - } - std::sort(distances.begin(), distances.end(), - [](const std::pair<double, const eis::DataPoint*>& a, const std::pair<double, const eis::DataPoint*>& b) -> bool - {return a.first < b.first;}); - - eis::DataPoint base = (*distances[0].second)-(*distances[1].second); - base = base/base.complexVectorLength(); - eis::DataPoint diff = (*distances[0].second)-a[i]; - diff = diff/diff.complexVectorLength(); - fvalue dprod = base.im.real()*diff.im.real() + base.im.imag()*diff.im.imag(); - fvalue dist = diff.complexVectorLength()*(1-dprod); - accum += std::pow(dist, 2); - } - return std::sqrt(accum/a.size()); -} - - EisSpectra::EisSpectra(const std::vector<DataPoint>& dataIn, const std::string& modelIn, const std::string& headerIn, std::vector<double> labelsIn, std::vector<std::string> labelNamesIn): data(dataIn), model(modelIn), header(headerIn), labels(labelsIn), labelNames(labelNamesIn) diff --git a/kissplotcsv b/kissplotcsv index 3416d42438695064a8cb842d86926a26edd81a1d..d608fcf489917fcf00c399e3ba5654f3a6a27990 100755 --- a/kissplotcsv +++ b/kissplotcsv @@ -91,6 +91,7 @@ while getopts "?rihy:x:f:lno:" opt; do fi plotterminal="set term png size 1024,1024; set output \"$outfilename\";" mkdir $OPTARG 2> /dev/null || true + echo "Will save image to $outfilename" ;; esac done