Commit 56cc4af5 authored by Locatelli's avatar Locatelli
Browse files

Implement functionalities:

- Error bar
- Optimization result
- Optimization fit
parent 537a8df3
......@@ -63,6 +63,9 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
for (float64 ratio : plotMessage.aspect_ratios()) {
aspectRatios.push_back(ratio);
}
for (bool errorbar: plotMessage.error_bars()) {
errorBars.push_back(errorbar);
}
numorId = plotMessage.numor_id();
titleId = plotMessage.title_id();
xaxisTitleId = plotMessage.xaxis_title_id();
......@@ -71,6 +74,33 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
xaxisTitle = plotMessage.xaxis_title();
yaxisTitle = plotMessage.yaxis_title();
dataPlotProperties = plotMessage.dataplotproperties();
for (int32 id : plotMessage.optimization_result_found_id()) {
if (id != 0) {
optimizationResultFoundId.push_back(id);
}
}
for (int32 id : plotMessage.optimization_result_x_id()) {
if (id != 0) {
optimizationResultXId.push_back(id);
}
}
for (string color : plotMessage.optimization_result_color()) {
optimizationResultColor.push_back(color);
}
for (int32 id : plotMessage.optimization_fit_found_id()) {
if (id != 0) {
optimizationFitFoundId.push_back(id);
}
}
for (int32 id : plotMessage.optimization_fit_y_id()) {
if (id != 0) {
optimizationFitYId.push_back(id);
}
}
for (string color : plotMessage.optimization_fit_color()) {
optimizationFitColor.push_back(color);
}
hasx = false;
hasy = false;
hasz = false;
......@@ -99,7 +129,7 @@ plot::PlotType PropertyPlotDataContainer::getPlotType() {
try {
size = ServerRequesterManager::getInstance()->getPropertyArraySize(id);
DBGMSG("new Plot Type x size : " << size);
if (size > 0) {
if (size > 1) {
hasx = true;
break;
}
......@@ -117,7 +147,7 @@ plot::PlotType PropertyPlotDataContainer::getPlotType() {
try {
size = ServerRequesterManager::getInstance()->getPropertyArraySize(id);
DBGMSG("new Plot Type y size : " << size);
if (size > 0) {
if (size > 1) {
hasy = true;
break;
}
......@@ -135,7 +165,7 @@ plot::PlotType PropertyPlotDataContainer::getPlotType() {
try {
size = ServerRequesterManager::getInstance()->getPropertyArraySize(id);
DBGMSG("new Plot Type z size : " << size);
if (size > 0) {
if (size > 1) {
hasz = true;
break;
}
......
......@@ -54,12 +54,19 @@ public:
std::map<int32, std::string> dataXPropertyTypes; //! Property types of data x
std::map<int32, std::string> dataYPropertyTypes; //! Property types of data y
std::map<int32, std::string> dataZPropertyTypes; //! Property types of data z
std::vector<float64> aspectRatios; //! Property Ids of data z
std::vector<float64> aspectRatios; //! X/Y Aspect ratio values
std::vector<bool> errorBars; //! Plot using error bar
int32 numorId; //! Property Id of numor
int32 titleId; //! Property Id of title
int32 xaxisTitleId; //! Property Id of x axis title
int32 yaxisTitleId; //! Property Id of y axis title
DataPlotProperties dataPlotProperties; //! Container of properties id for data plot nomad controller
std::vector<int32> optimizationResultFoundId; //! Property id list for optimization result found
std::vector<int32> optimizationResultXId; //! Property id list for optimization result x
std::vector<std::string> optimizationResultColor; //! Color of optimization result
std::vector<int32> optimizationFitFoundId; //! Property id list for optimization fit found
std::vector<int32> optimizationFitYId; //! Property id list for optimization fit y values found
std::vector<std::string> optimizationFitColor; //! Color of optimization fit
bool hasx; //! Flag tells if there is x data (run getPlotType() before)
bool hasy; //! Flag tells if there is y data (run getPlotType() before)
......
......@@ -56,24 +56,10 @@ void Plot1D::display() throw (Error) {
throw Error("Plot1D", "display", "Failed to do subplot");
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
string title = getTitle();
try {
m_MplPlot1D.title(title);
if (m_PlotWindow != nullptr) {
m_PlotWindow->setWindowTitle(title);
}
} catch (Error &e) {
Warning("Plot1D", "display", "Failed to set window title", title);
}
///////////////////////////////////////////////////////////////////////////////////////
//// Fill x and y arrays
////
m_NbPlots = getNbPlots();
m_PlotXPropertyTypes.resize(m_NbPlots);
m_PlotXArrays.resize(m_NbPlots);
m_PlotYPropertyTypes.resize(m_NbPlots);
......@@ -82,54 +68,81 @@ void Plot1D::display() throw (Error) {
getDataArray(i);
getXData(i);
getYData(i);
localplot(i);
}
}
////
//// Set plot parameters
////
std::map<std::string, std::string> keywords;
keywords["label"] = getLegendKey(i);
keywords["color"] = string("#") + getColor(i);
keywords["linewidth"] = "0.5";
/*
* localplot
*/
void Plot1D::localplot(uint32 numplot) throw (Error) {
////
//// Plot arrays
////
if ((m_PlotXPropertyTypes[i] == "int32array") && (m_PlotYPropertyTypes[i] == "int32array")) {
DBGMSG("Plot1D : int32array , int32array");
try {
m_MplPlot1D.plot(i, m_PlotXArrays[i], m_PlotYArrays[i], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[i] == "float64array") && (m_PlotYPropertyTypes[i] == "float64array")) {
DBGMSG("Plot1D : float64array , float64array");
try {
m_MplPlot1D.plot(i, m_PlotXArrays[i], m_PlotYArrays[i], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[i] == "int32array") && (m_PlotYPropertyTypes[i] == "float64array")) {
DBGMSG("Plot1D : int32array , float64array");
try {
m_MplPlot1D.plot(i, m_PlotXArrays[i], m_PlotYArrays[i], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[i] == "float64array") && (m_PlotYPropertyTypes[i] == "int32array")) {
DBGMSG("Plot1D : float64array , int32array");
try {
m_MplPlot1D.plot(i, m_PlotXArrays[i], m_PlotYArrays[i], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[i].empty() == true) && (m_PlotYPropertyTypes[i] == "float64array")) {
DBGMSG("Plot1D : none , float64array");
try {
m_MplPlot1D.plot(i, m_PlotYArrays[i], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "y = float64array");
}
////
//// Set plot parameters
////
bp::dict keywords;
keywords["label"] = getLegendKey(numplot);
keywords["color"] = string("#") + getColor(numplot);
////
//// Plot arrays
////
if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "int32array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "int32array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot].empty() == true) && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "y = float64array");
}
}
///////////////////////////////////////////////////////////////////////////////////////
//// optimization Plot if there is
////
try {
optimizationPlot(numplot);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot optimization y");
}
try {
optimizationResult(numplot);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot optimization result");
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
string title = getTitle();
try {
m_MplPlot1D.title(title);
if (m_PlotWindow != nullptr) {
m_PlotWindow->setWindowTitle(title);
}
} catch (Error &e) {
Warning("Plot1D", "display", "Failed to set window title", title);
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -156,7 +169,7 @@ void Plot1D::display() throw (Error) {
//// set legend
////
try {
std::map<std::string, std::string> keywordslegend;
bp::dict keywordslegend;
keywordslegend["fontsize"] = "xx-small";
keywordslegend["loc"] = "upper right";
m_MplPlot1D.legend(keywordslegend);
......@@ -168,7 +181,9 @@ void Plot1D::display() throw (Error) {
//// check grid
////
try {
grid(m_PlotWindow->gridActivated());
if (m_PlotWindow != nullptr) {
grid(m_PlotWindow->gridActivated());
}
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to show plot grid");
}
......@@ -177,7 +192,9 @@ void Plot1D::display() throw (Error) {
//// check log
////
try {
log(m_PlotWindow->logActivated());
if (m_PlotWindow != nullptr) {
log(m_PlotWindow->logActivated());
}
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to activate log");
}
......@@ -193,7 +210,7 @@ void Plot1D::display() throw (Error) {
*/
void Plot1D::resizeX() throw (Error) {
float64 gxmin = numeric_limits<float64>::max();
float64 gxmax = numeric_limits<float64>::min();
float64 gxmax = -numeric_limits<float64>::max();
bool hasx = false;
for (uint32 i = 0; i < m_PlotXArrays.size(); ++i) {
if (m_PlotXArrays[i].empty() == false) {
......@@ -218,7 +235,7 @@ void Plot1D::resizeX() throw (Error) {
*/
void Plot1D::resizeY() throw (Error) {
float64 gymin = numeric_limits<float64>::max();
float64 gymax = numeric_limits<float64>::min();
float64 gymax = -numeric_limits<float64>::max();
for (uint32 i = 0; i < m_PlotYArrays.size(); ++i) {
if (m_PlotYArrays[i].empty() == false) {
float64 min = *std::min_element(m_PlotYArrays[i].begin(), m_PlotYArrays[i].end());
......
......@@ -106,6 +106,27 @@ protected:
*/
virtual void getYData(int32 index) = 0;
/*!
* \brief plot data with one dimension (y)
* \param[in] numplot the plot index
* \param[in] y data
* \param[in] keywords plot options
* \throws Error
*/
virtual void plot(uint32 numplot, const std::vector<float64> &y,
bp::dict& keywords) throw (Error) = 0;
/*!
* \brief plot data with two dimensions (x and y)
* \param[in] numplot the plot index
* \param[in] x data
* \param[in] y data
* \param[in] keywords plot options
* \throws Error
*/
virtual void plot(uint32 numplot, const std::vector<float64> &x, const std::vector<float64> &y,
bp::dict& keywords) throw (Error) = 0;
/*!
* \brief Get the legend key of plot
* \param[in] index The index in the data plot
......@@ -132,6 +153,29 @@ protected:
*/
virtual std::string getYLabel() = 0;
/*!
* \brief local plot method factorisation
* \param[in] numplot the plot index
* \throws Error
*/
void localplot(uint32 numplot) throw (Error);
/*!
* \brief Optimization plot fit creation
* \param[in] numplot the plot index
* \throws Error
*/
virtual void optimizationPlot(uint32 numplot) throw (Error) {
}
/*!
* \brief Optimization plot result creation
* \param[in] numplot the plot index
* \throws Error
*/
virtual void optimizationResult(uint32 numplot) throw (Error) {
}
/*!
* \brief Resise X dimension
* \throws Error
......
......@@ -85,50 +85,50 @@ void PlotWindow::display() throw (Error) {
///////////////////////////////////////////////////////////////////////////////////////
//// Create plot
////
if ((m_PropertyPlotDataContainer->dataXIds.size() > 0) || (m_PropertyPlotDataContainer->dataYIds.size() > 0)
|| (m_PropertyPlotDataContainer->dataZIds.size() > 0)) {
// get plot type
plot::PlotType ptype = m_PropertyPlotDataContainer->getPlotType();
switch (ptype) {
case plot::PLOT_2D: {
// 2d plot
try {
m_Plot = new property::PropertyPlot2D(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl, this);
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create 2d plot", m_PropertyPlotDataContainer->plotKey);
}
// get plot type
plot::PlotType ptype = m_PropertyPlotDataContainer->getPlotType();
switch (ptype) {
case plot::PLOT_2D: {
// 2d plot
try {
m_Plot = new property::PropertyPlot2D(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl,
this);
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create 2d plot", m_PropertyPlotDataContainer->plotKey);
}
break;
case plot::PLOT_1D: {
// 1d plot
try {
m_Plot = new property::PropertyPlot1D(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl, this, getMplFigure());
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create 1d plot", m_PropertyPlotDataContainer->plotKey);
}
}
break;
case plot::EMPTY_PLOT: {
// empty plot
try {
m_Plot = new property::PropertyEmptyPlot(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl, this);
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create empty plot", m_PropertyPlotDataContainer->plotKey);
}
}
break;
default:
Error("PlotWindow", "display", "bad plot type", m_PropertyPlotDataContainer->plotKey);
break;
}
break;
case plot::PLOT_1D: {
// 1d plot
try {
m_Plot = new property::PropertyPlot1D(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl,
this, getMplFigure());
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create 1d plot", m_PropertyPlotDataContainer->plotKey);
}
m_QtWindow->switchPlot(ptype);
}
break;
case plot::EMPTY_PLOT: {
// empty plot
try {
m_Plot = new property::PropertyEmptyPlot(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl,
this);
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create empty plot", m_PropertyPlotDataContainer->plotKey);
}
}
break;
default:
Error("PlotWindow", "display", "bad plot type", m_PropertyPlotDataContainer->plotKey);
break;
}
m_QtWindow->switchPlot(ptype);
}
/*
......
......@@ -28,7 +28,8 @@ namespace offscreen {
/*
* constructor
*/
OffScreenPlot1D::OffScreenPlot1D(view::mpl::MplFigure* figure, const std::string& plotkey, view::mpl::Mpl* mpl,int32 index, buffer::Data* data) :
OffScreenPlot1D::OffScreenPlot1D(view::mpl::MplFigure* figure, const std::string& plotkey, view::mpl::Mpl* mpl, int32 index,
buffer::Data* data) :
Plot1D(plotkey, mpl, nullptr, figure), OffScreenPlot(figure, index, data) {
m_NbPlots = 0;
}
......@@ -42,7 +43,7 @@ OffScreenPlot1D::~OffScreenPlot1D() {
/*
* save
*/
void OffScreenPlot1D::save() throw (Error) {
void OffScreenPlot1D::save() throw (Error) {
ostringstream filename;
filename << getenv("HOME") << "/offscreenImages/log/" << m_PlotKey;
m_Mpl->savefig(m_Figure->getFigure(), filename.str());
......@@ -60,7 +61,7 @@ string OffScreenPlot1D::getTitle() {
} else {
title << m_PlotKey;
}
if (m_Data->has_extratitle() == true) {
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
}
return title.str();
......@@ -86,8 +87,7 @@ void OffScreenPlot1D::getDataArray(int32 index) {
}
if (m_Data->ydata(m_Index).arrays(index).datadouble_size() > 0) {
m_PlotYPropertyTypes[index] = "float64array";
}
else if (m_Data->zdata(m_Index).dataint_size() > 0) {
} else if (m_Data->zdata(m_Index).dataint_size() > 0) {
m_PlotYPropertyTypes[index] = "int32array";
}
}
......@@ -95,15 +95,17 @@ void OffScreenPlot1D::getDataArray(int32 index) {
/*
* getXdata
*/
void OffScreenPlot1D::getXData(int32 index){
copy(m_Data->xdata(m_Index).datadouble().begin(), m_Data->xdata(m_Index).datadouble().end(), back_inserter(m_PlotXArrays[index]));
void OffScreenPlot1D::getXData(int32 index) {
copy(m_Data->xdata(m_Index).datadouble().begin(), m_Data->xdata(m_Index).datadouble().end(),
back_inserter(m_PlotXArrays[index]));
}
/*
* getYData
*/
void OffScreenPlot1D::getYData(int32 index) {
copy(m_Data->ydata(m_Index).arrays(index).datadouble().begin(), m_Data->ydata(m_Index).arrays(index).datadouble().end(), back_inserter(m_PlotYArrays[index]));
copy(m_Data->ydata(m_Index).arrays(index).datadouble().begin(), m_Data->ydata(m_Index).arrays(index).datadouble().end(),
back_inserter(m_PlotYArrays[index]));
}
/*
......@@ -145,6 +147,72 @@ std::string OffScreenPlot1D::getYLabel() {
return ylabel;
}
/*
* plot
*/
void OffScreenPlot1D::plot(uint32 numplot, const std::vector<float64> &y, bp::dict& keywords) throw (Error) {
if (m_Data->errorbars(numplot) == true) {
keywords["marker"] = "o";
keywords["markersize"] = 2;
keywords["elinewidth"] = 1;
keywords["capsize"] = 3;
keywords["linewidth"] = 0.2;
m_MplPlot1D.errorbar(numplot, y, keywords);
} else {
keywords["linewidth"] = 0.5;
m_MplPlot1D.plot(numplot, y, keywords);
}
}
/*
* plot
*/
void OffScreenPlot1D::plot(uint32 numplot, const std::vector<float64> &x, const std::vector<float64> &y, bp::dict& keywords)
throw (Error) {
if (m_Data->errorbars(numplot) == true) {
keywords["marker"] = "o";
keywords["markersize"] = 2;
keywords["elinewidth"] = 1;
keywords["capsize"] = 3;
keywords["linewidth"] = 0.2;
m_MplPlot1D.errorbar(numplot, x, y, keywords);
} else {
keywords["linewidth"] = 0.5;
m_MplPlot1D.plot(numplot, x, y, keywords);
}
}
/*
* optimizationPlot
*/
void OffScreenPlot1D::optimizationPlot(uint32 numplot) throw (Error) {
if (numplot < m_Data->optimizationfitdata_size()) {
if (m_Data->optimizationfitdata(numplot).datadouble_size() == m_PlotXArrays[numplot].size()) {
bp::dict keywords;
keywords["linewidth"] = 0.5;
keywords["label"] = "Fit";
keywords["color"] = "#FFA800";
vector<float64> yvalues;
copy(m_Data->optimizationfitdata(numplot).datadouble().begin(),
m_Data->optimizationfitdata(numplot).datadouble().end(), back_inserter(yvalues));
m_MplPlot1D.optimizationPlot(numplot, m_PlotXArrays[numplot], yvalues, keywords);
}
}
}
/*
* optimizationResult
*/
void OffScreenPlot1D::optimizationResult(uint32 numplot) throw (Error) {
if (m_Data->optimizationresultfound(numplot) == true) {
bp::dict keywords;
keywords["linestyle"] = "dashed";
keywords["linewidth"] = 1;
keywords["color"] = "#FFA800";
float64 xvalue = m_Data->optimizationresultvalue(numplot);
m_MplPlot1D.optimizationResult(numplot, xvalue, keywords);
}
}
}
}
......@@ -81,6 +81,41 @@ private:
*/
virtual void getYData(int32 index);
/*!
* \brief plot data with one dimension (y)
* \param[in] numplot the plot index
* \param[in] y data
* \param[in] keywords plot options
* \throws Error
*/
virtual void plot(uint32 numplot, const std::vector<float64> &y,
bp::dict& keywords) throw (Error);
/*!
* \brief plot data with two dimensions (x and y)
* \param[in] numplot the plot index
* \param[in] x data
* \param[in] y data
* \param[in] keywords plot options
* \throws Error
*/
virtual void plot(uint32 numplot, const std::vector<float64> &x, const std::vector<float64> &y,
bp::dict& keywords) throw (Error);
/*!
* \brief Optimization plot fit creation
* \param[in] numplot the plot index
* \throws Error
*/
virtual void optimizationPlot(uint32 numplot) throw (Error);
/*!
* \brief Optimization plot result creation