Skip to content

Commit

Permalink
Merge pull request #167 from aglowacki/master
Browse files Browse the repository at this point in the history
Update grapher to plot line series
  • Loading branch information
aglowacki authored Sep 27, 2023
2 parents cad63c8 + 5802d4b commit a81843b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 49 deletions.
4 changes: 4 additions & 0 deletions src/core/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ const std::string STR_CALIB_CURVE_US_IC = "Calibration_Curve_US_IC";
const std::string STR_CALIB_CURVE_DS_IC = "Calibration_Curve_DS_IC";
const std::string STR_CALIB_LABELS = "Calibration_Curve_Labels";

const std::string STR_DS_IC_ELEMENT_INFO_VALUES = "DS_IC_Element_Info_Values";
const std::string STR_US_IC_ELEMENT_INFO_VALUES = "US_IC_Element_Info_Values";
const std::string STR_SR_CURRENT_ELEMENT_INFO_VALUES = "SR_Current_Element_Info_Values";

const std::string STR_BEAMLINES = "BeamLines";
const std::string STR_SCALERS = "Scalers";
const std::string STR_TIME_NORMALIZED_SCALERS = "TimeNormalizedScalers";
Expand Down
2 changes: 1 addition & 1 deletion src/core/process_whole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ bool perform_quantification(data_struct::Analysis_Job<double>* analysis_job, boo
if (fn_str_len > 5 &&
dataset_file[fn_str_len - 4] == '.' &&
dataset_file[fn_str_len - 3] == 'm' &&
dataset_file[fn_str_len - 2] == 'c' &&
dataset_file[fn_str_len - 2] == 'd' &&
dataset_file[fn_str_len - 1] == 'a')
{
full_save_path += ".h5" + str_detector_num;
Expand Down
105 changes: 57 additions & 48 deletions src/visual/grapher.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ freely, subject to the following restrictions:
#include <QtCharts/QLogValueAxis>
#include <QtCharts/QValueAxis>
#include <QApplication>
#include <QtCharts/QBarSeries>
#include <QtCharts/QLineSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QScatterSeries>

using namespace data_struct;

Expand Down Expand Up @@ -246,11 +246,12 @@ DLL_EXPORT void SavePlotCalibrationCurve(std::string path,
Detector<T_real>* detector,
std::string quantifier_scaler_name,
std::unordered_map<std::string, Element_Quant<T_real>*>* all_elements_with_weights,
std::vector<Element_Quant<T_real>>* calibration_curve,
std::unordered_map<Electron_Shell, std::vector<Element_Quant<T_real>> >* curve_quant_map,
//std::vector<Element_Quant<T_real>>* calibration_curve,
int zstart,
int zstop)
{
if (all_elements_with_weights == nullptr || detector == nullptr || calibration_curve == nullptr)
if (all_elements_with_weights == nullptr || detector == nullptr || curve_quant_map == nullptr)
{
logW << "detector is null. Cannot save png " << path << ". \n";
return;
Expand Down Expand Up @@ -289,38 +290,42 @@ DLL_EXPORT void SavePlotCalibrationCurve(std::string path,
QChart* chart = chartView->chart();
chart->addAxis(axisYLog10, Qt::AlignLeft);
//chart->addAxis(axisY, Qt::AlignLeft);
chart->setTitle(QString::fromStdString(quantifier_scaler_name));


QBarCategoryAxis* axisX = new QBarCategoryAxis();
QStringList categories;
QBarSet* set0 = new QBarSet("Element");

QBarSeries* series = new QBarSeries();
series->setName(QString::fromStdString(quantifier_scaler_name));

QCategoryAxis* axisX = new QCategoryAxis();
bool isfirst = true;
T_real min_y = 9999999.0;
T_real max_y = -9999999.0;
for (int i = zstart; i <= zstop; i++)
for (const auto& citr : *curve_quant_map)
{
T_real val = (*calibration_curve)[i].calib_curve_val;
if (val <= 0)
QLineSeries* series = new QLineSeries();
series->setName(QString::fromStdString(quantification::models::Shell_To_String.at(citr.first)));
for (int i = zstart-1; i <= zstop; i++)
{
val = 0.00000001;
T_real val = citr.second[i].calib_curve_val;
if (val <= 0)
{
val = 0.00000001;
}
series->append(i, val);
series->append(i + 1, val);
if (isfirst)
{
axisX->append(QString::fromStdString(citr.second[i].name), i);
}
}
chart->addSeries(series);
if (isfirst)
{
chart->addAxis(axisX, Qt::AlignBottom);
}
categories << QString::fromStdString((*calibration_curve)[i].name);
*set0 << val;
min_y = std::min(min_y, val);
max_y = std::max(max_y, val);
series->attachAxis(axisX);
series->attachAxis(axisYLog10);

isfirst = false;
}
series->append(set0);
chart->addSeries(series);

axisX->append(categories);
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
series->attachAxis(axisYLog10);
//series->attachAxis(axisY);



for (auto& s_itr : detector->quantification_standards)
{
QScatterSeries* e_series = new QScatterSeries();
Expand All @@ -339,7 +344,7 @@ DLL_EXPORT void SavePlotCalibrationCurve(std::string path,
{
plot_val = 0.000000001;
}
e_series->append(((element_info->number - 1) - zstart), plot_val);
e_series->append(((element_info->number - 1.5)), plot_val);
min_y = std::min(min_y, plot_val);
max_y = std::max(max_y, plot_val);
}
Expand All @@ -351,11 +356,9 @@ DLL_EXPORT void SavePlotCalibrationCurve(std::string path,
//e_series->attachAxis(axisY);
}

//min_y -= 1.0;
max_y += 10.0;

axisYLog10->setMin(min_y);
axisYLog10->setMax(max_y);
T_real diff = (max_y - min_y ) / 5.0;
T_real diff2 = (max_y - min_y) / 100.0;
axisYLog10->setRange(min_y - diff2, max_y + diff);


QPixmap pix = chartView->grab();
Expand Down Expand Up @@ -387,26 +390,32 @@ DLL_EXPORT void SavePlotQuantification(std::string path, Detector<T_real>* detec
//iterate through quantifier {sr_current, us_ic, ds_ic}
for (auto& itr2 : itr1.second.quant_scaler_map)
{

int minZ = CALIBRATION_CURVE_SIZE;
int maxZ = 0;
for (const auto& shell_itr : Shells_Quant_List)
{
int zstart = 0;
int zstop = CALIBRATION_CURVE_SIZE;

if (contains_shell(shell_itr, &(detector->all_element_quants.at(itr1.first).at(itr2.first))))
{
int zstart = 0;
int zstop = CALIBRATION_CURVE_SIZE;
find_shell_Z_offset(shell_itr, &(detector->all_element_quants.at(itr1.first).at(itr2.first)), zstart, zstop);

std::string str_path_full = path + "calib_" + Fitting_Routine_To_Str.at(itr1.first) + "_" + itr2.first + "_" + quantification::models::Shell_To_String.at(shell_itr) + "_det";
if (detector->number() != -1)
{
str_path_full += std::to_string(detector->number()) + ".png";
}
else
{
str_path_full += ".png";
}
SavePlotCalibrationCurve(str_path_full, detector, itr2.first, &(detector->all_element_quants.at(itr1.first).at(itr2.first)), &(itr2.second.curve_quant_map.at(shell_itr)), zstart, zstop);
minZ = std::min(minZ, zstart);
maxZ = std::max(maxZ, zstop);
}
}
std::string str_path_full = path + "calib_" + Fitting_Routine_To_Str.at(itr1.first) + "_" + itr2.first + "_det";
if (detector->number() != -1)
{
str_path_full += std::to_string(detector->number()) + ".png";
}
else
{
str_path_full += ".png";
}
SavePlotCalibrationCurve(str_path_full, detector, itr2.first, &(detector->all_element_quants.at(itr1.first).at(itr2.first)), &(itr2.second.curve_quant_map), minZ, maxZ);

}
}
}
Expand Down

0 comments on commit a81843b

Please sign in to comment.