Skip to content

Commit

Permalink
Merge pull request #57 from aglowacki/master
Browse files Browse the repository at this point in the history
Added scatter plot
  • Loading branch information
Arthur Glowacki authored Mar 16, 2023
2 parents 42fabce + 318757e commit 452ed69
Show file tree
Hide file tree
Showing 13 changed files with 1,194 additions and 142 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ ZeroMQ
Note that if you have Qt installed though the QT installer, you don't need to have qt5-base or qt5-charts, you will have to point cmake to them.
5) vcpkg set Linux
1) ./bootstrap-vcpkg.sh
2) ./vcpkg install hdf5 netcdf-c yaml-cpp zeromq opencv2 tiff qt5-base qt5-charts
2) ./vcpkg install hdf5 netcdf-c yaml-cpp zeromq opencv tiff jsoncpp qt5-base qt5-charts
6) vcpkg setup windows
1) .\bootstrap-vcpkg.bat
2) .\vcpkg install hdf5 netcdf-c yaml-cpp zeromq opencv2 tiff qt5-base qt5-charts --triplet x64-windows
2) .\vcpkg install hdf5 netcdf-c yaml-cpp zeromq opencv tiff jsoncpp qt5-base qt5-charts --triplet x64-windows
7) cd ../build
8) cmake `-DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DBUILD_WITH_ZMQ=ON ..`
9) make
Expand Down
34 changes: 34 additions & 0 deletions src/core/CorrelationCoefficient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*-----------------------------------------------------------------------------
* Copyright (c) 2023, UChicago Argonne, LLC
* See LICENSE file.
*---------------------------------------------------------------------------*/

#ifndef Correlation_Coefficient_H
#define Correlation_Coefficient_H

#include <Eigen/Core>

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

template<typename _T>
_T find_coefficient(const Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor>& x_arr, const Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor>& y_arr)
{
Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> xy_arr = x_arr * y_arr;
Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> xx_arr = x_arr * x_arr;
Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> yy_arr = y_arr * y_arr;
_T sum_x = x_arr.sum();
_T sum_y = y_arr.sum();
_T sum_xy = xy_arr.sum();
_T sqsum_x = xx_arr.sum();
_T sqsum_y = yy_arr.sum();
_T n = (_T)x_arr.size();
_T corr = (n * sum_xy - sum_x * sum_y) / sqrt((n * sqsum_x - sum_x * sum_x) * (n * sqsum_y - sum_y * sum_y));
return corr;
}

/*---------------------------------------------------------------------------*/

#endif

/*---------------------------------------------------------------------------*/
135 changes: 0 additions & 135 deletions src/mvc/CoLocalizationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,141 +252,6 @@ void CoLocalizationWidget::onNewGridLayout(int rows, int cols)

//---------------------------------------------------------------------------

void CoLocalizationWidget::createActions()
{
/*
_addRoiMaskAction = new QAction("Add ROI Mask", this);
connect(_addRoiMaskAction,
SIGNAL(triggered()),
this,
SLOT(addRoiMask()));
*/
}

//---------------------------------------------------------------------------

void CoLocalizationWidget::displayContextMenu(QWidget* parent,
const QPoint& pos)
{
/*
if (m_annotationsEnabled == false)
return;
QMenu menu(parent);
menu.addAction(m_addMarkerAction);
menu.addAction(m_addRulerAction);
menu.addAction(_addRoiMaskAction);
if (m_treeModel != nullptr && m_treeModel->rowCount() > 0)
{
if (m_selectionModel->hasSelection())
{
menu.addSeparator();
menu.addAction(m_duplicateAction);
menu.addSeparator();
menu.addAction(m_deleteAction);
}
}
//ruler properties
menu.addSeparator();
menu.addAction(m_showRulerDialogAction);
QAction* result = menu.exec(pos);
if (result == nullptr)
{
m_selectionModel->clearSelection();
}
*/
}

