1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
6fbb0f70ef data plot with filters 2024-06-19 17:22:59 +09:00
f4dff86ce6 error check fix 2024-06-19 17:22:29 +09:00
4 changed files with 103 additions and 2 deletions

View File

@ -206,6 +206,42 @@ PlotData::PlotData(const XYStatData &data, const Index i, const Index j, const b
setCommand("'" + tmpFileName + "' " + usingCmd); 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 constructor ///////////////////////////////////////////////////////
PlotPoint::PlotPoint(const double x, const double y) PlotPoint::PlotPoint(const double x, const double y)
{ {
@ -775,7 +811,7 @@ void Plot::display(void)
ostringstream scriptBuf; ostringstream scriptBuf;
getProgramPath(); getProgramPath();
command = gnuplotPath_ + "/" + gnuplotBin_ + " 2>/dev/null"; command = gnuplotPath_ + "/" + gnuplotBin_;
gnuplotPipe = popen(command.c_str(), "w"); gnuplotPipe = popen(command.c_str(), "w");
if (!gnuplotPipe) if (!gnuplotPipe)
{ {

View File

@ -94,6 +94,10 @@ public:
PlotData(const DMatSample &x, const DVec &y, const bool abs = false); PlotData(const DMatSample &x, const DVec &y, const bool abs = false);
PlotData(const XYStatData &data, const Index i = 0, const Index j = 0, PlotData(const XYStatData &data, const Index i = 0, const Index j = 0,
const bool abs = false); 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 // destructor
virtual ~PlotData(void) = default; virtual ~PlotData(void) = default;
}; };

View File

@ -184,7 +184,7 @@ void XYStatData::setXError(const Index i, const DVec &err)
void XYStatData::setYError(const Index j, const DVec &err) void XYStatData::setYError(const Index j, const DVec &err)
{ {
checkXDim(j); checkYDim(j);
checkErrVec(err, yyVar_(j, j)); checkErrVec(err, yyVar_(j, j));
yyVar_(j, j).diagonal() = err.cwiseProduct(err); yyVar_(j, j).diagonal() = err.cwiseProduct(err);
scheduleFitVarMatInit(); scheduleFitVarMatInit();
@ -251,6 +251,62 @@ DMat XYStatData::getTable(const Index i, const Index j) const
return table; return table;
} }
DMat XYStatData::getTable(const Index i, const Index j, CoordFilter &coordFilter) const
{
checkXDim(i);
checkYDim(j);
DMat table(getYSize(j), 4);
Index row = 0;
for (auto &p: yData_[j])
{
Index k = p.first;
auto c = dataCoord(k);
if (coordFilter(c))
{
Index r = c[i];
table(row, 0) = x(k)(i);
table(row, 2) = p.second;
table(row, 1) = xxVar_(i, i).diagonal().cwiseSqrt()(r);
table(row, 3) = yyVar_(j, j).diagonal().cwiseSqrt()(row);
row++;
}
}
table.conservativeResize(row, 4);
return table;
}
DMat XYStatData::getTable(const Index i, const Index j, PointFilter &ptFilter) const
{
checkXDim(i);
checkYDim(j);
DMat table(getYSize(j), 4);
Index row = 0;
for (auto &p: yData_[j])
{
Index k = p.first;
auto c = dataCoord(k);
if (ptFilter(x(k)))
{
Index r = c[i];
table(row, 0) = x(k)(i);
table(row, 2) = p.second;
table(row, 1) = xxVar_(i, i).diagonal().cwiseSqrt()(r);
table(row, 3) = yyVar_(j, j).diagonal().cwiseSqrt()(row);
row++;
}
}
table.conservativeResize(row, 4);
return table;
}
// get total fit variance matrix /////////////////////////////////////////////// // get total fit variance matrix ///////////////////////////////////////////////
const DMat & XYStatData::getFitVarMat(void) const DMat & XYStatData::getFitVarMat(void)
{ {

View File

@ -65,6 +65,9 @@ private:
******************************************************************************/ ******************************************************************************/
class XYStatData: public FitInterface class XYStatData: public FitInterface
{ {
public:
typedef std::function<bool(const std::vector<Index> &)> CoordFilter;
typedef std::function<bool(const DVec &)> PointFilter;
public: public:
// constructor // constructor
XYStatData(void) = default; XYStatData(void) = default;
@ -89,6 +92,8 @@ public:
DVec getXError(const Index i) const; DVec getXError(const Index i) const;
DVec getYError(const Index j) const; DVec getYError(const Index j) const;
DMat getTable(const Index i, 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 // get total fit variance & correlation matrices and their pseudo-inverse
const DMat & getFitVarMat(void); const DMat & getFitVarMat(void);
const DMat & getFitVarMatPInv(void); const DMat & getFitVarMatPInv(void);