From 6fbb0f70efee83a40a6c98bb7e8056b8d356a225 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 19 Jun 2024 17:22:59 +0900 Subject: [PATCH] data plot with filters --- lib/LatAnalyze/Core/Plot.cpp | 38 +++++++++++++++++++++++- lib/LatAnalyze/Core/Plot.hpp | 4 +++ lib/LatAnalyze/Statistics/XYStatData.hpp | 5 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/LatAnalyze/Core/Plot.cpp b/lib/LatAnalyze/Core/Plot.cpp index 143e45d..6b93960 100644 --- a/lib/LatAnalyze/Core/Plot.cpp +++ b/lib/LatAnalyze/Core/Plot.cpp @@ -206,6 +206,42 @@ PlotData::PlotData(const XYStatData &data, const Index i, const Index j, const b setCommand("'" + tmpFileName + "' " + usingCmd); } +PlotData::PlotData(const XYStatData & data, XYStatData::CoordFilter f, Index i, const Index j, const bool abs) +{ + string usingCmd, tmpFileName; + + if (!abs) + { + usingCmd = (data.isXExact(i)) ? "u 1:3:4 w yerr" : "u 1:3:2:4 w xyerr"; + } + else + { + usingCmd = (data.isXExact(i)) ? "u 1:(abs($3)):4 w yerr" : "u 1:(abs($3)):2:4 w xyerr"; + } + + tmpFileName = dumpToTmpFile(data.getTable(i, j, f)); + pushTmpFile(tmpFileName); + setCommand("'" + tmpFileName + "' " + usingCmd); +} + +PlotData::PlotData(const XYStatData & data, XYStatData::PointFilter f, Index i, const Index j, const bool abs) +{ + string usingCmd, tmpFileName; + + if (!abs) + { + usingCmd = (data.isXExact(i)) ? "u 1:3:4 w yerr" : "u 1:3:2:4 w xyerr"; + } + else + { + usingCmd = (data.isXExact(i)) ? "u 1:(abs($3)):4 w yerr" : "u 1:(abs($3)):2:4 w xyerr"; + } + + tmpFileName = dumpToTmpFile(data.getTable(i, j, f)); + pushTmpFile(tmpFileName); + setCommand("'" + tmpFileName + "' " + usingCmd); +} + // PlotPoint constructor /////////////////////////////////////////////////////// PlotPoint::PlotPoint(const double x, const double y) { @@ -775,7 +811,7 @@ void Plot::display(void) ostringstream scriptBuf; getProgramPath(); - command = gnuplotPath_ + "/" + gnuplotBin_ + " 2>/dev/null"; + command = gnuplotPath_ + "/" + gnuplotBin_; gnuplotPipe = popen(command.c_str(), "w"); if (!gnuplotPipe) { diff --git a/lib/LatAnalyze/Core/Plot.hpp b/lib/LatAnalyze/Core/Plot.hpp index eed57a6..ae578c5 100644 --- a/lib/LatAnalyze/Core/Plot.hpp +++ b/lib/LatAnalyze/Core/Plot.hpp @@ -94,6 +94,10 @@ public: PlotData(const DMatSample &x, const DVec &y, const bool abs = false); PlotData(const XYStatData &data, const Index i = 0, const Index j = 0, const bool abs = false); + PlotData(const XYStatData &data, XYStatData::CoordFilter f, Index i = 0, + const Index j = 0, const bool abs = false); + PlotData(const XYStatData &data, XYStatData::PointFilter f, Index i = 0, + const Index j = 0, const bool abs = false); // destructor virtual ~PlotData(void) = default; }; diff --git a/lib/LatAnalyze/Statistics/XYStatData.hpp b/lib/LatAnalyze/Statistics/XYStatData.hpp index 49cbd28..07f5138 100644 --- a/lib/LatAnalyze/Statistics/XYStatData.hpp +++ b/lib/LatAnalyze/Statistics/XYStatData.hpp @@ -65,6 +65,9 @@ private: ******************************************************************************/ class XYStatData: public FitInterface { +public: + typedef std::function &)> CoordFilter; + typedef std::function PointFilter; public: // constructor XYStatData(void) = default; @@ -89,6 +92,8 @@ public: DVec getXError(const Index i) const; DVec getYError(const Index j) const; DMat getTable(const Index i, const Index j) const; + DMat getTable(const Index i, const Index j, CoordFilter &coordFilter) const; + DMat getTable(const Index i, const Index j, PointFilter &ptFilter) const; // get total fit variance & correlation matrices and their pseudo-inverse const DMat & getFitVarMat(void); const DMat & getFitVarMatPInv(void);