//---------------------------------------------------------------------------
/*
void CoLocalizationWidget::onAnalysisSelect(QString name)
{
_calib_curve = _model->get_calibration_curve(name.toStdString(), _cb_normalize->currentText().toStdString());
redrawCounts();
}
//---------------------------------------------------------------------------
void CoLocalizationWidget::onElementSelect(QString name, int viewIdx)
{
// update label on element select since it could be scaler
if (_normalizer != nullptr && _calib_curve != nullptr)
{
int cnt = _imageViewWidget->getViewCount();
for (int i = 0; i < cnt; i++)
{
QString label = _imageViewWidget->getLabelAt(i);
if (_calib_curve->calib_curve.count(label.toStdString()) > 0)
{
_imageViewWidget->setUnitLabel(i, "ug/cm2");
}
else
{
_imageViewWidget->setUnitLabel(i, "cts/s");
}
}
}
if (_model != nullptr && _model->regionLinks().count(name) > 0)
{
_imageViewWidget->scene(viewIdx)->setPixmap(QPixmap::fromImage((_model->regionLinks().at(name))));
}
else
{
QString analysisName = _cb_analysis->currentText();
if (analysisName.length() > 0 && name.length() > 0)
{
displayCounts(analysisName.toStdString(), name.toStdString(), _chk_log_color->isChecked(), viewIdx);
}
}
}
//---------------------------------------------------------------------------
void CoLocalizationWidget::onSelectNormalizer(QString name)
{
if (name == "1")
{
_normalizer = nullptr;
_calib_curve = nullptr;
_imageViewWidget->setUnitLabels("cts/s");
}
else
{
if (_model != nullptr)
{
std::map<std::string, data_struct::ArrayXXr<float>>* scalers = _model->getScalers();
if (scalers->count(name.toStdString()) > 0)
{
_normalizer = &(scalers->at(name.toStdString()));
}
_calib_curve = _model->get_calibration_curve(_cb_analysis->currentText().toStdString(), name.toStdString());
}
}
if (_normalizer != nullptr && _calib_curve != nullptr)
{
int cnt = _imageViewWidget->getViewCount();
for (int i = 0; i < cnt; i++)
{
QString label = _imageViewWidget->getLabelAt(i);
if (_calib_curve->calib_curve.count(label.toStdString()) > 0)
{
_imageViewWidget->setUnitLabel(i, "ug/cm2");
}
}
}
redrawCounts();
}
*/
//---------------------------------------------------------------------------

void CoLocalizationWidget::onSetAnalysisType(QString name)
{
_curAnalysis = name;
Expand Down
4 changes: 0 additions & 4 deletions src/mvc/CoLocalizationWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public slots:
*/
void _createLayout();

virtual void createActions();

virtual void displayContextMenu(QWidget* parent, const QPoint& pos);

MapsH5Model *_model;

QLabel *_dataset_directory;
Expand Down
1 change: 1 addition & 0 deletions src/mvc/ImageStackControlWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void ImageStackControlWidget::createLayout()

connect(_image_name_cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(model_IndexChanged(QString)));

connect(_imageGrid, &MapsElementsWidget::loaded_perc, this, &ImageStackControlWidget::update_progress_bar);
connect(_mapsFilsWidget, &MapsWorkspaceFilesWidget::loaded_perc, this, &ImageStackControlWidget::update_progress_bar);

vlayout->addItem(hlayout1);
Expand Down
8 changes: 8 additions & 0 deletions src/mvc/MapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ void MapsElementsWidget::_createLayout(bool create_image_nav)

_co_loc_widget = new CoLocalizationWidget();

_scatter_plot_widget = new ScatterPlotWidget();
connect(_scatter_plot_widget, &ScatterPlotWidget::updateProgressBar, this, &MapsElementsWidget::loaded_perc);

_tab_widget->addTab(_counts_window, "Analyzed Counts");
_tab_widget->addTab(_spectra_widget, DEF_STR_INT_SPECTRA);
_tab_widget->addTab(_co_loc_widget, "CoLocalization");
_tab_widget->addTab(_scatter_plot_widget, "Scatter Plot");
_tab_widget->addTab(_extra_pvs_table_widget, "Extra PV's");


Expand Down Expand Up @@ -568,6 +572,7 @@ void MapsElementsWidget::onAnalysisSelect(QString name)
{
_calib_curve = _model->get_calibration_curve(name.toStdString(), _cb_normalize->currentText().toStdString());
_co_loc_widget->onSetAnalysisType(name);
_scatter_plot_widget->setAnalysisType(name);
redrawCounts();
}

Expand Down Expand Up @@ -748,6 +753,9 @@ void MapsElementsWidget::setModel(MapsH5Model* model)
_co_loc_widget->onSetAnalysisType(_cb_analysis->currentText());
_co_loc_widget->setModel(_model);

_scatter_plot_widget->setAnalysisType(_cb_analysis->currentText());
_scatter_plot_widget->setModel(_model);

annoTabChanged(m_tabWidget->currentIndex());
}
m_imageWidgetToolBar->clickFill();
Expand Down
6 changes: 6 additions & 0 deletions src/mvc/MapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <mvc/ExportMapsDialog.h>
#include <mvc/CoLocalizationWidget.h>
#include <mvc/ImageSegROIDialog.h>
#include <mvc/ScatterPlotWidget.h>

class HDF5PropertyWidget;
class QAbstractTableModel;
Expand Down Expand Up @@ -57,6 +58,9 @@ class MapsElementsWidget

MapsH5Model *getModel(){return _model;}

signals:
void loaded_perc(int, int);

public slots:

void redrawCounts();
Expand Down Expand Up @@ -189,6 +193,8 @@ public slots:

CoLocalizationWidget* _co_loc_widget;

ScatterPlotWidget* _scatter_plot_widget;

ImageSegRoiDialog _img_seg_diag;

