Commit 46c24e723a1c578409cc962a486ace39dccc27c3
1 parent
aea2c74b
Exists in
master
and in
7 other branches
Fix mean calculation in Histo2D
Showing
2 changed files
with
18 additions
and
4 deletions
Show diff stats
src/ParamOutputImpl/Plot/HistoPlot/Histo2DFunction.cc
@@ -132,11 +132,25 @@ void Mean2DFunction::apply(MatrixGrid &matrixGrid, double* xData, double* yData, | @@ -132,11 +132,25 @@ void Mean2DFunction::apply(MatrixGrid &matrixGrid, double* xData, double* yData, | ||
132 | allValues = getMatrixValues(xData,yData,zData,nbData,xRange,yRange,xBinNumber,yBinNumber); | 132 | allValues = getMatrixValues(xData,yData,zData,nbData,xRange,yRange,xBinNumber,yBinNumber); |
133 | 133 | ||
134 | for (unsigned int i(0); i < matrixGrid.size(); ++i){ | 134 | for (unsigned int i(0); i < matrixGrid.size(); ++i){ |
135 | + double mean = NAN; | ||
136 | + if (!allValues[i].empty()) { | ||
137 | + int nb = 0; | ||
138 | + for (std::vector<double>::iterator it = allValues[i].begin(); it != allValues[i].end(); ++it){ | ||
139 | + if (std::isfinite(*it) && !std::isnan(*it)) { | ||
140 | + if (std::isnan(mean)) { | ||
141 | + mean = 0; | ||
142 | + } | ||
143 | + mean += *it; | ||
144 | + nb++; | ||
145 | + } | ||
146 | + } | ||
147 | + if (nb > 0) { | ||
148 | + mean /= nb; | ||
149 | + } | ||
150 | + } | ||
151 | + matrixGrid[i].value = mean; | ||
135 | 152 | ||
136 | - double sum = std::accumulate(allValues[i].begin(), allValues[i].end(), 0); | ||
137 | - matrixGrid[i].value=sum/allValues[i].size(); | ||
138 | - | ||
139 | - if(zMax < matrixGrid[i].value) | 153 | + if(zMax < matrixGrid[i].value) |
140 | zMax = matrixGrid[i].value; | 154 | zMax = matrixGrid[i].value; |
141 | if(zMin > matrixGrid[i].value) | 155 | if(zMin > matrixGrid[i].value) |
142 | zMin = matrixGrid[i].value; | 156 | zMin = matrixGrid[i].value; |
test/plots_ref/centos-7/TmaAmda/ReLease5/Histo2D/plot_histo2d_06_REF.png