From fd83a707b611d54cfa91da36dc385f69b8199b60 Mon Sep 17 00:00:00 2001 From: samo38 Date: Thu, 16 May 2024 14:31:44 -0600 Subject: [PATCH 01/21] us_legacy_converter: fixed the issue with different filename petterns for interference and other types --- programs/us_legacy_converter/us_legacy_converter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index e1007bebf..783999ca2 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -384,18 +384,20 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp QRegularExpression re; re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch match; + // RunId1991-s0001-c2-s0009-w260-r_-n1.ri2 + // RunId1991-s0002-c1-s0001-n1.ip1 + QString pattern = "^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-(?:w(\\d{3})-)?(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$"; + re.setPattern(pattern); QString runid; QString runtype; QMap file_map; QMap> tcws_map; + foreach (QString fpath, flist) { QFileInfo finfo = QFileInfo(fpath); QFile file(fpath); QString fname = finfo.fileName(); - - // RunId1991-s0001-c2-s0009-w260-r_-n1.ri2 - re.setPattern("^(.+)-s(\\d{4,6})-c(\\d)-s(\\d{4,6})-w(\\d{3})-(.+?)[.](?:RA|RI|IP|FI|WA|WI)\\d$"); match = re.match(fname); if (match.hasMatch()) { if (runid.size() == 0) { From 8ea8d434166555da395c6bef18a5d60ebe5e9f75 Mon Sep 17 00:00:00 2001 From: samo38 Date: Thu, 16 May 2024 16:11:19 -0600 Subject: [PATCH 02/21] us_legacy_converter: edited the error messanges --- programs/us_legacy_converter/us_legacy_converter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/programs/us_legacy_converter/us_legacy_converter.cpp b/programs/us_legacy_converter/us_legacy_converter.cpp index 783999ca2..085860bca 100644 --- a/programs/us_legacy_converter/us_legacy_converter.cpp +++ b/programs/us_legacy_converter/us_legacy_converter.cpp @@ -300,7 +300,7 @@ void US_LegacyConverter::reload() { } QFileInfo tar_finfo = QFileInfo(tar_fpath); if (! tar_finfo.exists()) { - QMessageBox::warning(this, "Error!", tr("File Not Found!\n\n(%1)!").arg(tar_finfo.absoluteFilePath())); + QMessageBox::warning(this, "Error!", tr("TAR File Not Found!\n\n(%1)!").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); qApp->restoreOverrideCursor(); return; @@ -327,13 +327,13 @@ void US_LegacyConverter::reload() { QStringList filelist; list_files(tmp_dir.path(), filelist); if (filelist.size() == 0) { - QMessageBox::warning(this, "Warning!", tr("Empty File!\n(%1)").arg(tar_finfo.absoluteFilePath())); + QMessageBox::warning(this, "Warning!", tr("File is empty!\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); qApp->restoreOverrideCursor(); return; } if (! sort_files( filelist, tmp_dir_sorted.path() ) ) { - QMessageBox::warning(this, "Warning!", tr("No right files found in the TAR file!\n\n(%1)").arg(tar_finfo.absoluteFilePath())); + QMessageBox::warning(this, "Warning!", tr("Incorrect filename pattern!\n\n(%1)").arg(tar_finfo.absoluteFilePath())); tar_fpath.clear(); qApp->restoreOverrideCursor(); return; @@ -421,7 +421,7 @@ bool US_LegacyConverter::sort_files(const QStringList& flist, const QString& tmp } QString tcws = tcw + "-" + QString::number(scan); if (file_map.contains(tcws)) { - QMessageBox::warning(this, "Error!", "Scan number redundancy!"); + QMessageBox::warning(this, "Error!", "Some of scans are redundant!"); return false; } else { file_map.insert(tcws, fpath); From d276f0c3e7ccda141fbb2bd99e1a8057a5bf4c97 Mon Sep 17 00:00:00 2001 From: samo38 Date: Wed, 5 Jun 2024 03:43:42 -0600 Subject: [PATCH 03/21] us_pseudo_absorbance/us_convert_scan: updated to the new version --- .../us_pseudo_absorbance/us_convert_scan.cpp | 2400 +++++++---------- .../us_pseudo_absorbance/us_convert_scan.h | 314 +-- 2 files changed, 1048 insertions(+), 1666 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 427718858..e6cb43a05 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -1,162 +1,167 @@ #include "us_convert_scan.h" - +#include US_ConvertScan::US_ConvertScan() : US_Widgets() { - dbCon = new US_DB2(); setPalette( US_GuiSettings::frameColorDefault() ); - - // Put the Run Info across the entire window - QLabel* lb_last_scans = us_label("Last Scan(s):"); - ct_last_scans = us_counter(1, 1, 100, 5); - ct_last_scans->setSingleStep(1); - ct_last_scans->setMaximumWidth(100); - - QLabel* lb_runInfoInt = us_banner( tr( "Intensity Data Control" ) ); - pb_import = us_pushbutton(tr("Import")); - pb_reset = us_pushbutton("Reset", false, 0 ); - pb_reset->setDisabled(true); - - QLabel* lb_runIdInt = us_label( tr( "Run ID:" ) ); - lb_runIdInt->setAlignment(Qt::AlignRight); - le_runIdInt = us_lineedit( "", 0, true ); - QLabel* lb_desc = us_label( tr( "Description:" ), 0 ); - lb_desc->setAlignment(Qt::AlignRight); + font = QFont( US_Widgets::fixedFont().family(), US_GuiSettings::fontSize() ); + // font.setPointSize(font.pointSize() - 1); + + QLabel* lb_runInfoInt = us_banner("Intensity Data Control"); + pb_import = us_pushbutton("Import Run"); + pb_reset = us_pushbutton("Reset"); + pb_load_ref = us_pushbutton("Load Reference Scan"); + + QHBoxLayout *imp_lyt_1 = new QHBoxLayout(); + imp_lyt_1->addWidget(pb_import); + imp_lyt_1->addWidget(pb_load_ref); + imp_lyt_1->addWidget(pb_reset); + + QLabel* lb_runIdInt = us_label("Run ID:"); + lb_runIdInt->setAlignment(Qt::AlignCenter); + le_runid = us_lineedit("", 0, true ); + QLabel* lb_desc = us_label("Description:", 0 ); + lb_desc->setAlignment(Qt::AlignCenter); le_desc = us_lineedit( "", 0, true); - QGridLayout* import_lyt = new QGridLayout(); - import_lyt->addWidget(lb_last_scans, 0, 0, 1, 2); - import_lyt->addWidget(ct_last_scans, 0, 2, 1, 1); - import_lyt->addWidget(pb_import, 0, 3, 1, 3); - import_lyt->addWidget(pb_reset, 0, 6, 1, 3); - import_lyt->addWidget(lb_runIdInt, 1, 0, 1, 2); - import_lyt->addWidget(le_runIdInt, 1, 2, 1, 7); - import_lyt->addWidget(lb_desc, 2, 0, 1, 2); - import_lyt->addWidget(le_desc, 2, 2, 1, 7); + QGridLayout *imp_lyt_2 = new QGridLayout(); + imp_lyt_2->addWidget(lb_runIdInt, 0, 0, 1, 1); + imp_lyt_2->addWidget(le_runid, 0, 1, 1, 3); + imp_lyt_2->addWidget(lb_desc, 1, 0, 1, 1); + imp_lyt_2->addWidget(le_desc, 1, 1, 1, 3); + + QVBoxLayout* import_lyt = new QVBoxLayout(); + import_lyt->addWidget(lb_runInfoInt); + import_lyt->addLayout(imp_lyt_1); + import_lyt->addLayout(imp_lyt_2); + + // Cell / Channel / Wavelength + int width_lb = 170; + int width_ct = 130; + QLabel* lb_buffer = us_banner("Absorbance Data Control"); + + QLabel* lb_lscns_smp = us_label("# Scans (Sample)", 0); + lb_lscns_smp->setAlignment(Qt::AlignCenter); + lb_lscns_smp->setFixedWidth(width_lb); + + QLabel* lb_lscns_buf = us_label("# Scans (Buffer)", 0); + lb_lscns_buf->setAlignment(Qt::AlignCenter); + lb_lscns_buf->setFixedWidth(width_lb); + + QLabel *lb_smooth = us_label("Smoothing Level", 0); + lb_smooth->setAlignment(Qt::AlignCenter); + lb_smooth->setFixedWidth(width_lb); + + pb_apply = us_pushbutton("Apply"); + + ns_smp = 1; + ct_lscns_smp = us_counter(2, 1, 200, ns_smp); + ct_lscns_smp->setSingleStep(1); + ct_lscns_smp->setFixedWidth(width_ct); + + ns_buf = 10; + ct_lscns_buf = us_counter(2, 1, 200, ns_buf); + ct_lscns_buf->setSingleStep(1); + ct_lscns_buf->setFixedWidth(width_ct); + + smooth = 0; + ct_smooth = us_counter(2, 0, 10, smooth); + ct_smooth->setSingleStep(1); + ct_smooth->setFixedWidth(width_ct); + + QGridLayout* ccw_lyt_1_l = new QGridLayout(); + ccw_lyt_1_l->addWidget(lb_lscns_smp, 0, 0, 1, 1); + ccw_lyt_1_l->addWidget(ct_lscns_smp, 0, 1, 1, 1); + ccw_lyt_1_l->addWidget(lb_lscns_buf, 1, 0, 1, 1); + ccw_lyt_1_l->addWidget(ct_lscns_buf, 1, 1, 1, 1); + ccw_lyt_1_l->addWidget(lb_smooth, 2, 0, 1, 1); + ccw_lyt_1_l->addWidget(ct_smooth, 2, 1, 1, 1); + QHBoxLayout* ccw_lyt_1 = new QHBoxLayout(); + ccw_lyt_1->addLayout(ccw_lyt_1_l, 0); + ccw_lyt_1->addSpacing(1); + ccw_lyt_1->addWidget(pb_apply, 0, Qt::AlignVCenter); - // Multi-Wavelength Lambda Controls static QChar clambda( 955 ); // Lambda character - lb_lambstrt = us_label ( tr( "%1 Start:" ).arg( clambda ) ); - lb_lambstop = us_label ( tr( "%1 End:" ).arg( clambda ) ); - // lb_lambstrt->setMaximumWidth(100); - // lb_lambstop->setMaximumWidth(100); + QLabel* lb_lambstrt = us_label(tr( "%1 Start:" ).arg( clambda ) ); + lb_lambstrt->setAlignment(Qt::AlignCenter); + QLabel* lb_lambstop = us_label(tr( "%1 End:" ).arg( clambda ) ); + lb_lambstop->setAlignment(Qt::AlignCenter); + + le_lambstrt = us_lineedit("", -1, true); + le_lambstop = us_lineedit("", -1, true); + lb_lambstrt->setFixedWidth(70); + lb_lambstop->setFixedWidth(70); cb_plot_id = us_comboBox(); cb_plot_id->setEditable(true); - cb_plot_id->setMaximumWidth(100); + cb_plot_id->setFixedWidth(100); + + QHBoxLayout* ccw_lyt_2 = new QHBoxLayout(); + ccw_lyt_2->addWidget(lb_lambstrt, 0); + ccw_lyt_2->addSpacing(1); + ccw_lyt_2->addWidget(le_lambstrt, 1); + ccw_lyt_2->addSpacing(1); + ccw_lyt_2->addWidget(cb_plot_id, 0); + ccw_lyt_2->addSpacing(1); + ccw_lyt_2->addWidget(lb_lambstop, 0); + ccw_lyt_2->addSpacing(1); + ccw_lyt_2->addWidget(le_lambstop, 1); + pb_prev_id = us_pushbutton( "Previous", true, 0 ); pb_next_id = us_pushbutton( "Next", true, 0 ); pb_prev_id->setIcon( US_Images::getIcon( US_Images::ARROW_LEFT ) ); pb_next_id->setIcon( US_Images::getIcon( US_Images::ARROW_RIGHT ) ); - - QHBoxLayout* wvl_rng_lyt = new QHBoxLayout(); - wvl_rng_lyt->addWidget(lb_lambstrt); - wvl_rng_lyt->addWidget(cb_plot_id); - wvl_rng_lyt->addWidget(lb_lambstop); - - QHBoxLayout* wvl_ctl_lyt = new QHBoxLayout(); - wvl_ctl_lyt->addWidget(pb_prev_id); - wvl_ctl_lyt->addWidget(pb_next_id); - - // Cell / Channel / Wavelength - QLabel* lb_triple = us_banner(tr( "Cell / Channel / Wavelength" ) ); - lw_triple = us_listwidget(); - QLabel* lb_ccw_info = us_label(tr("Manage Triples")); - lb_ccw_info->setAlignment(Qt::AlignCenter); - QPushButton* pb_del_ccw_item = us_pushbutton(tr("Delete Selected CCW")); - QPushButton* pb_default_ccw = us_pushbutton(tr("Default")); - QVBoxLayout* ccw_vbl = new QVBoxLayout(); - ccw_vbl->addWidget(lb_ccw_info); - ccw_vbl->addWidget(pb_del_ccw_item); - ccw_vbl->addWidget(pb_default_ccw); - ccw_vbl->addStretch(1); - QHBoxLayout* ccw_hbl = new QHBoxLayout(); - ccw_hbl->addWidget(lw_triple); - ccw_hbl->addLayout(ccw_vbl); - - ckb_act_refscan = new QCheckBox(); - ckb_act_refscan->setChecked(false); - QGridLayout* actref_lyt = us_checkbox("Remove TI with Reference Scan", ckb_act_refscan); - - frm_refScan = new QFrame(); - QLabel* lb_refScan = us_banner( tr( "Reference Scan Control" ) ); - frm_refScan->setContentsMargins(0, 0, 0, 0); - diskDB_ctrl = new US_Disk_DB_Controls(); - pb_import_refScans = us_pushbutton(tr("Import"), true, 0); - pb_reset_refData = us_pushbutton(tr("Reset"), false, 0); - QString ref_range("%1 Range:"); - QLabel* lb_ref_range = us_label(ref_range.arg(QChar(955))); - lb_ref_range->setMaximumWidth(80); - le_ref_range = us_lineedit(""); - le_ref_range->setMaximumWidth(140); - le_ref_range->setReadOnly(true); - QHBoxLayout* rfs_imp_lyt = new QHBoxLayout(); - rfs_imp_lyt->addWidget(pb_import_refScans); - rfs_imp_lyt->addWidget(pb_reset_refData); - rfs_imp_lyt->addWidget(lb_ref_range); - rfs_imp_lyt->addWidget(le_ref_range); - - ckb_ChroAberCorr = new QCheckBox(); - QGridLayout *cac_lyt = us_checkbox("Chromatic Aberration Correction", ckb_ChroAberCorr); - QFont font = ckb_ChroAberCorr->font(); - font.setPointSize(font.pointSize() - 1); - ckb_ChroAberCorr->setFont(font); - - QVBoxLayout* rfs_lyt = new QVBoxLayout(); - rfs_lyt->addWidget(lb_refScan); - rfs_lyt->addLayout(diskDB_ctrl); - rfs_lyt->addLayout(rfs_imp_lyt); - rfs_lyt->addLayout(cac_lyt); - rfs_lyt->setContentsMargins(0, 0, 0, 0); - rfs_lyt->setSpacing(1); - frm_refScan->setLayout(rfs_lyt); - - QLabel* lb_bufferBanner = us_banner( tr( "Absorbance Data Control" ) ); - QLabel *lb_buffer = us_label("Buffer Triple:"); - lb_buffer->setMaximumWidth(108); - cb_buffer = us_comboBox(); - QLabel *lb_smooth = us_label("Smooth Level:"); - lb_smooth->setMaximumWidth(120); - ct_smooth = us_counter(1, 0, 10, 5); - ct_smooth->setSingleStep(1); - ct_smooth->setMaximumWidth(70); - - QHBoxLayout *buffer_lyt = new QHBoxLayout(); - buffer_lyt->addWidget(lb_buffer); - buffer_lyt->addWidget(cb_buffer); - buffer_lyt->addWidget(lb_smooth); - buffer_lyt->addWidget(ct_smooth); - - // QLabel* lb_runInfoAbs = us_banner( tr( "Absorbance Data Information" ) ); - QLabel* lb_runIdAbs = us_label( tr( "Run ID:" ) ); -// le_runIdAbs = us_lineedit( "", 0, false ); - le_runIdAbs = new US_LineEdit_RE("", 0, false ); - - QGridLayout* abs_info_lyt = new QGridLayout(); - abs_info_lyt->addWidget(lb_runIdAbs, 0, 0, 1, 1); - abs_info_lyt->addWidget(le_runIdAbs, 0, 1, 1, 1); - - ckb_zeroing = new QCheckBox(); - QGridLayout *us_zeroing = us_checkbox("Shift to Zero", - ckb_zeroing); - ckb_xrange = new QCheckBox(); - QGridLayout *us_xrange = us_checkbox("Limit Radius", - ckb_xrange); - pb_pick_rp = us_pushbutton("Pick Two Radial Points", false); - QHBoxLayout *ckb_lyt = new QHBoxLayout(); - ckb_lyt->addLayout(us_zeroing); - ckb_lyt->addLayout(us_xrange); - ckb_lyt->addWidget(pb_pick_rp); - - QLabel *lb_r_rng = us_label("Radius Range:"); - le_xrange = us_lineedit("", 0, true); - QHBoxLayout *xrange_lyt = new QHBoxLayout(); - xrange_lyt->addWidget(lb_r_rng); - xrange_lyt->addWidget(le_xrange); - - QLabel* lb_status = us_label(tr("Status:")); - le_status = us_lineedit(tr(""), -1, true); + pb_prev_id->setFixedWidth(150); + pb_next_id->setFixedWidth(150); + + QHBoxLayout* ccw_lyt_3 = new QHBoxLayout(); + ccw_lyt_3->addWidget(pb_prev_id, 0, Qt::AlignRight); + ccw_lyt_3->addWidget(pb_next_id, 0, Qt::AlignLeft); + + tb_triple = new QTableWidget(); + tb_triple->setRowCount(0); + tb_triple->setColumnCount(4); + tb_triple-> setHorizontalHeaderLabels(QStringList{"Cell/Channel", "Lambda", "Reference", "Save"}); + tb_triple->setStyleSheet("QTableWidget { background-color: white; }"); + QHeaderView* header = tb_triple->horizontalHeader(); + header->setFont(font); + header->setSectionResizeMode(QHeaderView::Fixed); + header->resizeSection(header->logicalIndex(0), 130); + header->resizeSection(header->logicalIndex(1), 145); + header->resizeSection(header->logicalIndex(2), 123); + header->resizeSection(header->logicalIndex(3), 50); + + tb_triple->verticalHeader()->setVisible(false); + + QVBoxLayout* ccw_lyt = new QVBoxLayout(); + ccw_lyt->addWidget(lb_buffer); + ccw_lyt->addLayout(ccw_lyt_1); + ccw_lyt->addWidget(tb_triple); + ccw_lyt->addLayout(ccw_lyt_2); + ccw_lyt->addLayout(ccw_lyt_3); + + QLabel *lb_zero = us_label("Shift to Zero"); + lb_zero->setAlignment(Qt::AlignCenter); + lb_zero->setFixedWidth(120); + pb_pick_rp = us_pushbutton("Pick Region"); + QPushButton *pb_default = us_pushbutton("Default"); + + QHBoxLayout *buff_lyt_1 = new QHBoxLayout(); + buff_lyt_1->addWidget(lb_zero); + buff_lyt_1->addWidget(pb_pick_rp); + buff_lyt_1->addWidget(pb_default); + + pb_save = us_pushbutton("Save Absorbance Data"); + pb_save->setFixedWidth(250); + + QVBoxLayout* buffer_lyt = new QVBoxLayout(); + buffer_lyt->addLayout(buff_lyt_1); + buffer_lyt->addWidget(pb_save, 0, Qt::AlignCenter); + + QLabel* lb_status = us_label("Status:"); + lb_status->setAlignment(Qt::AlignCenter); + le_status = us_lineedit("", -1, true); QPalette stpal; stpal.setColor( QPalette::Text, Qt::white ); stpal.setColor( QPalette::Base, Qt::blue ); @@ -165,11 +170,6 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() status_lyt->addWidget(lb_status); status_lyt->addWidget(le_status); - pb_save = us_pushbutton("Save Absorbance Data", false, 0 ); - pb_save->setDisabled(true); - int ss = 250; - pb_save->setMinimumWidth(ss); - pb_save->setMaximumWidth(ss); QPushButton* pb_help = us_pushbutton("Help", true, 0 ); pb_close = us_pushbutton("Close", true, 0 ); @@ -178,29 +178,26 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() close_lyt->addWidget(pb_close); QVBoxLayout* left_lyt = new QVBoxLayout(); - left_lyt->addStretch(0); left_lyt->setSpacing(1); - left_lyt->addWidget(lb_runInfoInt); left_lyt->addLayout(import_lyt); - left_lyt->addWidget(lb_triple); - left_lyt->addLayout(ccw_hbl); - left_lyt->addLayout(wvl_rng_lyt); - left_lyt->addLayout(wvl_ctl_lyt); - left_lyt->addLayout(actref_lyt); - left_lyt->addWidget(frm_refScan); - left_lyt->addWidget(lb_bufferBanner); + left_lyt->addSpacing(3); + left_lyt->addLayout(ccw_lyt); + left_lyt->addSpacing(3); left_lyt->addLayout(buffer_lyt); - left_lyt->addLayout(ckb_lyt); - left_lyt->addLayout(xrange_lyt); - left_lyt->addLayout(abs_info_lyt); - left_lyt->addWidget(pb_save, 0, Qt::AlignCenter); - left_lyt->addStretch(1); + left_lyt->addSpacing(3); left_lyt->addLayout(status_lyt); left_lyt->addLayout(close_lyt); - left_lyt->addStretch(0); + left_lyt->setSpacing(1); + left_lyt->setMargin(0); + + QFrame* frm_left = new QFrame(); + frm_left->setLayout(left_lyt); + frm_left->setFrameShadow(QFrame::Plain); + frm_left->setFrameShape(QFrame::NoFrame); + frm_left->setMaximumWidth(450); -// //*****right*****// -// plot_title = us_label(""); + // //*****right*****// + // plot_title = us_label(""); plot_title = us_label(""); plot_title->setAlignment(Qt::AlignCenter); @@ -209,8 +206,8 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QwtText xLabel, yLabel; usplot_insty = new US_Plot( qwtplot_insty, tr( "" ), - tr( "Radius (in cm)" ), tr( "Intensity" ), - true, "", "rainbow" ); + tr( "Radius (in cm)" ), tr( "Intensity" ), + true, "", "rainbow" ); qwtplot_insty->setMinimumSize( 650, 300 ); qwtplot_insty->enableAxis( QwtPlot::xBottom, true ); qwtplot_insty->enableAxis( QwtPlot::yLeft , true ); @@ -218,49 +215,22 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() grid = us_grid(qwtplot_insty); usplot_abs = new US_Plot( qwtplot_abs, tr( "" ), - tr( "Radius (in cm)" ), tr( "Absorbance" ), - true, "", "rainbow" ); + tr( "Radius (in cm)" ), tr( "Absorbance" ), + true, "", "rainbow" ); qwtplot_abs->setMinimumSize( 650, 300 ); qwtplot_abs->enableAxis( QwtPlot::xBottom, true ); qwtplot_abs->enableAxis( QwtPlot::yLeft , true ); qwtplot_abs->setCanvasBackground(QBrush(Qt::black)); grid = us_grid(qwtplot_abs); - ct_scan_l = us_counter(3, 0, 0, 0); - ct_scan_l->setSingleStep(1); - ct_scan_u = us_counter(3, 0, 0, 0); - ct_scan_u->setSingleStep(1); - QLabel *lb_scan_ctrl = us_banner("Scans Control"); - QLabel *lb_scan_1 = us_label("Scan Focus From:"); - lb_scan_1->setAlignment(Qt::AlignRight); - QLabel *lb_scan_2 = us_label("To:"); - lb_scan_2->setAlignment(Qt::AlignRight); - QPushButton *pb_reset_curr_scans = us_pushbutton("Reset Current", true, 0); - QPushButton *pb_reset_allscans = us_pushbutton("Reset All", true, 0); - QPushButton *pb_apply_allscans = us_pushbutton("Apply All", true, 0); - - QGridLayout *scan_ctrl_lyt = new QGridLayout(); - scan_ctrl_lyt->addWidget(lb_scan_ctrl, 0, 0, 1, 4); - scan_ctrl_lyt->addWidget(lb_scan_1, 1, 0, 1, 1); - scan_ctrl_lyt->addWidget(ct_scan_l, 1, 1, 1, 1); - scan_ctrl_lyt->addWidget(pb_reset_curr_scans, 1, 2, 1, 2); - scan_ctrl_lyt->addWidget(lb_scan_2, 2, 0, 1, 1); - scan_ctrl_lyt->addWidget(ct_scan_u, 2, 1, 1, 1); - scan_ctrl_lyt->addWidget(pb_reset_allscans, 2, 2, 1, 1); - scan_ctrl_lyt->addWidget(pb_apply_allscans, 2, 3, 1, 1); - QVBoxLayout* right_lyt = new QVBoxLayout(); right_lyt->setSpacing(0); right_lyt->addWidget(plot_title); right_lyt->addLayout(usplot_insty); right_lyt->addLayout(usplot_abs); -// right_lyt->addStretch(1); - right_lyt->addLayout(scan_ctrl_lyt); QHBoxLayout* main_lyt = new QHBoxLayout(this); - left_lyt->setSizeConstraint(QLayout::SetMinimumSize); - main_lyt->addLayout(left_lyt, 0); -// main_lyt->addStretch(1); + main_lyt->addWidget(frm_left, 0); main_lyt->addLayout(right_lyt, 1); main_lyt->setSpacing(1); main_lyt->setMargin(1); @@ -269,325 +239,287 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() picker_abs = new US_PlotPicker(qwtplot_abs); picker_abs->setRubberBand ( QwtPicker::VLineRubberBand ); picker_abs->setMousePattern( QwtEventPattern::MouseSelect1, - Qt::LeftButton, Qt::ControlModifier ); + Qt::LeftButton, Qt::ControlModifier ); picker_insty = new US_PlotPicker(qwtplot_insty); - slt_reset(); - - slt_act_refScans(Qt::Unchecked); - - connect(pb_import, SIGNAL(clicked()), this, SLOT(slt_import())); - connect(pb_default_ccw, SIGNAL(clicked()), this, SLOT(slt_set_ccw_default())); - connect(pb_del_ccw_item, SIGNAL(clicked()), - this, SLOT(slt_del_item())); - connect(pb_reset, SIGNAL(clicked()), this, SLOT(slt_reset())); - connect(pb_prev_id, SIGNAL(clicked()), this, SLOT(slt_prev_id())); - connect(pb_next_id, SIGNAL(clicked()), this, SLOT(slt_next_id())); - - connect(this, SIGNAL(sig_plot()), this, SLOT(slt_plot())); - - connect(ckb_act_refscan, SIGNAL(stateChanged(int)), - this, SLOT(slt_act_refScans(int))); - connect(pb_import_refScans, SIGNAL(clicked()), this, SLOT(slt_load_refScans())); - connect(ckb_zeroing, SIGNAL(stateChanged(int)), this, SLOT(slt_zeroing(int))); - connect(ckb_xrange, SIGNAL(stateChanged(int)), this, SLOT(slt_xrange(int))); - - connect(pb_reset_curr_scans, SIGNAL(clicked()), this, SLOT(slt_reset_scans())); - connect(pb_reset_allscans, SIGNAL(clicked()), this, SLOT(slt_reset_allscans())); - connect(pb_apply_allscans, SIGNAL(clicked()), this, SLOT(slt_apply_allscans())); - connect(pb_reset_refData, SIGNAL(clicked()), this, SLOT(slt_reset_refData())); - connect(this, SIGNAL(sig_save_button()), this, SLOT(slt_save_avail())); - - connect(pb_save, SIGNAL(clicked()), this, SLOT(slt_save())); - - connect(cb_buffer, SIGNAL(currentIndexChanged(int)), - this, SLOT(slt_update_buffer(int))); - - connect(ct_smooth, SIGNAL(valueChanged(double)), this, SLOT(slt_update_smooth(double))); - connect(pb_pick_rp, SIGNAL(clicked()), this, SLOT(slt_pick_point())); + reset(); + + connect(this, &US_ConvertScan::sig_plot, this, &US_ConvertScan::plot_all); + connect(pb_import, &QPushButton::clicked, this, &US_ConvertScan::import_run); + connect(pb_reset, &QPushButton::clicked, this, &US_ConvertScan::reset); + connect(pb_prev_id, &QPushButton::clicked, this, &US_ConvertScan::prev_id); + connect(pb_next_id, &QPushButton::clicked, this, &US_ConvertScan::next_id); + connect(pb_save, &QPushButton::clicked, this, &US_ConvertScan::save_run); + connect(pb_pick_rp, &QPushButton::clicked, this, &US_ConvertScan::pick_region); + connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_scan_smooth); + connect(pb_default, &QPushButton::clicked, this, &US_ConvertScan::default_region); + connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + connect(ct_lscns_buf, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + connect(ct_lscns_smp, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); } -void US_ConvertScan::slt_reset(){ +void US_ConvertScan::reset(){ picker_abs->disconnect(); - ct_last_scans->setEnabled(true); + tb_triple->disconnect(); + tb_triple->clearContents(); + tb_triple->setRowCount(0); hasData = false; - intRunIds.clear(); - intDataId.clear(); - xvalues.clear(); - intensity.clear(); - absorbance.clear(); - absorbanceBuffer.clear(); - allIntData.clear(); - allIntDataFiles.clear(); - ccwList.clear(); - ccwListMain.clear(); - ccwStrListMain.clear(); - ccwItemList.clear(); - scansRange.clear(); - le_cursor_pos = -1; + wavl_id = 0; + ref_file_id = -1; wavelength.clear(); - refData.clear(); - xvaluesRefCAC.clear(); - x_min_picked = -1; - x_max_picked = -1; - runIdAbs.clear(); - le_ref_range->clear(); - lb_lambstrt->setText(tr("%1 Start:").arg( QChar(955) )); - lb_lambstop->setText(tr("%1 End:").arg( QChar(955) )); - le_runIdAbs->clear(); - le_runIdInt->clear(); + ccw_items.clear(); + intensity_data.clear(); + absorbance_data.clear(); + absorbance_state.clear(); + absorbance_shifts.clear(); + refscan_data.clear(); + refscan_files.clear(); + le_lambstrt->clear(); + le_lambstop->clear(); + le_runid->clear(); le_desc->clear(); - le_xrange->clear(); - set_listWidget(); set_wavl_ctrl(); - pb_reset->setDisabled(true); - pb_import->setEnabled(true); - pb_import_refScans->setEnabled(true); - pb_reset_refData->setDisabled(true); - pb_save->setDisabled(true); - ckb_zeroing->setCheckState(Qt::Unchecked); - uncheck_CA_silently(); - return; } -void US_ConvertScan::slt_import(void){ +void US_ConvertScan::update_scan_smooth() { + pb_apply->setStyleSheet("QPushButton { background-color: red }"); +} + +void US_ConvertScan::apply_scan_smooth() { + QColor color = US_GuiSettings::pushbColor().color(QPalette::Active, QPalette::Button); + QString qs = "QPushButton { background-color: %1 }"; + pb_apply->setStyleSheet(qs.arg(color.name())); + ns_smp = static_cast(ct_lscns_smp->value()); + ns_buf = static_cast(ct_lscns_buf->value()); + smooth = static_cast(ct_smooth->value()); + QGuiApplication::setOverrideCursor(Qt::WaitCursor); + for (int ii = 0; ii < ccw_items.size(); ii++) { + calc_absorbance(ii); + } + QGuiApplication::restoreOverrideCursor(); + emit sig_plot(); +} + +void US_ConvertScan::import_run(){ QString dir; dir = QFileDialog::getExistingDirectory( this, - tr( "Open Raw Data Directory" ), - US_Settings::importDir(), - QFileDialog::DontResolveSymlinks ); + tr( "Open Run ID" ), + US_Settings::importDir(), + QFileDialog::DontResolveSymlinks ); if (dir.isEmpty()) return; QDir inDir = QDir( dir, "*.auc", QDir::Name, QDir::Files | QDir::Readable ); if (inDir.count() == 0){ - le_status->setText("auc files not found"); + le_status->setText("auc files not found!"); return; } inDir.makeAbsolute(); - le_status->setText("parsing error!"); + le_status->setText("parsing files!"); + QFileInfoList fileList = inDir.entryInfoList(); - QString runId; - QString runType; - QStringList runTypesList; - runTypesList << "RI"; + QStringList bad_files; + QString run_id; + QString run_type; + QStringList run_type_avail{"RI"}; QRegExp re( "[^A-Za-z0-9_-]" ); bool runId_changed = false; - bool multiple_runid = false; - QString ccw_str("%1 / %2 / %3"); - int n_scans = ct_last_scans->value(); - for (int i = 0; i < fileList.size(); ++i){ - QString fname = fileList.at(i).fileName(); - QString rtp = fname.section(".", -5, -5); - QString rid = fname.section(".", 0, -6); + // QString ccw_str("%1 / %2 / %3"); + + QVector rawdata; + QVector>> absorbance; + QVector> shifts; + QVector> refscans; + // QStringList fnames; + QStringList loaded_runids; + foreach (CellChannel cc, ccw_items) { + loaded_runids << cc.runid; + } + + for (int ii = 0; ii < fileList.size(); ++ii){ + QString fn = fileList.at(ii).fileName(); + US_DataIO::RawData rdata = US_DataIO::RawData(); + int state = US_DataIO::readRawData(fileList.at(ii).absoluteFilePath(), rdata); + if (state != US_DataIO::OK) { + bad_files << fn; + continue; + } + QString rtp = QChar::fromLatin1(rdata.type[0]); + rtp.append(QChar::fromLatin1(rdata.type[1])); + QString rid = fn.section(".", 0, -6); int reIdx = rid.indexOf(re, 0); if (reIdx >=0) runId_changed = true; while (reIdx >=0){ rid = rid.replace(reIdx, 1, "_"); reIdx = rid.indexOf(re, reIdx); } - if (runId.isEmpty()) { - runId = rid; + if (run_id.isEmpty()) { + run_id = rid; } else { - if (runId != rid) multiple_runid = true; + if (run_id != rid) { + QMessageBox::warning( this, tr( "Warning!" ), + tr( "Multiple RunIDs Found!")); + return; + } } - if (! runTypesList.contains(rtp)){ + if (! run_type_avail.contains(rtp)){ QMessageBox::warning( this, tr( "Error" ), - tr( "The Run type (%1) is not supported." ).arg(rtp)); + tr( "The Run type (%1) is not supported!" ).arg(rtp)); return; } - if (runType.isEmpty()) runType = rtp; - else { - if (runType != rtp){ + if (run_type.isEmpty()){ + run_type = rtp; + } else { + if (run_type != rtp){ QMessageBox::warning( this, tr( "Error" ), - tr( "Multiple run types found in the directory" )); + tr( "Multiple run types are found in the directory!" )); return; } } - if (intRunIds.contains(rid)) { + if (loaded_runids.contains(run_id)) { QMessageBox::warning( this, tr( "Error" ), - tr( "The RunID Already Loaded!\n(%1)" ).arg(rid)); + tr( "The RunID (%1) is already loaded!" ).arg(run_id)); return; } - - US_DataIO::RawData rdata = US_DataIO::RawData(); - US_DataIO::readRawData(fileList.at(i).absoluteFilePath(), rdata); - QVector scl; + rawdata << rdata; + // fnames << fn; int ns = rdata.scanCount(); - if (ns < n_scans) { - QMessageBox::warning(this, "Error!", tr("The number of scans in the following run is fewer than that is needed:(%1)\n" - "(%2)\n\nIf you want to load them, do reset, decrease the " - "number of the last scans, and reload your experiments.") - .arg(ns).arg(fileList.at(i).fileName())); - return; + int np = rdata.pointCount(); + QVector rf(np, 0); + refscans << rf; + QVector> abs; + for (int jj = 0; jj < ns; jj++) { + QVector a(np, 0); + abs << a; } - QVector scans; - scans << rdata.scanData; - rdata.scanData.clear(); - rdata.scanData << scans.mid(ns - n_scans); - - scl << 0 << n_scans << n_scans; - scansRange << scl; - allIntData << rdata; - - allIntDataFiles << fileList.at(i); - - int cell = rdata.cell; - char channel = rdata.channel; - double wl = rdata.scanData.at(0).wavelength; - ccwStrListMain << ccw_str.arg(cell).arg(channel).arg(wl); - - ccwListMain.index << allIntData.size() - 1; - ccwListMain.cell << cell; - ccwListMain.channel << channel; - ccwListMain.wavelength << wl; - ccwListMain.runId << rid; - - ccwList.index << allIntData.size() - 1; - ccwList.cell << cell; - ccwList.channel << channel; - ccwList.wavelength << wl; - ccwList.runId << rid; + absorbance << abs; + QVector sh(ns, 0); + shifts << sh; } if ( runId_changed ) { - QMessageBox::warning( this, tr( "Warning!" ), - tr( "The RunID changed. It can only be alphanumeric," - "underscore, and hyphen characters.")); + QMessageBox::warning( this, tr( "Warning!" ), + tr( "The RunID changed. It can only have alphanumeric," + "underscore, and hyphen characters.")); } - if ( multiple_runid ) { + + if (!bad_files.isEmpty()) { QMessageBox::warning( this, tr( "Warning!" ), - tr( "Multiple RunIDs Found!")); + tr( "Unable to load %1 of the files").arg(bad_files.size())); } - intRunIds.clear(); - for (int ii = 0; ii < ccwListMain.size(); ii++){ - QString rundId = ccwListMain.runId.at(ii); - if (! intRunIds.contains(rundId)) { - intRunIds << rundId; - } + if (rawdata.isEmpty()) { + return; } -// re.setPattern("-run[0-9]+$"); -// int reIdx = runId.indexOf(re); -// QString s1 = runId.left(reIdx); -// QString s2 = runId.right(runId.size() - reIdx); -// runIdAbs = s1.append("_Absorbance").append(s2); - ct_last_scans->setDisabled(true); - runIdAbs = runId.prepend("P-ABS_"); - le_runIdAbs->setText(runIdAbs); - make_ccwItemList(); - set_listWidget(); + QVector states(rawdata.size(), false); + + intensity_data << rawdata; + absorbance_data << absorbance; + refscan_data << refscans; + absorbance_state << states; + absorbance_shifts << shifts; + + list_ccw_items(run_id); + set_table(); set_wavl_ctrl(); - // pb_import->setDisabled(true); pb_reset->setEnabled(true); - emit sig_save_button(); hasData = true; le_status->clear(); return; } -void US_ConvertScan::set_wavl_ctrl(){ - cb_plot_id->disconnect(); - cb_plot_id->clear(); - intDataId.clear(); - wavelength.clear(); - wavl_id = 0; - n_wavls = 0; - if (lw_triple->count() == 0){ - lb_lambstrt->setText(tr("%1 Start:").arg( QChar(955) )); - lb_lambstop->setText(tr("%1 End:").arg( QChar(955) )); - le_runIdInt->clear(); - offon_prev_next(); - emit sig_plot(); - return; - } - int ccw_id = lw_triple->currentRow(); - QString runId = intRunIds.at(ccwItemList.runClass.at(ccw_id)); - le_runIdInt->setText(runId); - n_wavls = ccwItemList.wavelength.at(ccw_id).size(); - intDataId = ccwItemList.index.at(ccw_id); - wavelength = ccwItemList.wavelength.at(ccw_id); - lb_lambstrt->setText(tr("%1 Start: %2").arg(QChar(955)).arg(wavelength.first())); - lb_lambstop->setText(tr("%1 End: %2").arg(QChar(955)).arg(wavelength.last())); - foreach (double wvl, wavelength) { - cb_plot_id->addItem(QString::number(wvl)); - } - offon_prev_next(); - connect(cb_plot_id, SIGNAL(currentIndexChanged(int)), this, SLOT(slt_set_id(int))); - slt_set_id(0); - return; -} - -void US_ConvertScan::slt_prev_id(void){ +void US_ConvertScan::prev_id(){ --wavl_id; cb_plot_id->setCurrentIndex(wavl_id); return; } -void US_ConvertScan::slt_next_id(void){ +void US_ConvertScan::next_id(){ ++wavl_id; cb_plot_id->setCurrentIndex(wavl_id); return; } void US_ConvertScan::offon_prev_next(){ + int n_wavls = wavelength.size(); pb_prev_id->setDisabled(wavl_id <= 0); pb_next_id->setDisabled(wavl_id >= (n_wavls - 1)); return; } -void US_ConvertScan::slt_set_ccw_default(){ - ccwList.clear(); - ccwList.index << ccwListMain.index; - ccwList.cell << ccwListMain.cell; - ccwList.channel << ccwListMain.channel; - ccwList.wavelength << ccwListMain.wavelength; - make_ccwItemList(); - set_listWidget(); - set_wavl_ctrl(); - emit sig_save_button(); - return; -} +void US_ConvertScan::set_wavl_ctrl(){ + if (tb_triple->currentColumn() == 2) return; -void US_ConvertScan::slt_del_item(){ - le_desc->setText(""); - if (lw_triple->count() == 0) + cb_plot_id->disconnect(); + cb_plot_id->clear(); + wavelength.clear(); + wavl_id = 0; + ref_file_id = -1; + if (ccw_items.isEmpty()) { + le_lambstrt->clear(); + le_lambstop->clear(); + le_runid->clear(); + le_desc->clear(); + offon_prev_next(); + emit sig_plot(); return; - int row = lw_triple->currentRow(); - ccwItemList.index.removeAt(row); - ccwItemList.cell.removeAt(row); - ccwItemList.channel.removeAt(row); - ccwItemList.wavelength.removeAt(row); - set_listWidget(); - set_wavl_ctrl(); - emit sig_save_button(); - return; -} + } -void US_ConvertScan::slt_wavl_ctrl(int){ - set_wavl_ctrl(); - return; + int row = tb_triple->currentRow(); + QString cellname = tb_triple->item(row, 0)->text(); + if (cellname.startsWith("Reference", Qt::CaseInsensitive)) { + for (int ii = 0; ii < refscan_files.size(); ii++) { + if (refscan_files.at(ii).name.compare(cellname) == 0) { + wavelength << refscan_files.at(ii).wavelength; + ref_file_id = ii; + } + } + } else { + wavelength << ccw_items.at(row).wavelength; + ref_file_id = -1; + } + le_lambstrt->setText(tr("%1").arg(wavelength.first())); + le_lambstop->setText(tr("%1").arg(wavelength.last())); + foreach (double wvl, wavelength) { + cb_plot_id->addItem(QString::number(wvl)); + } + offon_prev_next(); + + // connect(cb_plot_id, QOverload::of(&QComboBox::currentIndexChanged), + // [=](int index){ select_id(index); }); + + connect(cb_plot_id, SIGNAL(currentIndexChanged(int)), this, SLOT(select_id(int))); + select_id(0); } -void US_ConvertScan::slt_set_id(int id){ +void US_ConvertScan::select_id(int id){ + disconnect_picker(); wavl_id = id; offon_prev_next(); - le_desc->setText(allIntData.at(id).description); - set_scan_ct(); + if (ref_file_id >= 0) { + le_runid->clear(); + le_desc->setText(refscan_files.at(ref_file_id).filename); + } else { + int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + le_runid->setText(ccw_items.at(tb_triple->currentRow()).runid); + le_desc->setText(intensity_data.at(raw_id).description); + } emit sig_plot(); return; } -void US_ConvertScan::slt_plot(){ +void US_ConvertScan::plot_all(){ le_status->clear(); - if (lw_triple->count() == 0) + if (ccw_items.isEmpty()) { plot_title->setText(""); - else{ - QString title("Wavelength= %1 nm"); + } else{ + QString title("Wavelength= %1 nm; #Scans= %2"); double wl = wavelength.at(wavl_id); - plot_title->setText(title.arg(wl)); + int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + int ns = intensity_data.at(raw_id).scanData.size(); + plot_title->setText(title.arg(wl).arg(ns)); } plot_intensity(); plot_refscan(); @@ -595,601 +527,420 @@ void US_ConvertScan::slt_plot(){ return; } -void US_ConvertScan::slt_update_scrng(double){ - int row = lw_triple->currentRow(); - int index = ccwItemList.index.at(row).at(wavl_id); - int lower = qRound(ct_scan_l->value()); - int upper = qRound(ct_scan_u->value()); - scansRange[index][0] = lower; - scansRange[index][1] = upper; - emit sig_plot(); - return; -} - -void US_ConvertScan::slt_zeroing(int){ - emit sig_plot(); - emit sig_save_button(); - return; -} - -void US_ConvertScan::slt_act_refScans(int state){ - if (state == Qt::Checked){ - frm_refScan->show(); - } - else { - frm_refScan->hide(); - } - slt_reset_refData(); - emit sig_save_button(); - return; -} - -void US_ConvertScan::slt_xrange(int state){ - x_min_picked = -1; - x_max_picked = -1; - le_xrange->setText(""); - QString qs = "QPushButton { background-color: %1 }"; - QColor color = US_GuiSettings::pushbColor().color(QPalette::Active, QPalette::Button); - if (state == Qt::Checked){ - pb_pick_rp->setEnabled(true); - pb_pick_rp->setStyleSheet(qs.arg("yellow")); - }else{ - pb_pick_rp->setDisabled(true); - pb_pick_rp->setStyleSheet(qs.arg(color.name())); - } - emit sig_plot(); - emit sig_save_button(); - return; -} - -void US_ConvertScan::slt_pick_point(){ - picker_abs->disconnect(); - x_min_picked = -1; - x_max_picked = -1; - le_xrange->setText(""); - if (absorbance.size() == 0) - return; - pb_pick_rp->setStyleSheet("QPushButton { background-color: red }"); - emit sig_plot(); - emit sig_save_button(); - connect(picker_abs, SIGNAL(cMouseUp(const QwtDoublePoint&)), - this, SLOT(slt_mouse(const QwtDoublePoint&))); - return; -} - -void US_ConvertScan::slt_mouse(const QwtDoublePoint& point){ - double x = point.x(); - int np = xvalues.size(); - double min_x = xvalues.at(0); - double max_x = xvalues.at(np - 1); - QString str; - if (x > min_x && x < max_x){ - if (x_min_picked == -1){ - x_min_picked = x; - str = tr("%1 -"); - le_xrange->setText(str.arg(x_min_picked, 0, 'f', 3)); - emit sig_plot(); - } else { - if (x <= x_min_picked){ - QString mess("Pick a radial point greater than: %1 cm"); - QMessageBox::warning( this, tr( "Warning" ), mess.arg(x_min_picked)); - return; +void US_ConvertScan::select_refscan(int ref_row) { + QComboBox* combo = qobject_cast(sender()); + if (combo) { + QString ref_text = combo->itemText(ref_row); + int item_row = tb_triple->indexAt(combo->pos()).row(); + if (ref_row == 0) { + ccw_items[item_row].ref_id = -1; + } else if (ref_text.startsWith("Reference", Qt::CaseInsensitive)) { + for (int ii = 0; ii < refscan_files.size(); ii++) { + if (refscan_files.at(ii).name.compare(ref_text) == 0) { + ccw_items[item_row].ref_id = ii + 100; + break; + } } - x_max_picked = x; - picker_abs->disconnect(); - str = tr("%1 - %2 cm"); - le_xrange->setText(str.arg(x_min_picked, 0, 'f', 3). - arg(x_max_picked, 0, 'f', 3)); - pb_pick_rp->setStyleSheet("QPushButton { background-color: green }"); - emit sig_plot(); - } - }else{ - QString mess("Pick a point between the minimum and maximum" - "values of the radial points.\n" - "Minimum= %1 cm, Maximum= %2 cm"); - QMessageBox::warning( this, tr( "Warning" ), mess.arg(min_x).arg(max_x)); - } - emit sig_save_button(); - return; -} - -void US_ConvertScan::slt_reset_allscans(){ - if (scansRange.size() == 0 || lw_triple->count() == 0) - return; - for (int i = 0; i < scansRange.size(); ++i){ - scansRange[i][0] = 0; - scansRange[i][1] = scansRange.at(i).at(2); - } - set_scan_ct(); - emit sig_plot(); - return; -} - -void US_ConvertScan::slt_apply_allscans(){ - if (scansRange.size() == 0 || lw_triple->count() == 0) - return; - int row = lw_triple->currentRow(); - int index = ccwItemList.index.at(row).at(wavl_id); - QString curr_ccw = ccwStrListMain.at(index); - int lower = scansRange.at(index).at(0); - int upper = scansRange.at(index).at(1); - QVector mismatch; - for (int i = 0; i < ccwItemList.size(); ++i){ - for (int j = 0; j < ccwItemList.index.at(i).size(); ++j){ - int id = ccwItemList.index.at(i).at(j); - int max = scansRange.at(id).at(2); - if (lower <= max && upper <= max){ - scansRange[id][0] = lower; - scansRange[id][1] = upper; - } else - mismatch << id; - } - } - - if (mismatch.size() > 0){ - QListWidget* wl_mm = new QListWidget(); - QString item("%1- %2; # scans= %3"); - for (int i = 0; i < mismatch.size(); ++i){ - int id = mismatch.at(i); - QString ccw = ccwStrListMain.at(id); - int ns = scansRange.at(id).at(2); - wl_mm->addItem(item.arg(i + 1).arg(ccw).arg(ns)); + } else { + ccw_items[item_row].ref_id = ref_row - 1; } - QLabel* mess = us_label("The number of scans in the CCW list " - "below does not match the current CCW= " - + curr_ccw + "\nPlease modify them separately."); - mess->setAlignment(Qt::AlignHCenter | Qt::AlignTop); - mess->setWordWrap(true); - mess->setStyleSheet(tr("border: 1px solid white;" - "color: black;" - "background-color: white;")); - QLabel* lb_wrn = new QLabel(); - lb_wrn->setPixmap(this->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(50)); - QHBoxLayout* mess_lyt = new QHBoxLayout(); - mess_lyt->addWidget(lb_wrn,0 ); - mess_lyt->addWidget(mess, 1); - - QPushButton* ok = new QPushButton("&Ok"); - ok->setIcon(this->style()->standardIcon(QStyle::SP_DialogOkButton)); - QHBoxLayout* ok_lyt = new QHBoxLayout(); - ok_lyt->addStretch(1); - ok_lyt->addWidget(ok); - ok_lyt->addStretch(1); - - QVBoxLayout* lyt = new QVBoxLayout(); - lyt->addLayout(mess_lyt); - lyt->addWidget(wl_mm); - lyt->addLayout(ok_lyt); - - QDialog *qd = new QDialog(this); - qd->setWindowTitle("Warning !"); - qd->setWindowIcon(this->style()->standardIcon(QStyle::SP_MessageBoxWarning)); - qd->setLayout(lyt); - connect(ok, SIGNAL(clicked()), qd, SLOT(close())); - qd->exec(); + QModelIndex index = tb_triple->model()->index(item_row, 0); + tb_triple->selectionModel()-> + select(index, QItemSelectionModel::Select | QItemSelectionModel::Current); + QGuiApplication::setOverrideCursor(Qt::WaitCursor); + calc_absorbance(item_row); + QGuiApplication::restoreOverrideCursor(); + emit sig_plot(); } } -void US_ConvertScan::slt_reset_scans(){ - if (scansRange.size() == 0 || lw_triple->count() == 0) - return; - - int row = lw_triple->currentRow(); - int index = ccwItemList.index.at(row).at(wavl_id); - scansRange[index][0] = 0; - scansRange[index][1] = scansRange.at(index).at(2); - set_scan_ct(); - emit sig_plot(); - return; +void US_ConvertScan::disconnect_picker() { + picker_abs->disconnect(); + pb_pick_rp->setEnabled(true); } -void US_ConvertScan::slt_reset_refData(){ - refId = -1; - refData.clear(); - le_ref_range->setText(""); - pb_import_refScans->setEnabled(true); - pb_reset_refData->setDisabled(true); - pb_save->setDisabled(true); - uncheck_CA_silently(); - emit sig_plot(); - return; +void US_ConvertScan::default_region() { + disconnect_picker(); + if (ccw_items.isEmpty()) return; + ccw_items[tb_triple->currentRow()].minmax_x = qMakePair(-1, -1); + plot_absorbance(); } -void US_ConvertScan::slt_load_refScans(void){ - if (diskDB_ctrl->db()){ - load_from_DB(); - return; - }else{ - QString fname; - fname = QFileDialog::getOpenFileName( this, - tr( "Open Reference Scan File" ), - US_Settings::importDir(), tr("*.aucrs")); - if (fname.isEmpty()) return; - qDebug() << fname; - refData.clear(); - xvaluesRefCAC.clear(); - int error = US_RefScanDataIO::readRefData(fname, refData); - if (error != US_RefScanDataIO::OK){ - refData.clear(); - QString mess = US_RefScanDataIO::errorString(error); - le_status->setText(mess); - uncheck_CA_silently(); - } else{ - pb_import_refScans->setDisabled(true); - pb_reset_refData->setEnabled(true); - bool state; - xvaluesRefCAC = refData.get_CA_corrected(state); - if (! state){ - xvaluesRefCAC.clear(); - uncheck_CA_silently(); - le_status->setText("Error in chromatic aberration correction!"); - } else - ckb_ChroAberCorr->setEnabled(true); - emit sig_save_button(); - } - QString text("%1 - %2 nm"); - int nw = refData.nWavelength; - double w1 = refData.wavelength.at(0); - double w2 = refData.wavelength.at(nw - 1); - le_ref_range->setText(text.arg(w1).arg(w2)); - plot_refscan(); - plot_absorbance(); - le_status->clear(); +void US_ConvertScan::pick_region(){ + if (! abs_plt_on) { return; } + disconnect_picker(); + ccw_items[tb_triple->currentRow()].minmax_x = qMakePair(-1, -1); + pb_pick_rp->setEnabled(false); + connect(picker_abs, &US_PlotPicker::cMouseUp, this, &US_ConvertScan::mouse_click); + plot_absorbance(); } -void US_ConvertScan::slt_save_avail(void){ - if (lw_triple->count() == 0 || - ( refData.nWavelength == 0 && - ckb_act_refscan->isChecked()) ) - { - pb_save->setDisabled(true); - return; - } - - if (!ckb_act_refscan->isChecked() && - cb_buffer->currentIndex() == 0){ - pb_save->setDisabled(true); +void US_ConvertScan::mouse_click(const QwtDoublePoint& point){ + double x = point.x(); + int row = tb_triple->currentRow(); + double min_x = intensity_data.at(ccw_items.at(row).rawdata_ids.at(0)).xvalues.first(); + double max_x = intensity_data.at(ccw_items.at(row).rawdata_ids.at(0)).xvalues.last(); + if (x < min_x || x > max_x) { + QString mess("The picked point is beyond the data values. Please try again!\n" + "The picked point = %1 cm\n" + "Minimum radial point: %2 cm\n" + "Maximum radial point: %3 cm\n"); + QMessageBox::warning( this, tr( "Warning" ), mess.arg(x, min_x, max_x)); return; } - - if (ckb_xrange->isChecked()){ - if (x_min_picked != -1 && x_max_picked != -1) - pb_save->setEnabled(true); - else - pb_save->setDisabled(true); - }else{ - pb_save->setEnabled(true); + double first = ccw_items.at(tb_triple->currentRow()).minmax_x.first; + if (first <= 0) { + ccw_items[row].minmax_x.first = x; + plot_absorbance(); + } else { + if ( x <= first) { + QString mess("The second point has to be greater than the first one. Please try again!\n" + "The picked point = %1 cm\n" + "The first point s= %2 cm\n"); + QMessageBox::warning( this, tr( "Warning" ), mess.arg(x, first)); + return; + } else { + ccw_items[row].minmax_x.second = x; + update_shifts(row); + plot_absorbance(); + disconnect_picker(); + } } - return; } -void US_ConvertScan::select_CCW_save(QVector& selist) { - selist.clear(); +bool US_ConvertScan::set_abs_runid(QString& runid) { QDialog *dialog = new QDialog(this); - QList chk_list; - QVBoxLayout *lyt = new QVBoxLayout(); - QLabel *label = us_banner("Select Triple(s) To Save"); - lyt->addWidget(label); - for (int ii = 0; ii < lw_triple->count(); ii++) { - QCheckBox* chk = new QCheckBox(lw_triple->item(ii)->text()); - QGridLayout *gl = us_checkbox(lw_triple->item(ii)->text(), chk); - chk_list << chk; - lyt->addLayout(gl); - } + dialog->setPalette( US_GuiSettings::frameColorDefault() ); + QHBoxLayout *lyt1 = new QHBoxLayout(); + QLabel *label = us_label("Absorbance RunID:"); + US_LineEdit_RE* wg_runid = new US_LineEdit_RE(); + wg_runid->setText(runid); + lyt1->addWidget(label); + lyt1->addWidget(wg_runid); + + QVBoxLayout *lyt2 = new QVBoxLayout(); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - lyt->addStretch(1); - lyt->addWidget(buttons); - lyt->setMargin(1); - lyt->setSpacing(1); - dialog->setLayout(lyt); - dialog->setMaximumWidth(500); + buttons->setFont(font); + + lyt2->addLayout(lyt1); + lyt2->addStretch(1); + lyt2->addWidget(buttons); + lyt2->setMargin(1); + lyt2->setSpacing(2); + lyt2->setMargin(2); + dialog->setLayout(lyt2); + dialog->setMinimumWidth(600); + dialog->setFixedHeight(75); connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); int state = dialog->exec(); - if (state != QDialog::Accepted) return; - for (int ii = 0; ii < chk_list.size(); ii++) { - if (chk_list.at(ii)->isChecked()) selist << ii; + if (state != QDialog::Accepted) { + return false; } -} -void US_ConvertScan::slt_save(void){ - QVector selist; - select_CCW_save(selist); - if (selist.size() == 0) return; - - runIdAbs = le_runIdAbs->text(); - QDir dir = QDir(US_Settings::importDir()); - if (dir.cd(runIdAbs)){ - QString absPath = dir.absolutePath(); - int ck = QMessageBox::question(this, tr( "Warning!" ), - tr( "Output directory exists!\n" ) + runIdAbs + - tr( "\n\n Do you really want to replace it?")); - if (ck == QMessageBox::Yes){ + QString path = US_Settings::importDir(); + QDir dir(path); + if (! dir.exists()) { + dir.mkpath(dir.absolutePath()); + } + dir.setPath(dir.absoluteFilePath(wg_runid->text())); + if (dir.exists()) { + int ans = QMessageBox::question(this, "Absorbance RunID", + "The output directory exists!\n\n" + + dir.absolutePath() + + "\n\nBy clicking on 'YES', " + "all data will be overwritten! " + + "Do you want to proceed?"); + if (ans == QMessageBox::No) { + return false; + } else { dir.removeRecursively(); - dir.mkpath(absPath); - dir.setPath(absPath); - }else return; - }else{ - dir.mkdir(runIdAbs); - dir.cd(runIdAbs); + } } - dir.makeAbsolute(); + dir.mkpath(dir.absolutePath()); + runid.clear(); + runid = wg_runid->text(); + return true; +} - int nwl_tot = 0; - foreach (int ii, selist) { - nwl_tot += ccwItemList.wavelength.at(ii).size(); +void US_ConvertScan::save_run() { + if (ccw_items.isEmpty()) { + return; } - int cb_buffer_row = cb_buffer->currentIndex(); - int n = 1; - QString status = tr("writting: %1 %2"); - QString percent; - QString fileName("%1.RA.%2.%3.%4.auc"); - foreach (int ii, selist){ - for (int jj = 0; jj < ccwItemList.wavelength.at(ii).size(); ++jj){ - percent = QString::number(100.0 * n / nwl_tot, 'f', 1); - le_status->setText(status.arg(percent).arg(QChar(37))); - qApp->processEvents(); - n++; - int dataId = ccwItemList.index.at(ii).at(jj); - double wavelength = ccwItemList.wavelength.at(ii).at(jj); - - int dataId_buff = -1; - if (cb_buffer_row > 0){ - dataId_buff = ccwItemList.index.at(cb_buffer_row - 1).at(jj); + QStringList run_list; + QVector item_list; + for (int ii = 0; ii < ccw_items.size(); ii++) { + bool ok = false; + QString runid = ccw_items.at(ii).runid; + QWidget *wgt = tb_triple->cellWidget(ii, 3); + if (wgt) { + QCheckBox *chkb = wgt->findChild(); + if (chkb && chkb->isChecked()) { + ok = true; + } + } + if (ok) { + item_list << ii; + if (! run_list.contains(runid)) { + run_list << runid; } + } + } + if (run_list.size() == 0) { + QMessageBox::warning(this, "Warning!", "No triple selected to save!"); + return; + } else if (run_list.size() > 1) { + QMessageBox::warning(this, "Warning!", "Triples from multiple RunID are selected!\n" + "Please select the triples of each RunID separately."); + return; + } - if (!ckb_act_refscan->isChecked()){ - get_absorbance(dataId, dataId_buff); - } else{ - if (! get_refId(wavelength)){ - qDebug() << tr("Not found corrosponding reference data for: ") << - allIntDataFiles.at(dataId).fileName(); - continue; + QVector out_rawdata; + QStringList miss_ccw; + QString ccw_str("%1/%2/%3"); + foreach (int ii, item_list) { + double x_1 = ccw_items.at(ii).minmax_x.first; + double x_2 = ccw_items.at(ii).minmax_x.second; + bool shift = false; + if (x_1 > 0 && x_2 > 0) { + shift = true; + } + foreach (int jj, ccw_items.at(ii).rawdata_ids) { + int rid = ccw_items.at(ii).rawdata_ids.at(jj); + int cell = ccw_items.at(ii).cell; + char channel = ccw_items.at(ii).channel; + if (! absorbance_state.at(rid)) { + double wvl = ccw_items.at(ii).wavelength.at(jj); + miss_ccw << ccw_str.arg(cell).arg(channel).arg(wvl); + } else { + US_DataIO::RawData rawdata = intensity_data.at(rid); + int nn = absorbance_data.at(rid).size() - ns_smp; + if (nn < 0) { + nn = 0; } - get_pseudo_absorbance(refId, dataId, false); - if (dataId_buff != -1){ - get_relative_absorbance(dataId_buff); + QVector> absorbance = absorbance_data.at(rid).mid(nn); + QVector shifts = absorbance_shifts.at(rid).mid(nn); + QVector scans = rawdata.scanData.mid(nn); + for (int mm = 0; mm < absorbance.size(); mm++) { + for (int nn = 0; nn < absorbance.at(mm).size(); nn++) { + double val = absorbance.at(mm).at(nn); + if (shift) { + val += shifts.at(mm); + } + scans[mm].rvalues[nn] = val; + } + scans[mm].stddevs.clear(); } + rawdata.scanData.clear(); + rawdata.scanData << scans; + rawdata.type[0] = 'R'; + rawdata.type[1] = 'A'; + uchar uuid[ 16 ]; + QString uuid_string = US_Util::new_guid(); + US_Util::uuid_parse( uuid_string, uuid ); + memcpy(rawdata.rawGUID, (char*) uuid, 16); + out_rawdata << rawdata; } - trim_absorbance(); - int scan_l1 = scansRange.at(dataId).at(0); - int scan_l2 = scansRange.at(dataId).at(1); - QVector absorbance_sel; - for (int k = scan_l1; k setText("written on the local disk !"); - - return; -} - -void US_ConvertScan::slt_update_buffer(int index){ - if (index == 0) - ckb_xrange->setEnabled(true); - else{ - ckb_xrange->setCheckState(Qt::Checked); - ckb_xrange->setDisabled(true); + if (out_rawdata.isEmpty()) { + QMessageBox::warning(this, "Error!", "No absorbance data found to save!"); + return; + } + if (! miss_ccw.isEmpty()) { + int ans = QMessageBox::question(this, "Warning!", + tr("Absorbance data for (%1) triples is missing.\n" + "Do you proceed to save the remaining (%2) " + "triples ?").arg(miss_ccw.size()).arg(out_rawdata.size())); + if (ans == QMessageBox::No) { + return; + } + } + QString abs_runid = "PABS_" + run_list.at(0); + if (! set_abs_runid(abs_runid)) { + return; } - emit sig_plot(); - return; -} -void US_ConvertScan::slt_update_smooth(double){ - emit sig_plot(); - return; -} + QString fileName("%1.RA.%2.%3.%4.auc"); + QDir dir = QDir(US_Settings::importDir()); + dir.setPath(dir.absoluteFilePath(abs_runid)); + for (int ii = 0; ii < out_rawdata.size(); ii++) { + US_DataIO::RawData rawdata = out_rawdata.at(ii); + int cell = rawdata.cell; + char channel = rawdata.channel; + double wvl = rawdata.scanData.at(0).wavelength; + QString fn = fileName.arg(abs_runid).arg(cell).arg(channel).arg(wvl); + QFileInfo fileInfo(dir, fn); + US_DataIO::writeRawData(fileInfo.absoluteFilePath(), rawdata); + } -void US_ConvertScan::slt_cac(int){ - slt_plot(); } -void US_ConvertScan::set_listWidget(){ - lw_triple->disconnect(); - lw_triple->clear(); - if (ccwItemList.size() == 0) return; - bool uniqueRun = true; - int r0 = ccwItemList.runClass.at(0); - for (int i = 1; i < ccwItemList.runClass.size(); i++) { - if (ccwItemList.runClass.at(i) != r0) { - uniqueRun = false; - break; +void US_ConvertScan::set_table(){ + tb_triple->disconnect(); + tb_triple->clearContents(); + tb_triple->setRowCount(ccw_items.size()); + + QString runid; + int rcode = 1; + QVector rcode_list; + for (int ii = 0; ii < ccw_items.size(); ii++) { + QString ccw_runid = ccw_items.at(ii).runid; + if (runid.isEmpty()) { + runid = ccw_runid; + } else if ( runid.compare(ccw_runid) != 0) { + rcode += 1; + runid = ccw_runid; } - } - QString item_uq("%1 / %2 / %3-%4 (%5)"); - QString item("[%1] %2 / %3 / %4-%5 (%6)"); - for (int i = 0; i < ccwItemList.size(); ++i){ - int run = ccwItemList.runClass.at(i); - int cell = ccwItemList.cell.at(i); - char channel = ccwItemList.channel.at(i); - double min_wl = ccwItemList.wavelength.at(i).first(); - double max_wl = ccwItemList.wavelength.at(i).last(); - int nwl = ccwItemList.wavelength.at(i).size(); - QString item_i; - if (uniqueRun) { - item_i = item_uq.arg(cell).arg(channel).arg(min_wl).arg(max_wl).arg(nwl); + rcode_list << rcode; + } + + QStringList combo_items; + for (int ii = 0; ii < ccw_items.size(); ii++){ + rcode = rcode_list.at(ii); + int cell = ccw_items.at(ii).cell; + char channel = ccw_items.at(ii).channel; + double min_wl = ccw_items.at(ii).wavelength.first(); + double max_wl = ccw_items.at(ii).wavelength.last(); + int nwl = ccw_items.at(ii).wavelength.size(); + QString item_cc; + if (rcode_list.last() == 1) { + item_cc = tr("%1 / %2").arg(cell).arg(channel); } else { - item_i = item.arg(run).arg(cell).arg(channel).arg(min_wl).arg(max_wl).arg(nwl); + item_cc = tr("[%1] %2 / %3").arg(rcode).arg(cell).arg(channel); + } + combo_items << item_cc; + QTableWidgetItem *twi_cc; + twi_cc = new QTableWidgetItem(item_cc); + twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); + twi_cc->setFont(font); + tb_triple->setItem(ii, 0, twi_cc); + + QString item_wvl = tr("%1-%2 (%3)").arg(min_wl).arg(max_wl).arg(nwl); + QTableWidgetItem *twi_wvl; + twi_wvl = new QTableWidgetItem(item_wvl); + twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); + twi_wvl->setFont(font); + tb_triple->setItem(ii, 1, twi_wvl); + } + + for (int ii = 0; ii < refscan_files.size(); ii++) { + QString item_cc = refscan_files.at(ii).name; + combo_items << item_cc; + QTableWidgetItem *twi_cc; + twi_cc = new QTableWidgetItem(item_cc); + twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); + twi_cc->setFont(font); + tb_triple->setItem(ii, 0, twi_cc); + + QString item_wvl = tr("%1-%2 (%3)").arg(refscan_files.at(ii).min_wvl) + .arg(refscan_files.at(ii).max_wvl).arg(refscan_files.at(ii).nwvl); + QTableWidgetItem *twi_wvl; + twi_wvl = new QTableWidgetItem(item_wvl); + twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); + twi_wvl->setFont(font); + tb_triple->setItem(ii, 1, twi_wvl); + } + + for (int ii = 0; ii < ccw_items.size(); ii++) { + QComboBox *combo = us_comboBox(); + combo->addItem("none"); + for (int jj = 0; jj < combo_items.size(); jj++) { + combo->addItem(tb_triple->item(jj, 0)->text()); + } + int re_fid = ccw_items.at(ii).ref_id; + if ( re_fid >= 0 && re_fid < 100) { + combo->setCurrentIndex(re_fid); + } else if ( re_fid >= 0 && re_fid >= 100) { + QString name = refscan_files.at(re_fid - 100).name; + combo->setCurrentText(name); } + tb_triple->setCellWidget(ii, 2, combo); + connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(select_refscan(int))); - lw_triple->addItem(item_i); - } - lw_triple->setCurrentRow(0); - set_buffer_list(); - int *scp; - for (int i = 0; i < scansRange.size(); ++i){ - scp = scansRange[i].data(); - scp[0] = 0; - scp[1] = scp[2]; - } - connect( lw_triple, SIGNAL( currentRowChanged(int) ), - this, SLOT( slt_wavl_ctrl(int) ) ); - return; -} + // connect(combo, QOverload::of(&QComboBox::currentIndexChanged), + // [=](int index){ select_refscan(index); }); -void US_ConvertScan::set_buffer_list(){ - cb_buffer->disconnect(); - cb_buffer->clear(); - QStringList list; - list << "None"; - for (int i = 0; i < lw_triple->count(); ++i){ - list << lw_triple->item(i)->text(); - } - cb_buffer->addItems(list); - cb_buffer->setCurrentIndex(0); - absorbanceBuffer.clear(); - connect(cb_buffer, SIGNAL(currentIndexChanged(int)), - this, SLOT(slt_update_buffer(int))); - emit sig_save_button(); - return; -} + QCheckBox* checkbox = new QCheckBox(); + QWidget *wgt = new QWidget(); + QHBoxLayout *lyt = new QHBoxLayout(wgt); + lyt->addWidget(checkbox); + lyt->setAlignment(Qt::AlignCenter); + lyt->setContentsMargins(0, 0, 0, 0); + wgt->setLayout(lyt); + tb_triple->setCellWidget(ii, 3, wgt); -void US_ConvertScan::load_from_DB(){ - QString error; - dbCon->connect(pw.getPasswd(), error); - if (dbCon->isConnected()){ - QStringList DB = US_Settings::defaultDB(); - if (DB.isEmpty()){ - le_status->setText("database: Undefined"); - return; - } - else - le_status->setText("database: " + DB.at(3)); - }else{ - le_status->setText("database connection failed!"); - return; - } - - LoadDBWidget *db_w = new LoadDBWidget(this, dbCon, refData); - int state_db = db_w->exec(); - if (state_db != QDialog::Accepted){ - le_status->setText("Load Reference data!"); - return; - }else - le_status->clear(); - xvaluesRefCAC.clear(); - bool state; - xvaluesRefCAC = refData.get_CA_corrected(state); - if (! state){ - xvaluesRefCAC.clear(); - le_status->setText("Error in chromatic aberration correction!"); } - pb_import_refScans->setDisabled(true); - pb_reset_refData->setEnabled(true); - emit sig_save_button(); - QString text("%1 - %2 nm"); - int nw = refData.nWavelength; - double w1 = refData.wavelength.at(0); - double w2 = refData.wavelength.at(nw - 1); - le_ref_range->setText(text.arg(w1).arg(w2)); - plot_refscan(); - plot_absorbance(); - + tb_triple->setCurrentCell(0, 0); + connect( tb_triple, &QTableWidget::currentCellChanged, this, &US_ConvertScan::set_wavl_ctrl); return; } -void US_ConvertScan::make_ccwItemList(){ - ccwItemList.clear(); - if (ccwList.size() == 0){ +void US_ConvertScan::list_ccw_items(QString& runid){ + if (intensity_data.size() == 0) { return; } + int II = -1; + for (int ii = 0; ii < ccw_items.size(); ii++) { + for (int jj = 0; jj < ccw_items.at(ii).rawdata_ids.size(); jj++) { + II = qMax(II, ccw_items.at(ii).rawdata_ids.at(jj)); + } + } + II++; QMap>> wavl_idx_map; - QString key_str("%1-%2-%3"); - for (int ii = 0; ii < ccwList.size(); ii++){ - int runId = intRunIds.indexOf(ccwList.runId.at(ii)); - int cell = ccwList.cell.at(ii); - char channel = ccwList.channel.at(ii); - QString key = key_str.arg(runId).arg(cell).arg(channel); - wavl_idx_map[key] << qMakePair(ccwList.wavelength.at(ii), ccwList.index.at(ii)); + QString key_str("%1-%2"); + for (int ii = II; ii < intensity_data.size(); ii++){ + int cell = intensity_data.at(ii).cell; + char channel = intensity_data.at(ii).channel; + double wavelength = intensity_data.at(ii).scanData.at(0).wavelength; + QString key = key_str.arg(cell).arg(channel); + wavl_idx_map[key] << qMakePair(wavelength, ii); } QStringList keys = wavl_idx_map.keys(); std::sort(keys.begin(), keys.end()); foreach (QString key, keys) { + CellChannel cc; + // cc.has_ref = false; QStringList ksp = key.split("-"); - int runClass = ksp.at(0).toInt(); - int cell = ksp.at(1).toInt(); - char channel = ksp.at(2).at(0).toLatin1(); + cc.cell = ksp.at(0).toInt(); + cc.channel = ksp.at(1).at(0).toLatin1(); + cc.minmax_x = qMakePair(-1, -1); + cc.ref_id = -1; + cc.runid = runid; QVector> wavl_idx = wavl_idx_map.value(key); std::sort(wavl_idx.begin(), wavl_idx.end(), [](auto a, auto b) { return a.first < b.first;}); - QVector wavls; - QVector idx; for (int ii = 0; ii < wavl_idx.size(); ii++) { - wavls << wavl_idx.at(ii).first; - idx << wavl_idx.at(ii).second; + cc.wavelength << wavl_idx.at(ii).first; + cc.rawdata_ids << wavl_idx.at(ii).second; } - ccwItemList.runClass << runClass; - ccwItemList.cell << cell; - ccwItemList.channel << channel; - ccwItemList.index << idx; - ccwItemList.wavelength << wavls; + ccw_items << cc; } - return; } -void US_ConvertScan::set_scan_ct(){ - ct_scan_l->disconnect(); - ct_scan_u->disconnect(); - int row = lw_triple->currentRow(); - int index = ccwItemList.index.at(row).at(wavl_id); - int lower = scansRange.at(index).at(0); - int upper = scansRange.at(index).at(1); - int max = scansRange.at(index).at(2); - ct_scan_l->setRange(0, max); - ct_scan_l->setValue(lower); - ct_scan_u->setRange(0, max); - ct_scan_u->setValue(upper); - connect(ct_scan_l, SIGNAL(valueChanged(double)), - this, SLOT(slt_update_scrng(double))); - connect(ct_scan_u, SIGNAL(valueChanged(double)), - this, SLOT(slt_update_scrng(double))); - return; -} - -void US_ConvertScan::plot_intensity(void){ +void US_ConvertScan::plot_intensity(){ qwtplot_insty->detachItems(QwtPlotItem::Rtti_PlotItem, false); - if (lw_triple->count() == 0){ + if (ccw_items.isEmpty()){ grid = us_grid(qwtplot_insty); qwtplot_insty->replot(); return; } - int row = lw_triple->currentRow(); - int index = ccwItemList.index.at(row).at(wavl_id); -// QVector xvalues = allIntData.at(index).xvalues; - get_intensity(index); - int ns = intensity.size(); - if (ns == 0){ - grid = us_grid(qwtplot_insty); - qwtplot_insty->replot(); - return; + int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + US_DataIO::RawData raw_data = intensity_data.at(raw_id); + int nn = raw_data.scanCount() - ns_smp; + if (nn < 0) { + nn = 0; } - + int ns = raw_data.scanCount() - nn; QPen pen_plot(Qt::yellow); pen_plot.setWidth(1); double rb = qCeil(ns / 50.0); @@ -1199,15 +950,15 @@ void US_ConvertScan::plot_intensity(void){ int error = colormap.get_colorlist(colorList); const double *x, *r; - x = xvalues.data(); + x = raw_data.xvalues.data(); double min_x = 1e20; double max_x = -1e20; double min_r = 1e20; double max_r = -1e20; - int np = xvalues.size(); - for (int i = 0; i < ns; ++i){ - r = intensity.at(i).rvalues.data(); + int np = raw_data.pointCount(); + for (int ii = nn; ii < raw_data.scanCount(); ++ii){ + r = raw_data.scanData.at(ii).rvalues.data(); for (int j = 0; j < np; ++j){ min_x = qMin(min_x, x[j]); max_x = qMax(max_x, x[j]); @@ -1216,7 +967,7 @@ void US_ConvertScan::plot_intensity(void){ } QwtPlotCurve* curve = us_curve( qwtplot_insty,""); if (error == 0) - pen_plot.setColor(colorList[ i % nc ]); + pen_plot.setColor(colorList[ ii % nc ]); curve->setPen( pen_plot ); curve->setSamples(x, r, np); } @@ -1231,101 +982,88 @@ void US_ConvertScan::plot_intensity(void){ return; } -void US_ConvertScan::plot_refscan(void){ - if (refData.xValues.size() == 0 || lw_triple->count() == 0){ - refId = -1; - return; +void US_ConvertScan::plot_refscan(){ + if (ccw_items.isEmpty()) return; + + QVector yvalues; + QVector xvalues; + if (ref_file_id >= 0) { + le_runid->clear(); + le_desc->setText(refscan_files.at(ref_file_id).filename); + xvalues << refscan_files.at(ref_file_id).xvalues; + yvalues << refscan_files.at(ref_file_id).yvalues.at(wavl_id); + } else { + int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + if (! absorbance_state.at(raw_id)) { + return; + } + xvalues << intensity_data.at(raw_id).xvalues; + yvalues << refscan_data.at(raw_id); } - if (intensity.size() == 0) + + if (xvalues.size() != yvalues.size()) { + QMessageBox::warning(this, "Warning!", "Number of the radial points and intesity values" + " in the reference scan don't match!"); return; + } QPen pen = QPen( QBrush( Qt::white ), 2.0 ); double min_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).lowerBound(); double max_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).upperBound(); - if (! get_refId(wavelength.at(wavl_id))){ - le_status->setText("reference data: wavelength not found !"); - return; - } - le_status->clear(); - const double *xp; - if (ckb_ChroAberCorr->isChecked() && refData.CAState){ - xp = xvaluesRefCAC.at(refId).data(); - } else { - xp = refData.xValues.data(); - } - const double *rp = refData.rValues.at(refId).data(); + const double *xp, *rp; + xp = xvalues.data(); + rp = yvalues.data(); + int np = xvalues.size(); - for (int i = 0; i < refData.nPoints; ++i){ - min_r = qMin(min_r, rp[i]); - max_r = qMax(max_r, rp[i]); + for (int ii = 0; ii < np; ++ii){ + min_r = qMin(min_r, rp[ii]); + max_r = qMax(max_r, rp[ii]); } QwtPlotCurve* curve = us_curve( qwtplot_insty,""); curve->setPen(pen); - curve->setSamples(xp, rp, refData.nPoints); + curve->setSamples(xp, rp, np); double dr = (max_r - min_r) * 0.05; qwtplot_insty->setAxisScale( QwtPlot::yLeft , min_r - dr, max_r + dr); qwtplot_insty->updateAxes(); qwtplot_insty->replot(); - - return; } -void US_ConvertScan::plot_absorbance(void){ +void US_ConvertScan::plot_absorbance(){ + abs_plt_on = false; qwtplot_abs->detachItems(QwtPlotItem::Rtti_PlotItem, false); grid = us_grid(qwtplot_abs); qwtplot_abs->replot(); - bool quit = false; - if (lw_triple->count() == 0){ - quit = true; + if (ccw_items.isEmpty()) return; + + int row = tb_triple->currentRow(); + int raw_id = ccw_items.at(row).rawdata_ids.at(wavl_id); + if (! absorbance_state.at(raw_id)) return; + + double x_1 = ccw_items.at(row).minmax_x.first; + double x_2 = ccw_items.at(row).minmax_x.second; + + int nn = absorbance_data.at(raw_id).size() - ns_smp; + if (nn < 0) { + nn = 0; } - if (!ckb_act_refscan->isChecked()){ - if (cb_buffer->count() == 0 || cb_buffer->currentIndex() == 0){ - quit = true; - } - } else{ - if (refData.xValues.size() == 0 || refId == -1){ - quit = true; + QVector> absorbance = absorbance_data.at(raw_id).mid(nn); + QVector shifts = absorbance_shifts.at(raw_id).mid(nn); + if (x_1 > 0 && x_2 > 0) { + for (int ii = 0; ii < absorbance.size(); ii++) { + for (int jj = 0; jj < absorbance.at(ii).size(); jj++) { + absorbance[ii][jj] += shifts.at(ii); + } } } - if (quit) return; + QVector xvalues = intensity_data.at(raw_id).xvalues; double min_x = qwtplot_insty->axisScaleDiv(QwtPlot::xBottom).lowerBound(); double max_x = qwtplot_insty->axisScaleDiv(QwtPlot::xBottom).upperBound(); double min_r = 1e20; double max_r = -1e20; - int row = lw_triple->currentRow(); - int dataId = ccwItemList.index.at(row).at(wavl_id); - - row = cb_buffer->currentIndex(); - int dataId_buff = -1; - if (row > 0){ - dataId_buff = ccwItemList.index.at(row - 1).at(wavl_id); - } - - if (!ckb_act_refscan->isChecked()){ - if (! get_absorbance(dataId, dataId_buff)) return; - } else{ - get_pseudo_absorbance(refId, dataId, false); - if (dataId_buff != -1){ - get_relative_absorbance(dataId_buff); - } - } - trim_absorbance(); - - int scan_l1 = scansRange.at(dataId).at(0); - int scan_l2 = scansRange.at(dataId).at(1); - QVector absorbance_sel; - for (int i = scan_l1; i replot(); - return; - } - - int ns = absorbance_sel.size(); + int ns = absorbance.size(); QPen pen_plot(Qt::yellow); pen_plot.setWidth(1); double rb = qCeil(ns / 50.0); @@ -1334,22 +1072,22 @@ void US_ConvertScan::plot_absorbance(void){ QVector colorList; int error = colormap.get_colorlist(colorList); - const double *xp = allIntData.at(dataId).xvalues.data(); + const double *xp = xvalues.data(); const double *rp; - int np = allIntData.at(dataId).xvalues.size(); + int np = xvalues.size(); int l1 = np * 0.2; int l2 = np * 0.8; - for (int i = 0; i < ns; ++i){ - rp = absorbance_sel.at(i).rvalues.data(); - for (int j = 0; j < np; ++j) - if (j > l1 && j < l2){ - min_r = qMin(min_r, rp[j]); - max_r = qMax(max_r, rp[j]); + for (int ii = 0; ii < ns; ++ii){ + rp = absorbance.at(ii).data(); + for (int jj = 0; jj < np; ++jj) + if (jj > l1 && jj < l2){ + min_r = qMin(min_r, rp[jj]); + max_r = qMax(max_r, rp[jj]); } QwtPlotCurve* curve = us_curve( qwtplot_abs,""); if (error == 0) - pen_plot.setColor(colorList[ i % nc ]); + pen_plot.setColor(colorList[ ii % nc ]); curve->setPen( pen_plot ); curve->setSamples(xp, rp, np); } @@ -1357,15 +1095,15 @@ void US_ConvertScan::plot_absorbance(void){ double dr = (max_r - min_r) * 0.05; min_r -= dr; max_r += dr; - if (x_min_picked != -1){ + if (x_1 > 0){ QVector xx; QVector yy; int np = 50; double dyy = (max_r - min_r + 2 * dr) / np; - double x0 = min_r - dr; + double y0 = min_r - dr; for (int i = 0; i < np; ++i){ - xx << x_min_picked; - yy << x0 + i * dyy; + xx << x_1; + yy << y0 + i * dyy; } pen_plot.setWidth(3); pen_plot.setColor(QColor(Qt::yellow)); @@ -1375,15 +1113,15 @@ void US_ConvertScan::plot_absorbance(void){ curve->setSamples(xx.data(), yy.data(), np); } - if (x_max_picked != -1){ + if (x_2 > -1){ QVector xx; QVector yy; int np = 50; double dyy = (max_r - min_r + 2 * dr) / np; - double x0 = min_r - dr; + double y0 = min_r - dr; for (int i = 0; i < np; ++i){ - xx << x_max_picked; - yy << x0 + i * dyy; + xx << x_2; + yy << y0 + i * dyy; } pen_plot.setWidth(3); pen_plot.setColor(QColor(Qt::yellow)); @@ -1397,251 +1135,202 @@ void US_ConvertScan::plot_absorbance(void){ qwtplot_abs->setAxisScale( QwtPlot::yLeft , min_r, max_r); qwtplot_abs->updateAxes(); qwtplot_abs->replot(); - return; -} - -void US_ConvertScan::get_intensity(int data_id){ - intensity.clear(); - int scan_l1 = scansRange.at(data_id).at(0); - int scan_l2 = scansRange.at(data_id).at(1); - xvalues.clear(); - xvalues << allIntData.at(data_id).xvalues; - for (int i = scan_l1; i < scan_l2; ++i) - intensity << allIntData.at(data_id).scanData.at(i); - return; + abs_plt_on = true; } -bool US_ConvertScan::get_refId(double wavelength){ - refId = -1; - if (refData.xValues.size() == 0 || lw_triple->count() == 0) - return false; - bool flag = false; - int wl = qRound(wavelength * 10); - double *wp = refData.wavelength.data(); - int wlref; - for (int i = 0; i < refData.nWavelength; ++i){ - wlref = qRound(wp[i] * 10); - if (wlref == wl){ - refId = i; - flag = true; +bool US_ConvertScan::get_refval_file(int ref_id, int rid, QVector& yvals) { + + ref_id -= 100; + US_DataIO::RawData rawdata = intensity_data.at(rid); + int iwvl_tgt = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); + QVector xvals_tgt = rawdata.xvalues; + QVector ref_xvals; + QVector ref_yvals; + bool ok = false; + + for (int ii = 0; ii < refscan_files.at(ref_id).wavelength.size(); ii++) { + int iwvl = static_cast(qRound(refscan_files.at(ref_id).wavelength.at(ii) * 10)); + if (iwvl == iwvl_tgt) { + ref_xvals << refscan_files.at(ref_id).xvalues; + ref_yvals << refscan_files.at(ref_id).yvalues.at(ii); + ok = true; break; } } - return flag; -} -void US_ConvertScan::get_pseudo_absorbance(int id_ref, int id_data, bool buffer){ - if (buffer) - absorbanceBuffer.clear(); - else - absorbance.clear(); - const double *xp_ref; - if (ckb_ChroAberCorr->isChecked() && refData.CAState){ - xp_ref = xvaluesRefCAC.at(id_ref).data(); - } else { - xp_ref = refData.xValues.data(); + if (! ok) { + return false; } - const double *rp_ref = refData.rValues.at(id_ref).data(); - const double *xp_dta = allIntData.at(id_data).xvalues.data(); - const double *rp_dta; - int xref, xdta, id; - double *rp_abs; - double rdta; - int np = allIntData.at(id_data).xvalues.size(); - int np_ref = refData.nPoints; - int ns = allIntData.at(id_data).scanData.size(); - for (int i = 0; i < ns; ++i){ - US_DataIO::Scan scan = allIntData.at(id_data).scanData.at(i); - rp_dta = scan.rvalues.data(); - QVector rval_abs(np); - rp_abs = rval_abs.data(); - id = 0; - for (int j = 0; j < np; ++j){ - xdta = qRound(xp_dta[j] * 1000); - xref = qRound(xp_ref[id] * 1000); - if (xref < xdta){ - while(xref < xdta && id < (np_ref - 1)) - xref = qRound(xp_ref[++id] * 1000); - if (xref > xdta){ - qDebug() << "Radial Steps Not Matched!"; - le_status->setText("Radial Steps Not Matched!"); - absorbance.clear(); - return ; + ok = linear_interpolation(xvals_tgt, ref_xvals, ref_yvals); + if (ok) { + yvals.clear(); + yvals << ref_yvals; + } + return ok; +} + +bool US_ConvertScan::get_refval_buffer(int ref_row, int rid, QVector& yvals) { + + int iwvl_tgt = static_cast(qRound(intensity_data.at(rid).scanData.at(0).wavelength * 10)); + QVector xvals_tgt = intensity_data.at(rid).xvalues; + + bool ok = false; + QVector ref_xvals; + QVector ref_yvals; + foreach (int rid, ccw_items.at(ref_row).rawdata_ids) { + US_DataIO::RawData rawdata = intensity_data.at(rid); + int iwvl = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); + if (iwvl_tgt == iwvl) { + ref_xvals << rawdata.xvalues; + int nn = rawdata.scanCount() - static_cast(ns_buf); + if (nn < 0) { + nn = 0; + } + int N = rawdata.scanCount() - nn; + for (int ii = 0; ii < rawdata.pointCount(); ii++) { + double val = 0; + for (int jj = nn; jj < rawdata.scanCount(); jj++) { + val += rawdata.reading(jj, ii); } + ref_yvals << val / N; } - rdta = rp_dta[j]; - if (rdta <= 0) - rdta = 1e-5; - rp_abs[j] = std::log10(rp_ref[id] / rdta); + ok = true; + break; } - scan.rvalues.clear(); - scan.rvalues = rval_abs; - scan.stddevs.clear(); - scan.nz_stddev = false; - if (buffer) - absorbanceBuffer << scan; - else - absorbance << scan; - rval_abs.clear(); } - return; -} - -bool US_ConvertScan::get_absorbance(int id_data, int id_buff){ - int ns = allIntData.at(id_data).scanData.size(); - if (ns != allIntData.at(id_buff).scanData.size()){ - qDebug() << "Number Scans Not Matched!"; - le_status->setText("Number Scans Not Matched!"); - absorbance.clear(); - // QMessageBox::warning(this, "Error!", "Number Scans Not Matched!"); + if (! ok) { return false; } - absorbance.clear(); - - int smooth_l = ct_smooth->value(); - - QVector< QVector> buffer_rvalues; - for (int i = 0; i < ns; i++){ - if (smooth_l > 0){ - QVector rval = get_smooth(allIntData.at(id_buff).scanData.at(i).rvalues, - smooth_l, true, true); - buffer_rvalues << rval; - } else { - buffer_rvalues << allIntData.at(id_buff).scanData.at(i).rvalues; - } - } - - for (int ii = 0; ii < ns; ++ii){ - US_DataIO::Scan scan = allIntData.at(id_data).scanData.at(ii); - QVector rval_data(scan.rvalues); - QVector xval_data(allIntData.at(id_data).xvalues); - QVector xval_buff(allIntData.at(id_buff).xvalues); - - if( !linear_interpolation(xval_buff, xval_data, rval_data)) { - QMessageBox::warning(this, "Error!", "len(x) != len(y)"); - return false; - } - for (int jj = 0; jj < rval_data.size(); ++jj){ - double val = buffer_rvalues.at(ii).at(jj) / rval_data.at(jj); - if (val <= 0) val = 1e-5; - rval_data[jj] = std::log10(val); - } - scan.rvalues.clear(); - scan.rvalues << rval_data; - scan.stddevs.clear(); - scan.nz_stddev = false; - absorbance << scan; + ok = linear_interpolation(xvals_tgt, ref_xvals, ref_yvals); + if (ok) { + yvals.clear(); + yvals << ref_yvals; } - return true; + return ok; } -void US_ConvertScan::get_relative_absorbance(int bufferId){ - get_pseudo_absorbance(refId, bufferId, true); +void US_ConvertScan::calc_absorbance(int item_row){ + if (ccw_items.isEmpty()) return; - if (absorbanceBuffer.size() == 0) - return; - if (absorbance.size() != absorbanceBuffer.size()){ - qDebug() << "Number Scans Not Matched!"; - QMessageBox::warning(this, "Error!", "Number Scans Not Matched!"); + QVector rawdata_ids = ccw_items.at(item_row).rawdata_ids; + int ref_id = ccw_items.at(item_row).ref_id; + bool buffer = true; + if ( ref_id == -1) { + foreach (int rid, rawdata_ids) { + absorbance_state[rid] = false; + } return; - } - int smooth_l = ct_smooth->value(); - if (smooth_l > 1){ - for (int i = 0; i < absorbanceBuffer.size(); ++i){ - QVector rval = absorbanceBuffer.at(i).rvalues; - QVector rval_s = get_smooth(rval, smooth_l, true, false); - absorbanceBuffer[i].rvalues.clear(); - absorbanceBuffer[i].rvalues << rval_s; + } else if (ref_id >= 100) { + buffer = false; + } + + double x_1 = ccw_items.at(item_row).minmax_x.first; + double x_2 = ccw_items.at(item_row).minmax_x.second; + bool shift = false; + if (x_1 > 0 && x_2 > 0) { + shift = true; + } + + QVector not_found_wvl; + for (int ii = 0; ii < rawdata_ids.size(); ii++) { + QVector ref_yvals; + int rid = rawdata_ids.at(ii); + US_DataIO::RawData rawdata = intensity_data.at(rid); + double wvl = ccw_items.at(item_row).wavelength.at(ii); + bool ok = false; + if (buffer) { + ok = get_refval_buffer(ref_id, rid, ref_yvals); + } else { + ok = get_refval_file(ref_id, rid, ref_yvals); } - } - for (int i = 0; i < absorbance.size(); ++i){ - int np = absorbance.at(i).rvalues.size(); - int np_b = absorbanceBuffer.at(i).rvalues.size(); - if (np != np_b){ - QMessageBox::warning(this, "Error!", "Number Radial Points Not Matched!"); - return; + absorbance_state[rid] = false; + if (! ok) { + not_found_wvl << wvl; + continue; } - double *rp = absorbance[i].rvalues.data(); - const double *rbp = absorbanceBuffer.at(i).rvalues.data(); - for (int j = 0; j < np; ++j) - if (rp[j] < maxAbs - 0.1) - rp[j] -= rbp[j]; - for (int j = 0; j < np; ++j){ - if (rp[j] > maxAbs) - rp[j] = maxAbs; - else if (rp[j] < -maxAbs) - rp[j] = -maxAbs; + //// smooth + if (smooth > 0){ + QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); + ref_yvals.clear(); + ref_yvals << yvals; } - } - return; -} -void US_ConvertScan::trim_absorbance(){ - bool cutting = true; - bool zeroing = true; - if (x_min_picked == -1 || x_max_picked == -1) - cutting = false; - if (!ckb_zeroing->isChecked()) - zeroing = false; - const double *xp = xvalues.data(); - int id_min = 0; - int id_max = xvalues.size(); - if (cutting){ - id_min = -1; - id_max = -1; - bool check_min = true; - for (int i = 0; i < xvalues.size(); ++i){ - if (check_min){ - if (xp[i] >= x_min_picked){ - id_min = i; - check_min = false; + int nn = rawdata.scanCount() - ns_smp; + if (nn < 0) { + nn = 0; + } + QVector xvalues = rawdata.xvalues; + for (int jj = nn; jj < rawdata.scanCount(); jj++) { + double miny = 1e99; + for (int kk = 0; kk < rawdata.pointCount(); kk++){ + double x = xvalues.at(kk); + double val = ref_yvals.at(kk) / rawdata.reading(jj, kk); + if (val <= 0) { + val = 1e-5; } - } else{ - if (xp[i] > x_max_picked){ - id_max = i; - break; + val = std::log10(val); + if (val > maxAbs) val = maxAbs; + else if (val < -maxAbs) val = -maxAbs; + absorbance_data[rid][jj][kk] = val; + if (shift && x >= x_1 && x <= x_2) { + miny = qMin(miny, val); } + if (jj == nn) { + refscan_data[rid][kk] = ref_yvals.at(kk); + } + } + if (shift) { + absorbance_shifts[rid][jj] = -1 * miny; } } - if (id_max == -1) - id_max = xvalues.size(); + absorbance_state[rid] = true; + } + if (not_found_wvl.isEmpty()) { + tb_triple->item(item_row, 0)->setBackground(QBrush(Qt::white)); + tb_triple->item(item_row, 1)->setBackground(QBrush(Qt::white)); + } else { + tb_triple->item(item_row, 0)->setBackground(QBrush(Qt::yellow)); + tb_triple->item(item_row, 1)->setBackground(QBrush(Qt::yellow)); } +} +void US_ConvertScan::update_shifts(int item_row){ + if (ccw_items.isEmpty()) return; - int row = lw_triple->currentRow(); - int dataId = ccwItemList.index.at(row).at(wavl_id); - int scan_l1 = scansRange.at(dataId).at(0); - int scan_l2 = scansRange.at(dataId).at(1); + QVector rawdata_ids = ccw_items.at(item_row).rawdata_ids; + double x_1 = ccw_items.at(item_row).minmax_x.first; + double x_2 = ccw_items.at(item_row).minmax_x.second; + if (x_1 <= 0 || x_2 <= 0) { + return; + } - double min_r = 1e20; - bool zr = false; - for (int i = 0; i < absorbance.size(); ++i){ - int np = absorbance.at(i).rvalues.size(); - double *rp = absorbance[i].rvalues.data(); - for (int j = 0; j < np; ++j){ - if (j < id_min || j > id_max) - rp[j] = 0; - else if (zeroing){ - if (i >= scan_l1 && i < scan_l2){ - min_r = qMin(min_r, rp[j]); - zr = true; + for (int ii = 0; ii < rawdata_ids.size(); ii++) { + int rid = rawdata_ids.at(ii); + if (! absorbance_state.at(rid)) { + continue; + } + US_DataIO::RawData rawdata = intensity_data.at(rid); + int nn = rawdata.scanCount() - ns_smp; + if (nn < 0) { + nn = 0; + } + QVector xvalues = rawdata.xvalues; + for (int jj = nn; jj < rawdata.scanCount(); jj++) { + double miny = 1e99; + for (int kk = 0; kk < rawdata.pointCount(); kk++){ + double x = xvalues.at(kk); + double val = absorbance_data.at(rid).at(jj).at(kk); + if (x >= x_1 && x <= x_2) { + miny = qMin(miny, val); } } + absorbance_shifts[rid][jj] = -1 * miny; } } - qDebug() << min_r << scan_l1 << scan_l2; - if (zeroing && zr){ - for (int i = 0; i < absorbance.size(); ++i){ - double *rp = absorbance[i].rvalues.data(); - for (int j = id_min; j < id_max; ++j) - rp[j] -= min_r; - } - } - return; } -QVector US_ConvertScan::get_smooth(QVector array, int winlen, - bool ave, bool intsy){ +QVector US_ConvertScan::smooth_refscan(QVector array, int winlen, + bool ave, bool intsy, double maxVal){ if (ave){ int np = array.size(); QVector array_s(np, 0); @@ -1660,7 +1349,7 @@ QVector US_ConvertScan::get_smooth(QVector array, int winlen, if (intsy){ continue; } - if (rp[i + j] > (maxAbs - 0.1)){ + if (rp[i + j] > (maxVal - 0.1)){ flag = false; rsp[i] = rp[i]; break; @@ -1677,11 +1366,11 @@ QVector US_ConvertScan::get_smooth(QVector array, int winlen, return array; } -bool US_ConvertScan::linear_interpolation(QVector& xt_vals, +bool US_ConvertScan::linear_interpolation(const QVector& xt_vals, QVector& x_vals, QVector& y_vals) { if (x_vals.size() != y_vals.size()) return false; - double *xtp = xt_vals.begin(); + const double *xtp = xt_vals.constBegin(); double *xp = x_vals.begin(); if (x_vals.size() == xt_vals.size()) { bool eq = true; @@ -1741,239 +1430,10 @@ bool US_ConvertScan::linear_interpolation(QVector& xt_vals, } } } - x_vals.clear(); - x_vals << xt_vals; + // x_vals.clear(); + // x_vals << xt_vals; y_vals.clear(); y_vals << yo_vals; return true; } -void US_ConvertScan::uncheck_CA_silently(){ - ckb_ChroAberCorr->disconnect(); - ckb_ChroAberCorr->setCheckState(Qt::Unchecked); - connect(ckb_ChroAberCorr, SIGNAL(stateChanged(int)), this, SLOT(slt_cac(int))); - ckb_ChroAberCorr->setDisabled(true); -} - -//// -/// -LoadDBWidget::LoadDBWidget(QWidget* w, US_DB2 *dbCon, - US_RefScanDataIO::RefData &refDataIn): US_WidgetsDialog(w, Qt::Dialog) -{ - setPalette( US_GuiSettings::frameColor() ); - db = dbCon; - refData = &refDataIn; - QStringList DB = US_Settings::defaultDB(); - setWindowTitle( "Database: " + DB.at(3)); - - QStringList q( "" ); - q.clear(); - q << QString( "get_instrument_names" ) - << QString::number( 1 ); - db->query( q ); - - if ( db->lastErrno() == US_DB2::OK ){ - // If not, no instruments defined - QList< int > instIDs; - while (db->next()) { - int ID = db->value( 0 ).toString().toInt(); - instIDs << ID; - qDebug() << "InstID: " << ID; - } - - foreach ( int ID, instIDs ){ - q.clear(); - q << QString( "get_instrument_info_new" ) - << QString::number( ID ); - db->query( q ); - db->next(); - QString name = db->value( 0 ).toString(); - - if ( name.contains("Optima")){ - instrumentIDs << ID; - instrumentNames << name; - } - } - } - - // Let's see if we can find the run ID - q.clear(); - q << "get_referenceScan_info"; - db->query( q ); - qDebug() << db->numRows(); - if ( db->lastErrno() == US_DB2::NOROWS ){ - qDebug() << "reference table is empty!"; - } - while (db->next()){ - refScanTableInfo refScanInfo; - refScanInfo.id = db->value(0).toString().toInt(); - refScanInfo.instrumentID = db->value(1).toString().toInt(); - refScanInfo.personID = db->value(2).toString().toInt(); - refScanInfo.type = db->value(3).toString(); - refScanInfo.exprimentIds = db->value(4).toString().split(","); - refScanInfo.referenceTime = str2date(db->value(5).toString()); - refScanInfo.nWavelength = db->value(6).toString().toInt(); - refScanInfo.nPoints = db->value(7).toString().toInt(); - refScanInfo.startWavelength = db->value(8).toString().toDouble(); - refScanInfo.stopWavelength = db->value(9).toString().toDouble(); - int nb = db->value(10).toString().toInt(); - if (nb == 0) - refScanInfo.null_blob = false; - else - refScanInfo.null_blob = true; - refScanInfo.lastUpdated = str2date(db->value(11).toString()); - if (! refScanInfo.null_blob) - refTable << refScanInfo; - } - - for (int i = 0; i < instrumentNames.size(); ++i){ - QVector refTime; - QVector ids_i; - for (int j = 0; j < refTable.size(); ++j) - if (refTable.at(j).instrumentID == instrumentIDs.at(i)){ - refTime << refTable.at(j).referenceTime; - ids_i << j; - } - if (ids_i.size() > 1) - std::stable_sort(ids_i.begin(), ids_i.end(), [&refTime](int i1, int i2) - {return refTime.at(i1) > refTime.at(i2);}); - instrumentRefList << ids_i; - } - //// - QLabel *lb_instrument = us_label("Instruments List", 2, 1); - lb_instrument->setAlignment(Qt::AlignCenter); - tw_instruments = new QTreeWidget(); - tw_instruments->setColumnCount(1); - tw_instruments->setHeaderLabels(QStringList() << "ID" << "Name"); - for (int i = 0; i < instrumentNames.size(); ++i){ - QTreeWidgetItem *twi = new QTreeWidgetItem(static_cast(nullptr)); - twi->setText(0, QString::number(i + 1)); - twi->setText(1, instrumentNames.at(i)); - tw_instruments->addTopLevelItem(twi); - } - tw_instruments->setStyleSheet("background-color: white"); - tw_instruments->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - - QLabel *lb_refTable = us_label("Available Reference Scans", 2, 1); - lb_refTable->setAlignment(Qt::AlignCenter); - tw_refData = new QTreeWidget(); - tw_refData->setColumnCount(5); - QStringList sl; - sl << "ID" << "Date" << tr("#( ") + QString(QChar(955)) + " )"; - sl << tr("Min( ") + QString(QChar(955)) + tr(" )"); - sl << tr("Max( ") + QString(QChar(955)) + tr(" )"); - tw_refData->setHeaderLabels(sl); - tw_refData->setStyleSheet("background-color: white"); - tw_refData->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - - tw_instruments->setMaximumWidth(200); - tw_refData->setMinimumWidth(600); - QGridLayout *widget_lyt = new QGridLayout(); - widget_lyt->addWidget(lb_instrument, 0, 0, 1, 1); - widget_lyt->addWidget(lb_refTable, 0, 1, 1, 1); - widget_lyt->addWidget(tw_instruments, 1, 0, 1, 1); - widget_lyt->addWidget(tw_refData, 1, 1, 1, 1); - - QPushButton *pb_apply = new QPushButton(); - pb_apply->setText("Apply"); - pb_apply->setIcon(this->style()->standardIcon(QStyle::SP_DialogApplyButton)); - QPushButton *pb_cancel = new QPushButton(); - pb_cancel->setText("Cancel"); - pb_cancel->setIcon(this->style()->standardIcon(QStyle::SP_DialogCancelButton)); - - QHBoxLayout *close_lyt = new QHBoxLayout(); - close_lyt->addStretch(); - close_lyt->addWidget(pb_cancel); - close_lyt->addWidget(pb_apply); - - QVBoxLayout *main_lyt = new QVBoxLayout(this); - main_lyt->addLayout(widget_lyt); - main_lyt->addSpacing(10); - main_lyt->addLayout(close_lyt); - this->setLayout(main_lyt); - - connect(pb_cancel, SIGNAL(clicked()), this, SLOT(close())); - connect(pb_apply, SIGNAL(clicked()), this, SLOT(slt_apply())); - connect(tw_instruments, SIGNAL(itemSelectionChanged()), - this, SLOT(slt_set_refTable())); - -} - -void LoadDBWidget::slt_set_refTable(){ - tw_refData->clear(); - QTreeWidgetItem *item = tw_instruments->currentItem(); - int row = item->text(0).toInt() - 1; - QVector ids; - ids << instrumentRefList.at(row); - for (int i = 0; i < ids.size(); ++i){ - int refId = ids.at(i); - QTreeWidgetItem *twi = new QTreeWidgetItem(static_cast(nullptr)); - twi->setText(0, QString::number(i + 1)); - twi->setText(1, refTable.at(refId).referenceTime.toString("MMM dd, yyyy")); - twi->setText(2, QString::number(refTable.at(refId).nWavelength)); - twi->setText(3, QString::number(refTable.at(refId).startWavelength)); - twi->setText(4, QString::number(refTable.at(refId).stopWavelength)); - tw_refData->addTopLevelItem(twi); - } - return; -} - -QDate LoadDBWidget::str2date(QString date){ - QRegExp re("\\d+:\\d+:\\d+"); - QStringList match = date.remove(re).simplified().split("-"); - if (match.size() == 3) { - int year = match.at(0).toInt(); - int month = match.at(1).toInt(); - int day = match.at(2).toInt(); - return QDate(year, month, day); - }else - return QDate(); -} - -void LoadDBWidget::slt_apply(){ - QTreeWidgetItem *item_inst = tw_instruments->currentItem(); - int id_inst = item_inst->text(0).toInt() - 1; - QVector ids; - ids << instrumentRefList.at(id_inst); - QTreeWidgetItem *item_table = tw_refData->currentItem(); - int id_widgetItem = item_table->text(0).toInt() - 1; - int id_refTable = ids.at(id_widgetItem); - int refScanId = refTable.at(id_refTable).id; - - QDir tempDir = QDir::temp(); - QString fname("reference_scans_%1.aucrs"); - qint64 ms = QDateTime::currentMSecsSinceEpoch(); - QFileInfo finfo(tempDir, fname.arg(ms)); - QString fpath = finfo.absoluteFilePath(); - - int db_read = db->readBlobFromDB(fpath, QString( "download_referenceScanData" ), - refScanId ); - if (db_read == US_DB2::DBERROR){ - QMessageBox::warning(this, "Error", "Error processing file:\n" - + fpath + "\n" + db->lastError() + - "\n" + "Could not open file or no data \n"); - }else if (db_read != US_DB2::OK){ - QMessageBox::warning(this, "Error", "returned processing file:\n" + - fpath + "\n" + db->lastError() + "\n"); - }else{ - US_RefScanDataIO::RefData data; - int referr = US_RefScanDataIO::readRefData(fpath, data); - if (referr == US_RefScanDataIO::OK){ - refData->clear(); - refData->type[0] = data.type[0]; - refData->type[1] = data.type[1]; - refData->nWavelength = data.nWavelength; - refData->nPoints = data.nPoints; - refData->wavelength << data.wavelength; - refData->xValues << data.xValues; - refData->rValues << data.rValues; - refData->std << data.std; - } - } - QFile f(fpath); - if (f.exists()){ - f.remove(); - } - this->accept(); -} - diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index fb0ce1f03..082f2d9fb 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -1,7 +1,5 @@ -//! \file us_convert_scan.h #ifndef US_CONVERT_SCAN_H #define US_CONVERT_SCAN_H - #include #include #include @@ -9,7 +7,7 @@ #include "us_plot.h" #include "us_pabs_common.h" #include "us_db2.h" -#include "us_passwd.h" +// #include "us_passwd.h" #include "us_images.h" #include "us_util.h" #include "us_math2.h" @@ -17,205 +15,129 @@ //#include "us_extern.h" //#include "us_help.h" -/** - * @class US_ConvertScan - * @brief The US_ConvertScan class handles the conversion and management of scan data. - */ + class US_ConvertScan : public US_Widgets { Q_OBJECT +public: + US_ConvertScan(); + QPushButton* pb_close; + bool hasData; + +signals: + void sig_plot(void); + +private slots: + void import_run(); + void set_wavl_ctrl(); + void reset(); + void select_id(int); + void prev_id(); + void next_id(); + void plot_all(); + void select_refscan(int); + void update_scan_smooth(); + void apply_scan_smooth(); + void save_run(void); + void pick_region(void); + void mouse_click(const QwtDoublePoint&); + void default_region(); + +private: + + class RefscanFile + { public: - /** - * @brief Constructor for US_ConvertScan. - */ - US_ConvertScan(); - QPushButton* pb_close; ///< Close button - bool hasData; ///< Flag to check if data is available - - signals: - /** - * @brief Signal to plot data. - */ - void sig_plot(void); - - /** - * @brief Signal to enable save button. - */ - void sig_save_button(void); - - private slots: - void slt_import(void); - void slt_set_ccw_default(void); - void slt_del_item(void); - void slt_wavl_ctrl(int); - void slt_reset(void); - void slt_set_id(int); - void slt_prev_id(void); - void slt_next_id(void); - void slt_plot(void); - void slt_act_refScans(int); - void slt_load_refScans(void); - void slt_update_scrng(double); - void slt_zeroing(int); - void slt_xrange(int); - void slt_reset_scans(void); - void slt_reset_allscans(void); - void slt_apply_allscans(void); - void slt_reset_refData(void); - void slt_save_avail(void); - void slt_save(void); - void slt_update_buffer(int); - void slt_update_smooth(double); - void slt_pick_point(void); - void slt_mouse(const QwtDoublePoint&); - void slt_cac(int); - - private: - const double maxAbs = 3; ///< Maximum absorbance - - QPushButton* pb_prev_id; ///< Previous ID button - QPushButton* pb_next_id; ///< Next ID button - QPushButton* pb_import; ///< Import button - QPushButton* pb_reset; ///< Reset button - QPushButton* pb_import_refScans; ///< Import reference scans button - QPushButton* pb_reset_refData; ///< Reset reference data button - QPushButton* pb_save; ///< Save button - QPushButton* pb_pick_rp; ///< Pick reference point button - - QLabel* lb_lambstrt; ///< Label for start wavelength - QLabel* lb_lambstop; ///< Label for stop wavelength - QLineEdit* le_runIdInt; ///< Line edit for internal run ID - US_LineEdit_RE* le_runIdAbs; ///< Line edit for absolute run ID - QLineEdit* le_desc; ///< Line edit for description - QLineEdit* le_status; ///< Line edit for status - QLineEdit* le_ref_range; ///< Line edit for reference range - QLineEdit* le_xrange; ///< Line edit for X range - QLabel* plot_title; ///< Plot title label - QString runIdAbs; ///< Absolute run ID - - QComboBox* cb_plot_id; ///< Combo box for plot ID - QComboBox* cb_buffer; ///< Combo box for buffer - - US_PlotPicker *picker_abs; ///< Absorbance plot picker - US_PlotPicker *picker_insty; ///< Intensity plot picker - US_Plot* usplot_insty; ///< Intensity plot - US_Plot* usplot_abs; ///< Absorbance plot - QwtPlot* qwtplot_insty; ///< Qwt plot for intensity - QwtPlot* qwtplot_abs; ///< Qwt plot for absorbance - QwtPlotGrid* grid; ///< Plot grid - - QwtCounter* ct_scan_l; ///< Scan lower counter - QwtCounter* ct_scan_u; ///< Scan upper counter - QwtCounter* ct_smooth; ///< Smooth counter - QwtCounter* ct_last_scans; ///< Last scans counter - - QFrame *frm_refScan; ///< Reference scan frame - - QListWidget* lw_triple; ///< List widget for triples - QCheckBox *ckb_act_refscan; ///< Check box for active reference scan - QCheckBox *ckb_zeroing; ///< Check box for zeroing - QCheckBox *ckb_xrange; ///< Check box for X range - QCheckBox *ckb_ChroAberCorr; ///< Check box for Chromatic Aberration Correction - US_Disk_DB_Controls* diskDB_ctrl; ///< Disk/DB controls - - CCW ccwList; ///< List of CCW - CCW ccwListMain; ///< Main list of CCW - QStringList ccwStrListMain; ///< Main string list of CCW - CCW_ITEM ccwItemList; ///< List of CCW items - - US_DB2 *dbCon; ///< Database connection - US_Passwd pw; ///< Password object - int cpos, le_cursor_pos = -1; ///< Cursor positions - double x_min_picked, x_max_picked; ///< Picked X range - int wavl_id; ///< Wavelength ID - int n_wavls; ///< Number of wavelengths - int refId; ///< Reference ID - QStringList intRunIds; ///< Internal run IDs - QVector intDataId; ///< Internal data IDs - QVector wavelength; ///< Wavelengths - QVector xvalues; ///< X values - QVector> xvaluesRefCAC; ///< X values for Reference Chromatic Aberration Correction - QVector intensity; ///< Intensity data - QVector absorbance; ///< Absorbance data - QVector absorbanceBuffer; ///< Absorbance buffer data - QVector allIntData; ///< All intensity data - QVector> scansRange; ///< Scans range - US_RefScanDataIO::RefData refData; ///< Reference data - QFileInfoList allIntDataFiles; ///< All intensity data files - - void make_ccwItemList(void); - void set_wavl_ctrl(void); - void set_listWidget(void); - void offon_prev_next(void); - void plot_intensity(void); - void plot_refscan(void); - void plot_absorbance(void); - void set_scan_ct(void); - void get_pseudo_absorbance(int, int, bool buffer); - bool get_absorbance(int, int); - void get_intensity(int); - bool get_refId(double); - void set_buffer_list(void); - void get_relative_absorbance(int); - void trim_absorbance(void); - QVector get_smooth(QVector, int, bool, bool); - void load_from_DB(void); - void uncheck_CA_silently(void); - bool linear_interpolation(QVector&, QVector&, QVector&); - void select_CCW_save(QVector&); -}; - -/** - * @class LoadDBWidget - * @brief The LoadDBWidget class provides a dialog for loading data from the database. - */ -class LoadDBWidget : public US_WidgetsDialog { - Q_OBJECT + RefscanFile() {} + + QString filename; + QString name; + double min_wvl; + double max_wvl; + int nwvl; + QVector wavelength; + QVector xvalues; + QVector> yvalues; + }; + + class CellChannel + { public: - /** - * @brief Constructor for LoadDBWidget. - * @param w Parent widget - * @param dbCon Database connection - * @param refData Reference data - */ - LoadDBWidget(QWidget* w, US_DB2 *dbCon, US_RefScanDataIO::RefData& refData); - - private slots: - void slt_set_refTable(void); - void slt_apply(void); - - private: - US_DB2 *db; ///< Database connection - US_RefScanDataIO::RefData *refData; ///< Reference data - QVector instrumentIDs; ///< Instrument IDs - QStringList instrumentNames; ///< Instrument names - QVector> instrumentRefList; ///< Instrument reference list - QTreeWidget *tw_instruments; ///< Tree widget for instruments - QTreeWidget *tw_refData; ///< Tree widget for reference data - - /** - * @class refScanTableInfo - * @brief Holds information about reference scan table entries. - */ - class refScanTableInfo { - public: - int id; ///< Table ID - int instrumentID; ///< Instrument ID - int personID; ///< Person ID - QString type; ///< Type of scan - QStringList exprimentIds; ///< Experiment IDs - QDate referenceTime; ///< Reference time - int nWavelength; ///< Number of wavelengths - int nPoints; ///< Number of points - double startWavelength; ///< Start wavelength - double stopWavelength; ///< Stop wavelength - bool null_blob; ///< Null blob flag - QDate lastUpdated; ///< Last updated date - }; - - QVector refTable; ///< Reference table - QDate str2date(QString); ///< Convert string to date + CellChannel() {}; + + char channel; + int cell; + int ref_id; + QString runid; + QVector wavelength; + QVector rawdata_ids; + QPair minmax_x; + }; + + QPushButton* pb_prev_id; + QPushButton* pb_next_id; + QPushButton* pb_import; + QPushButton* pb_reset; + QPushButton* pb_load_ref; + QPushButton* pb_set_sample; + QPushButton* pb_save; + QPushButton* pb_pick_rp; + QPushButton* pb_apply; + + QLineEdit* le_lambstrt; + QLineEdit* le_lambstop; + QLineEdit* le_runid; + QLineEdit* le_desc; + QLineEdit* le_status; + QLabel* plot_title; + QComboBox* cb_plot_id; + + US_PlotPicker *picker_abs; + US_PlotPicker *picker_insty; + US_Plot* usplot_insty; + US_Plot* usplot_abs; + QwtPlot* qwtplot_insty; + QwtPlot* qwtplot_abs; + QwtPlotGrid* grid; + + QwtCounter* ct_smooth; + QwtCounter* ct_lscns_smp; + QwtCounter* ct_lscns_buf; + + QTableWidget* tb_triple; + QFont font; + + const double maxAbs = 3; + bool abs_plt_on; + int ns_smp; + int ns_buf; + int smooth; + int wavl_id; + int ref_file_id; + QVector wavelength; + QVector ccw_items; + QVector intensity_data; + QVector>> absorbance_data; + QVector> absorbance_shifts; + QVector> refscan_data; + QVector refscan_files; + QVector absorbance_state; + + void list_ccw_items(QString&); + void set_table(); + void offon_prev_next(); + void plot_intensity(); + void plot_refscan(); + void plot_absorbance(); + void calc_absorbance(int); + void update_shifts(int); + bool get_refval_file(int, int, QVector&); + bool get_refval_buffer(int, int, QVector&); + QVector smooth_refscan(QVector, int, bool, bool, double); + bool linear_interpolation(const QVector&, QVector&, QVector&); + void disconnect_picker(); + bool set_abs_runid(QString&); }; #endif // US_CONVERT_SCAN_H From d6849183728eeaa7942bcfbe21e7df43dfc58425 Mon Sep 17 00:00:00 2001 From: samo38 Date: Sun, 16 Jun 2024 18:35:11 -0600 Subject: [PATCH 04/21] us_pseudo_absorbance/us_convert_scan: removed the buffer counter used in buffer averaging tools --- .../us_pseudo_absorbance/us_convert_scan.cpp | 78 +++++++++---------- .../us_pseudo_absorbance/us_convert_scan.h | 6 +- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index e6cb43a05..f5408a197 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -36,51 +36,47 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() import_lyt->addLayout(imp_lyt_2); // Cell / Channel / Wavelength - int width_lb = 170; - int width_ct = 130; + int width_lb = 90; + int width_ct = 90; QLabel* lb_buffer = us_banner("Absorbance Data Control"); - QLabel* lb_lscns_smp = us_label("# Scans (Sample)", 0); - lb_lscns_smp->setAlignment(Qt::AlignCenter); - lb_lscns_smp->setFixedWidth(width_lb); + QLabel* lb_scans = us_label("# Scans", 0); + lb_scans->setAlignment(Qt::AlignCenter); + lb_scans->setFixedWidth(width_lb); - QLabel* lb_lscns_buf = us_label("# Scans (Buffer)", 0); - lb_lscns_buf->setAlignment(Qt::AlignCenter); - lb_lscns_buf->setFixedWidth(width_lb); - - QLabel *lb_smooth = us_label("Smoothing Level", 0); + QLabel *lb_smooth = us_label("Smooth", 0); lb_smooth->setAlignment(Qt::AlignCenter); lb_smooth->setFixedWidth(width_lb); pb_apply = us_pushbutton("Apply"); - ns_smp = 1; - ct_lscns_smp = us_counter(2, 1, 200, ns_smp); - ct_lscns_smp->setSingleStep(1); - ct_lscns_smp->setFixedWidth(width_ct); - - ns_buf = 10; - ct_lscns_buf = us_counter(2, 1, 200, ns_buf); - ct_lscns_buf->setSingleStep(1); - ct_lscns_buf->setFixedWidth(width_ct); + nscans = 1; + ct_scans = us_counter(1, 1, 1, nscans); + ct_scans->setSingleStep(1); + ct_scans->setFixedWidth(width_ct); smooth = 0; - ct_smooth = us_counter(2, 0, 10, smooth); + ct_smooth = us_counter(1, 0, 0, smooth); ct_smooth->setSingleStep(1); ct_smooth->setFixedWidth(width_ct); - QGridLayout* ccw_lyt_1_l = new QGridLayout(); - ccw_lyt_1_l->addWidget(lb_lscns_smp, 0, 0, 1, 1); - ccw_lyt_1_l->addWidget(ct_lscns_smp, 0, 1, 1, 1); - ccw_lyt_1_l->addWidget(lb_lscns_buf, 1, 0, 1, 1); - ccw_lyt_1_l->addWidget(ct_lscns_buf, 1, 1, 1, 1); - ccw_lyt_1_l->addWidget(lb_smooth, 2, 0, 1, 1); - ccw_lyt_1_l->addWidget(ct_smooth, 2, 1, 1, 1); + // QGridLayout* ccw_lyt_1_l = new QGridLayout(); + // ccw_lyt_1_l->addWidget(lb_scans, 0, 0, 1, 1); + // ccw_lyt_1_l->addWidget(ct_scans, 0, 1, 1, 1); + // ccw_lyt_1_l->addWidget(lb_smooth, 1, 0, 1, 1); + // ccw_lyt_1_l->addWidget(ct_smooth, 1, 1, 1, 1); + + QHBoxLayout* ss_lyt = new QHBoxLayout(); + ss_lyt->addWidget(lb_scans); + ss_lyt->addWidget(ct_scans); + ss_lyt->addWidget(lb_smooth); + ss_lyt->addWidget(ct_smooth); + ss_lyt->addWidget(pb_apply); - QHBoxLayout* ccw_lyt_1 = new QHBoxLayout(); - ccw_lyt_1->addLayout(ccw_lyt_1_l, 0); - ccw_lyt_1->addSpacing(1); - ccw_lyt_1->addWidget(pb_apply, 0, Qt::AlignVCenter); + // QHBoxLayout* ccw_lyt_1 = new QHBoxLayout(); + // ccw_lyt_1->addLayout(ss_lyt, 0); + // ccw_lyt_1->addSpacing(1); + // ccw_lyt_1->addWidget(pb_apply, 0, Qt::AlignVCenter); static QChar clambda( 955 ); // Lambda character QLabel* lb_lambstrt = us_label(tr( "%1 Start:" ).arg( clambda ) ); @@ -136,7 +132,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QVBoxLayout* ccw_lyt = new QVBoxLayout(); ccw_lyt->addWidget(lb_buffer); - ccw_lyt->addLayout(ccw_lyt_1); + ccw_lyt->addLayout(ss_lyt); ccw_lyt->addWidget(tb_triple); ccw_lyt->addLayout(ccw_lyt_2); ccw_lyt->addLayout(ccw_lyt_3); @@ -254,8 +250,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_scan_smooth); connect(pb_default, &QPushButton::clicked, this, &US_ConvertScan::default_region); connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); - connect(ct_lscns_buf, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); - connect(ct_lscns_smp, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); } void US_ConvertScan::reset(){ @@ -289,8 +284,7 @@ void US_ConvertScan::apply_scan_smooth() { QColor color = US_GuiSettings::pushbColor().color(QPalette::Active, QPalette::Button); QString qs = "QPushButton { background-color: %1 }"; pb_apply->setStyleSheet(qs.arg(color.name())); - ns_smp = static_cast(ct_lscns_smp->value()); - ns_buf = static_cast(ct_lscns_buf->value()); + nscans = static_cast(ct_scans->value()); smooth = static_cast(ct_smooth->value()); QGuiApplication::setOverrideCursor(Qt::WaitCursor); for (int ii = 0; ii < ccw_items.size(); ii++) { @@ -719,7 +713,7 @@ void US_ConvertScan::save_run() { miss_ccw << ccw_str.arg(cell).arg(channel).arg(wvl); } else { US_DataIO::RawData rawdata = intensity_data.at(rid); - int nn = absorbance_data.at(rid).size() - ns_smp; + int nn = absorbance_data.at(rid).size() - nscans; if (nn < 0) { nn = 0; } @@ -936,7 +930,7 @@ void US_ConvertScan::plot_intensity(){ int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); US_DataIO::RawData raw_data = intensity_data.at(raw_id); - int nn = raw_data.scanCount() - ns_smp; + int nn = raw_data.scanCount() - nscans; if (nn < 0) { nn = 0; } @@ -1043,7 +1037,7 @@ void US_ConvertScan::plot_absorbance(){ double x_1 = ccw_items.at(row).minmax_x.first; double x_2 = ccw_items.at(row).minmax_x.second; - int nn = absorbance_data.at(raw_id).size() - ns_smp; + int nn = absorbance_data.at(raw_id).size() - nscans; if (nn < 0) { nn = 0; } @@ -1182,7 +1176,7 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int rid, QVector& yv int iwvl = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); if (iwvl_tgt == iwvl) { ref_xvals << rawdata.xvalues; - int nn = rawdata.scanCount() - static_cast(ns_buf); + int nn = rawdata.scanCount(); if (nn < 0) { nn = 0; } @@ -1255,7 +1249,7 @@ void US_ConvertScan::calc_absorbance(int item_row){ ref_yvals << yvals; } - int nn = rawdata.scanCount() - ns_smp; + int nn = rawdata.scanCount() - nscans; if (nn < 0) { nn = 0; } @@ -1310,7 +1304,7 @@ void US_ConvertScan::update_shifts(int item_row){ continue; } US_DataIO::RawData rawdata = intensity_data.at(rid); - int nn = rawdata.scanCount() - ns_smp; + int nn = rawdata.scanCount() - nscans; if (nn < 0) { nn = 0; } diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 082f2d9fb..ef356011a 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -102,16 +102,14 @@ private slots: QwtPlotGrid* grid; QwtCounter* ct_smooth; - QwtCounter* ct_lscns_smp; - QwtCounter* ct_lscns_buf; + QwtCounter* ct_scans; QTableWidget* tb_triple; QFont font; const double maxAbs = 3; bool abs_plt_on; - int ns_smp; - int ns_buf; + int nscans; int smooth; int wavl_id; int ref_file_id; From f86b28bfc0c2d66f425ea67597daac793849af61 Mon Sep 17 00:00:00 2001 From: samo38 Date: Sun, 16 Jun 2024 19:09:29 -0600 Subject: [PATCH 05/21] us_pseudo_absorbance/us_convert_scan: modify the layout --- .../us_pseudo_absorbance/us_convert_scan.cpp | 99 +++++++------------ 1 file changed, 38 insertions(+), 61 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index f5408a197..db27fa187 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -60,12 +60,6 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() ct_smooth->setSingleStep(1); ct_smooth->setFixedWidth(width_ct); - // QGridLayout* ccw_lyt_1_l = new QGridLayout(); - // ccw_lyt_1_l->addWidget(lb_scans, 0, 0, 1, 1); - // ccw_lyt_1_l->addWidget(ct_scans, 0, 1, 1, 1); - // ccw_lyt_1_l->addWidget(lb_smooth, 1, 0, 1, 1); - // ccw_lyt_1_l->addWidget(ct_smooth, 1, 1, 1, 1); - QHBoxLayout* ss_lyt = new QHBoxLayout(); ss_lyt->addWidget(lb_scans); ss_lyt->addWidget(ct_scans); @@ -73,48 +67,6 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() ss_lyt->addWidget(ct_smooth); ss_lyt->addWidget(pb_apply); - // QHBoxLayout* ccw_lyt_1 = new QHBoxLayout(); - // ccw_lyt_1->addLayout(ss_lyt, 0); - // ccw_lyt_1->addSpacing(1); - // ccw_lyt_1->addWidget(pb_apply, 0, Qt::AlignVCenter); - - static QChar clambda( 955 ); // Lambda character - QLabel* lb_lambstrt = us_label(tr( "%1 Start:" ).arg( clambda ) ); - lb_lambstrt->setAlignment(Qt::AlignCenter); - QLabel* lb_lambstop = us_label(tr( "%1 End:" ).arg( clambda ) ); - lb_lambstop->setAlignment(Qt::AlignCenter); - - le_lambstrt = us_lineedit("", -1, true); - le_lambstop = us_lineedit("", -1, true); - lb_lambstrt->setFixedWidth(70); - lb_lambstop->setFixedWidth(70); - - cb_plot_id = us_comboBox(); - cb_plot_id->setEditable(true); - cb_plot_id->setFixedWidth(100); - - QHBoxLayout* ccw_lyt_2 = new QHBoxLayout(); - ccw_lyt_2->addWidget(lb_lambstrt, 0); - ccw_lyt_2->addSpacing(1); - ccw_lyt_2->addWidget(le_lambstrt, 1); - ccw_lyt_2->addSpacing(1); - ccw_lyt_2->addWidget(cb_plot_id, 0); - ccw_lyt_2->addSpacing(1); - ccw_lyt_2->addWidget(lb_lambstop, 0); - ccw_lyt_2->addSpacing(1); - ccw_lyt_2->addWidget(le_lambstop, 1); - - pb_prev_id = us_pushbutton( "Previous", true, 0 ); - pb_next_id = us_pushbutton( "Next", true, 0 ); - pb_prev_id->setIcon( US_Images::getIcon( US_Images::ARROW_LEFT ) ); - pb_next_id->setIcon( US_Images::getIcon( US_Images::ARROW_RIGHT ) ); - pb_prev_id->setFixedWidth(150); - pb_next_id->setFixedWidth(150); - - QHBoxLayout* ccw_lyt_3 = new QHBoxLayout(); - ccw_lyt_3->addWidget(pb_prev_id, 0, Qt::AlignRight); - ccw_lyt_3->addWidget(pb_next_id, 0, Qt::AlignLeft); - tb_triple = new QTableWidget(); tb_triple->setRowCount(0); tb_triple->setColumnCount(4); @@ -134,26 +86,51 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() ccw_lyt->addWidget(lb_buffer); ccw_lyt->addLayout(ss_lyt); ccw_lyt->addWidget(tb_triple); - ccw_lyt->addLayout(ccw_lyt_2); - ccw_lyt->addLayout(ccw_lyt_3); + + static QChar clambda( 955 ); // Lambda character + QLabel* lb_lambstrt = us_label(tr( "%1 Start:" ).arg( clambda ) ); + lb_lambstrt->setAlignment(Qt::AlignCenter); + QLabel* lb_lambstop = us_label(tr( "%1 End:" ).arg( clambda ) ); + lb_lambstop->setAlignment(Qt::AlignCenter); + + le_lambstrt = us_lineedit("", -1, true); + le_lambstop = us_lineedit("", -1, true); + + cb_plot_id = us_comboBox(); + cb_plot_id->setEditable(true); + + pb_prev_id = us_pushbutton( "Previous", true, 0 ); + pb_next_id = us_pushbutton( "Next", true, 0 ); + pb_prev_id->setIcon( US_Images::getIcon( US_Images::ARROW_LEFT ) ); + pb_next_id->setIcon( US_Images::getIcon( US_Images::ARROW_RIGHT ) ); + pb_prev_id->setFixedWidth(150); + pb_next_id->setFixedWidth(150); QLabel *lb_zero = us_label("Shift to Zero"); lb_zero->setAlignment(Qt::AlignCenter); - lb_zero->setFixedWidth(120); pb_pick_rp = us_pushbutton("Pick Region"); QPushButton *pb_default = us_pushbutton("Default"); + pb_save = us_pushbutton("Save Absorbance Data"); - QHBoxLayout *buff_lyt_1 = new QHBoxLayout(); - buff_lyt_1->addWidget(lb_zero); - buff_lyt_1->addWidget(pb_pick_rp); - buff_lyt_1->addWidget(pb_default); + QGridLayout* save_lyt = new QGridLayout(); + save_lyt->addWidget(pb_prev_id, 0, 1, 1, 2); + save_lyt->addWidget(pb_next_id, 0, 3, 1, 2); - pb_save = us_pushbutton("Save Absorbance Data"); - pb_save->setFixedWidth(250); + save_lyt->addWidget(lb_lambstrt, 1, 0, 1, 1); + save_lyt->addWidget(le_lambstrt, 1, 1, 1, 1); + save_lyt->addWidget(cb_plot_id, 1, 2, 1, 2); + save_lyt->addWidget(lb_lambstop, 1, 4, 1, 1); + save_lyt->addWidget(le_lambstop, 1, 5, 1, 1); + + save_lyt->addWidget(lb_zero, 2, 0, 1, 2); + save_lyt->addWidget(pb_pick_rp, 2, 2, 1, 2); + save_lyt->addWidget(pb_default, 2, 4, 1, 2); - QVBoxLayout* buffer_lyt = new QVBoxLayout(); - buffer_lyt->addLayout(buff_lyt_1); - buffer_lyt->addWidget(pb_save, 0, Qt::AlignCenter); + save_lyt->addWidget(pb_save, 3, 1, 1, 4); + + for (int ii = 0; ii < save_lyt->columnCount(); ii++) { + save_lyt->setColumnMinimumWidth(ii, 75); + } QLabel* lb_status = us_label("Status:"); lb_status->setAlignment(Qt::AlignCenter); @@ -179,7 +156,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() left_lyt->addSpacing(3); left_lyt->addLayout(ccw_lyt); left_lyt->addSpacing(3); - left_lyt->addLayout(buffer_lyt); + left_lyt->addLayout(save_lyt); left_lyt->addSpacing(3); left_lyt->addLayout(status_lyt); left_lyt->addLayout(close_lyt); From 0aa114551c73466842cbc26560d6c6b0e76442d7 Mon Sep 17 00:00:00 2001 From: samo38 Date: Mon, 17 Jun 2024 01:10:07 -0600 Subject: [PATCH 06/21] us_pseudo_absorbance/us_convert_scan: compute reference data scan by scan. centered combobox texts. there is a bug that when a new reference triple selected, absorbance data not updated correctly --- .../us_pseudo_absorbance/us_convert_scan.cpp | 203 ++++++++++-------- .../us_pseudo_absorbance/us_convert_scan.h | 13 +- 2 files changed, 124 insertions(+), 92 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index db27fa187..f9228c6da 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -51,12 +51,13 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() pb_apply = us_pushbutton("Apply"); nscans = 1; + max_nscans = 1000; ct_scans = us_counter(1, 1, 1, nscans); ct_scans->setSingleStep(1); ct_scans->setFixedWidth(width_ct); smooth = 0; - ct_smooth = us_counter(1, 0, 0, smooth); + ct_smooth = us_counter(1, 0, 10, smooth); ct_smooth->setSingleStep(1); ct_smooth->setFixedWidth(width_ct); @@ -88,9 +89,9 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() ccw_lyt->addWidget(tb_triple); static QChar clambda( 955 ); // Lambda character - QLabel* lb_lambstrt = us_label(tr( "%1 Start:" ).arg( clambda ) ); + QLabel* lb_lambstrt = us_label(tr( "%1 Start" ).arg( clambda ) ); lb_lambstrt->setAlignment(Qt::AlignCenter); - QLabel* lb_lambstop = us_label(tr( "%1 End:" ).arg( clambda ) ); + QLabel* lb_lambstop = us_label(tr( "%1 End" ).arg( clambda ) ); lb_lambstop->setAlignment(Qt::AlignCenter); le_lambstrt = us_lineedit("", -1, true); @@ -98,6 +99,8 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() cb_plot_id = us_comboBox(); cb_plot_id->setEditable(true); + cb_plot_id->lineEdit()->setAlignment(Qt::AlignCenter); + cb_plot_id->lineEdit()->setReadOnly(true); pb_prev_id = us_pushbutton( "Previous", true, 0 ); pb_next_id = us_pushbutton( "Next", true, 0 ); @@ -227,7 +230,6 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_scan_smooth); connect(pb_default, &QPushButton::clicked, this, &US_ConvertScan::default_region); connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); - connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); } void US_ConvertScan::reset(){ @@ -235,9 +237,10 @@ void US_ConvertScan::reset(){ tb_triple->disconnect(); tb_triple->clearContents(); tb_triple->setRowCount(0); + set_ct_scans(); hasData = false; wavl_id = 0; - ref_file_id = -1; + plot_ref_file = -1; wavelength.clear(); ccw_items.clear(); intensity_data.clear(); @@ -300,14 +303,16 @@ void US_ConvertScan::import_run(){ QVector rawdata; QVector>> absorbance; + QVector>> refscans; QVector> shifts; - QVector> refscans; // QStringList fnames; QStringList loaded_runids; foreach (CellChannel cc, ccw_items) { loaded_runids << cc.runid; } + int maxscans = 1000000; + for (int ii = 0; ii < fileList.size(); ++ii){ QString fn = fileList.at(ii).fileName(); US_DataIO::RawData rdata = US_DataIO::RawData(); @@ -316,6 +321,8 @@ void US_ConvertScan::import_run(){ bad_files << fn; continue; } + if (rdata.scanCount() == 0) continue; + QString rtp = QChar::fromLatin1(rdata.type[0]); rtp.append(QChar::fromLatin1(rdata.type[1])); QString rid = fn.section(".", 0, -6); @@ -356,15 +363,17 @@ void US_ConvertScan::import_run(){ rawdata << rdata; // fnames << fn; int ns = rdata.scanCount(); + maxscans = qMin(maxscans, ns); int np = rdata.pointCount(); - QVector rf(np, 0); - refscans << rf; QVector> abs; + QVector> rf; for (int jj = 0; jj < ns; jj++) { QVector a(np, 0); abs << a; + rf << a; } absorbance << abs; + refscans << rf; QVector sh(ns, 0); shifts << sh; } @@ -384,13 +393,13 @@ void US_ConvertScan::import_run(){ return; } - QVector states(rawdata.size(), false); + QVector states(rawdata.size(), -1); intensity_data << rawdata; absorbance_data << absorbance; - refscan_data << refscans; absorbance_state << states; absorbance_shifts << shifts; + refscan_data << refscans; list_ccw_items(run_id); set_table(); @@ -398,9 +407,31 @@ void US_ConvertScan::import_run(){ pb_reset->setEnabled(true); hasData = true; le_status->clear(); + + maxscans = qMin(max_nscans, maxscans); + set_ct_scans(maxscans); return; } +void US_ConvertScan::set_ct_scans(int maxval) { + ct_scans->disconnect(); + if (maxval == 0) { + max_nscans = 1000; + ct_scans->setValid(1); + ct_scans->setMaximum(1); + } else { + int cv = ct_scans->value(); + max_nscans = maxval; + ct_scans->setMaximum(max_nscans); + if (cv > max_nscans) { + cv = max_nscans; + apply_scan_smooth(); + } + ct_scans->setValue(cv); + } + connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); +} + void US_ConvertScan::prev_id(){ --wavl_id; cb_plot_id->setCurrentIndex(wavl_id); @@ -427,7 +458,7 @@ void US_ConvertScan::set_wavl_ctrl(){ cb_plot_id->clear(); wavelength.clear(); wavl_id = 0; - ref_file_id = -1; + plot_ref_file = -1; if (ccw_items.isEmpty()) { le_lambstrt->clear(); le_lambstop->clear(); @@ -444,18 +475,23 @@ void US_ConvertScan::set_wavl_ctrl(){ for (int ii = 0; ii < refscan_files.size(); ii++) { if (refscan_files.at(ii).name.compare(cellname) == 0) { wavelength << refscan_files.at(ii).wavelength; - ref_file_id = ii; + plot_ref_file = ii; } } } else { wavelength << ccw_items.at(row).wavelength; - ref_file_id = -1; + plot_ref_file = -1; } le_lambstrt->setText(tr("%1").arg(wavelength.first())); + le_lambstrt->setAlignment(Qt::AlignCenter); le_lambstop->setText(tr("%1").arg(wavelength.last())); + le_lambstop->setAlignment(Qt::AlignCenter); foreach (double wvl, wavelength) { cb_plot_id->addItem(QString::number(wvl)); } + for (int ii = 0; ii < cb_plot_id->count(); ii++) { + cb_plot_id->setItemData(ii, Qt::AlignCenter, Qt::TextAlignmentRole); + } offon_prev_next(); // connect(cb_plot_id, QOverload::of(&QComboBox::currentIndexChanged), @@ -469,9 +505,9 @@ void US_ConvertScan::select_id(int id){ disconnect_picker(); wavl_id = id; offon_prev_next(); - if (ref_file_id >= 0) { + if (plot_ref_file >= 0) { le_runid->clear(); - le_desc->setText(refscan_files.at(ref_file_id).filename); + le_desc->setText(refscan_files.at(plot_ref_file).filename); } else { int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); le_runid->setText(ccw_items.at(tb_triple->currentRow()).runid); @@ -685,7 +721,7 @@ void US_ConvertScan::save_run() { int rid = ccw_items.at(ii).rawdata_ids.at(jj); int cell = ccw_items.at(ii).cell; char channel = ccw_items.at(ii).channel; - if (! absorbance_state.at(rid)) { + if (absorbance_state.at(rid) == -1) { double wvl = ccw_items.at(ii).wavelength.at(jj); miss_ccw << ccw_str.arg(cell).arg(channel).arg(wvl); } else { @@ -820,17 +856,23 @@ void US_ConvertScan::set_table(){ for (int ii = 0; ii < ccw_items.size(); ii++) { QComboBox *combo = us_comboBox(); + combo->setEditable(true); + combo->lineEdit()->setAlignment(Qt::AlignCenter); + combo->lineEdit()->setReadOnly(true); combo->addItem("none"); for (int jj = 0; jj < combo_items.size(); jj++) { combo->addItem(tb_triple->item(jj, 0)->text()); } int re_fid = ccw_items.at(ii).ref_id; if ( re_fid >= 0 && re_fid < 100) { - combo->setCurrentIndex(re_fid); + combo->setCurrentIndex(re_fid + 1); } else if ( re_fid >= 0 && re_fid >= 100) { QString name = refscan_files.at(re_fid - 100).name; combo->setCurrentText(name); } + for (int jj = 0; jj < combo->count(); jj++) { + combo->setItemData(jj, Qt::AlignCenter, Qt::TextAlignmentRole); + } tb_triple->setCellWidget(ii, 2, combo); connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(select_refscan(int))); @@ -895,6 +937,7 @@ void US_ConvertScan::list_ccw_items(QString& runid){ } ccw_items << cc; } + qDebug(); } void US_ConvertScan::plot_intensity(){ @@ -958,18 +1001,18 @@ void US_ConvertScan::plot_refscan(){ QVector yvalues; QVector xvalues; - if (ref_file_id >= 0) { + if (plot_ref_file >= 0) { le_runid->clear(); - le_desc->setText(refscan_files.at(ref_file_id).filename); - xvalues << refscan_files.at(ref_file_id).xvalues; - yvalues << refscan_files.at(ref_file_id).yvalues.at(wavl_id); + le_desc->setText(refscan_files.at(plot_ref_file).filename); + xvalues << refscan_files.at(plot_ref_file).xvalues; + yvalues << refscan_files.at(plot_ref_file).yvalues.at(wavl_id); } else { int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); - if (! absorbance_state.at(raw_id)) { + if (absorbance_state.at(raw_id) < 100) { return; } xvalues << intensity_data.at(raw_id).xvalues; - yvalues << refscan_data.at(raw_id); + yvalues << refscan_data.at(raw_id).last(); } if (xvalues.size() != yvalues.size()) { @@ -1009,7 +1052,7 @@ void US_ConvertScan::plot_absorbance(){ int row = tb_triple->currentRow(); int raw_id = ccw_items.at(row).rawdata_ids.at(wavl_id); - if (! absorbance_state.at(raw_id)) return; + if (absorbance_state.at(raw_id) == -1) return; double x_1 = ccw_items.at(row).minmax_x.first; double x_2 = ccw_items.at(row).minmax_x.second; @@ -1109,74 +1152,72 @@ void US_ConvertScan::plot_absorbance(){ abs_plt_on = true; } -bool US_ConvertScan::get_refval_file(int ref_id, int rid, QVector& yvals) { +bool US_ConvertScan::get_refval_file(int ref_id, int raw_id) { ref_id -= 100; - US_DataIO::RawData rawdata = intensity_data.at(rid); + US_DataIO::RawData rawdata = intensity_data.at(raw_id); int iwvl_tgt = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); QVector xvals_tgt = rawdata.xvalues; - QVector ref_xvals; - QVector ref_yvals; - bool ok = false; + bool ok = false; for (int ii = 0; ii < refscan_files.at(ref_id).wavelength.size(); ii++) { int iwvl = static_cast(qRound(refscan_files.at(ref_id).wavelength.at(ii) * 10)); if (iwvl == iwvl_tgt) { - ref_xvals << refscan_files.at(ref_id).xvalues; - ref_yvals << refscan_files.at(ref_id).yvalues.at(ii); + QVector ref_xvals = refscan_files.at(ref_id).xvalues; + QVector ref_yvals = refscan_files.at(ref_id).yvalues.at(ii); + if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { + if (smooth > 0){ + QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); + ref_yvals.clear(); + ref_yvals << yvals; + } + int N = rawdata.scanCount() - nscans; + for (int jj = N; jj < rawdata.scanCount(); jj++) { + for (int kk = 0; kk < ref_yvals.size(); kk++) { + refscan_data[raw_id][jj][kk] = ref_yvals.at(kk); + } + } + } else { + return false; + } ok = true; break; } } - - if (! ok) { - return false; - } - ok = linear_interpolation(xvals_tgt, ref_xvals, ref_yvals); - if (ok) { - yvals.clear(); - yvals << ref_yvals; - } return ok; } -bool US_ConvertScan::get_refval_buffer(int ref_row, int rid, QVector& yvals) { +bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { - int iwvl_tgt = static_cast(qRound(intensity_data.at(rid).scanData.at(0).wavelength * 10)); - QVector xvals_tgt = intensity_data.at(rid).xvalues; + int iwvl_tgt = static_cast(qRound(intensity_data.at(raw_id).scanData.at(0).wavelength * 10)); + QVector xvals_tgt = intensity_data.at(raw_id).xvalues; bool ok = false; - QVector ref_xvals; - QVector ref_yvals; foreach (int rid, ccw_items.at(ref_row).rawdata_ids) { US_DataIO::RawData rawdata = intensity_data.at(rid); int iwvl = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); if (iwvl_tgt == iwvl) { - ref_xvals << rawdata.xvalues; - int nn = rawdata.scanCount(); - if (nn < 0) { - nn = 0; - } - int N = rawdata.scanCount() - nn; - for (int ii = 0; ii < rawdata.pointCount(); ii++) { - double val = 0; - for (int jj = nn; jj < rawdata.scanCount(); jj++) { - val += rawdata.reading(jj, ii); + QVector ref_xvals = rawdata.xvalues; + int N = rawdata.scanCount() - nscans; + for (int ii = N; ii < rawdata.scanCount(); ii++) { + QVector ref_yvals = rawdata.scanData.at(ii).rvalues; + if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { + if (smooth > 0){ + QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); + ref_yvals.clear(); + ref_yvals << yvals; + } + for (int jj = 0; jj < ref_yvals.size(); jj++) { + refscan_data[raw_id][ii][jj] = ref_yvals.at(jj); + } + } else { + return false; } - ref_yvals << val / N; } ok = true; break; } } - if (! ok) { - return false; - } - ok = linear_interpolation(xvals_tgt, ref_xvals, ref_yvals); - if (ok) { - yvals.clear(); - yvals << ref_yvals; - } return ok; } @@ -1184,11 +1225,11 @@ void US_ConvertScan::calc_absorbance(int item_row){ if (ccw_items.isEmpty()) return; QVector rawdata_ids = ccw_items.at(item_row).rawdata_ids; - int ref_id = ccw_items.at(item_row).ref_id; + const int ref_id = ccw_items.at(item_row).ref_id; bool buffer = true; if ( ref_id == -1) { foreach (int rid, rawdata_ids) { - absorbance_state[rid] = false; + absorbance_state[rid] = -1; } return; } else if (ref_id >= 100) { @@ -1204,38 +1245,29 @@ void US_ConvertScan::calc_absorbance(int item_row){ QVector not_found_wvl; for (int ii = 0; ii < rawdata_ids.size(); ii++) { - QVector ref_yvals; int rid = rawdata_ids.at(ii); US_DataIO::RawData rawdata = intensity_data.at(rid); double wvl = ccw_items.at(item_row).wavelength.at(ii); bool ok = false; if (buffer) { - ok = get_refval_buffer(ref_id, rid, ref_yvals); + ok = get_refval_buffer(ref_id, rid); } else { - ok = get_refval_file(ref_id, rid, ref_yvals); + ok = get_refval_file(ref_id, rid); } - absorbance_state[rid] = false; + absorbance_state[rid] = -1; if (! ok) { not_found_wvl << wvl; continue; } - //// smooth - if (smooth > 0){ - QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); - ref_yvals.clear(); - ref_yvals << yvals; - } - int nn = rawdata.scanCount() - nscans; - if (nn < 0) { - nn = 0; - } + int N = rawdata.scanCount() - nscans; QVector xvalues = rawdata.xvalues; - for (int jj = nn; jj < rawdata.scanCount(); jj++) { + for (int jj = N; jj < rawdata.scanCount(); jj++) { double miny = 1e99; for (int kk = 0; kk < rawdata.pointCount(); kk++){ double x = xvalues.at(kk); - double val = ref_yvals.at(kk) / rawdata.reading(jj, kk); + double rfv = refscan_data.at(rid).at(jj).at(kk); + double val = rfv / rawdata.reading(jj, kk); if (val <= 0) { val = 1e-5; } @@ -1246,15 +1278,12 @@ void US_ConvertScan::calc_absorbance(int item_row){ if (shift && x >= x_1 && x <= x_2) { miny = qMin(miny, val); } - if (jj == nn) { - refscan_data[rid][kk] = ref_yvals.at(kk); - } } if (shift) { absorbance_shifts[rid][jj] = -1 * miny; } } - absorbance_state[rid] = true; + absorbance_state[rid] = ref_id; } if (not_found_wvl.isEmpty()) { tb_triple->item(item_row, 0)->setBackground(QBrush(Qt::white)); @@ -1277,7 +1306,7 @@ void US_ConvertScan::update_shifts(int item_row){ for (int ii = 0; ii < rawdata_ids.size(); ii++) { int rid = rawdata_ids.at(ii); - if (! absorbance_state.at(rid)) { + if (absorbance_state.at(rid) == -1) { continue; } US_DataIO::RawData rawdata = intensity_data.at(rid); diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index ef356011a..d81e0abdf 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -110,17 +110,18 @@ private slots: const double maxAbs = 3; bool abs_plt_on; int nscans; + int max_nscans; int smooth; int wavl_id; - int ref_file_id; + int plot_ref_file; QVector wavelength; QVector ccw_items; QVector intensity_data; QVector>> absorbance_data; + QVector>> refscan_data; QVector> absorbance_shifts; - QVector> refscan_data; QVector refscan_files; - QVector absorbance_state; + QVector absorbance_state; void list_ccw_items(QString&); void set_table(); @@ -130,12 +131,14 @@ private slots: void plot_absorbance(); void calc_absorbance(int); void update_shifts(int); - bool get_refval_file(int, int, QVector&); - bool get_refval_buffer(int, int, QVector&); + bool get_refval_file(int, int); + bool get_refval_buffer(int, int); QVector smooth_refscan(QVector, int, bool, bool, double); bool linear_interpolation(const QVector&, QVector&, QVector&); void disconnect_picker(); bool set_abs_runid(QString&); + void set_ct_scans(int = 0); + }; #endif // US_CONVERT_SCAN_H From a7bba2bfa685ca54a7067b241dcab78ee9c61089 Mon Sep 17 00:00:00 2001 From: samo38 Date: Mon, 17 Jun 2024 11:08:49 -0600 Subject: [PATCH 07/21] us_pseudo_absorbance/us_convert_scan: fixed saving pseudo-absorbance run --- .../us_pseudo_absorbance/us_convert_scan.cpp | 43 ++++++++++--------- .../us_pseudo_absorbance/us_convert_scan.h | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index f9228c6da..751bcc52b 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -552,13 +552,15 @@ void US_ConvertScan::select_refscan(int ref_row) { ccw_items[item_row].ref_id = ref_row - 1; } - QModelIndex index = tb_triple->model()->index(item_row, 0); - tb_triple->selectionModel()-> - select(index, QItemSelectionModel::Select | QItemSelectionModel::Current); QGuiApplication::setOverrideCursor(Qt::WaitCursor); calc_absorbance(item_row); QGuiApplication::restoreOverrideCursor(); - emit sig_plot(); + + QModelIndex index = tb_triple->model()->index(item_row, 0); + // tb_triple->selectionModel()-> + // select(index, QItemSelectionModel::Select | QItemSelectionModel::Current); + tb_triple->setCurrentIndex(index); + set_wavl_ctrl(); } } @@ -702,8 +704,8 @@ void US_ConvertScan::save_run() { QMessageBox::warning(this, "Warning!", "No triple selected to save!"); return; } else if (run_list.size() > 1) { - QMessageBox::warning(this, "Warning!", "Triples from multiple RunID are selected!\n" - "Please select the triples of each RunID separately."); + QMessageBox::warning(this, "Warning!", "Triples from multiple RunIDs are selected!\n" + "Please select triples of each RunID separately."); return; } @@ -717,7 +719,7 @@ void US_ConvertScan::save_run() { if (x_1 > 0 && x_2 > 0) { shift = true; } - foreach (int jj, ccw_items.at(ii).rawdata_ids) { + for (int jj = 0; jj < ccw_items.at(ii).rawdata_ids.size(); jj++) { int rid = ccw_items.at(ii).rawdata_ids.at(jj); int cell = ccw_items.at(ii).cell; char channel = ccw_items.at(ii).channel; @@ -726,15 +728,13 @@ void US_ConvertScan::save_run() { miss_ccw << ccw_str.arg(cell).arg(channel).arg(wvl); } else { US_DataIO::RawData rawdata = intensity_data.at(rid); - int nn = absorbance_data.at(rid).size() - nscans; - if (nn < 0) { - nn = 0; - } - QVector> absorbance = absorbance_data.at(rid).mid(nn); - QVector shifts = absorbance_shifts.at(rid).mid(nn); - QVector scans = rawdata.scanData.mid(nn); - for (int mm = 0; mm < absorbance.size(); mm++) { - for (int nn = 0; nn < absorbance.at(mm).size(); nn++) { + int N = absorbance_data.at(rid).size() - nscans; + QVector> absorbance = absorbance_data.at(rid).mid(N); + QVector shifts = absorbance_shifts.at(rid).mid(N); + QVector scans = rawdata.scanData.mid(N); + for (int mm = 0; mm < nscans; mm++) { + int np = absorbance.at(mm).size(); + for (int nn = 0; nn < np; nn++) { double val = absorbance.at(mm).at(nn); if (shift) { val += shifts.at(mm); @@ -1191,6 +1191,7 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { int iwvl_tgt = static_cast(qRound(intensity_data.at(raw_id).scanData.at(0).wavelength * 10)); QVector xvals_tgt = intensity_data.at(raw_id).xvalues; + int N_tgt = intensity_data[raw_id].scanCount() - nscans; bool ok = false; foreach (int rid, ccw_items.at(ref_row).rawdata_ids) { @@ -1198,9 +1199,11 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { int iwvl = static_cast(qRound(rawdata.scanData.at(0).wavelength * 10)); if (iwvl_tgt == iwvl) { QVector ref_xvals = rawdata.xvalues; - int N = rawdata.scanCount() - nscans; - for (int ii = N; ii < rawdata.scanCount(); ii++) { - QVector ref_yvals = rawdata.scanData.at(ii).rvalues; + int N_ref = rawdata.scanCount() - nscans; + for (int ii = 0; ii < nscans; ii++) { + int II_ref = ii + N_ref; + int II_tgt = ii + N_tgt; + QVector ref_yvals = rawdata.scanData.at(II_ref).rvalues; if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { if (smooth > 0){ QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); @@ -1208,7 +1211,7 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { ref_yvals << yvals; } for (int jj = 0; jj < ref_yvals.size(); jj++) { - refscan_data[raw_id][ii][jj] = ref_yvals.at(jj); + refscan_data[raw_id][II_tgt][jj] = ref_yvals.at(jj); } } else { return false; diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index d81e0abdf..468604164 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -107,7 +107,7 @@ private slots: QTableWidget* tb_triple; QFont font; - const double maxAbs = 3; + const double maxAbs = 2; bool abs_plt_on; int nscans; int max_nscans; From 5ac1b1511fa7d496471453fc5f7e193afa6c371b Mon Sep 17 00:00:00 2001 From: samo38 Date: Mon, 17 Jun 2024 11:37:45 -0600 Subject: [PATCH 08/21] us_pseudo_absorbance/us_convert_scan: add scan counter, add aligning method to center all qwtcounters --- .../us_pseudo_absorbance/us_convert_scan.cpp | 57 ++++++++++++++----- .../us_pseudo_absorbance/us_convert_scan.h | 3 + 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 751bcc52b..933d9bea9 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -17,10 +17,10 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() imp_lyt_1->addWidget(pb_load_ref); imp_lyt_1->addWidget(pb_reset); - QLabel* lb_runIdInt = us_label("Run ID:"); + QLabel* lb_runIdInt = us_label("Run ID"); lb_runIdInt->setAlignment(Qt::AlignCenter); le_runid = us_lineedit("", 0, true ); - QLabel* lb_desc = us_label("Description:", 0 ); + QLabel* lb_desc = us_label("Description", 0 ); lb_desc->setAlignment(Qt::AlignCenter); le_desc = us_lineedit( "", 0, true); @@ -36,17 +36,13 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() import_lyt->addLayout(imp_lyt_2); // Cell / Channel / Wavelength - int width_lb = 90; - int width_ct = 90; QLabel* lb_buffer = us_banner("Absorbance Data Control"); QLabel* lb_scans = us_label("# Scans", 0); lb_scans->setAlignment(Qt::AlignCenter); - lb_scans->setFixedWidth(width_lb); QLabel *lb_smooth = us_label("Smooth", 0); lb_smooth->setAlignment(Qt::AlignCenter); - lb_smooth->setFixedWidth(width_lb); pb_apply = us_pushbutton("Apply"); @@ -54,19 +50,42 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() max_nscans = 1000; ct_scans = us_counter(1, 1, 1, nscans); ct_scans->setSingleStep(1); - ct_scans->setFixedWidth(width_ct); + align_center(ct_scans); smooth = 0; ct_smooth = us_counter(1, 0, 10, smooth); ct_smooth->setSingleStep(1); - ct_smooth->setFixedWidth(width_ct); + align_center(ct_smooth); - QHBoxLayout* ss_lyt = new QHBoxLayout(); - ss_lyt->addWidget(lb_scans); - ss_lyt->addWidget(ct_scans); - ss_lyt->addWidget(lb_smooth); - ss_lyt->addWidget(ct_smooth); - ss_lyt->addWidget(pb_apply); + QLabel* lb_scan_from = us_label("Scan Focus From:"); + lb_scan_from->setAlignment(Qt::AlignRight); + QLabel* lb_scan_to = us_label("To:"); + lb_scan_to->setAlignment(Qt::AlignRight); + + ct_scan_from = us_counter(3, 1, 1, 1); + ct_scan_from->setSingleStep(1); + align_center(ct_scan_from); + + ct_scan_to = us_counter(3, 1, 1, 1); + ct_scan_to->setSingleStep(1); + align_center(ct_scan_to); + + QGridLayout* scan_lyt = new QGridLayout(); + scan_lyt->addWidget(lb_scans, 0, 0, 1, 1); + scan_lyt->addWidget(ct_scans, 0, 1, 1, 1); + scan_lyt->addWidget(lb_smooth, 0, 2, 1, 1); + scan_lyt->addWidget(ct_smooth, 0, 3, 1, 1); + scan_lyt->addWidget(pb_apply, 0, 4, 1, 1); + + scan_lyt->addWidget(lb_scan_from, 1, 0, 1, 2); + scan_lyt->addWidget(ct_scan_from, 1, 2, 1, 3); + + scan_lyt->addWidget(lb_scan_to, 2, 0, 1, 2); + scan_lyt->addWidget(ct_scan_to, 2, 2, 1, 3); + + for(int ii = 0; ii < scan_lyt->columnCount(); ii++) { + scan_lyt->setColumnMinimumWidth(ii, 90); + } tb_triple = new QTableWidget(); tb_triple->setRowCount(0); @@ -85,7 +104,8 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QVBoxLayout* ccw_lyt = new QVBoxLayout(); ccw_lyt->addWidget(lb_buffer); - ccw_lyt->addLayout(ss_lyt); + ccw_lyt->addLayout(scan_lyt); + ccw_lyt->addSpacing(1); ccw_lyt->addWidget(tb_triple); static QChar clambda( 955 ); // Lambda character @@ -232,6 +252,13 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); } +void US_ConvertScan::align_center(QwtCounter* ct) { + QLineEdit *le = ct->findChild(); + if (le) { + le->setAlignment(Qt::AlignCenter); + } +} + void US_ConvertScan::reset(){ picker_abs->disconnect(); tb_triple->disconnect(); diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 468604164..37baabbc3 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -103,6 +103,8 @@ private slots: QwtCounter* ct_smooth; QwtCounter* ct_scans; + QwtCounter* ct_scan_from; + QwtCounter* ct_scan_to; QTableWidget* tb_triple; QFont font; @@ -138,6 +140,7 @@ private slots: void disconnect_picker(); bool set_abs_runid(QString&); void set_ct_scans(int = 0); + void align_center(QwtCounter*); }; From cb89fc50d1cfc4b5333e889a590c5218ca0838bf Mon Sep 17 00:00:00 2001 From: samo38 Date: Mon, 17 Jun 2024 11:42:21 -0600 Subject: [PATCH 09/21] us_pseudo_absorbance/us_convert_scan: set back a fixed size to scan counters --- programs/us_pseudo_absorbance/us_convert_scan.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 933d9bea9..82fe38c72 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -36,13 +36,17 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() import_lyt->addLayout(imp_lyt_2); // Cell / Channel / Wavelength + int width_lb = 90; + int width_ct = 90; QLabel* lb_buffer = us_banner("Absorbance Data Control"); QLabel* lb_scans = us_label("# Scans", 0); lb_scans->setAlignment(Qt::AlignCenter); + lb_scans->setFixedWidth(width_lb); QLabel *lb_smooth = us_label("Smooth", 0); lb_smooth->setAlignment(Qt::AlignCenter); + lb_smooth->setFixedWidth(width_lb); pb_apply = us_pushbutton("Apply"); @@ -50,11 +54,13 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() max_nscans = 1000; ct_scans = us_counter(1, 1, 1, nscans); ct_scans->setSingleStep(1); + ct_scans->setFixedWidth(width_ct); align_center(ct_scans); smooth = 0; ct_smooth = us_counter(1, 0, 10, smooth); ct_smooth->setSingleStep(1); + ct_smooth->setFixedWidth(width_ct); align_center(ct_smooth); QLabel* lb_scan_from = us_label("Scan Focus From:"); From 387ab019c3818475c24170f8d9d30aff7348d0d3 Mon Sep 17 00:00:00 2001 From: samo38 Date: Mon, 17 Jun 2024 19:39:36 -0600 Subject: [PATCH 10/21] us_pseudo_absorbance/us_convert_scan: add lower_scan_range and upper_scan_range to handle scan control and edit the saving function in order to support it --- .../us_pseudo_absorbance/us_convert_scan.cpp | 91 ++++++++++++++----- .../us_pseudo_absorbance/us_convert_scan.h | 2 + 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 82fe38c72..4b9b53213 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -68,11 +68,11 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QLabel* lb_scan_to = us_label("To:"); lb_scan_to->setAlignment(Qt::AlignRight); - ct_scan_from = us_counter(3, 1, 1, 1); + ct_scan_from = us_counter(2, 1, 1, 1); ct_scan_from->setSingleStep(1); align_center(ct_scan_from); - ct_scan_to = us_counter(3, 1, 1, 1); + ct_scan_to = us_counter(2, 1, 1, 1); ct_scan_to->setSingleStep(1); align_center(ct_scan_to); @@ -304,6 +304,21 @@ void US_ConvertScan::apply_scan_smooth() { calc_absorbance(ii); } QGuiApplication::restoreOverrideCursor(); + + ct_scan_from->disconnect(); + ct_scan_to->disconnect(); + double cv = ct_scans->value(); + ct_scan_from->setMaximum(cv); + ct_scan_to->setMaximum(cv); + if (ct_scan_from->value() > cv) { + ct_scan_from->setValue(cv); + } + if (ct_scan_to->value() > cv) { + ct_scan_to->setValue(cv); + } + connect(ct_scan_from, &QwtCounter::valueChanged, this, &US_ConvertScan::lower_scan_range); + connect(ct_scan_to, &QwtCounter::valueChanged, this, &US_ConvertScan::upper_scan_range); + emit sig_plot(); } @@ -448,10 +463,15 @@ void US_ConvertScan::import_run(){ void US_ConvertScan::set_ct_scans(int maxval) { ct_scans->disconnect(); + if (maxval == 0) { max_nscans = 1000; ct_scans->setValid(1); ct_scans->setMaximum(1); + ct_scan_from->disconnect(); + ct_scan_to->disconnect(); + ct_scan_from->setMaximum(1); + ct_scan_to->setMaximum(1); } else { int cv = ct_scans->value(); max_nscans = maxval; @@ -465,6 +485,24 @@ void US_ConvertScan::set_ct_scans(int maxval) { connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); } +void US_ConvertScan::lower_scan_range(double value) { + if (value > ct_scan_to->value()) { + ct_scan_to->disconnect(); + ct_scan_to->setValue(value); + connect(ct_scan_to, &QwtCounter::valueChanged, this, &US_ConvertScan::upper_scan_range); + } + emit sig_plot(); +} + +void US_ConvertScan::upper_scan_range(double value) { + if (value < ct_scan_from->value()) { + ct_scan_from->disconnect(); + ct_scan_from->setValue(value); + connect(ct_scan_from, &QwtCounter::valueChanged, this, &US_ConvertScan::lower_scan_range); + } + emit sig_plot(); +} + void US_ConvertScan::prev_id(){ --wavl_id; cb_plot_id->setCurrentIndex(wavl_id); @@ -762,10 +800,12 @@ void US_ConvertScan::save_run() { } else { US_DataIO::RawData rawdata = intensity_data.at(rid); int N = absorbance_data.at(rid).size() - nscans; - QVector> absorbance = absorbance_data.at(rid).mid(N); - QVector shifts = absorbance_shifts.at(rid).mid(N); - QVector scans = rawdata.scanData.mid(N); - for (int mm = 0; mm < nscans; mm++) { + int pos = ct_scan_from->value() - 1 + N; + int len = ct_scan_to->value() + N - pos; + QVector> absorbance = absorbance_data.at(rid).mid(pos, len); + QVector shifts = absorbance_shifts.at(rid).mid(pos, len); + QVector scans = rawdata.scanData.mid(pos, len); + for (int mm = 0; mm < absorbance.size(); mm++) { int np = absorbance.at(mm).size(); for (int nn = 0; nn < np; nn++) { double val = absorbance.at(mm).at(nn); @@ -983,15 +1023,11 @@ void US_ConvertScan::plot_intensity(){ int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); US_DataIO::RawData raw_data = intensity_data.at(raw_id); - int nn = raw_data.scanCount() - nscans; - if (nn < 0) { - nn = 0; - } - int ns = raw_data.scanCount() - nn; + int N = raw_data.scanCount() - nscans; QPen pen_plot(Qt::yellow); pen_plot.setWidth(1); - double rb = qCeil(ns / 50.0); - int nc = qCeil(ns / rb); + double rb = qCeil(nscans / 50.0); + int nc = qCeil(nscans / rb); HSVcolormap colormap(nc); QVector colorList; int error = colormap.get_colorlist(colorList); @@ -1004,8 +1040,11 @@ void US_ConvertScan::plot_intensity(){ double min_r = 1e20; double max_r = -1e20; int np = raw_data.pointCount(); - for (int ii = nn; ii < raw_data.scanCount(); ++ii){ - r = raw_data.scanData.at(ii).rvalues.data(); + int ii_0 = ct_scan_from->value() - 1; + int ii_1 = ct_scan_to->value(); + int cnt = 0; + for (int ii = ii_0; ii < ii_1; ++ii){ + r = raw_data.scanData.at(N + ii).rvalues.data(); for (int j = 0; j < np; ++j){ min_x = qMin(min_x, x[j]); max_x = qMax(max_x, x[j]); @@ -1014,9 +1053,10 @@ void US_ConvertScan::plot_intensity(){ } QwtPlotCurve* curve = us_curve( qwtplot_insty,""); if (error == 0) - pen_plot.setColor(colorList[ ii % nc ]); + pen_plot.setColor(colorList[ cnt % nc ]); curve->setPen( pen_plot ); curve->setSamples(x, r, np); + cnt++; } grid = us_grid(qwtplot_insty); @@ -1090,12 +1130,10 @@ void US_ConvertScan::plot_absorbance(){ double x_1 = ccw_items.at(row).minmax_x.first; double x_2 = ccw_items.at(row).minmax_x.second; - int nn = absorbance_data.at(raw_id).size() - nscans; - if (nn < 0) { - nn = 0; - } - QVector> absorbance = absorbance_data.at(raw_id).mid(nn); - QVector shifts = absorbance_shifts.at(raw_id).mid(nn); + int N = absorbance_data.at(raw_id).size() - nscans; + + QVector> absorbance = absorbance_data.at(raw_id).mid(N); + QVector shifts = absorbance_shifts.at(raw_id).mid(N); if (x_1 > 0 && x_2 > 0) { for (int ii = 0; ii < absorbance.size(); ii++) { for (int jj = 0; jj < absorbance.at(ii).size(); jj++) { @@ -1125,7 +1163,11 @@ void US_ConvertScan::plot_absorbance(){ int np = xvalues.size(); int l1 = np * 0.2; int l2 = np * 0.8; - for (int ii = 0; ii < ns; ++ii){ + + int ii_0 = ct_scan_from->value() - 1; + int ii_1 = ct_scan_to->value(); + int cnt = 0; + for (int ii = ii_0; ii < ii_1; ++ii){ rp = absorbance.at(ii).data(); for (int jj = 0; jj < np; ++jj) if (jj > l1 && jj < l2){ @@ -1134,9 +1176,10 @@ void US_ConvertScan::plot_absorbance(){ } QwtPlotCurve* curve = us_curve( qwtplot_abs,""); if (error == 0) - pen_plot.setColor(colorList[ ii % nc ]); + pen_plot.setColor(colorList[ cnt % nc ]); curve->setPen( pen_plot ); curve->setSamples(xp, rp, np); + cnt++; } grid = us_grid(qwtplot_abs); double dr = (max_r - min_r) * 0.05; diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 37baabbc3..5ceda9507 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -43,6 +43,8 @@ private slots: void pick_region(void); void mouse_click(const QwtDoublePoint&); void default_region(); + void lower_scan_range(double); + void upper_scan_range(double); private: From 8b78c5be2ab986f27d79ed3eb793c85c925ea254 Mon Sep 17 00:00:00 2001 From: samo38 Date: Tue, 18 Jun 2024 09:57:20 -0600 Subject: [PATCH 11/21] us_pseudo_absorbance/us_convert_scan: add functions to load a run from both local disk and database --- .../us_pseudo_absorbance/us_convert_scan.cpp | 123 +++++++++++------- .../us_pseudo_absorbance/us_convert_scan.h | 3 + 2 files changed, 79 insertions(+), 47 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 4b9b53213..679352daf 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -1,4 +1,5 @@ #include "us_convert_scan.h" +#include "us_load_auc.h" #include US_ConvertScan::US_ConvertScan() : US_Widgets() @@ -7,6 +8,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() font = QFont( US_Widgets::fixedFont().family(), US_GuiSettings::fontSize() ); // font.setPointSize(font.pointSize() - 1); + disk_controls = new US_Disk_DB_Controls; QLabel* lb_runInfoInt = us_banner("Intensity Data Control"); pb_import = us_pushbutton("Import Run"); pb_reset = us_pushbutton("Reset"); @@ -32,6 +34,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QVBoxLayout* import_lyt = new QVBoxLayout(); import_lyt->addWidget(lb_runInfoInt); + import_lyt->addLayout(disk_controls); import_lyt->addLayout(imp_lyt_1); import_lyt->addLayout(imp_lyt_2); @@ -322,43 +325,47 @@ void US_ConvertScan::apply_scan_smooth() { emit sig_plot(); } -void US_ConvertScan::import_run(){ - QString dir; - - dir = QFileDialog::getExistingDirectory( this, - tr( "Open Run ID" ), - US_Settings::importDir(), - QFileDialog::DontResolveSymlinks ); - - if (dir.isEmpty()) return; +int US_ConvertScan::read_auc(QVector& rawdata, + QVector>>& absorbance, + QVector>>& refscans, + QVector>& shifts, QString& dir) { QDir inDir = QDir( dir, "*.auc", QDir::Name, QDir::Files | QDir::Readable ); if (inDir.count() == 0){ le_status->setText("auc files not found!"); - return; + return -1; } - inDir.makeAbsolute(); - le_status->setText("parsing files!"); - QFileInfoList fileList = inDir.entryInfoList(); - QStringList bad_files; - QString run_id; - QString run_type; - QStringList run_type_avail{"RI"}; + QFileInfo finfo(dir); + QString run_id = finfo.baseName(); QRegExp re( "[^A-Za-z0-9_-]" ); - bool runId_changed = false; - // QString ccw_str("%1 / %2 / %3"); + bool run_id_changed = false; + int reIdx = run_id.indexOf(re, 0); + if (reIdx >=0) { + run_id_changed = true; + } + while (reIdx >=0){ + run_id = run_id.replace(reIdx, 1, "_"); + reIdx = run_id.indexOf(re, reIdx); + } - QVector rawdata; - QVector>> absorbance; - QVector>> refscans; - QVector> shifts; - // QStringList fnames; QStringList loaded_runids; foreach (CellChannel cc, ccw_items) { loaded_runids << cc.runid; } + if (loaded_runids.contains(run_id)) { + QMessageBox::warning( this, tr( "Error" ), + tr( "The RunID (%1) is already loaded!" ).arg(run_id)); + return -1; + } + inDir.makeAbsolute(); + le_status->setText("parsing files!"); + QFileInfoList fileList = inDir.entryInfoList(); + QStringList bad_files; + QString run_type; + QStringList run_type_avail{"RI"}; + // QStringList fnames; int maxscans = 1000000; for (int ii = 0; ii < fileList.size(); ++ii){ @@ -369,30 +376,28 @@ void US_ConvertScan::import_run(){ bad_files << fn; continue; } - if (rdata.scanCount() == 0) continue; + if (rdata.scanCount() == 0) { + bad_files << fn; + continue; + } QString rtp = QChar::fromLatin1(rdata.type[0]); rtp.append(QChar::fromLatin1(rdata.type[1])); QString rid = fn.section(".", 0, -6); int reIdx = rid.indexOf(re, 0); - if (reIdx >=0) runId_changed = true; while (reIdx >=0){ rid = rid.replace(reIdx, 1, "_"); reIdx = rid.indexOf(re, reIdx); } - if (run_id.isEmpty()) { - run_id = rid; - } else { - if (run_id != rid) { - QMessageBox::warning( this, tr( "Warning!" ), - tr( "Multiple RunIDs Found!")); - return; - } + if (run_id != rid) { + QMessageBox::warning( this, tr( "Warning!" ), + tr( "Multiple RunIDs Found!")); + return -1; } if (! run_type_avail.contains(rtp)){ QMessageBox::warning( this, tr( "Error" ), tr( "The Run type (%1) is not supported!" ).arg(rtp)); - return; + return -1; } if (run_type.isEmpty()){ run_type = rtp; @@ -400,14 +405,10 @@ void US_ConvertScan::import_run(){ if (run_type != rtp){ QMessageBox::warning( this, tr( "Error" ), tr( "Multiple run types are found in the directory!" )); - return; + return -1; } } - if (loaded_runids.contains(run_id)) { - QMessageBox::warning( this, tr( "Error" ), - tr( "The RunID (%1) is already loaded!" ).arg(run_id)); - return; - } + rawdata << rdata; // fnames << fn; int ns = rdata.scanCount(); @@ -426,7 +427,7 @@ void US_ConvertScan::import_run(){ shifts << sh; } - if ( runId_changed ) { + if ( run_id_changed ) { QMessageBox::warning( this, tr( "Warning!" ), tr( "The RunID changed. It can only have alphanumeric," "underscore, and hyphen characters.")); @@ -438,27 +439,55 @@ void US_ConvertScan::import_run(){ } if (rawdata.isEmpty()) { + return -1; + } + + return maxscans; + +} + +void US_ConvertScan::import_run() { + QVector rawdata; + QVector>> absorbance; + QVector>> refscans; + QVector> shifts; + QString workingDir; + + if (disk_controls->db()) { + QVector< US_DataIO::RawData > allData; + QStringList triples; + US_LoadAUC* dialog = new US_LoadAUC( false, allData, triples, workingDir ); + if ( dialog->exec() == QDialog::Rejected ) return; + } else { + workingDir = QFileDialog::getExistingDirectory( this, + tr( "Open Run ID" ), + US_Settings::importDir(), + QFileDialog::DontResolveSymlinks ); + if (workingDir.isEmpty()) return; + } + + int maxscn = read_auc(rawdata, absorbance, refscans, shifts, workingDir); + if (maxscn == -1) { return; } QVector states(rawdata.size(), -1); - intensity_data << rawdata; absorbance_data << absorbance; absorbance_state << states; absorbance_shifts << shifts; refscan_data << refscans; - list_ccw_items(run_id); + list_ccw_items(workingDir); set_table(); set_wavl_ctrl(); pb_reset->setEnabled(true); hasData = true; le_status->clear(); - maxscans = qMin(max_nscans, maxscans); - set_ct_scans(maxscans); - return; + maxscn = qMin(max_nscans, maxscn); + set_ct_scans(maxscn); + } void US_ConvertScan::set_ct_scans(int maxval) { diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 5ceda9507..04aa4d00d 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -77,6 +77,7 @@ private slots: QPair minmax_x; }; + US_Disk_DB_Controls* disk_controls; QPushButton* pb_prev_id; QPushButton* pb_next_id; QPushButton* pb_import; @@ -143,6 +144,8 @@ private slots: bool set_abs_runid(QString&); void set_ct_scans(int = 0); void align_center(QwtCounter*); + int read_auc(QVector&, QVector>>&, + QVector>>&, QVector>&, QString&); }; From c7c5b4478c88723be486b5a5d555a1964f633448 Mon Sep 17 00:00:00 2001 From: samo38 Date: Tue, 18 Jun 2024 10:57:24 -0600 Subject: [PATCH 12/21] us_convert_scan: fixed the issue with loaded runid --- programs/us_pseudo_absorbance/us_convert_scan.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 679352daf..3da25bd54 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -328,15 +328,15 @@ void US_ConvertScan::apply_scan_smooth() { int US_ConvertScan::read_auc(QVector& rawdata, QVector>>& absorbance, QVector>>& refscans, - QVector>& shifts, QString& dir) { + QVector>& shifts, QString& working_dir) { - QDir inDir = QDir( dir, "*.auc", QDir::Name, QDir::Files | QDir::Readable ); + QDir inDir = QDir( working_dir, "*.auc", QDir::Name, QDir::Files | QDir::Readable ); if (inDir.count() == 0){ le_status->setText("auc files not found!"); return -1; } - QFileInfo finfo(dir); + QFileInfo finfo(working_dir); QString run_id = finfo.baseName(); QRegExp re( "[^A-Za-z0-9_-]" ); bool run_id_changed = false; @@ -441,7 +441,8 @@ int US_ConvertScan::read_auc(QVector& rawdata, if (rawdata.isEmpty()) { return -1; } - + working_dir.clear(); + working_dir = run_id; return maxscans; } From 9a4ea4b5f63a58059ce5531816f35544f1ccd9a6 Mon Sep 17 00:00:00 2001 From: samo38 Date: Tue, 18 Jun 2024 23:43:20 -0600 Subject: [PATCH 13/21] us_convert_scan: removed smoothing, added od threshol cotrol, added plotting both intensity and reference scan chechbox --- .../us_pseudo_absorbance/us_convert_scan.cpp | 150 +++++++++++------- .../us_pseudo_absorbance/us_convert_scan.h | 11 +- 2 files changed, 100 insertions(+), 61 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 3da25bd54..4534be002 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -39,37 +39,47 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() import_lyt->addLayout(imp_lyt_2); // Cell / Channel / Wavelength - int width_lb = 90; - int width_ct = 90; + int width_lb = 150; + int width_ct = 150; QLabel* lb_buffer = us_banner("Absorbance Data Control"); QLabel* lb_scans = us_label("# Scans", 0); lb_scans->setAlignment(Qt::AlignCenter); lb_scans->setFixedWidth(width_lb); - QLabel *lb_smooth = us_label("Smooth", 0); - lb_smooth->setAlignment(Qt::AlignCenter); - lb_smooth->setFixedWidth(width_lb); + // QLabel *lb_smooth = us_label("Smooth", 0); + // lb_smooth->setAlignment(Qt::AlignCenter); + // lb_smooth->setFixedWidth(width_lb); + + QLabel *lb_maxod = us_label("Max OD", 0); + lb_maxod->setAlignment(Qt::AlignCenter); + lb_maxod->setFixedWidth(width_lb); pb_apply = us_pushbutton("Apply"); nscans = 1; max_nscans = 1000; - ct_scans = us_counter(1, 1, 1, nscans); + ct_scans = us_counter(2, 1, 1, nscans); ct_scans->setSingleStep(1); ct_scans->setFixedWidth(width_ct); align_center(ct_scans); smooth = 0; - ct_smooth = us_counter(1, 0, 10, smooth); - ct_smooth->setSingleStep(1); - ct_smooth->setFixedWidth(width_ct); - align_center(ct_smooth); - - QLabel* lb_scan_from = us_label("Scan Focus From:"); - lb_scan_from->setAlignment(Qt::AlignRight); - QLabel* lb_scan_to = us_label("To:"); - lb_scan_to->setAlignment(Qt::AlignRight); + // ct_smooth = us_counter(2, 0, 10, smooth); + // ct_smooth->setSingleStep(1); + // ct_smooth->setFixedWidth(width_ct); + // align_center(ct_smooth); + + max_OD = 2.0; + ct_maxod = us_counter(2, 0, 10, max_OD); + ct_maxod->setSingleStep(0.1); + ct_maxod->setFixedWidth(width_ct); + align_center(ct_maxod); + + QLabel* lb_scan_from = us_label("Scans From"); + lb_scan_from->setAlignment(Qt::AlignCenter); + QLabel* lb_scan_to = us_label("Scans To"); + lb_scan_to->setAlignment(Qt::AlignCenter); ct_scan_from = us_counter(2, 1, 1, 1); ct_scan_from->setSingleStep(1); @@ -82,19 +92,17 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QGridLayout* scan_lyt = new QGridLayout(); scan_lyt->addWidget(lb_scans, 0, 0, 1, 1); scan_lyt->addWidget(ct_scans, 0, 1, 1, 1); - scan_lyt->addWidget(lb_smooth, 0, 2, 1, 1); - scan_lyt->addWidget(ct_smooth, 0, 3, 1, 1); - scan_lyt->addWidget(pb_apply, 0, 4, 1, 1); - - scan_lyt->addWidget(lb_scan_from, 1, 0, 1, 2); - scan_lyt->addWidget(ct_scan_from, 1, 2, 1, 3); + // scan_lyt->addWidget(lb_smooth, 1, 0, 1, 1); + // scan_lyt->addWidget(ct_smooth, 1, 1, 1, 1); + scan_lyt->addWidget(pb_apply, 1, 2, 1, 1); + scan_lyt->addWidget(lb_maxod, 1, 0, 1, 1); + scan_lyt->addWidget(ct_maxod, 1, 1, 1, 1); - scan_lyt->addWidget(lb_scan_to, 2, 0, 1, 2); - scan_lyt->addWidget(ct_scan_to, 2, 2, 1, 3); + scan_lyt->addWidget(lb_scan_from, 2, 0, 1, 1); + scan_lyt->addWidget(ct_scan_from, 2, 1, 1, 2); - for(int ii = 0; ii < scan_lyt->columnCount(); ii++) { - scan_lyt->setColumnMinimumWidth(ii, 90); - } + scan_lyt->addWidget(lb_scan_to, 3, 0, 1, 1); + scan_lyt->addWidget(ct_scan_to, 3, 1, 1, 2); tb_triple = new QTableWidget(); tb_triple->setRowCount(0); @@ -209,6 +217,10 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() plot_title->setStyleSheet("background-color: white;" "color:black; font-size: 11pt"); + chkb_abs_int = new QCheckBox(); + QGridLayout* chkb_lyt = us_checkbox("Plot Both Intensity and Reference scans", chkb_abs_int); + chkb_lyt->setAlignment(Qt::AlignCenter); + QwtText xLabel, yLabel; usplot_insty = new US_Plot( qwtplot_insty, tr( "" ), tr( "Radius (in cm)" ), tr( "Intensity" ), @@ -231,6 +243,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() QVBoxLayout* right_lyt = new QVBoxLayout(); right_lyt->setSpacing(0); right_lyt->addWidget(plot_title); + right_lyt->addLayout(chkb_lyt); right_lyt->addLayout(usplot_insty); right_lyt->addLayout(usplot_abs); @@ -256,9 +269,16 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(pb_next_id, &QPushButton::clicked, this, &US_ConvertScan::next_id); connect(pb_save, &QPushButton::clicked, this, &US_ConvertScan::save_run); connect(pb_pick_rp, &QPushButton::clicked, this, &US_ConvertScan::pick_region); - connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_scan_smooth); + connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_nscans); connect(pb_default, &QPushButton::clicked, this, &US_ConvertScan::default_region); - connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + // connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + connect(ct_maxod, &QwtCounter::valueChanged, this, &US_ConvertScan::update_nscans); + connect(chkb_abs_int, &QCheckBox::stateChanged, this, &US_ConvertScan::plot_ref_state); +} + +void US_ConvertScan::plot_ref_state() { + plot_intensity(); + plot_refscan(); } void US_ConvertScan::align_center(QwtCounter* ct) { @@ -292,16 +312,17 @@ void US_ConvertScan::reset(){ set_wavl_ctrl(); } -void US_ConvertScan::update_scan_smooth() { +void US_ConvertScan::update_nscans() { pb_apply->setStyleSheet("QPushButton { background-color: red }"); } -void US_ConvertScan::apply_scan_smooth() { +void US_ConvertScan::apply_nscans() { QColor color = US_GuiSettings::pushbColor().color(QPalette::Active, QPalette::Button); QString qs = "QPushButton { background-color: %1 }"; pb_apply->setStyleSheet(qs.arg(color.name())); nscans = static_cast(ct_scans->value()); - smooth = static_cast(ct_smooth->value()); + max_OD = ct_maxod->value(); + // smooth = static_cast(ct_smooth->value()); QGuiApplication::setOverrideCursor(Qt::WaitCursor); for (int ii = 0; ii < ccw_items.size(); ii++) { calc_absorbance(ii); @@ -508,11 +529,11 @@ void US_ConvertScan::set_ct_scans(int maxval) { ct_scans->setMaximum(max_nscans); if (cv > max_nscans) { cv = max_nscans; - apply_scan_smooth(); + apply_nscans(); } ct_scans->setValue(cv); } - connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); + connect(ct_scans, &QwtCounter::valueChanged, this, &US_ConvertScan::update_nscans); } void US_ConvertScan::lower_scan_range(double value) { @@ -1052,6 +1073,10 @@ void US_ConvertScan::plot_intensity(){ } int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + bool flag = chkb_abs_int->isChecked(); + flag = flag && (absorbance_state.at(raw_id) >= 0 && absorbance_state.at(raw_id) < 100); + flag = !flag; + US_DataIO::RawData raw_data = intensity_data.at(raw_id); int N = raw_data.scanCount() - nscans; QPen pen_plot(Qt::yellow); @@ -1081,9 +1106,11 @@ void US_ConvertScan::plot_intensity(){ min_r = qMin(min_r, r[j]); max_r = qMax(max_r, r[j]); } - QwtPlotCurve* curve = us_curve( qwtplot_insty,""); - if (error == 0) + QwtPlotCurve* curve = us_curve( qwtplot_insty, tr("Intensity %1").arg(cnt + 1)); + pen_plot.setColor(QColor(Qt::red)); + if (flag && error == 0) { pen_plot.setColor(colorList[ cnt % nc ]); + } curve->setPen( pen_plot ); curve->setSamples(x, r, np); cnt++; @@ -1102,8 +1129,8 @@ void US_ConvertScan::plot_intensity(){ void US_ConvertScan::plot_refscan(){ if (ccw_items.isEmpty()) return; - QVector yvalues; QVector xvalues; + QVector> yvalues; if (plot_ref_file >= 0) { le_runid->clear(); le_desc->setText(refscan_files.at(plot_ref_file).filename); @@ -1111,35 +1138,44 @@ void US_ConvertScan::plot_refscan(){ yvalues << refscan_files.at(plot_ref_file).yvalues.at(wavl_id); } else { int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); - if (absorbance_state.at(raw_id) < 100) { + if (absorbance_state.at(raw_id) == -1) { + return; + } + if (absorbance_state.at(raw_id) < 100 && !chkb_abs_int->isChecked()) { return; } xvalues << intensity_data.at(raw_id).xvalues; - yvalues << refscan_data.at(raw_id).last(); - } - - if (xvalues.size() != yvalues.size()) { - QMessageBox::warning(this, "Warning!", "Number of the radial points and intesity values" - " in the reference scan don't match!"); - return; + int N = absorbance_data.at(raw_id).size() - nscans; + QVector> refscan = refscan_data.at(raw_id).mid(N); + int ii_0 = ct_scan_from->value() - 1; + int ii_1 = ct_scan_to->value(); + yvalues << refscan.at(ii_0); + ii_0++; + if (absorbance_state.at(raw_id) < 100) { + for (int ii = ii_0; ii < ii_1; ++ii){ + yvalues << refscan.at(ii); + } + } } - QPen pen = QPen( QBrush( Qt::white ), 2.0 ); + QPen pen = QPen( QBrush( Qt::white ), 1. ); double min_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).lowerBound(); double max_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).upperBound(); const double *xp, *rp; xp = xvalues.data(); - rp = yvalues.data(); int np = xvalues.size(); - for (int ii = 0; ii < np; ++ii){ - min_r = qMin(min_r, rp[ii]); - max_r = qMax(max_r, rp[ii]); + for (int ii = 0; ii < yvalues.size(); ii++) { + rp = yvalues.at(ii).data(); + for (int jj = 0; jj < np; ++jj){ + min_r = qMin(min_r, rp[jj]); + max_r = qMax(max_r, rp[jj]); + } + QwtPlotCurve* curve = us_curve( qwtplot_insty, tr("Reference %1").arg(ii + 1)); + curve->setPen(pen); + curve->setSamples(xp, rp, np); } - QwtPlotCurve* curve = us_curve( qwtplot_insty,""); - curve->setPen(pen); - curve->setSamples(xp, rp, np); double dr = (max_r - min_r) * 0.05; qwtplot_insty->setAxisScale( QwtPlot::yLeft , min_r - dr, max_r + dr); qwtplot_insty->updateAxes(); @@ -1204,7 +1240,7 @@ void US_ConvertScan::plot_absorbance(){ min_r = qMin(min_r, rp[jj]); max_r = qMax(max_r, rp[jj]); } - QwtPlotCurve* curve = us_curve( qwtplot_abs,""); + QwtPlotCurve* curve = us_curve( qwtplot_abs, tr("Absorbance %1").arg(cnt + 1)); if (error == 0) pen_plot.setColor(colorList[ cnt % nc ]); curve->setPen( pen_plot ); @@ -1273,7 +1309,7 @@ bool US_ConvertScan::get_refval_file(int ref_id, int raw_id) { QVector ref_yvals = refscan_files.at(ref_id).yvalues.at(ii); if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { if (smooth > 0){ - QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); + QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, max_OD); ref_yvals.clear(); ref_yvals << yvals; } @@ -1312,7 +1348,7 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { QVector ref_yvals = rawdata.scanData.at(II_ref).rvalues; if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { if (smooth > 0){ - QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, maxAbs); + QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, max_OD); ref_yvals.clear(); ref_yvals << yvals; } @@ -1381,8 +1417,8 @@ void US_ConvertScan::calc_absorbance(int item_row){ val = 1e-5; } val = std::log10(val); - if (val > maxAbs) val = maxAbs; - else if (val < -maxAbs) val = -maxAbs; + if (val > max_OD) val = max_OD; + else if (val < -max_OD) val = -max_OD; absorbance_data[rid][jj][kk] = val; if (shift && x >= x_1 && x <= x_2) { miny = qMin(miny, val); diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 04aa4d00d..63b033de5 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -37,14 +37,15 @@ private slots: void next_id(); void plot_all(); void select_refscan(int); - void update_scan_smooth(); - void apply_scan_smooth(); + void update_nscans(); + void apply_nscans(); void save_run(void); void pick_region(void); void mouse_click(const QwtDoublePoint&); void default_region(); void lower_scan_range(double); void upper_scan_range(double); + void plot_ref_state(); private: @@ -103,8 +104,10 @@ private slots: QwtPlot* qwtplot_insty; QwtPlot* qwtplot_abs; QwtPlotGrid* grid; + QCheckBox* chkb_abs_int; - QwtCounter* ct_smooth; + // QwtCounter* ct_smooth; + QwtCounter* ct_maxod; QwtCounter* ct_scans; QwtCounter* ct_scan_from; QwtCounter* ct_scan_to; @@ -112,7 +115,7 @@ private slots: QTableWidget* tb_triple; QFont font; - const double maxAbs = 2; + double max_OD = 2; bool abs_plt_on; int nscans; int max_nscans; From 5d0399d4f33e191ae5f8ca3d2458f862918c0cee Mon Sep 17 00:00:00 2001 From: samo38 Date: Wed, 19 Jun 2024 09:28:45 -0600 Subject: [PATCH 14/21] us_convert_scan: debug max_OD issue --- .../us_pseudo_absorbance/us_convert_scan.cpp | 63 +++++++++++-------- .../us_pseudo_absorbance/us_convert_scan.h | 5 +- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 4534be002..4ca0e3b33 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -70,10 +70,9 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() // ct_smooth->setFixedWidth(width_ct); // align_center(ct_smooth); - max_OD = 2.0; - ct_maxod = us_counter(2, 0, 10, max_OD); + ct_maxod = us_counter(2, 0.1, 10, 2.0); ct_maxod->setSingleStep(0.1); - ct_maxod->setFixedWidth(width_ct); + // ct_maxod->setFixedWidth(width_ct); align_center(ct_maxod); QLabel* lb_scan_from = us_label("Scans From"); @@ -94,9 +93,9 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() scan_lyt->addWidget(ct_scans, 0, 1, 1, 1); // scan_lyt->addWidget(lb_smooth, 1, 0, 1, 1); // scan_lyt->addWidget(ct_smooth, 1, 1, 1, 1); - scan_lyt->addWidget(pb_apply, 1, 2, 1, 1); + scan_lyt->addWidget(pb_apply, 0, 2, 1, 1); scan_lyt->addWidget(lb_maxod, 1, 0, 1, 1); - scan_lyt->addWidget(ct_maxod, 1, 1, 1, 1); + scan_lyt->addWidget(ct_maxod, 1, 1, 1, 2); scan_lyt->addWidget(lb_scan_from, 2, 0, 1, 1); scan_lyt->addWidget(ct_scan_from, 2, 1, 1, 2); @@ -272,7 +271,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(pb_apply, &QPushButton::clicked, this, &US_ConvertScan::apply_nscans); connect(pb_default, &QPushButton::clicked, this, &US_ConvertScan::default_region); // connect(ct_smooth, &QwtCounter::valueChanged, this, &US_ConvertScan::update_scan_smooth); - connect(ct_maxod, &QwtCounter::valueChanged, this, &US_ConvertScan::update_nscans); + connect(ct_maxod, &QwtCounter::valueChanged, this, &US_ConvertScan::plot_absorbance); connect(chkb_abs_int, &QCheckBox::stateChanged, this, &US_ConvertScan::plot_ref_state); } @@ -321,7 +320,6 @@ void US_ConvertScan::apply_nscans() { QString qs = "QPushButton { background-color: %1 }"; pb_apply->setStyleSheet(qs.arg(color.name())); nscans = static_cast(ct_scans->value()); - max_OD = ct_maxod->value(); // smooth = static_cast(ct_smooth->value()); QGuiApplication::setOverrideCursor(Qt::WaitCursor); for (int ii = 0; ii < ccw_items.size(); ii++) { @@ -856,16 +854,11 @@ void US_ConvertScan::save_run() { QVector> absorbance = absorbance_data.at(rid).mid(pos, len); QVector shifts = absorbance_shifts.at(rid).mid(pos, len); QVector scans = rawdata.scanData.mid(pos, len); + trim_absorbance(absorbance, shifts, shift); for (int mm = 0; mm < absorbance.size(); mm++) { - int np = absorbance.at(mm).size(); - for (int nn = 0; nn < np; nn++) { - double val = absorbance.at(mm).at(nn); - if (shift) { - val += shifts.at(mm); - } - scans[mm].rvalues[nn] = val; - } scans[mm].stddevs.clear(); + scans[mm].rvalues.clear(); + scans[mm].rvalues << absorbance.at(mm); } rawdata.scanData.clear(); rawdata.scanData << scans; @@ -1199,14 +1192,13 @@ void US_ConvertScan::plot_absorbance(){ int N = absorbance_data.at(raw_id).size() - nscans; QVector> absorbance = absorbance_data.at(raw_id).mid(N); - QVector shifts = absorbance_shifts.at(raw_id).mid(N); + QVector shift = absorbance_shifts.at(raw_id).mid(N); + bool state = false; if (x_1 > 0 && x_2 > 0) { - for (int ii = 0; ii < absorbance.size(); ii++) { - for (int jj = 0; jj < absorbance.at(ii).size(); jj++) { - absorbance[ii][jj] += shifts.at(ii); - } - } + state = true; } + trim_absorbance(absorbance, shift, state); + QVector xvalues = intensity_data.at(raw_id).xvalues; double min_x = qwtplot_insty->axisScaleDiv(QwtPlot::xBottom).lowerBound(); @@ -1263,7 +1255,7 @@ void US_ConvertScan::plot_absorbance(){ } pen_plot.setWidth(3); pen_plot.setColor(QColor(Qt::yellow)); - QwtPlotCurve* curve = us_curve( qwtplot_abs,""); + QwtPlotCurve* curve = us_curve( qwtplot_abs,"left"); curve->setStyle(QwtPlotCurve::Dots); curve->setPen(pen_plot); curve->setSamples(xx.data(), yy.data(), np); @@ -1281,7 +1273,7 @@ void US_ConvertScan::plot_absorbance(){ } pen_plot.setWidth(3); pen_plot.setColor(QColor(Qt::yellow)); - QwtPlotCurve* curve = us_curve( qwtplot_abs,""); + QwtPlotCurve* curve = us_curve( qwtplot_abs,"right"); curve->setStyle(QwtPlotCurve::Dots); curve->setPen(pen_plot); curve->setSamples(xx.data(), yy.data(), np); @@ -1309,6 +1301,7 @@ bool US_ConvertScan::get_refval_file(int ref_id, int raw_id) { QVector ref_yvals = refscan_files.at(ref_id).yvalues.at(ii); if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { if (smooth > 0){ + double max_OD = ct_maxod->value(); QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, max_OD); ref_yvals.clear(); ref_yvals << yvals; @@ -1348,6 +1341,7 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { QVector ref_yvals = rawdata.scanData.at(II_ref).rvalues; if (linear_interpolation(xvals_tgt, ref_xvals, ref_yvals)) { if (smooth > 0){ + double max_OD = ct_maxod->value(); QVector yvals = smooth_refscan(ref_yvals, smooth, true, true, max_OD); ref_yvals.clear(); ref_yvals << yvals; @@ -1366,6 +1360,27 @@ bool US_ConvertScan::get_refval_buffer(int ref_row, int raw_id) { return ok; } +void US_ConvertScan::trim_absorbance(QVector>& absorbance, + QVector& shift, bool state) { + double max_OD = ct_maxod->value(); + int ns = absorbance.size(); + for (int ii = 0; ii < ns; ii++) { + int np = absorbance.at(ii).size(); + for (int jj = 0; jj < np; jj++) { + double val = absorbance.at(ii).at(jj); + if (state) { + val += shift.at(ii); + } + if (val > max_OD) { + val = max_OD; + } else if (val < -max_OD) { + val = -max_OD; + } + absorbance[ii][jj] = val; + } + } +} + void US_ConvertScan::calc_absorbance(int item_row){ if (ccw_items.isEmpty()) return; @@ -1417,8 +1432,6 @@ void US_ConvertScan::calc_absorbance(int item_row){ val = 1e-5; } val = std::log10(val); - if (val > max_OD) val = max_OD; - else if (val < -max_OD) val = -max_OD; absorbance_data[rid][jj][kk] = val; if (shift && x >= x_1 && x <= x_2) { miny = qMin(miny, val); diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 63b033de5..6137627da 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -36,6 +36,7 @@ private slots: void prev_id(); void next_id(); void plot_all(); + void plot_absorbance(); void select_refscan(int); void update_nscans(); void apply_nscans(); @@ -115,7 +116,6 @@ private slots: QTableWidget* tb_triple; QFont font; - double max_OD = 2; bool abs_plt_on; int nscans; int max_nscans; @@ -136,8 +136,9 @@ private slots: void offon_prev_next(); void plot_intensity(); void plot_refscan(); - void plot_absorbance(); + void calc_absorbance(int); + void trim_absorbance(QVector>&, QVector&, bool); void update_shifts(int); bool get_refval_file(int, int); bool get_refval_buffer(int, int); From a284a39dbe202c542e195f587432bab228936a78 Mon Sep 17 00:00:00 2001 From: samo38 Date: Wed, 19 Jun 2024 18:45:46 -0600 Subject: [PATCH 15/21] us_pseudo_absorbance/us_add_refScan: new GUI layout, add saving reference scans data into a csv file --- .../us_pseudo_absorbance/us_add_refScan.cpp | 192 +++++++++++------- .../us_pseudo_absorbance/us_add_refScan.h | 12 +- 2 files changed, 124 insertions(+), 80 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_add_refScan.cpp b/programs/us_pseudo_absorbance/us_add_refScan.cpp index 31810bf04..bbb0d809a 100644 --- a/programs/us_pseudo_absorbance/us_add_refScan.cpp +++ b/programs/us_pseudo_absorbance/us_add_refScan.cpp @@ -1,4 +1,5 @@ #include "us_add_refScan.h" +#include US_AddRefScan::US_AddRefScan() : US_Widgets() { @@ -64,6 +65,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() ckb_align->setCheckState(Qt::Unchecked); pb_clscltr = us_pushbutton("Clustering Control", false, 0 ); pb_clscltr->setDisabled(true); + pb_clscltr->setFixedWidth(150); QHBoxLayout* cls_aln_lyt = new QHBoxLayout(); cls_aln_lyt->addLayout(ckb_cls_lyt); @@ -73,7 +75,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() QLabel* lb_CA = us_banner(tr("Chromatic Aberration Correction")); ckb_CA_state = new QCheckBox(); QGridLayout* ckb_CA_state_lyt = us_checkbox("Do Not Correct", ckb_CA_state); - ckb_CA_state->setCheckState(Qt::Unchecked); + ckb_CA_state->setCheckState(Qt::Checked); ckb_CA_local = new QCheckBox(); QGridLayout* ckb_CA_source_lyt = us_checkbox("Local Disk", ckb_CA_local); ckb_CA_local->setCheckState(Qt::Unchecked); @@ -82,36 +84,48 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() ckb_CA_state->setDisabled(true); ckb_CA_local->setDisabled(true); pb_loadCA->setDisabled(true); - QHBoxLayout *CA_lyt = new QHBoxLayout(); - CA_lyt->addLayout(ckb_CA_state_lyt); - CA_lyt->addLayout(ckb_CA_source_lyt); - CA_lyt->addWidget(pb_loadCA); + // QHBoxLayout *CA_lyt = new QHBoxLayout(); + // CA_lyt->addLayout(ckb_CA_state_lyt); + // CA_lyt->addLayout(ckb_CA_source_lyt); + // CA_lyt->addWidget(pb_loadCA); + + lb_CA->hide(); + ckb_CA_state->hide(); + for (int ii = 0; ii < ckb_CA_state_lyt->count(); ii++) { + ckb_CA_state_lyt->itemAt(ii)->widget()->hide(); + } + for (int ii = 0; ii < ckb_CA_source_lyt->count(); ii++) { + ckb_CA_source_lyt->itemAt(ii)->widget()->hide(); + } + pb_loadCA->hide(); + // save refScan control - QLabel* lb_save = us_banner(tr("Saving Control")); - dkdb_ctrl = new US_Disk_DB_Controls(); - dkdb_ctrl->set_disk(); - - lb_dir = us_label( tr( "Directory:" ), -1 ); - le_dir = us_lineedit( US_Settings::importDir(), -1, true ); - lb_dbName = us_label( tr( "Database:" ), -1 ); - le_dbName = us_lineedit( "", -1, true ); + // QLabel* lb_save = us_banner(tr("Saving Control")); + // dkdb_ctrl = new US_Disk_DB_Controls(); + // dkdb_ctrl->set_disk(); + + // lb_dir = us_label( tr( "Directory:" ), -1 ); + // le_dir = us_lineedit( US_Settings::workBaseDir(), -1, true ); + // lb_dbName = us_label( tr( "Database:" ), -1 ); + // le_dbName = us_lineedit( "", -1, true ); pb_save = us_pushbutton("Save", false, 0 ); pb_save->setDisabled(true); - - if (dkdb_ctrl->db()){ - lb_dir->hide(); - le_dir->hide(); - }else{ - lb_dbName->hide(); - le_dbName->hide(); - } - QHBoxLayout* dir_lyt = new QHBoxLayout(); - dir_lyt->addWidget(lb_dir); - dir_lyt->addWidget(le_dir); - QHBoxLayout* db_lyt = new QHBoxLayout(); - db_lyt->addWidget(lb_dbName); - db_lyt->addWidget(le_dbName); + pb_save->setFixedWidth(150); + + // if (dkdb_ctrl->db()){ + // lb_dir->hide(); + // le_dir->hide(); + // }else{ + // lb_dbName->hide(); + // le_dbName->hide(); + // } + // QHBoxLayout* dir_lyt = new QHBoxLayout(); + // dir_lyt->addWidget(lb_dir); + // dir_lyt->addWidget(le_dir); + // QHBoxLayout* db_lyt = new QHBoxLayout(); + // db_lyt->addWidget(lb_dbName); + // db_lyt->addWidget(le_dbName); // status QLabel* lb_status = us_label(tr("Status:")); @@ -134,7 +148,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() // layout QVBoxLayout* left_lyt = new QVBoxLayout(); left_lyt->addStretch(0); - left_lyt->setSpacing(5); + left_lyt->setSpacing(1); left_lyt->addWidget(lb_run); left_lyt->addLayout(import_lyt); left_lyt->addLayout(rid_lyt); @@ -144,14 +158,14 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() left_lyt->addLayout(wavl_plt_lyt); left_lyt->addWidget(lb_cluster); left_lyt->addLayout(cls_aln_lyt); - left_lyt->addWidget(pb_clscltr); - left_lyt->addWidget(lb_CA); - left_lyt->addLayout(CA_lyt); - left_lyt->addWidget(lb_save); - left_lyt->addLayout(dkdb_ctrl); - left_lyt->addLayout(dir_lyt); - left_lyt->addLayout(db_lyt); - left_lyt->addWidget(pb_save); + left_lyt->addWidget(pb_clscltr, 0, Qt::AlignCenter); + // left_lyt->addWidget(lb_CA); + // left_lyt->addLayout(CA_lyt); + // left_lyt->addWidget(lb_save); + // left_lyt->addLayout(dkdb_ctrl); + // left_lyt->addLayout(dir_lyt); + // left_lyt->addLayout(db_lyt); + left_lyt->addWidget(pb_save, 0, Qt::AlignCenter); // left_lyt->setStretch(0); // left_lyt->addSpacing(20); left_lyt->addStretch(1); @@ -325,7 +339,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() connect(pb_save, SIGNAL(clicked()), this, SLOT(slt_save())); connect(pb_loadCA, SIGNAL(clicked()), this, SLOT(slt_load_CA())); connect(ckb_CA_state, SIGNAL(stateChanged(int)), this, SLOT(slt_CA_state(int))); - connect(dkdb_ctrl, SIGNAL(changed(bool)), this, SLOT(slt_db_local(bool))); + // connect(dkdb_ctrl, SIGNAL(changed(bool)), this, SLOT(slt_db_local(bool))); connect(this, SIGNAL(sig_plot_l(bool)), this, SLOT(slt_plot_l(bool))); connect(this, SIGNAL(sig_plot_r(bool)), this, SLOT(slt_plot_r(bool))); connect(this, SIGNAL(sig_plot_dist(bool)), this, SLOT(slt_plot_dist(bool))); @@ -700,29 +714,31 @@ void US_AddRefScan::slt_save(void){ } this->setCursor(QCursor(Qt::ArrowCursor)); - if (dkdb_ctrl->db()) - save_db(referenceScans); - else - save_local(referenceScans); + // if (dkdb_ctrl->db()) + // save_db(referenceScans); + // else + // save_local(referenceScans); + + save_local(referenceScans); return; } -void US_AddRefScan::slt_db_local(bool status){ - if (status){ - lb_dir->hide(); - le_dir->hide(); - lb_dbName->show(); - le_dbName->show(); - check_connection(); - }else{ - lb_dir->show(); - le_dir->show(); - lb_dbName->hide(); - le_dbName->hide(); - } +// void US_AddRefScan::slt_db_local(bool status){ +// if (status){ +// lb_dir->hide(); +// le_dir->hide(); +// lb_dbName->show(); +// le_dbName->show(); +// check_connection(); +// }else{ +// lb_dir->show(); +// le_dir->show(); +// lb_dbName->hide(); +// le_dbName->hide(); +// } - return; -} +// return; +// } void US_AddRefScan::slt_plot_l(bool state){ tab0_plotLU->detachItems(QwtPlotItem::Rtti_PlotItem, false); @@ -2354,20 +2370,48 @@ bool US_AddRefScan::check_runIDs(US_DB2* db, QVector& experimentIDs, } void US_AddRefScan::save_local(US_RefScanDataIO::RefData &refScans){ - QString outFileName; - FileNameWidget FileName(outFileName); - FileName.show(); - int s = FileName.exec(); - if (s == QDialog::Accepted){ - qDebug() << outFileName; - int error = US_RefScanDataIO::writeRefData(outFileName, refScans); - if (error != US_RefScanDataIO::OK) - le_status->setText(US_RefScanDataIO::errorString(error)); - else{ - le_status->setText("Written on the local disk"); - US_RefScanDataIO::RefData refScans2; - US_RefScanDataIO::readRefData(outFileName, refScans2); - qDebug() << ""; + // QString outFileName; + // FileNameWidget FileName(outFileName); + // FileName.show(); + // int s = FileName.exec(); + // if (s == QDialog::Accepted){ + // qDebug() << outFileName; + // int error = US_RefScanDataIO::writeRefData(outFileName, refScans); + // if (error != US_RefScanDataIO::OK) + // le_status->setText(US_RefScanDataIO::errorString(error)); + // else{ + // le_status->setText("Written on the local disk"); + // US_RefScanDataIO::RefData refScans2; + // US_RefScanDataIO::readRefData(outFileName, refScans2); + // qDebug() << ""; + // } + // } + + QString fpath = QFileDialog::getSaveFileName(this, "Save Reference Scan File", + US_Settings::dataDir(), tr("dat (*.dat)")); + if (fpath.isEmpty()) { + return; + } + if (!fpath.endsWith(".dat", Qt::CaseInsensitive)) { + fpath.append(".dat"); + } + QFile file(fpath); + + if (file.open(QIODevice::WriteOnly)) { + QTextStream textout{&file}; + // textout << "Points(cm)"; + textout << "cm"; + for (int ii = 0; ii < refScans.nWavelength; ii++) { + // textout << tr(";Lambda(%1)").arg(refScans.wavelength.at(ii)); + textout << tr(";%1nm").arg(refScans.wavelength.at(ii)); + } + textout << "\n"; + for (int ii = 0; ii < refScans.nPoints; ii++) { + textout << QString::number(refScans.xValues.at(ii)); + for (int jj = 0; jj < refScans.nWavelength; jj++) { + textout << ";" << QString::number(refScans.rValues.at(jj).at(ii)); + } + textout << "\n"; } } return; @@ -2492,10 +2536,10 @@ void US_AddRefScan::check_connection(){ // First row if (dbCon->isConnected()){ QStringList DB = US_Settings::defaultDB(); - if (DB.isEmpty()) - le_dbName->setText("Undefined"); - else - le_dbName->setText(DB.at(3)); + // if (DB.isEmpty()) + // le_dbName->setText("Undefined"); + // else + // le_dbName->setText(DB.at(3)); } return; } diff --git a/programs/us_pseudo_absorbance/us_add_refScan.h b/programs/us_pseudo_absorbance/us_add_refScan.h index 76399d993..ebe15ebfb 100644 --- a/programs/us_pseudo_absorbance/us_add_refScan.h +++ b/programs/us_pseudo_absorbance/us_add_refScan.h @@ -87,7 +87,7 @@ class US_AddRefScan : public US_Widgets void slt_plot_ovlp(bool); void slt_plot_inty(bool); void slt_save(void); - void slt_db_local(bool); + // void slt_db_local(bool); void slt_reset(void); void slt_CA_state(int); void slt_load_CA(void); @@ -175,11 +175,11 @@ class US_AddRefScan : public US_Widgets QLineEdit* le_lambstrt; ///< Line edit for start wavelength QLineEdit* le_lambstop; ///< Line edit for stop wavelength QLineEdit* le_status; ///< Line edit for status - QLineEdit* le_dir; ///< Line edit for directory - QLineEdit* le_dbName; ///< Line edit for database name + // QLineEdit* le_dir; ///< Line edit for directory + // QLineEdit* le_dbName; ///< Line edit for database name - QLabel* lb_dbName; ///< Label for database name - QLabel* lb_dir; ///< Label for directory + // QLabel* lb_dbName; ///< Label for database name + // QLabel* lb_dir; ///< Label for directory QLabel* lb_wavlBw; ///< Label for wavelength bandwidth QLabel* lb_runIDs; ///< Label for run IDs QLabel* lb_wavl; ///< Label for wavelength @@ -207,7 +207,7 @@ class US_AddRefScan : public US_Widgets QRadioButton *rb_db; ///< Radio button for database QTabWidget* tabs; ///< Tab widget - US_Disk_DB_Controls* dkdb_ctrl; ///< Disk/DB controls + // US_Disk_DB_Controls* dkdb_ctrl; ///< Disk/DB controls US_Passwd pw; ///< Password object US_DB2* dbCon; ///< Database connection From 981fe32d21d37705de6947d17eb994c9b58fd2f0 Mon Sep 17 00:00:00 2001 From: samo38 Date: Wed, 19 Jun 2024 18:46:50 -0600 Subject: [PATCH 16/21] us_pseudo_absorbance/us_convert_scan: initialize loading the reference scan from a csv file --- .../us_pseudo_absorbance/us_convert_scan.cpp | 173 ++++++++++++++++-- .../us_pseudo_absorbance/us_convert_scan.h | 1 + 2 files changed, 160 insertions(+), 14 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 4ca0e3b33..c52bed7dc 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -1,5 +1,6 @@ #include "us_convert_scan.h" #include "us_load_auc.h" +#include "us_csv_loader.h" #include US_ConvertScan::US_ConvertScan() : US_Widgets() @@ -89,19 +90,17 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() align_center(ct_scan_to); QGridLayout* scan_lyt = new QGridLayout(); - scan_lyt->addWidget(lb_scans, 0, 0, 1, 1); - scan_lyt->addWidget(ct_scans, 0, 1, 1, 1); + scan_lyt->addWidget(lb_scans, 0, 0, 1, 1); + scan_lyt->addWidget(ct_scans, 0, 1, 1, 1); // scan_lyt->addWidget(lb_smooth, 1, 0, 1, 1); // scan_lyt->addWidget(ct_smooth, 1, 1, 1, 1); - scan_lyt->addWidget(pb_apply, 0, 2, 1, 1); - scan_lyt->addWidget(lb_maxod, 1, 0, 1, 1); - scan_lyt->addWidget(ct_maxod, 1, 1, 1, 2); - - scan_lyt->addWidget(lb_scan_from, 2, 0, 1, 1); - scan_lyt->addWidget(ct_scan_from, 2, 1, 1, 2); - - scan_lyt->addWidget(lb_scan_to, 3, 0, 1, 1); - scan_lyt->addWidget(ct_scan_to, 3, 1, 1, 2); + scan_lyt->addWidget(pb_apply, 0, 2, 1, 1); + scan_lyt->addWidget(lb_scan_from, 1, 0, 1, 1); + scan_lyt->addWidget(ct_scan_from, 1, 1, 1, 2); + scan_lyt->addWidget(lb_scan_to, 2, 0, 1, 1); + scan_lyt->addWidget(ct_scan_to, 2, 1, 1, 2); + scan_lyt->addWidget(lb_maxod, 3, 0, 1, 1); + scan_lyt->addWidget(ct_maxod, 3, 1, 1, 2); tb_triple = new QTableWidget(); tb_triple->setRowCount(0); @@ -263,6 +262,7 @@ US_ConvertScan::US_ConvertScan() : US_Widgets() connect(this, &US_ConvertScan::sig_plot, this, &US_ConvertScan::plot_all); connect(pb_import, &QPushButton::clicked, this, &US_ConvertScan::import_run); + connect(pb_load_ref, &QPushButton::clicked, this, &US_ConvertScan::load_ref_scan); connect(pb_reset, &QPushButton::clicked, this, &US_ConvertScan::reset); connect(pb_prev_id, &QPushButton::clicked, this, &US_ConvertScan::prev_id); connect(pb_next_id, &QPushButton::clicked, this, &US_ConvertScan::next_id); @@ -344,6 +344,142 @@ void US_ConvertScan::apply_nscans() { emit sig_plot(); } +void US_ConvertScan::load_ref_scan() { + QString filter = "text files (*);;csv files (*.csv);;dat files (*.dat)"; + QString fpath = QFileDialog::getOpenFileName(this, "Load Reference Scans", + US_Settings::dataDir(), filter); + if (fpath.isEmpty()) { + return; + } + + for (int ii = 0; ii < refscan_files.size(); ii++) { + QString file_loaded = refscan_files.at(ii).filename; + if (file_loaded.compare(fpath) == 0) { + QMessageBox::warning(this, "Error!", "The following file has already been uploaded!\n" + fpath); + return; + } + } + + + QString note = "A Header Instance: cm;220nm;222nm;224nm"; + US_CSV_Loader *csv_loader = new US_CSV_Loader(fpath, note, true, this); + int state = csv_loader->exec(); + if (state != QDialog::Accepted) return; + double min_r = 5; + double max_r = 8; + QString mesg = tr("Reference scan files should have at least two columns with the following pattern. " + "The preferred data separator is semicolon. " + "The first column is the radial points where header name is (cm). " + "The radial point should be between %1 to %2 cm and equally distanced with 0.001 cm. " + "The rest of the columns are reference profiles at different wavelengths. " + "They should be positive values where the header specifies what wavelength they are for." + "Each wavelength header item should be number followed by (nm). " + "Here is an example:\n\n" + "cm;220nm;222nm;224nm;226nm;230nm\n" + "5.8;1629.81;1712.49;1579.66;1732.45;1632.21\n" + "5.801;1631.89;1713.16;1580.46;1733.07;1632.54\n" + "....\n" + "....\n").arg(min_r).arg(max_r); + US_CSV_Loader::CSV_Data csv_data = csv_loader->data(); + if (csv_data.columnCount() < 2 ) { + QMessageBox::warning(this, "Error!", mesg + "\n\nError in the number of columns!"); + return; + } + QStringList header = csv_data.header(); + QVector wavl; + QVector> wavl_idx; + for (int ii = 0; ii < header.size(); ii++) { + QString name = header.at(ii).trimmed(); + if (ii == 0 && name.compare("cm", Qt::CaseSensitive) != 0) { + QMessageBox::warning(this, "Error!", mesg + "\n\nError in the header!"); + return; + } else if (ii > 0) { + if (name.endsWith("nm")) { + name.chop(2); + bool ok; + double val = name.toDouble(&ok); + if (!ok) { + QMessageBox::warning(this, "Error!", mesg + "\n\nError in the header!"); + return; + } + if (val < 180 || val > 800) { + QMessageBox::warning(this, "Error!", "Error in the header! Wavelengths are out of range. " + "They must be in a range of 180 to 800 nm."); + return; + } + if (wavl.contains(val)) { + QMessageBox::warning(this, "Error!", mesg + "\n\nError in the header! Wavelength redundancy!"); + return; + } else { + wavl << val; + wavl_idx << qMakePair(val, ii - 1); + } + } else { + QMessageBox::warning(this, "Error!", mesg + "\n\nError in the header!"); + return; + } + } + } + QVector xvalues = csv_data.columnAt(0); + QString mesg_r = mesg + "\n\nError in the radial points!"; + if (xvalues.first() < min_r || xvalues.last() > max_r) { + QMessageBox::warning(this, "Error!", mesg_r); + return; + } + for(int ii = 1; ii < xvalues.size(); ii++) { + double r = xvalues.at(ii); + if (r < min_r || r > max_r) { + QMessageBox::warning(this, "Error!", mesg_r); + return; + } + double dr = xvalues.at(ii) - xvalues.at(ii - 1); + if (dr < 0.0008 || dr > 0.003) { + QMessageBox::warning(this, "Error!", mesg_r); + return; + } + } + mesg_r = mesg + "\n\nError in the data values!"; + QVector> yvalues; + for (int ii = 1; ii < csv_data.columnCount(); ii++) { + QVector col = csv_data.columnAt(ii); + foreach (double d, col) { + if (d <= 0) { + QMessageBox::warning(this, "Error!", mesg_r + " Negative and zero values are not allowed!"); + return; + } + } + yvalues << col; + } + + std::sort(wavl_idx.begin(), wavl_idx.end(), + [](auto a, auto b) { return a.first < b.first;}); + RefscanFile reffile; + double min_wvl = 10000; + double max_wvl = 0; + reffile.xvalues << xvalues; + for (int ii = 0; ii < wavl_idx.size(); ii++) { + double wvl = wavl_idx.at(ii).first; + double idx = wavl_idx.at(ii).second; + min_wvl = qMin(min_wvl, wvl); + max_wvl = qMax(max_wvl, wvl); + reffile.wavelength << wvl; + reffile.yvalues << yvalues.at(idx); + } + reffile.min_wvl = min_wvl; + reffile.max_wvl = max_wvl; + reffile.nwvl = reffile.wavelength.size(); + reffile.filename = fpath; + reffile.name = tr("Reference %1").arg(refscan_files.size() + 1); + + refscan_files << reffile; + set_table(); + set_wavl_ctrl(); + pb_reset->setEnabled(true); + hasData = true; + le_status->clear(); + +} + int US_ConvertScan::read_auc(QVector& rawdata, QVector>>& absorbance, QVector>>& refscans, @@ -908,7 +1044,7 @@ void US_ConvertScan::save_run() { void US_ConvertScan::set_table(){ tb_triple->disconnect(); tb_triple->clearContents(); - tb_triple->setRowCount(ccw_items.size()); + tb_triple->setRowCount(ccw_items.size() + refscan_files.size()); QString runid; int rcode = 1; @@ -960,7 +1096,8 @@ void US_ConvertScan::set_table(){ twi_cc = new QTableWidgetItem(item_cc); twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); twi_cc->setFont(font); - tb_triple->setItem(ii, 0, twi_cc); + int II = ccw_items.size() + ii; + tb_triple->setItem(II, 0, twi_cc); QString item_wvl = tr("%1-%2 (%3)").arg(refscan_files.at(ii).min_wvl) .arg(refscan_files.at(ii).max_wvl).arg(refscan_files.at(ii).nwvl); @@ -968,7 +1105,15 @@ void US_ConvertScan::set_table(){ twi_wvl = new QTableWidgetItem(item_wvl); twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); twi_wvl->setFont(font); - tb_triple->setItem(ii, 1, twi_wvl); + tb_triple->setItem(II, 1, twi_wvl); + + QTableWidgetItem *twi_2 = new QTableWidgetItem(); + twi_2->setFlags(twi_2->flags() & ~Qt::ItemIsEditable); + tb_triple->setItem(II, 2, twi_2); + + QTableWidgetItem *twi_3 = new QTableWidgetItem(); + twi_3->setFlags(twi_3->flags() & ~Qt::ItemIsEditable); + tb_triple->setItem(II, 3, twi_3); } for (int ii = 0; ii < ccw_items.size(); ii++) { diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 6137627da..7260c55ac 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -47,6 +47,7 @@ private slots: void lower_scan_range(double); void upper_scan_range(double); void plot_ref_state(); + void load_ref_scan(); private: From a8a794e38a02b563a9dac06de5bea9dc3d34b72e Mon Sep 17 00:00:00 2001 From: samo38 Date: Thu, 20 Jun 2024 11:54:22 -0600 Subject: [PATCH 17/21] us_pseudo_absorbance/us_convert_scan: add highlighting, used data embeded into table and combo items to specify the reference scans of each channel --- .../us_pseudo_absorbance/us_convert_scan.cpp | 187 +++++++++++------- .../us_pseudo_absorbance/us_convert_scan.h | 2 +- 2 files changed, 112 insertions(+), 77 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index c52bed7dc..f39fd8e9e 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -295,7 +295,6 @@ void US_ConvertScan::reset(){ set_ct_scans(); hasData = false; wavl_id = 0; - plot_ref_file = -1; wavelength.clear(); ccw_items.clear(); intensity_data.clear(); @@ -473,7 +472,6 @@ void US_ConvertScan::load_ref_scan() { refscan_files << reffile; set_table(); - set_wavl_ctrl(); pb_reset->setEnabled(true); hasData = true; le_status->clear(); @@ -636,7 +634,6 @@ void US_ConvertScan::import_run() { list_ccw_items(workingDir); set_table(); - set_wavl_ctrl(); pb_reset->setEnabled(true); hasData = true; le_status->clear(); @@ -714,8 +711,8 @@ void US_ConvertScan::set_wavl_ctrl(){ cb_plot_id->clear(); wavelength.clear(); wavl_id = 0; - plot_ref_file = -1; - if (ccw_items.isEmpty()) { + // plot_ref_file = -1; + if (ccw_items.isEmpty() && refscan_files.isEmpty()) { le_lambstrt->clear(); le_lambstop->clear(); le_runid->clear(); @@ -726,18 +723,15 @@ void US_ConvertScan::set_wavl_ctrl(){ } int row = tb_triple->currentRow(); - QString cellname = tb_triple->item(row, 0)->text(); - if (cellname.startsWith("Reference", Qt::CaseInsensitive)) { - for (int ii = 0; ii < refscan_files.size(); ii++) { - if (refscan_files.at(ii).name.compare(cellname) == 0) { - wavelength << refscan_files.at(ii).wavelength; - plot_ref_file = ii; - } - } - } else { + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role < 100) { wavelength << ccw_items.at(row).wavelength; - plot_ref_file = -1; + // plot_ref_file = -1; + } else { + // plot_ref_file = role - 100; + wavelength << refscan_files.at(role - 100).wavelength; } + le_lambstrt->setText(tr("%1").arg(wavelength.first())); le_lambstrt->setAlignment(Qt::AlignCenter); le_lambstop->setText(tr("%1").arg(wavelength.last())); @@ -761,29 +755,28 @@ void US_ConvertScan::select_id(int id){ disconnect_picker(); wavl_id = id; offon_prev_next(); - if (plot_ref_file >= 0) { + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role >= 100) { le_runid->clear(); - le_desc->setText(refscan_files.at(plot_ref_file).filename); + le_desc->setText(refscan_files.at(role - 100).filename); + double wl = wavelength.at(wavl_id); + QString title("Wavelength= %1 nm"); + plot_title->setText(title.arg(wl)); } else { - int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); le_runid->setText(ccw_items.at(tb_triple->currentRow()).runid); le_desc->setText(intensity_data.at(raw_id).description); + double wl = wavelength.at(wavl_id); + int ns = intensity_data.at(raw_id).scanData.size(); + QString title("Wavelength= %1 nm; #Scans= %2"); + plot_title->setText(title.arg(wl).arg(ns)); } emit sig_plot(); return; } void US_ConvertScan::plot_all(){ - le_status->clear(); - if (ccw_items.isEmpty()) { - plot_title->setText(""); - } else{ - QString title("Wavelength= %1 nm; #Scans= %2"); - double wl = wavelength.at(wavl_id); - int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); - int ns = intensity_data.at(raw_id).scanData.size(); - plot_title->setText(title.arg(wl).arg(ns)); - } plot_intensity(); plot_refscan(); plot_absorbance(); @@ -793,30 +786,17 @@ void US_ConvertScan::plot_all(){ void US_ConvertScan::select_refscan(int ref_row) { QComboBox* combo = qobject_cast(sender()); if (combo) { - QString ref_text = combo->itemText(ref_row); int item_row = tb_triple->indexAt(combo->pos()).row(); - if (ref_row == 0) { - ccw_items[item_row].ref_id = -1; - } else if (ref_text.startsWith("Reference", Qt::CaseInsensitive)) { - for (int ii = 0; ii < refscan_files.size(); ii++) { - if (refscan_files.at(ii).name.compare(ref_text) == 0) { - ccw_items[item_row].ref_id = ii + 100; - break; - } - } - } else { - ccw_items[item_row].ref_id = ref_row - 1; - } + int role = combo->itemData(ref_row, Qt::UserRole).toInt(); + ccw_items[item_row].ref_id = role; QGuiApplication::setOverrideCursor(Qt::WaitCursor); calc_absorbance(item_row); QGuiApplication::restoreOverrideCursor(); + highlight(); QModelIndex index = tb_triple->model()->index(item_row, 0); - // tb_triple->selectionModel()-> - // select(index, QItemSelectionModel::Select | QItemSelectionModel::Current); tb_triple->setCurrentIndex(index); - set_wavl_ctrl(); } } @@ -1044,7 +1024,11 @@ void US_ConvertScan::save_run() { void US_ConvertScan::set_table(){ tb_triple->disconnect(); tb_triple->clearContents(); - tb_triple->setRowCount(ccw_items.size() + refscan_files.size()); + int nrows = ccw_items.size() + refscan_files.size(); + if (nrows == 0) { + return; + } + tb_triple->setRowCount(nrows); QString runid; int rcode = 1; @@ -1060,7 +1044,6 @@ void US_ConvertScan::set_table(){ rcode_list << rcode; } - QStringList combo_items; for (int ii = 0; ii < ccw_items.size(); ii++){ rcode = rcode_list.at(ii); int cell = ccw_items.at(ii).cell; @@ -1074,11 +1057,11 @@ void US_ConvertScan::set_table(){ } else { item_cc = tr("[%1] %2 / %3").arg(rcode).arg(cell).arg(channel); } - combo_items << item_cc; QTableWidgetItem *twi_cc; twi_cc = new QTableWidgetItem(item_cc); twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); twi_cc->setFont(font); + twi_cc->setData(Qt::UserRole, QVariant(ii)); tb_triple->setItem(ii, 0, twi_cc); QString item_wvl = tr("%1-%2 (%3)").arg(min_wl).arg(max_wl).arg(nwl); @@ -1091,7 +1074,6 @@ void US_ConvertScan::set_table(){ for (int ii = 0; ii < refscan_files.size(); ii++) { QString item_cc = refscan_files.at(ii).name; - combo_items << item_cc; QTableWidgetItem *twi_cc; twi_cc = new QTableWidgetItem(item_cc); twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); @@ -1105,6 +1087,7 @@ void US_ConvertScan::set_table(){ twi_wvl = new QTableWidgetItem(item_wvl); twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); twi_wvl->setFont(font); + twi_cc->setData(Qt::UserRole, QVariant(ii + 100)); tb_triple->setItem(II, 1, twi_wvl); QTableWidgetItem *twi_2 = new QTableWidgetItem(); @@ -1122,19 +1105,26 @@ void US_ConvertScan::set_table(){ combo->lineEdit()->setAlignment(Qt::AlignCenter); combo->lineEdit()->setReadOnly(true); combo->addItem("none"); - for (int jj = 0; jj < combo_items.size(); jj++) { + for (int jj = 0; jj < nrows; jj++) { combo->addItem(tb_triple->item(jj, 0)->text()); } + + int cid = 0; int re_fid = ccw_items.at(ii).ref_id; - if ( re_fid >= 0 && re_fid < 100) { - combo->setCurrentIndex(re_fid + 1); - } else if ( re_fid >= 0 && re_fid >= 100) { - QString name = refscan_files.at(re_fid - 100).name; - combo->setCurrentText(name); - } for (int jj = 0; jj < combo->count(); jj++) { + if (jj == 0) { + combo->setItemData(jj, -1, Qt::UserRole); + continue; + } + int role = tb_triple->item(jj - 1, 0)->data(Qt::UserRole).toInt(); + combo->setItemData(jj, role, Qt::UserRole); combo->setItemData(jj, Qt::AlignCenter, Qt::TextAlignmentRole); + if (role == re_fid) { + cid = jj; + } } + combo->setCurrentIndex(cid); + tb_triple->setCellWidget(ii, 2, combo); connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(select_refscan(int))); @@ -1151,9 +1141,10 @@ void US_ConvertScan::set_table(){ tb_triple->setCellWidget(ii, 3, wgt); } - tb_triple->setCurrentCell(0, 0); connect( tb_triple, &QTableWidget::currentCellChanged, this, &US_ConvertScan::set_wavl_ctrl); - return; + QModelIndex index = tb_triple->model()->index(0, 0); + tb_triple->setCurrentIndex(index); + highlight(); } void US_ConvertScan::list_ccw_items(QString& runid){ @@ -1210,7 +1201,13 @@ void US_ConvertScan::plot_intensity(){ return; } - int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role >= 100) { + return; + } + + int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); bool flag = chkb_abs_int->isChecked(); flag = flag && (absorbance_state.at(raw_id) >= 0 && absorbance_state.at(raw_id) < 100); flag = !flag; @@ -1265,15 +1262,19 @@ void US_ConvertScan::plot_intensity(){ } void US_ConvertScan::plot_refscan(){ - if (ccw_items.isEmpty()) return; + if (ccw_items.isEmpty() && refscan_files.isEmpty()) { + return; + } + double min_r = 1e99; + double max_r = -1e99; QVector xvalues; QVector> yvalues; - if (plot_ref_file >= 0) { - le_runid->clear(); - le_desc->setText(refscan_files.at(plot_ref_file).filename); - xvalues << refscan_files.at(plot_ref_file).xvalues; - yvalues << refscan_files.at(plot_ref_file).yvalues.at(wavl_id); + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role >= 100) { + xvalues << refscan_files.at(role - 100).xvalues; + yvalues << refscan_files.at(role - 100).yvalues.at(wavl_id); } else { int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); if (absorbance_state.at(raw_id) == -1) { @@ -1282,6 +1283,8 @@ void US_ConvertScan::plot_refscan(){ if (absorbance_state.at(raw_id) < 100 && !chkb_abs_int->isChecked()) { return; } + min_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).lowerBound(); + max_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).upperBound(); xvalues << intensity_data.at(raw_id).xvalues; int N = absorbance_data.at(raw_id).size() - nscans; QVector> refscan = refscan_data.at(raw_id).mid(N); @@ -1296,10 +1299,8 @@ void US_ConvertScan::plot_refscan(){ } } + grid = us_grid(qwtplot_insty); QPen pen = QPen( QBrush( Qt::white ), 1. ); - double min_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).lowerBound(); - double max_r = qwtplot_insty->axisScaleDiv(QwtPlot::yLeft).upperBound(); - const double *xp, *rp; xp = xvalues.data(); int np = xvalues.size(); @@ -1325,11 +1326,20 @@ void US_ConvertScan::plot_absorbance(){ qwtplot_abs->detachItems(QwtPlotItem::Rtti_PlotItem, false); grid = us_grid(qwtplot_abs); qwtplot_abs->replot(); - if (ccw_items.isEmpty()) return; + if (ccw_items.isEmpty()) { + return; + } int row = tb_triple->currentRow(); - int raw_id = ccw_items.at(row).rawdata_ids.at(wavl_id); - if (absorbance_state.at(raw_id) == -1) return; + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role >= 100) { + return; + } + + int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); + if (absorbance_state.at(raw_id) == -1) { + return; + } double x_1 = ccw_items.at(row).minmax_x.first; double x_2 = ccw_items.at(row).minmax_x.second; @@ -1588,12 +1598,37 @@ void US_ConvertScan::calc_absorbance(int item_row){ } absorbance_state[rid] = ref_id; } - if (not_found_wvl.isEmpty()) { - tb_triple->item(item_row, 0)->setBackground(QBrush(Qt::white)); - tb_triple->item(item_row, 1)->setBackground(QBrush(Qt::white)); - } else { - tb_triple->item(item_row, 0)->setBackground(QBrush(Qt::yellow)); - tb_triple->item(item_row, 1)->setBackground(QBrush(Qt::yellow)); +} + +void US_ConvertScan::highlight() { + for (int ii = 0; ii < ccw_items.size(); ii++) { + QVector wvls; + tb_triple->item(ii, 0)->setBackground(QBrush(Qt::white)); + tb_triple->item(ii, 1)->setBackground(QBrush(Qt::white)); + int ref_id = ccw_items.at(ii).ref_id; + if ( ref_id == -1) { + continue; + } else if ( ref_id < 100 ) { + foreach (double d, ccw_items.at(ref_id).wavelength) { + wvls << qRound(d * 10); + } + } else { + foreach (double d, refscan_files.at(ref_id - 100).wavelength) { + wvls << qRound(d * 10); + } + } + bool ok = true; + foreach (double val, ccw_items.at(ii).wavelength) { + int ival = qRound(val * 10); + if (! wvls.contains(ival)) { + ok = false; + break; + } + } + if (! ok) { + tb_triple->item(ii, 0)->setBackground(QBrush(Qt::yellow)); + tb_triple->item(ii, 1)->setBackground(QBrush(Qt::yellow)); + } } } diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 7260c55ac..26e8b3c91 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -122,7 +122,6 @@ private slots: int max_nscans; int smooth; int wavl_id; - int plot_ref_file; QVector wavelength; QVector ccw_items; QVector intensity_data; @@ -134,6 +133,7 @@ private slots: void list_ccw_items(QString&); void set_table(); + void highlight(); void offon_prev_next(); void plot_intensity(); void plot_refscan(); From 6faefe317b02cdc09f0d863d3218fab4b051e7cf Mon Sep 17 00:00:00 2001 From: samo38 Date: Thu, 20 Jun 2024 17:12:38 -0600 Subject: [PATCH 18/21] us_add_refScan.cpp: update GUI --- .../us_pseudo_absorbance/us_add_refScan.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_add_refScan.cpp b/programs/us_pseudo_absorbance/us_add_refScan.cpp index bbb0d809a..415717552 100644 --- a/programs/us_pseudo_absorbance/us_add_refScan.cpp +++ b/programs/us_pseudo_absorbance/us_add_refScan.cpp @@ -65,11 +65,11 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() ckb_align->setCheckState(Qt::Unchecked); pb_clscltr = us_pushbutton("Clustering Control", false, 0 ); pb_clscltr->setDisabled(true); - pb_clscltr->setFixedWidth(150); + // pb_clscltr->setFixedWidth(150); - QHBoxLayout* cls_aln_lyt = new QHBoxLayout(); - cls_aln_lyt->addLayout(ckb_cls_lyt); - cls_aln_lyt->addLayout(ckb_aln_lyt); + // QHBoxLayout* cls_aln_lyt = new QHBoxLayout(); + // cls_aln_lyt->addLayout(ckb_cls_lyt); + // cls_aln_lyt->addLayout(ckb_aln_lyt); // Chromatic Aberration Correction QLabel* lb_CA = us_banner(tr("Chromatic Aberration Correction")); @@ -111,7 +111,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() // le_dbName = us_lineedit( "", -1, true ); pb_save = us_pushbutton("Save", false, 0 ); pb_save->setDisabled(true); - pb_save->setFixedWidth(150); + // pb_save->setFixedWidth(150); // if (dkdb_ctrl->db()){ // lb_dir->hide(); @@ -127,6 +127,12 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() // db_lyt->addWidget(lb_dbName); // db_lyt->addWidget(le_dbName); + + QGridLayout* procctrl_lyt = new QGridLayout(); + procctrl_lyt->addLayout(ckb_cls_lyt, 0, 0, 1, 1); + procctrl_lyt->addLayout(ckb_aln_lyt, 0, 1, 1, 1); + procctrl_lyt->addWidget(pb_clscltr, 1, 0, 1, 1); + procctrl_lyt->addWidget(pb_save, 1, 1, 1, 1); // status QLabel* lb_status = us_label(tr("Status:")); le_status = us_lineedit(tr(""), -1, true); @@ -157,7 +163,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() left_lyt->addLayout(wavl_rng_lyt); left_lyt->addLayout(wavl_plt_lyt); left_lyt->addWidget(lb_cluster); - left_lyt->addLayout(cls_aln_lyt); + left_lyt->addLayout(procctrl_lyt); left_lyt->addWidget(pb_clscltr, 0, Qt::AlignCenter); // left_lyt->addWidget(lb_CA); // left_lyt->addLayout(CA_lyt); @@ -308,6 +314,7 @@ US_AddRefScan::US_AddRefScan() : US_Widgets() tab1_lyt->addLayout(tab1_plt_lyt3, 1); tab1_lyt->addLayout(tab1_plt_lyt4); tab1_lyt->setMargin(0); + tab1_lyt->setSpacing(1); //**// tabs = new QTabWidget(); From 6874704b11f25cc18eefabd2f708466ad881c998 Mon Sep 17 00:00:00 2001 From: samo38 Date: Thu, 20 Jun 2024 17:16:53 -0600 Subject: [PATCH 19/21] us_add_refScan.cpp: renamed titles --- programs/us_pseudo_absorbance/us_pseudo_absorbance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_pseudo_absorbance.cpp b/programs/us_pseudo_absorbance/us_pseudo_absorbance.cpp index a4595c4c9..3cfb25654 100644 --- a/programs/us_pseudo_absorbance/us_pseudo_absorbance.cpp +++ b/programs/us_pseudo_absorbance/us_pseudo_absorbance.cpp @@ -24,8 +24,8 @@ US_PseudoAbsorbance::US_PseudoAbsorbance() : US_Widgets() setWindowTitle( tr( "Pseudo-Absorbance Program" ) ); setPalette( US_GuiSettings::frameColorDefault() ); - pb_addRef = us_pushbutton("Add New Reference Scans"); - pb_cnvtSc = us_pushbutton("Convert Intensity to Absorbance"); + pb_addRef = us_pushbutton("Reference Scan Calculation"); + pb_cnvtSc = us_pushbutton("Pseudo-Absorbance Conversion"); pb_rmri = us_pushbutton("Radial Invariant Noise Correction"); int width = 350; pb_addRef->setMinimumWidth(width); From 520dbf025f0c6f6ed58b38a09eabc4eb4ea7dbb3 Mon Sep 17 00:00:00 2001 From: samo38 Date: Fri, 21 Jun 2024 12:12:52 -0600 Subject: [PATCH 20/21] us_pseudo_absorbance/us_convert_scan: centered items text, embed wavl_id into table items so that we can track of changes after selecting a new item --- .../us_pseudo_absorbance/us_convert_scan.cpp | 82 +++++++++++++------ .../us_pseudo_absorbance/us_convert_scan.h | 4 +- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index f39fd8e9e..33f96cf16 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -294,8 +294,6 @@ void US_ConvertScan::reset(){ tb_triple->setRowCount(0); set_ct_scans(); hasData = false; - wavl_id = 0; - wavelength.clear(); ccw_items.clear(); intensity_data.clear(); absorbance_data.clear(); @@ -469,6 +467,7 @@ void US_ConvertScan::load_ref_scan() { reffile.nwvl = reffile.wavelength.size(); reffile.filename = fpath; reffile.name = tr("Reference %1").arg(refscan_files.size() + 1); + reffile.wavl_id = 0; refscan_files << reffile; set_table(); @@ -686,50 +685,69 @@ void US_ConvertScan::upper_scan_range(double value) { } void US_ConvertScan::prev_id(){ - --wavl_id; - cb_plot_id->setCurrentIndex(wavl_id); - return; + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + int wavl_id; + if (role < 100) { + wavl_id = ccw_items.at(role).wavl_id; + } else { + wavl_id = refscan_files.at(role - 100).wavl_id; + } + cb_plot_id->setCurrentIndex(--wavl_id); } void US_ConvertScan::next_id(){ - ++wavl_id; - cb_plot_id->setCurrentIndex(wavl_id); - return; + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + int wavl_id; + if (role < 100) { + wavl_id = ccw_items.at(role).wavl_id; + } else { + wavl_id = refscan_files.at(role - 100).wavl_id; + } + cb_plot_id->setCurrentIndex(++wavl_id); } void US_ConvertScan::offon_prev_next(){ - int n_wavls = wavelength.size(); + int n_wavls, wavl_id; + int row = tb_triple->currentRow(); + int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + if (role < 100) { + n_wavls = ccw_items.at(role).wavelength.size(); + wavl_id = ccw_items.at(role).wavl_id; + } else { + n_wavls = refscan_files.at(role - 100).wavelength.size(); + wavl_id = refscan_files.at(role - 100).wavl_id; + } pb_prev_id->setDisabled(wavl_id <= 0); pb_next_id->setDisabled(wavl_id >= (n_wavls - 1)); return; } void US_ConvertScan::set_wavl_ctrl(){ - if (tb_triple->currentColumn() == 2) return; + if (tb_triple->currentColumn() >= 2) return; cb_plot_id->disconnect(); cb_plot_id->clear(); - wavelength.clear(); - wavl_id = 0; - // plot_ref_file = -1; if (ccw_items.isEmpty() && refscan_files.isEmpty()) { le_lambstrt->clear(); le_lambstop->clear(); le_runid->clear(); le_desc->clear(); - offon_prev_next(); emit sig_plot(); return; } int row = tb_triple->currentRow(); int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + QVector wavelength; + int wavl_id; if (role < 100) { wavelength << ccw_items.at(row).wavelength; - // plot_ref_file = -1; + wavl_id = ccw_items.at(row).wavl_id; } else { - // plot_ref_file = role - 100; wavelength << refscan_files.at(role - 100).wavelength; + wavl_id = refscan_files.at(role - 100).wavl_id; } le_lambstrt->setText(tr("%1").arg(wavelength.first())); @@ -742,36 +760,38 @@ void US_ConvertScan::set_wavl_ctrl(){ for (int ii = 0; ii < cb_plot_id->count(); ii++) { cb_plot_id->setItemData(ii, Qt::AlignCenter, Qt::TextAlignmentRole); } - offon_prev_next(); + cb_plot_id->setCurrentIndex(wavl_id); // connect(cb_plot_id, QOverload::of(&QComboBox::currentIndexChanged), // [=](int index){ select_id(index); }); connect(cb_plot_id, SIGNAL(currentIndexChanged(int)), this, SLOT(select_id(int))); - select_id(0); + select_id(wavl_id); } void US_ConvertScan::select_id(int id){ disconnect_picker(); - wavl_id = id; - offon_prev_next(); int row = tb_triple->currentRow(); int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); if (role >= 100) { le_runid->clear(); le_desc->setText(refscan_files.at(role - 100).filename); - double wl = wavelength.at(wavl_id); + double wl = refscan_files.at(role - 100).wavelength.at(id); + refscan_files[role - 100].wavl_id = id; + // double wl = wavelength.at(wavl_id); QString title("Wavelength= %1 nm"); plot_title->setText(title.arg(wl)); } else { - int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); + int raw_id = ccw_items.at(role).rawdata_ids.at(id); + ccw_items[role].wavl_id = id; le_runid->setText(ccw_items.at(tb_triple->currentRow()).runid); le_desc->setText(intensity_data.at(raw_id).description); - double wl = wavelength.at(wavl_id); + double wl = ccw_items.at(role).wavelength.at(id); int ns = intensity_data.at(raw_id).scanData.size(); QString title("Wavelength= %1 nm; #Scans= %2"); plot_title->setText(title.arg(wl).arg(ns)); } + offon_prev_next(); emit sig_plot(); return; } @@ -1062,12 +1082,14 @@ void US_ConvertScan::set_table(){ twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); twi_cc->setFont(font); twi_cc->setData(Qt::UserRole, QVariant(ii)); + twi_cc->setTextAlignment(Qt::AlignCenter); tb_triple->setItem(ii, 0, twi_cc); QString item_wvl = tr("%1-%2 (%3)").arg(min_wl).arg(max_wl).arg(nwl); QTableWidgetItem *twi_wvl; twi_wvl = new QTableWidgetItem(item_wvl); twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); + twi_wvl->setTextAlignment(Qt::AlignCenter); twi_wvl->setFont(font); tb_triple->setItem(ii, 1, twi_wvl); } @@ -1077,6 +1099,8 @@ void US_ConvertScan::set_table(){ QTableWidgetItem *twi_cc; twi_cc = new QTableWidgetItem(item_cc); twi_cc->setFlags(twi_cc->flags() & ~Qt::ItemIsEditable); + twi_cc->setData(Qt::UserRole, QVariant(ii + 100)); + twi_cc->setTextAlignment(Qt::AlignCenter); twi_cc->setFont(font); int II = ccw_items.size() + ii; tb_triple->setItem(II, 0, twi_cc); @@ -1087,7 +1111,7 @@ void US_ConvertScan::set_table(){ twi_wvl = new QTableWidgetItem(item_wvl); twi_wvl->setFlags(twi_wvl->flags() & ~Qt::ItemIsEditable); twi_wvl->setFont(font); - twi_cc->setData(Qt::UserRole, QVariant(ii + 100)); + twi_wvl->setTextAlignment(Qt::AlignCenter); tb_triple->setItem(II, 1, twi_wvl); QTableWidgetItem *twi_2 = new QTableWidgetItem(); @@ -1112,13 +1136,13 @@ void US_ConvertScan::set_table(){ int cid = 0; int re_fid = ccw_items.at(ii).ref_id; for (int jj = 0; jj < combo->count(); jj++) { + combo->setItemData(jj, Qt::AlignCenter, Qt::TextAlignmentRole); if (jj == 0) { combo->setItemData(jj, -1, Qt::UserRole); continue; } int role = tb_triple->item(jj - 1, 0)->data(Qt::UserRole).toInt(); combo->setItemData(jj, role, Qt::UserRole); - combo->setItemData(jj, Qt::AlignCenter, Qt::TextAlignmentRole); if (role == re_fid) { cid = jj; } @@ -1174,13 +1198,13 @@ void US_ConvertScan::list_ccw_items(QString& runid){ foreach (QString key, keys) { CellChannel cc; - // cc.has_ref = false; QStringList ksp = key.split("-"); cc.cell = ksp.at(0).toInt(); cc.channel = ksp.at(1).at(0).toLatin1(); cc.minmax_x = qMakePair(-1, -1); cc.ref_id = -1; cc.runid = runid; + cc.wavl_id = 0; QVector> wavl_idx = wavl_idx_map.value(key); std::sort(wavl_idx.begin(), wavl_idx.end(), [](auto a, auto b) { return a.first < b.first;}); @@ -1207,6 +1231,7 @@ void US_ConvertScan::plot_intensity(){ return; } + int wavl_id = ccw_items.at(role).wavl_id; int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); bool flag = chkb_abs_int->isChecked(); flag = flag && (absorbance_state.at(raw_id) >= 0 && absorbance_state.at(raw_id) < 100); @@ -1272,10 +1297,13 @@ void US_ConvertScan::plot_refscan(){ QVector> yvalues; int row = tb_triple->currentRow(); int role = tb_triple->item(row, 0)->data(Qt::UserRole).toInt(); + int wavl_id; if (role >= 100) { + wavl_id = refscan_files.at(role - 100).wavl_id; xvalues << refscan_files.at(role - 100).xvalues; yvalues << refscan_files.at(role - 100).yvalues.at(wavl_id); } else { + wavl_id = ccw_items.at(tb_triple->currentRow()).wavl_id; int raw_id = ccw_items.at(tb_triple->currentRow()).rawdata_ids.at(wavl_id); if (absorbance_state.at(raw_id) == -1) { return; @@ -1335,7 +1363,7 @@ void US_ConvertScan::plot_absorbance(){ if (role >= 100) { return; } - + int wavl_id = ccw_items.at(role).wavl_id; int raw_id = ccw_items.at(role).rawdata_ids.at(wavl_id); if (absorbance_state.at(raw_id) == -1) { return; diff --git a/programs/us_pseudo_absorbance/us_convert_scan.h b/programs/us_pseudo_absorbance/us_convert_scan.h index 26e8b3c91..5e1243859 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.h +++ b/programs/us_pseudo_absorbance/us_convert_scan.h @@ -61,6 +61,7 @@ private slots: double min_wvl; double max_wvl; int nwvl; + int wavl_id; QVector wavelength; QVector xvalues; QVector> yvalues; @@ -75,6 +76,7 @@ private slots: int cell; int ref_id; QString runid; + int wavl_id; QVector wavelength; QVector rawdata_ids; QPair minmax_x; @@ -121,8 +123,6 @@ private slots: int nscans; int max_nscans; int smooth; - int wavl_id; - QVector wavelength; QVector ccw_items; QVector intensity_data; QVector>> absorbance_data; From b6905b021b4b68396103ccde1404bba9ab9f58fc Mon Sep 17 00:00:00 2001 From: samo38 Date: Fri, 21 Jun 2024 12:21:42 -0600 Subject: [PATCH 21/21] us_convert_scan: update messages --- programs/us_pseudo_absorbance/us_convert_scan.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/us_pseudo_absorbance/us_convert_scan.cpp b/programs/us_pseudo_absorbance/us_convert_scan.cpp index 33f96cf16..96e04b6f2 100644 --- a/programs/us_pseudo_absorbance/us_convert_scan.cpp +++ b/programs/us_pseudo_absorbance/us_convert_scan.cpp @@ -961,7 +961,7 @@ void US_ConvertScan::save_run() { return; } else if (run_list.size() > 1) { QMessageBox::warning(this, "Warning!", "Triples from multiple RunIDs are selected!\n" - "Please select triples of each RunID separately."); + "Please save each RunID separately."); return; } @@ -1014,7 +1014,7 @@ void US_ConvertScan::save_run() { } if (! miss_ccw.isEmpty()) { int ans = QMessageBox::question(this, "Warning!", - tr("Absorbance data for (%1) triples is missing.\n" + tr("There is (%1) triple(s) missing.\n" "Do you proceed to save the remaining (%2) " "triples ?").arg(miss_ccw.size()).arg(out_rawdata.size())); if (ans == QMessageBox::No) {