float _min_contrast_perc;
Expand Down
110 changes: 110 additions & 0 deletions src/mvc/MapsH5Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,3 +1977,113 @@ Calibration_curve<double>* MapsH5Model::get_calibration_curve(std::string analys
}

/*---------------------------------------------------------------------------*/

void MapsH5Model::generateNameLists(QString analysis_type, std::vector<std::string> &names)
{

data_struct::Fit_Count_Dict<float> fit_counts;
getAnalyzedCounts(analysis_type.toStdString(), fit_counts);
std::map<std::string, data_struct::ArrayXXr<float>>* scalers = getScalers();
if (scalers != nullptr)
{
for (auto& itr : *scalers)
{
fit_counts.insert(itr);
}
}

//create save ordered vector by element Z number with K , L, M lines
std::vector<std::string> element_lines;
for (std::string el_name : data_struct::Element_Symbols)
{
element_lines.push_back(el_name);
}
for (std::string el_name : data_struct::Element_Symbols)
{
element_lines.push_back(el_name + "_L");
}
for (std::string el_name : data_struct::Element_Symbols)
{
element_lines.push_back(el_name + "_M");
}

std::vector<std::string> final_counts_to_add_before_scalers;
final_counts_to_add_before_scalers.push_back(STR_COHERENT_SCT_AMPLITUDE);
final_counts_to_add_before_scalers.push_back(STR_COMPTON_AMPLITUDE);
final_counts_to_add_before_scalers.push_back(STR_SUM_ELASTIC_INELASTIC_AMP);
final_counts_to_add_before_scalers.push_back(STR_TOTAL_FLUORESCENCE_YIELD);
final_counts_to_add_before_scalers.push_back(STR_NUM_ITR);
final_counts_to_add_before_scalers.push_back(STR_RESIDUAL);

std::vector<std::string> scalers_to_add_first;
scalers_to_add_first.push_back(STR_SR_CURRENT);
scalers_to_add_first.push_back(STR_US_IC);
scalers_to_add_first.push_back(STR_DS_IC);
scalers_to_add_first.push_back(STR_ELT);
scalers_to_add_first.push_back(STR_ELAPSED_LIVE_TIME);
scalers_to_add_first.push_back(STR_ERT);
scalers_to_add_first.push_back(STR_ELAPSED_REAL_TIME);
scalers_to_add_first.push_back(STR_INPUT_COUNTS);
scalers_to_add_first.push_back(STR_ICR);
scalers_to_add_first.push_back("INCNT");
scalers_to_add_first.push_back(STR_OUTPUT_COUNTS);
scalers_to_add_first.push_back(STR_OCR);
scalers_to_add_first.push_back("OUTCNT");
scalers_to_add_first.push_back(STR_DEAD_TIME);
scalers_to_add_first.push_back("abs_cfg");
scalers_to_add_first.push_back("abs_ic");
scalers_to_add_first.push_back("H_dpc_cfg");
scalers_to_add_first.push_back("V_dpc_cfg");
scalers_to_add_first.push_back("DPC1_IC");
scalers_to_add_first.push_back("DPC2_IC");
scalers_to_add_first.push_back("dia1_dpc_cfg");
scalers_to_add_first.push_back("dia2_dpc_cfg");
scalers_to_add_first.push_back("CFG_1");
scalers_to_add_first.push_back(STR_CFG_2);
scalers_to_add_first.push_back(STR_CFG_3);
scalers_to_add_first.push_back(STR_CFG_4);
scalers_to_add_first.push_back(STR_CFG_5);
scalers_to_add_first.push_back("CFG_6");
scalers_to_add_first.push_back("CFG_7");
scalers_to_add_first.push_back("CFG_8");
scalers_to_add_first.push_back("CFG_9");

// insert in z order
for (std::string el_name : element_lines)
{
if (fit_counts.count(el_name) > 0)
{
names.push_back(el_name);
fit_counts.erase(el_name);
}
}

// add end of element list that are not elements
for (auto& itr : final_counts_to_add_before_scalers)
{
if (fit_counts.count(itr) > 0)
{
names.push_back(itr);
fit_counts.erase(itr);
}
}

// add scalers in certain order
for (auto& itr : scalers_to_add_first)
{
if (fit_counts.count(itr) > 0)
{
names.push_back(itr);
fit_counts.erase(itr);
}
}

// add rest of scalers
for (auto& itr : fit_counts)
{
names.push_back(itr.first);
}

}

/*---------------------------------------------------------------------------*/
3 changes: 3 additions & 0 deletions src/mvc/MapsH5Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ class MapsH5Model : public QObject
void loadAllRoiMaps();

const std::unordered_map<std::string, struct Map_ROI >& get_map_rois() { return _map_rois; }

void generateNameLists(QString analysis_type, std::vector<std::string>& names);

signals:
void model_data_updated();

Expand Down
Loading

0 comments on commit 452ed69

Please sign in to comment.