37 for (
auto key : MapKeys())
38 workspace_->GetMap(name_, key)->HideMapWindow();
45 QStringList core_names = CoreMatrixKeys();
46 QStringList results_names = AnalysisResultsKeys();
48 H5File file(filename.toStdString(), H5F_ACC_TRUNC);
49 DataSpace str_dataspace(H5S_SCALAR);
50 StrType str_type(PredType::C_S1, H5T_VARIABLE);
53 if (file.attrExists(
"Name")) str_attr = file.openAttribute(
"Name");
54 else str_attr = file.createAttribute(
"Name", str_type, str_dataspace);
55 str_attr.write(str_type, name_.toStdString());
57 if (file.attrExists(
"x-Axis Description")) str_attr = file.openAttribute(
"x-Axis Description");
58 else str_attr = file.createAttribute(
"x-Axis Description", str_type, str_dataspace);
59 str_attr.write(str_type, x_axis_description_.toStdString());
61 if (file.attrExists(
"y-Axis Description")) str_attr = file.openAttribute(
"y-Axis Description");
62 else str_attr = file.createAttribute(
"y-Axis Description", str_type, str_dataspace);
63 str_attr.write(str_type, y_axis_description_.toStdString());
65 for (
auto core_name: core_names){
67 dims[0] = GetCoreMatrix(core_name).n_rows;
68 dims[1] = GetCoreMatrix(core_name).n_cols;
69 DataSpace dataspace(2, dims);
70 DataSet ds(file.createDataSet(core_name.toStdString(),
71 PredType::NATIVE_DOUBLE, dataspace));
72 ds.write(GetCoreMatrix(core_name).memptr(),
73 PredType::NATIVE_DOUBLE, dataspace);
77 for (
auto results_name: results_names){
78 QSharedPointer<AnalysisResults> results = GetAnalysisResult(results_name);
79 QStringList matrix_names = results->KeyList();
80 Group results_group(file.createGroup(results_name.toStdString()));
81 if (results_group.attrExists(
"type")) str_attr = results_group.openAttribute(
"type");
82 else str_attr = results_group.createAttribute(
"type", str_type, str_dataspace);
83 std::string results_type = results->type().toStdString();
84 str_attr.write(str_type, results_type);
85 for (
auto matrix_name: matrix_names){
87 dims[0] = results->GetMatrix(matrix_name).n_rows;
88 dims[1] = results->GetMatrix(matrix_name).n_cols;
89 DataSpace dataspace(2, dims);
90 DataSet ds(results_group.createDataSet(matrix_name.toStdString(),
91 PredType::NATIVE_DOUBLE,
93 ds.write(results->GetMatrix(matrix_name).memptr(),
94 PredType::NATIVE_DOUBLE);
97 results_group.close();
101 catch(FileIException error){
102 QString msg = QString::fromStdString(error.getDetailMsg());
103 main_window_->DisplayWarning(
"HDF5 FileIException", msg);
106 catch(DataSetIException error){
107 QString msg = QString::fromStdString(error.getDetailMsg());
108 main_window_->DisplayWarning(
"HDF5 DataSetIException", msg);
111 catch(AttributeIException error){
112 QString msg = QString::fromStdString(error.getDetailMsg());
113 main_window_->DisplayWarning(
"HDF5 AttributeIException", msg);
117 last_save_filename_ = filename;
119 state_changed_ =
false;
125 std::string filename_stdstring = filename.toStdString();
129 spectrum = spectra_.col(column);
130 success = spectrum.save(filename_stdstring, type);
133 main_window_->DisplayExceptionWarning(
"VespucciDataset::SaveSpectrum", e);
142 spectra_old_ = spectra_;
145 abscissa_old_ = abscissa_;
158 return CoreMatrixKeys().contains(key) || AnalysisResultsKeys().contains(key)
159 || AuxiliaryMatrixKeys().contains(key) || key ==
"Auxiliary Matrices";
164 bool has_spatial = x_.n_rows;
166 bool valid_spatial = has_spatial && (x_.n_rows == y_.n_rows);
168 bool spatial_match = valid_spatial && (x_.n_rows == spectra_.n_cols);
170 bool spectral_match = spectra_.n_elem && abscissa_.n_rows == spectra_.n_rows;
171 return spectral_match && (spatial_match || !has_spatial);
176 return state_changed_;
186 return last_save_filename_;
216 QSharedPointer<VespucciWorkspace> ws)
217 : auxiliary_matrices_(new
AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"))
220 filename_ = h5_filename;
221 last_save_filename_ = h5_filename;
223 QString fallback_name =
"Dataset";
224 directory_ = workspace_->directory_ptr();
226 while (workspace_->dataset_names().contains(fallback_name))
227 fallback_name =
"Dataset " + QString::number(counter++);
228 QString abs_label = workspace_->settings()->value(
"absLabel").toString();
229 QString abs_units = workspace_->settings()->value(
"absUnits").toString();
230 QString ord_label = workspace_->settings()->value(
"ordLabel").toString();
231 QString ord_units = workspace_->settings()->value(
"ordUnits").toString();
232 QString fallback_x_description = abs_label +
"(" + abs_units +
")";
233 QString fallback_y_description = ord_label +
"(" + ord_units +
")";
234 main_window_ = main_window;
235 if (!QFile::exists(h5_filename)){
236 constructor_canceled_ =
true;
242 H5File file(h5_filename.toStdString(), H5F_ACC_RDONLY);
244 if (file.attrExists(
"Name")){
245 Attribute attr = file.openAttribute(
"Name");
246 H5std_string buf(
"");
247 DataType type = attr.getDataType();
248 attr.read(type, buf);
249 name_ = QString::fromStdString(buf);
252 name_ = fallback_name;
254 if (file.attrExists(
"x-Axis Description")){
255 Attribute attr = file.openAttribute(
"x-Axis Description");
256 H5std_string buf(
"");
257 DataType type = attr.getDataType();
258 attr.read(type, buf);
259 x_axis_description_ = QString::fromStdString(buf);
262 x_axis_description_ = fallback_x_description;
264 if (file.attrExists(
"y-Axis Description")){
265 Attribute attr = file.openAttribute(
"y-Axis Description");
266 H5std_string buf(
"");
267 DataType type = attr.getDataType();
268 attr.read(type, buf);
269 y_axis_description_ = QString::fromStdString(buf);
272 y_axis_description_ = fallback_y_description;
275 for (hsize_t i = 0; i < file.getNumObjs(); ++i){
276 H5G_obj_t obj_type = file.getObjTypeByIdx(i);
277 string obj_name = file.getObjnameByIdx(i);
279 if (obj_type == H5G_DATASET){
280 DataSet ds = file.openDataSet(obj_name);
281 DataSpace dspace = ds.getSpace();
283 dspace.getSimpleExtentDims(dims);
284 mat matrix(dims[0], dims[1]);
285 ds.read(matrix.memptr(), PredType::NATIVE_DOUBLE);
286 AddMatrix(QString::fromStdString(obj_name), matrix);
289 if (obj_type == H5G_GROUP){
290 Group group = file.openGroup(obj_name);
291 H5std_string result_type(
"");
292 if (group.attrExists(
"type")){
293 Attribute attr = group.openAttribute(
"type");
294 DataType type = attr.getDataType();
295 attr.read(type, result_type);
297 QSharedPointer<AnalysisResults> result(
new AnalysisResults(QString::fromStdString(obj_name), QString::fromStdString(result_type)));
298 for (hsize_t j = 0; j < group.getNumObjs(); ++ j){
299 H5G_obj_t subobj_type = group.getObjTypeByIdx(j);
300 string subobj_name = group.getObjnameByIdx(j);
301 if (subobj_type == H5G_DATASET){
302 DataSet ds = group.openDataSet(subobj_name);
303 DataSpace dspace = ds.getSpace();
305 dspace.getSimpleExtentDims(dims);
306 mat matrix(dims[0], dims[1]);
307 ds.read(matrix.memptr(), PredType::NATIVE_DOUBLE);
308 result->AddMatrix(QString::fromStdString(subobj_name),
323 auxiliary_matrices_ = QSharedPointer<AnalysisResults>(
new AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"));
326 constructor_canceled_ =
false;
328 catch(H5::Exception error){
329 cerr << error.getDetailMsg() <<
"\n";
330 constructor_canceled_ =
IsValid();
332 catch(std::exception e){
333 cerr << e.what() <<
"\n";
334 constructor_canceled_ =
IsValid();
337 if (!constructor_canceled_){
368 : auxiliary_matrices_(new
AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"))
371 filename_ = text_filename;
373 QDateTime datetime = QDateTime::currentDateTimeUtc();
374 state_changed_ =
true;
377 non_spatial_ =
false;
381 map_loading_count_ = 0;
382 z_scores_calculated_ =
false;
383 directory_ = directory;
384 flipped_ = swap_spatial;
386 QProgressDialog progress(
"Loading Dataset...",
"Cancel", 0, 100, NULL);
390 if (format ==
"WideTabDel"){
395 x_, y_, swap_spatial);
396 indices_ = linspace<vec>(0, x_.n_elem - 1, x_.n_elem);
399 string str =
"Text import constructor:" + string(e.what());
400 throw std::runtime_error(str);
403 else if (format ==
"WideCSV"){
408 x_, y_, swap_spatial);
409 indices_ = linspace<vec>(0, x_.n_elem - 1, x_.n_elem);
412 string str =
"Text import constructor: " + string(e.what());
413 throw std::runtime_error(str);
416 else if (format ==
"LongTabDel" || format ==
"LongCSV"){
424 indices_.set_size(x_.n_elem);
425 for (uword i = 0; i < indices_.n_elem; ++i)
429 string str =
"Text import constructor: " + string(e.what());
430 throw std::runtime_error(str);
434 throw std::runtime_error(
"Invalid file format for text import constructor");
437 constructor_canceled_ =
false;
441 main_window_ = main_window;
451 : auxiliary_matrices_(new
AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"))
454 text_filenames_ = text_filenames;
457 QDateTime datetime = QDateTime::currentDateTimeUtc();
458 non_spatial_ =
false;
462 map_loading_count_ = 0;
463 z_scores_calculated_ =
false;
464 directory_ = directory;
476 string reason =
"Multi import constructor: " + string(e.what());
477 throw std::runtime_error(reason.c_str());
482 main_window_ = main_window;
497 QSharedPointer<VespucciDataset> original,
499 : auxiliary_matrices_(new
AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"))
505 state_changed_ =
true;
507 meta_ = original->meta();
508 map_loading_count_ = 0;
513 z_scores_calculated_ =
false;
514 directory_ = directory;
518 spectra_ = original->spectra(indices);
519 abscissa_ = original->wavelength();
520 x_ = original->x(indices);
521 y_ = original->y(indices);
522 parent_indices = original->indices();
523 indices_ = parent_indices(indices);
526 string str =
"Extraction constructor: " + string(e.what());
527 throw std::runtime_error(str);
531 main_window_ = main_window;
532 directory_ = directory;
547 : auxiliary_matrices_(new
AnalysisResults(
"Auxiliary Matrices",
"Auxiliary Matrices"))
551 state_changed_ =
true;
554 map_loading_count_ = 0;
555 z_scores_calculated_ =
false;
556 directory_ = directory;
558 main_window_ = main_window;
559 directory_ = directory;
572 mat spectra_buffer = spectra_;
575 vec abscissa_buffer = abscissa_;
577 spectra_.swap(spectra_old_);
580 abscissa_.swap(abscissa_old_);
595 string str =
"Undo: " + string(e.what());
596 throw std::runtime_error(str);
599 state_changed_ =
true;
600 last_operation_ =
"Undo";
614 double y_min,
double y_max,
615 double wl_min,
double wl_max)
619 if (!std::isnan(x_min) && !std::isnan(x_max) && !std::isnan(y_min) && !std::isnan(y_max)){
620 uvec valid_indices = find ((x_ >= x_min) && (x_ <= x_max));
622 spectra_ = spectra_.cols(valid_indices);
623 y_ = y_.rows(valid_indices);
624 x_ = x_.rows(valid_indices);
625 valid_indices = find((y_ >= y_min) && (y_ <= y_max));
626 y_ = y_.rows(valid_indices);
627 x_ = x_.rows(valid_indices);
628 spectra_ = spectra_.cols(valid_indices);
630 string str =
"CropSpectra: " + string(e.what());
631 throw std::runtime_error(str);
634 if (!std::isnan(wl_min) && !std::isnan(wl_max)){
635 uvec valid_indices = find(abscissa_ >= wl_min && abscissa_ <= wl_max);
637 spectra_ = spectra_.rows(valid_indices);
638 abscissa_ = abscissa_.rows(valid_indices);
641 string str =
"CropSpectra: " + string(e.what());
642 throw std::runtime_error(str);
646 last_operation_ =
"crop";
647 operations_ <<
"CropSpectra(" 648 + QString::number(x_min) +
", " 649 + QString::number(x_max) +
", " 650 + QString::number(y_min) +
", " 651 + QString::number(y_max) +
", " 652 + QString::number(wl_min) +
", " 653 + QString::number(wl_max) +
")";
654 state_changed_ =
true;
655 workspace_->UpdateModel();
669 for (uword i = 0; i < spectra_.n_cols; ++i){
670 spectrum_buffer = spectra_.col(i);
671 extrema_buffer = spectrum_buffer.min()*ones<vec>(spectra_.n_rows);
672 spectrum_buffer -= extrema_buffer;
673 extrema_buffer = spectrum_buffer.max()*ones<vec>(spectra_.n_rows);
674 spectrum_buffer /= extrema_buffer;
675 spectra_.col(i) = spectrum_buffer;
679 string str =
"MinMaxNormalize: " + string(e.what());
680 throw std::runtime_error(str);
682 last_operation_ =
"min/max normalize";
683 operations_ <<
"MinMaxNormalize()";
684 state_changed_ =
true;
693 if (!norm || norm > 2)
return;
694 state_changed_ =
true;
698 spectra_ = normalise(spectra_, norm);
701 string str =
"VectorNormalize()" + string(e.what());
702 throw std::runtime_error(str);
704 operations_ <<
"VectorNormalize(" + QString::number(norm) +
")";
705 last_operation_ =
"vector normalize";
714 state_changed_ =
true;
717 vec mean_intensity = mean(spectra_, 1);
718 spectra_.each_col() -= mean_intensity;
721 throw std::runtime_error(
"MeanCenter");
723 last_operation_ =
"mean centering";
724 operations_ <<
"MeanCenter()";
737 for (uword j = 0; j < spectra_.n_cols; ++j){
738 spectra_.col(j) /= peak_maxes(j);
740 last_operation_ =
"Peak intensity normalize";
741 operations_ <<
"PeakIntensityNormalize(" 742 + QString::number(left_bound) +
", " 743 + QString::number(right_bound) +
")";
756 last_operation_ =
"Booleanize";
761 spectra_.elem(find(spectra_ <= min && spectra_ >= max) ).zeros();
763 spectra_.elem(find(spectra_ >= min && spectra_ <= max) ).zeros();
768 spectra_.elem( find(spectra_) ).ones();
773 runtime_error f(
"Booleanize");
776 operations_ <<
"Booleanize(" + QString::number(min) +
", " 777 + QString::number(max) +
", " 778 + (keep_inside ?
"true" :
"false") +
", " 779 + (oneify ?
"true" :
"false") +
")";
790 last_operation_ =
"Clamp";
791 state_changed_ =
true;
795 spectra_ = clamp(spectra_, min, max);
799 runtime_error f(
"Clamp");
802 operations_ <<
"Clamp(" 803 + QString::number(min) +
", " 804 + QString::number(max) +
")";
813 for (uword i = 0; i < spectra_.n_cols; ++i){
814 current_col = spectra_.col(i);
815 indices_buffer = find(current_col, 1);
816 if (indices_buffer.n_elem > 0)
820 spectra_ = spectra_.cols(indices);
821 x_ = x_.rows(indices);
822 y_ = y_.rows(indices);
828 workspace_->UpdateModel();
829 operations_ <<
"ShedZeroSpectra()";
834 state_changed_ =
true;
839 for (uword i = 0; i < spectra_.n_rows; ++i){
840 current_row = spectra_.row(i);
841 indices_buffer = find(current_row, 1);
842 if (indices_buffer.n_elem > 0)
846 spectra_ = spectra_.rows(indices);
847 abscissa_ = abscissa_.rows(indices);
852 workspace_->UpdateModel();
853 operations_ <<
"ShedZeroWavelengths()";
870 string str =
"ZScoreNormCopy: " + string(e.what());
871 throw std::runtime_error(str);
873 return trans(normalized);
883 state_changed_ =
true;
891 string str =
"ZScoreNormalize: " + string(e.what());
892 throw std::runtime_error(str);
895 z_scores_calculated_ =
true;
896 last_operation_ =
"Z-score normalize";
897 operations_ <<
"ZScoreNormalize()";
904 state_changed_ =
true;
911 string str =
"SNVNormalize: " + string(e.what());
912 throw std::runtime_error(str);
915 last_operation_ =
"SNVNormalize";
916 operations_ <<
"SNVNormalize()";
921 state_changed_ =
true;
926 spectra_ = arma::abs(spectra_);
930 "AbsoluteValue: " + string(e.what());
931 throw std::runtime_error(str);
934 last_operation_ =
"Absolute value";
935 operations_ <<
"AbsoluteValue()";
944 mat background = workspace_->GetMatrix(data_keys);
945 state_changed_ =
true;
947 if (background.n_rows != spectra_.n_rows){
948 QMessageBox::warning(0,
949 "Improper Dimensions!",
950 "The background spectrum has a different number of" 951 " points than the map data." 952 " No subtraction can be performed");
957 spectra_.each_col() -= background.col(0);
960 string str =
"SubtractBackground: " + string(e.what());
961 throw std::runtime_error(str);
964 last_operation_ =
"background correction";
979 state_changed_ =
true;
982 baselines_ = spectra_;
983 for (uword i = 0; i < uword(iterations); ++i){
986 spectra_ -= baselines_;
989 string str =
"MFBaseline: " + string(e.what());
990 throw std::runtime_error(str);
993 last_operation_ =
"baseline correction (median filter)";
994 operations_ <<
"MFBaseline(" 995 + QString::number(window_size) +
", " 996 + QString::number(iterations) +
")";
1006 state_changed_ =
true;
1014 }
catch(exception e){
1015 string str =
"RollingBallBaseline " + string(e.what());
1016 throw std::runtime_error(str);
1018 last_operation_ =
"baseline correction (rolling ball)";
1019 operations_ <<
"RollingBallBaseline(" 1020 + QString::number(wm) +
", " 1021 + QString::number(ws) +
")";
1031 state_changed_ =
true;
1033 mat baselines(spectra_.n_rows, spectra_.n_cols);
1034 vec baseline, corrected;
1035 QProgressDialog *progress =
new QProgressDialog(main_window_);
1036 progress->setMinimum(0);
1037 progress->setMaximum(spectra_.n_cols-1);
1038 progress->setWindowTitle(
"Correcting Baseline");
1039 progress->setWindowModality(Qt::WindowModal);
1040 QString colcount =
" of " + QString::number(spectra_.n_cols);
1041 progress->setLabelText(
"Spectrum 0" + colcount);
1045 for (uword i = 0; i < spectra_.n_cols; ++i){
1046 progress->setValue(i);
1047 progress->setLabelText(
"Spectrum " + QString::number(i+1) + colcount);
1049 abscissa_, baseline,
1051 poly_order, max_it, threshold);
1052 baselines.col(i) = baseline;
1053 spectra_.col(i) = corrected;
1054 if (progress->wasCanceled()){
1060 }
catch(exception e){
1064 if (!progress->wasCanceled()){
1067 operations_ <<
"IModPolyBaseline(" 1068 + QString::number(poly_order) +
", " 1069 + QString::number(max_it) +
", " 1070 + QString::number(threshold) +
")";
1071 last_operation_ =
"IModPoly baseline";
1081 rowvec spectra_max =
max(spectra_, 0);
1083 uvec valid_indices = find(spectra_max < threshold);
1084 if (valid_indices.n_elem == 0)
1088 spectra_ = spectra_.cols(valid_indices);
1089 x_ = x_.rows(valid_indices);
1090 y_ = y_.rows(valid_indices);
1093 string str =
"RemoveClipped Spectra: " + string(e.what());
1094 throw std::runtime_error(str);
1097 if (spectra_.n_rows != spectra_old_.n_rows)
1098 non_spatial_ =
true;
1100 workspace_->UpdateModel();
1101 last_operation_ =
"threshold";
1102 operations_ <<
"RemovedClippedSpectra(" + QString::number(threshold) +
")";
1112 rowvec spectra_max =
max(spectra_, 0);
1114 uvec valid_indices = find(spectra_max > threshold);
1115 if (valid_indices.n_elem == 0)
1119 spectra_ = spectra_.cols(valid_indices);
1120 x_ = x_.rows(valid_indices);
1121 y_ = y_.rows(valid_indices);
1124 string str =
"RemoveClipped Spectra: " + string(e.what());
1125 throw std::runtime_error(str);
1128 if (spectra_.n_rows != spectra_old_.n_rows)
1129 non_spatial_ =
true;
1131 workspace_->UpdateModel();
1132 last_operation_ =
"threshold";
1133 operations_ <<
"RemoveFlatSpectra(" + QString::number(threshold) +
")";
1143 rowvec spectra_max =
max(spectra_, 0);
1144 uvec invalid_indices = find(spectra_max > threshold);
1145 if (invalid_indices.n_elem == 0)
1149 for (uword i = 0; i < invalid_indices.n_rows; ++i)
1150 spectra_.col(invalid_indices(i)) = zeros(spectra_.n_rows);
1153 string str =
"RemoveClipped Spectra: " + string(e.what());
1154 throw std::runtime_error(str);
1157 if (spectra_.n_rows != spectra_old_.n_rows)
1158 non_spatial_ =
true;
1160 workspace_->UpdateModel();
1161 last_operation_ =
"threshold";
1162 operations_ <<
"ZeroClippedSpectra(" + QString::number(threshold) +
")";
1172 rowvec spectra_max =
max(spectra_, 0);
1173 uvec invalid_indices = find(spectra_max < threshold);
1174 if (invalid_indices.n_elem == 0)
1178 for (uword i = 0; i < invalid_indices.n_rows; ++i)
1179 spectra_.col(invalid_indices(i)) = zeros(spectra_.n_rows);
1182 string str =
"RemoveClipped Spectra: " + string(e.what());
1183 throw std::runtime_error(str);
1186 if (spectra_.n_rows != spectra_old_.n_rows)
1187 non_spatial_ =
true;
1189 workspace_->UpdateModel();
1190 last_operation_ =
"threshold";
1191 operations_ <<
"ZeroFlatSpectra(" + QString::number(threshold) +
")";
1203 state_changed_ =
true;
1208 spectra_ = processed;
1211 string str =
"MedianFilter: " + string(e.what());
1212 throw std::runtime_error(str);
1215 last_operation_ =
"median filter";
1216 operations_ <<
"MedianFilter(" + QString::number(window_size) +
")";
1227 state_changed_ =
true;
1231 for (uword j = 0; j < spectra_.n_cols; ++j){
1236 string str =
"LinearMovingAverage: " + string(e.what());
1237 throw std::runtime_error(str);
1240 last_operation_ =
"moving average filter";
1241 operations_ <<
"LinearMovingAverage(" +QString::number(window_size) +
")";
1254 state_changed_ =
true;
1263 string str =
"SingularValue: " + string(e.what());
1264 throw std::runtime_error(str);
1267 vec SVD_vec({double(singular_values)});
1268 QSharedPointer<AnalysisResults> results(
new AnalysisResults(
"QUIC-SVD",
"QUIC-SVD"));
1269 results->AddMatrix(
"Left Singular Vectors", U);
1270 results->AddMatrix(
"Right Singular Vectors", V);
1271 results->AddMatrix(
"Singular Values", s);
1272 results->AddMatrix(
"Rank", SVD_vec);
1275 last_operation_ =
"truncated SVD de-noise";
1276 operations_ <<
"SingularValue(" + QString::number(singular_values) +
")";
1288 state_changed_ =
true;
1295 }
catch(exception e){
1296 string str =
"QUIC_SVD: " + string(e.what());
1297 throw std::runtime_error(str);
1300 vec SVD_vec({double(rank)});
1302 QSharedPointer<AnalysisResults> results(
new AnalysisResults(
"QUIC-SVD",
"QUIC-SVD"));
1303 results->AddMatrix(
"Left Singualr Vectors", U);
1304 results->AddMatrix(
"Right Singualr Vectors", V);
1305 results->AddMatrix(
"Singualr Values", s);
1306 results->AddMatrix(
"Rank", SVD_vec);
1308 last_operation_ =
"QUIC_SVD de-noise";
1309 operations_ <<
"QUIC_SVD(" + QString::number(epsilon) +
" )";
1321 unsigned int polynomial_order,
1322 unsigned int window_size)
1324 state_changed_ =
true;
1335 string str =
"SavitzkyGolay: " + string(e.what());
1336 throw std::runtime_error(str);
1339 last_operation_ =
"Savitzky-Golay filtering";
1340 operations_ <<
"SavitzkyGolay(" 1341 + QString::number(derivative_order) +
", " 1342 + QString::number(polynomial_order) +
", " 1343 + QString::number(window_size) +
")";
1348 state_changed_ =
true;
1352 spectra_ = spectra_ * scaling_factor;
1353 }
catch(exception e){
1354 string str =
"Scale(): " + string(e.what());
1355 throw std::runtime_error(str);
1358 last_operation_ =
"Scaling";
1359 operations_ <<
"Scale(" + QString::number(scaling_factor) +
")";
1368 state_changed_ =
true;
1372 spectra_.shed_col(index);
1375 indices_.shed_row(index);
1379 std::runtime_error exc(
"VespucciDataset::ShedSpectrum");
1382 cout <<
"spectra_ columns (post) = " << spectra_.n_cols;
1383 operations_ <<
"ShedSpectrum(" + QString::number(index) +
")";
1384 workspace_->UpdateModel();
1389 state_changed_ =
true;
1392 spectra_.col(index).fill(0);
1396 std::runtime_error exc(
"VespucciDataset::ShedSpectrum");
1399 operations_ <<
"ZeroSpectrum(" + QString::number(index) +
")";
1400 workspace_->UpdateModel();
1409 cout <<
"VespucciDataset::HySime\n";
1412 mat noise, noise_correlation, subspace;
1413 cout <<
"call EstimateAdditiveNoise\n";
1417 cout <<
"took " << timer.toc() <<
" seconds.\n";
1419 cout <<
"Call HySime\n";
1423 cout <<
"Took " << timer.toc() <<
" seconds.\n";
1437 state_changed_ =
true;
1438 if (input_units ==
"Wavelength"){
1439 if (output_units ==
"Energy"){
1442 x_axis_description_ = description;
1443 last_operation_ =
"Abscissa Transform";
1445 else if (output_units ==
"Wavenumber"){
1448 x_axis_description_ = description;
1449 last_operation_ =
"Abscissa Transform";
1451 else if (output_units ==
"Frequency"){
1454 x_axis_description_ = description;
1455 last_operation_ =
"Abscissa Transform";
1457 else if (output_units ==
"Wavelength"){
1459 abscissa_ = (input_factor * output_factor) * abscissa_;
1460 x_axis_description_ = description;
1461 last_operation_ =
"Abscissa Transform";
1465 else if (input_units ==
"Energy"){
1466 if (output_units ==
"Energy"){
1468 abscissa_ = (input_factor * output_factor) * abscissa_;
1469 x_axis_description_ = description;
1470 last_operation_ =
"Abscissa Transform";
1472 else if (output_units ==
"Wavenumber"){
1475 x_axis_description_ = description;
1476 last_operation_ =
"Abscissa Transform";
1478 else if (output_units ==
"Frequency"){
1481 x_axis_description_ = description;
1482 last_operation_ =
"Abscissa Transform";
1484 else if (output_units ==
"Wavelength"){
1487 x_axis_description_ = description;
1488 last_operation_ =
"Abscissa Transform";
1492 else if (input_units ==
"Wavenumber"){
1493 if (output_units ==
"Energy"){
1496 x_axis_description_ = description;
1497 last_operation_ =
"Abscissa Transform";
1499 else if (output_units ==
"Wavenumber"){
1501 abscissa_ = (input_factor * output_factor) * abscissa_;
1502 x_axis_description_ = description;
1503 last_operation_ =
"Abscissa Transform";
1505 else if (output_units ==
"Frequency"){
1508 x_axis_description_ = description;
1509 last_operation_ =
"Abscissa Transform";
1511 else if (output_units ==
"Wavelength"){
1514 x_axis_description_ = description;
1515 last_operation_ =
"Abscissa Transform";
1519 else if (input_units ==
"Frequency"){
1520 if (output_units ==
"Energy"){
1523 x_axis_description_ = description;
1524 last_operation_ =
"Abscissa Transform";
1526 else if (output_units ==
"Wavenumber"){
1529 x_axis_description_ = description;
1530 last_operation_ =
"Abscissa Transform";
1532 else if (output_units ==
"Frequency"){
1534 abscissa_ = (input_factor * output_factor) * abscissa_;
1535 x_axis_description_ = description;
1536 last_operation_ =
"Abscissa Transform";
1538 else if (output_units ==
"Wavelength"){
1541 x_axis_description_ = description;
1542 last_operation_ =
"Abscissa Transform";
1557 state_changed_ =
true;
1561 }
catch(exception e){
1562 string str =
"InterpolateToNewAbscissa(vec, uint, uint): " + string(e.what());
1563 throw std::runtime_error(str);
1566 abscissa_ = new_abscissa;
1567 spectra_ = new_spectra;
1568 last_operation_ =
"Abscissa Interpolation";
1569 workspace_->UpdateModel();
1578 state_changed_ =
true;
1582 }
catch(exception e){
1583 string str =
"InterpolateToNewAbscissa(vec): " + string(e.what());
1584 throw std::runtime_error(str);
1587 abscissa_ = new_abscissa;
1588 spectra_ = new_spectra;
1589 last_operation_ =
"Abscissa Interpolation";
1590 workspace_->UpdateModel();
1599 state_changed_ =
true;
1600 cx_mat f_spectra(spectra_.n_rows, spectra_.n_cols);
1601 vec f_abscissa(abscissa_.n_rows);
1604 f_spectra, f_abscissa,
1606 }
catch(exception e){
1607 string str =
"FourierTransform: " + string(e.what());
1608 throw std::runtime_error(str);
1611 spectra_ = real(f_spectra);
1612 spectra_imag_ = imag(f_spectra);
1613 abscissa_ = f_abscissa;
1614 x_axis_description_ =
"Frequency (Hz)";
1619 state_changed_ =
true;
1620 cx_mat t_spectra(spectra_.n_rows, spectra_.n_cols);
1621 vec t_abscissa(abscissa_.n_rows);
1628 }
catch(exception e){
1629 string str =
"InverseFourierTransform: " + string(e.what());
1630 throw std::runtime_error(str);
1633 spectra_ = real(t_spectra);
1634 spectra_imag_ = imag(t_spectra);
1635 abscissa_ = t_abscissa;
1636 x_axis_description_ =
"Time (s)";
1647 state_changed_ =
true;
1650 if (type ==
"Exponential"){shape =
"exp";}
1651 else{shape =
"gaus";}
1654 }
catch(exception e){
1670 state_changed_ =
true;
1678 }
catch(exception e){
1692 double &left_bound,
double &right_bound,
1695 state_changed_ =
true;
1696 QSharedPointer<UnivariateData> univariate_data(
new UnivariateData(name));
1698 univariate_data->Apply(left_bound, right_bound, bound_window, spectra_, abscissa_);
1699 }
catch(exception e){
1704 workspace_->UpdateModel();
1706 operations_ <<
"Univariate(" 1708 + QString::number(left_bound) +
", " 1709 + QString::number(right_bound) +
", " 1710 + QString::number(bound_window) +
")";
1716 state_changed_ =
true;
1717 QSharedPointer<UnivariateData> univariate_data(
new UnivariateData(name));
1719 univariate_data->Apply(peak_shape, left_bound, right_bound, spectra_, abscissa_);
1720 }
catch (exception e){
1724 workspace_->UpdateModel();
1735 void VespucciDataset::BandRatio(
const QString &
name,
double &first_left_bound,
double &first_right_bound,
double &second_left_bound,
double &second_right_bound, uword bound_window)
1737 state_changed_ =
true;
1738 QSharedPointer<UnivariateData> univariate_data(
new UnivariateData(name));
1740 univariate_data->Apply(first_left_bound, first_right_bound,
1741 second_left_bound, second_right_bound,
1743 spectra_, abscissa_);
1744 }
catch(exception e){
1749 workspace_->UpdateModel();
1750 operations_ <<
"BandRatio(" 1752 + QString::number(first_left_bound) +
", " 1753 + QString::number(first_right_bound) +
", " 1754 + QString::number(second_left_bound) +
", " 1755 + QString::number(second_right_bound) +
", " 1756 + QString::number(bound_window) +
")";
1770 QSharedPointer<MlpackPCAData> mlpack_pca_data(
new MlpackPCAData(name));
1771 state_changed_ =
true;
1774 mlpack_pca_data->Apply(spectra_, scale_data);
1777 throw std::runtime_error(
"VespucciDataset::PrincipalComponents");
1780 workspace_->UpdateModel();
1789 state_changed_ =
true;
1793 pca_data->Apply(spectra_);
1794 }
catch(exception e){
1795 string str =
"PrincipalComponents: " + string(e.what());
1796 throw std::runtime_error(str);
1799 workspace_->UpdateModel();
1800 operations_ <<
"PrincipalComponents(" + name +
")";
1844 QSharedPointer<AnalysisResults> ahca_results(
new AnalysisResults(name,
"AHCA"));
1850 ahca.
Link(spectra_);
1851 assignments = ahca.
Cluster(spectra_.n_cols);
1852 }
catch (exception e){
1853 string str =
"AgglomerativeClustering: " + string(e.what());
1854 throw runtime_error(str);
1857 ahca_results->AddMatrix(
"Assignments", assignments);
1858 ahca_results->AddMatrix(
"Spectrum Distances", ahca.
dist());
1859 ahca_results->AddMatrix(
"Cluster Distances", ahca.
merge_data());
1861 state_changed_ =
true;
1862 operations_ <<
"AgglomerativeClustering(" + name +
", " + linkage +
", " + metric +
")";
1863 workspace_->UpdateModel();
1878 }
catch(exception e){
1879 string str =
"CalculateRepresentativeSpectrum: " + string(e.what());
1880 throw runtime_error(str);
1882 QString matrix_name =
name;
1884 while (auxiliary_matrices_->HasMatrix(matrix_name))
1885 matrix_name = name +
" (" + QString::number(i++) +
")";
1886 auxiliary_matrices_->AddMatrix(matrix_name, rep);
1887 workspace_->UpdateModel();
1897 state_changed_ =
true;
1899 if(endmembers == 0){
1901 alert.setText(
"The HySime algorithm will take a long time.");
1902 alert.setInformativeText(
"OK to continue");
1904 alert.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1905 alert.setWindowTitle(
"Principal Components Analysis");
1906 alert.setIcon(QMessageBox::Question);
1908 int ret = alert.exec();
1911 if (ret == QMessageBox::Cancel){
1917 QSharedPointer<VCAData> vertex_components_data(
new VCAData(name));
1920 vertex_components_data->Apply(spectra_, endmembers);
1921 }
catch(exception e){
1922 cerr <<
"VespucciDataset::VertexComponents()\n";
1924 throw std::runtime_error(
"VertexComponents: " +
string(e.what()));
1927 workspace_->UpdateModel();
1928 operations_ <<
"VertexComponents(" 1930 + QString::number(endmembers) +
")";
1942 state_changed_ =
true;
1943 if(components == 0){
1947 QSharedPointer<PLSData> pls_data(
new PLSData(name));
1951 pls_data->Classify(spectra_, abscissa_, components);
1952 }
catch(exception e){
1953 string str =
"PartialLeastSquares: " + string(e.what());
1954 throw std::runtime_error(str);
1958 workspace_->UpdateModel();
1959 operations_ <<
"PartialLeastSquares(" 1961 + QString::number(components) +
")";
1967 state_changed_ =
true;
1968 QSharedPointer<PLSData> pls_data(
new PLSData(name));
1969 mat controls = workspace_->GetMatrix(control_keys);
1972 pls_data->Calibrate(spectra_, controls);
1973 }
catch(exception e){
1974 string str =
"PartialLeastSquares: " + string(e.what());
1975 throw std::runtime_error(str);
1979 workspace_->UpdateModel();
1984 state_changed_ =
true;
1985 QSharedPointer<PLSData> pls_data(
new PLSData(name));
1986 mat labels = workspace_->GetMatrix(label_keys);
1989 pls_data->Discriminate(spectra_, labels);
1990 }
catch(exception e){
1991 string str =
"PartialLeastSquares: " + string(e.what());
1992 throw std::runtime_error(str);
1996 workspace_->UpdateModel();
2007 if (!auxiliary_matrices_->HasMatrix(control_key)){
2008 main_window_->
DisplayWarning(
"Object does not exit",
"The object at the specified key does not exist!");
2013 control = auxiliary_matrices_->GetMatrix(control_key).col(0);
2014 }
catch(exception e){
2019 QSharedPointer<UnivariateData> univariate_data(
new UnivariateData(name));
2021 univariate_data->ApplyCorrelation(spectra_, control);
2022 }
catch(exception e){
2027 state_changed_ =
true;
2029 workspace_->UpdateModel();
2047 assignments = k.
Cluster(spectra_, clusters, centroids);
2048 }
catch(exception e){
2053 QSharedPointer<AnalysisResults> results(
new AnalysisResults(name,
"k-Means Analysis"));
2054 results->AddMatrix(
"Assignments", assignments);
2055 results->AddMatrix(
"Centroids", centroids);
2057 workspace_->UpdateModel();
2058 operations_ <<
"KMeans(" 2060 + QString::number(clusters) +
", " 2061 + metric_text +
", " 2062 + partition_policy +
", " 2063 + (allow_empty ?
"true" :
"false" ) +
")";
2068 state_changed_ =
true;
2069 mat reference = workspace_->GetMatrix(reference_keys);
2073 }
catch(exception e){
2074 string str =
"Vespucci::Math::LinLeastSq::OrdinaryLeastSquares" + string(e.what());
2075 throw runtime_error(str);
2078 QSharedPointer<AnalysisResults> results(
new AnalysisResults(name,
"CLS Analysis"));
2079 results->AddMatrix(
"Coefficients", coefs);
2081 workspace_->UpdateModel();
2082 QString operation =
"ClassicalLeastSquares(" +
name;
2083 for (
auto param: reference_keys)
2084 operation = operation +
", " + param;
2085 operation = operation +
")";
2086 operations_ << operation;
2115 double delta =
std::max(std::abs((x_(1) -
x(0))), std::abs((y_(1) - y_(0))));
2116 uvec zero_x = find(((0-delta) <= x_) && (0 + delta) >= x_);
2117 vec sub_y = y_.elem(zero_x);
2118 uvec zero_y = find(((0-delta) <= sub_y) && ((0+delta) >= sub_y));
2121 uword mid = ((x_.n_rows % 2 == 0) ? x_.n_rows : (2*(x_.n_rows + 1)) / 2);
2122 return (zero_y.n_rows > 0 ? zero_y(0) : mid);
2131 return spectra_.col((index < spectra_.n_cols ? index : spectra_.n_cols - 1));
2136 std::vector<double> abscissa_stdvector =
2137 conv_to< std::vector<double> >::from(abscissa_);
2139 QVector<double> abscissa_qvector =
2140 QVector<double>::fromStdVector(abscissa_stdvector);
2142 return abscissa_qvector;
2147 double delta = std::fabs(abscissa_(1) - abscissa_(0));
2148 uvec
indices = find((abscissa_value - delta) < abscissa_ <= (abscissa_value + delta));
2160 double lower = y_.min();
2161 double upper = y_.max();
2173 double lower = x_.min();
2174 double upper = x_.max();
2195 for(i=0; i<x_.n_elem; ++i){
2203 for (i=0; i<x_.n_elem; ++i){
2232 for (i=0; i<x_.n_elem; ++i){
2242 double y_buf = y_(0);
2243 for(i=0; i<y_.n_elem; ++i){
2273 return abscissa_.rows(indices);
2300 return (mat *) &indices_;
2329 if (index >= x_.n_rows)
2330 return x_(x_.n_rows - 1);
2358 if (index >= y_.n_rows)
2359 return y_(y_.n_rows - 1);
2375 if (spectra_imag_.n_rows == spectra_.n_rows && spectra_imag_.n_cols == spectra_.n_cols)
2376 return cx_mat(spectra_, spectra_imag_);
2378 return cx_mat(spectra_, zeros(spectra_.n_rows, spectra_.n_cols));
2383 if (spectra_imag_.n_rows == spectra_.n_rows && spectra_imag_.n_cols == spectra_.n_cols)
2384 return cx_mat(spectra_.cols(indices), spectra_imag_.cols(indices));
2386 return cx_mat(spectra_.cols(indices), zeros(spectra_.n_rows, indices.n_rows));
2396 return spectra_.cols(indices);
2448 return map_loading_count_;
2459 QString basename = map->name();
2461 while(
MapKeys().contains(map->name()))
2462 map->SetName(basename +
" (" + QString::number(++i) +
")", map->type());
2464 workspace_->UpdateModel();
2469 if (
MapKeys().contains(name)){
2470 int i = maps_.size();
2472 if (maps_[i]->
name() == name)
2484 double min = abscissa_.min();
2485 double max = abscissa_.max();
2497 vec row = spectra_.col(i);
2498 double min = row.min();
2499 double max = row.max();
2513 switch (gradient_number)
2589 return constructor_canceled_;
2602 mat spec_mean = mean(spectra_, 1);
2606 spec_stddev = stddev(spectra_, 0, 1);
2607 spec_mean.insert_cols(1, spec_stddev);
2621 return x_axis_description_;
2631 x_axis_description_ = description;
2640 y_axis_description_ = description;
2649 return y_axis_description_;
2700 return spectra_.n_cols;
2705 return abscissa_.min();
2710 return abscissa_.max();
2720 return (spectra_old_.n_elem > 0 ?
true :
false);
2725 vec unique_x = unique(x_);
2726 return unique_x.n_rows;
2731 vec unique_y = unique(y_);
2732 return unique_y.n_rows;
2742 return analysis_results_.size();
2783 return non_spatial_;
2806 return &parent_dataset_indices_;
2815 return last_operation_;
2821 QString
name = analysis_result->name();
2822 QString new_name =
name;
2825 new_name = name +
" " + QString::number(++i);
2826 analysis_result->SetName(new_name);
2827 analysis_result->AddParent(name_, 0, spectra_.n_cols);
2828 analysis_results_.append(analysis_result);
2829 state_changed_ =
true;
2830 workspace_->UpdateModel();
2835 QString
name = analysis_result->name();
2836 QString new_name =
name;
2839 new_name = name +
" " + QString::number(++i);
2840 analysis_result->SetName(new_name);
2841 analysis_result->AddParent(name_, start_row, end_row);
2842 analysis_results_.append(analysis_result);
2843 state_changed_ =
true;
2844 workspace_->UpdateModel();
2855 for (
auto result: analysis_results_)
2856 keys << result->name();
2866 QMap<QString, QStringList> tree_structure;
2867 for (
auto result: analysis_results_)
2868 tree_structure[result->name()] = result->KeyList();
2869 return tree_structure;
2880 bool ok = matrix.load(filename.toStdString());
2882 auxiliary_matrices_->AddMatrix(name, matrix);
2884 main_window_->
DisplayWarning(
"Matrix Not Loaded",
"The file " + name +
" could not be loaded");
2894 QString basename =
name;
2895 QString new_name =
name;
2897 while (auxiliary_matrices_->HasMatrix(new_name))
2898 new_name = basename +
" (" + QString::number(++i) +
")";
2899 auxiliary_matrices_->AddMatrix(new_name, matrix);
2900 workspace_->UpdateModel();
2901 state_changed_ =
true;
2906 if (name ==
"Spectra")
2908 else if (name ==
"x")
2910 else if (name ==
"y")
2912 else if (name ==
"Spectral Abscissa")
2913 abscissa_ = matrix.col(0);
2916 state_changed_ =
true;
2917 workspace_->UpdateModel();
2926 return auxiliary_matrices_->KeyList();
2935 return {
"Spectra",
"Spectral Abscissa",
"x",
"y"};
2947 for (
auto result: analysis_results_){
2948 if (result->name() == results_key)
2949 if (result->KeyList().contains(matrix_key))
2950 return result->GetMatrix(matrix_key);
2953 return empty_matrix_;
2959 for (
auto result: analysis_results_){
2960 if (result->name() == key)
2964 QSharedPointer<AnalysisResults> dummy(
new AnalysisResults(
"Dummy",
"Dummy"));
2970 if (auxiliary_matrices_->HasMatrix(key))
return auxiliary_matrices_->GetMatrix(key);
2972 return empty_matrix_;
2977 if (key ==
"Spectra"){
return spectra_;}
2978 else if (key ==
"Spectral Abscissa"){
return abscissa_;}
2979 else if (key ==
"x"){
return x_;}
2980 else if (key ==
"y"){
return y_;}
2981 else{
return empty_matrix_;}
2992 return (key ==
"Spectra" || key ==
"Spectral Abscissa" || key ==
"x" || key ==
"y");
2997 for (
auto map: maps_){
2998 if (map->name() == key)
return map;
3000 return QSharedPointer<MapData>(0);
3014 const QString &results_key,
3015 const QString &matrix_key,
3021 QStringList data_keys = {name_, results_key, matrix_key};
3023 QSharedPointer<MapData> new_map(
new MapData(map_name,
3029 new_map->setGradient(gradient);
3031 workspace_->UpdateModel();
3036 const QString &matrix_key,
3040 if (auxiliary_matrices_->HasMatrix(matrix_key)){
3041 QStringList data_keys = {name_, matrix_key};
3042 QSharedPointer<MapData> new_map(
new MapData(map_name,
3047 new_map->setGradient(gradient);
3049 workspace_->UpdateModel();
3055 if (!
MapKeys().contains(map_key))
return false;
3056 bool ok =
MapKeys().contains(map_key);
3058 for (
auto map: maps_){
3059 if (map->name() == map_key){
3060 map->ShowMapWindow(show);
3069 QStringList map_keys;
3070 for (
auto map: maps_)
3071 map_keys << map->name();
VESPUCCI_EXPORT arma::vec WavenumberToWavelength(const arma::vec &x, double wn_factor, double wl_factor)
Vespucci::Math::WavenumberToWavelength.
The PLSData class A class for performing and storing data related to partial least squares determinan...
void RemoveFlatSpectra(double threshold)
VespucciDataset::RemoveFlatSpectra.
mat * spectra_ptr()
VespucciDataset::spectra_ptr.
QSharedPointer< MapData > GetMapData(const QString &key)
VESPUCCI_EXPORT arma::mat StandardScoreMat(const arma::mat &X)
Vespucci::Math::Normalization::StandardScore.
const QString name() const
VespucciDataset::name.
void ApplyFTWeight(QString type, double param)
VespucciDataset::ApplyFTWeight.
void MeanCenter()
VespucciDataset::MeanCenter Subtract the mean of all spectra in the dataset at each wavelength from e...
QCPRange KeyRange() const
VespucciDataset::KeyRange Finds the minima and maxima of x variable to properly set axes of QCustomPl...
void ZScoreNormalize()
VespucciDataset::ZScoreNormalize Normalizes each row using the score of the normal distribution...
void PrincipalComponents(const QString &name)
VespucciDataset::PrincipalComponents Perform PCA without creating an image.
cx_mat cx_spectra() const
void TransformAbscissa(QString input_units, double input_factor, QString output_units, double output_factor, QString description)
VespucciDataset::TransformAbscissa.
QVector< double > WavelengthQVector() const
arma::vec Cluster(const arma::mat &data, const size_t clusters, arma::mat ¢roids)
void Clamp(double min, double max)
VespucciDataset::Clamp.
void VertexComponents(const QString &name, uword endmembers)
VespucciDataset::VertexComponents.
mat * y_ptr()
VespucciDataset::y_ptr.
const vec & x_ref()
VespucciDataset::x_ref.
The PrincipalComponentsData class A class for performing and storing data from principal components a...
VESPUCCI_EXPORT arma::vec WavelengthToEnergy(const arma::vec &x, double energy_factor, double wl_factor)
Vespucci::Math::WavelengthToEnergy.
VESPUCCI_EXPORT arma::vec ApplyFilter(const arma::vec &x, arma::mat coefficients, arma::uword window_size)
Vespucci::Math::Smoothing::ApplyFilter Apply FIR filters to a column vector.
const vec & y_ref()
VespucciDataset::y_ref.
VESPUCCI_EXPORT arma::vec EnergyToWavelength(const arma::vec &x, double wl_factor, double energy_factor)
Vespucci::Math::EnergyToWavelength.
double AbscissaMin() const
QStringList MapKeys() const
void ZeroFlatSpectra(double threshold)
VespucciDataset::ZeroFlatSpectra.
void CropSpectra(double x_min, double x_max, double y_min, double y_max, double wl_min, double wl_max)
VespucciDataset::CropSpectra Crops spectra_ based on.
int HySime()
VespucciDataset::HySime.
VESPUCCI_EXPORT arma::mat sgolayfilt(const arma::mat &x, arma::uword poly_order, arma::uword window_size, arma::uword deriv_order, arma::uword scaling_factor)
sgolayfilt Apply Savitzky-Golay smoothing to each column of a arma::matrix
void SetXDescription(QString description)
VespucciDataset::SetXDescription Sets the value of the spectral abscissa description.
const QString x_axis_description() const
VespucciDataset::x_axis_description The x_axis_description is printed on the spectrum viewer...
The MapData class Class for processed map data. Images are created from this data.
void CWTBaseline(int lambda, int penalty_order, double SNR_threshold, double peak_shape_threshold)
Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white.
void DisplayExceptionWarning(std::exception e)
MainWindow::DisplayExceptionWarning.
VESPUCCI_EXPORT arma::uword IModPoly(const arma::vec &spectrum, const arma::vec &abscissa, arma::vec &baseline, arma::vec &corrected, double &err, const arma::uword poly_order, const arma::uword max_it, const double threshold)
Vespucci::Math::LinLeastSq::IModPoly Perform the Vancouver Raman Algorithm to correct baseline...
void MFBaseline(int window_size, int iterations)
VespucciDataset::MFBaseline Baseline-adjusts the data. This function uses a median filter with a larg...
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
void SetData(const mat &spectra, const vec &wavelength, const vec &x, const vec &y)
VespucciDataset::SetData.
vec wavelength() const
VespucciDataset::wavelength.
QMap< QString, QStringList > AnalysisResultsTreeStructure() const
VespucciDataset::AnalysisResultsTreeStructure.
void Link(const arma::mat &data)
Vespucci::Math::Clustering::AHCA::Link.
VESPUCCI_EXPORT arma::vec EnergyToFrequency(const arma::vec &x, double freq_factor, double energy_factor)
Vespucci::Math::EnergyToFrequency.
QSharedPointer< VespucciWorkspace > workspace_ptr()
MainWindow::workspace_ptr.
VESPUCCI_EXPORT arma::vec RepresentativeSpectrum(const arma::mat &spectra, arma::uword &index, std::string metric_name="euclidean", std::string center="centroid")
Vespucci::Math::RepresentativeSpectrum.
QCPRange WavelengthRange() const
VespucciDataset::WavelengthRange.
void SetLinkage(std::string linkage_method)
void Univariate(const QString &name, double &left_bound, double &right_bound, uword bound_window)
VespucciDataset::Univariate.
VESPUCCI_EXPORT arma::vec WavenumberToEnergy(const arma::vec &x, double energy_factor, double wn_factor)
Vespucci::Math::WavenumberToEnergy.
int FindIndex(int x_value, int y_value) const
Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion ...
bool ConstructorCancelled() const
VespucciDataset::ConstructorCancelled Specifies whether or not the constructor has been canceled...
const mat & spectra_ref()
VespucciDataset::spectra_ref.
void SubtractBackground(const QStringList &data_keys)
VespucciDataset::SubtractBackground.
void Undo()
VespucciDataset::Undo Swap spectra_ and spectra_old_ to undo an action. Calling this function again r...
void SavitzkyGolay(unsigned int derivative_order, unsigned int polynomial_order, unsigned int window_size)
VespucciDataset::SavitzkyGolay Performs derivatization/Savitzky-Golay smoothing.
Continuous lightness from black over icey colors to white (suited for non-biased data representation)...
mat spectra() const
VespucciDataset::spectra.
An approximation of the visible light spectrum (creates banding illusion but allows more precise magn...
mat * x_ptr()
VespucciDataset::x_ptr.
VESPUCCI_EXPORT arma::vec WavelengthToFrequency(const arma::vec &x, double freq_factor, double wl_factor)
Vespucci::Math::WavelengthToFrequency.
void AddMatrix(const QString &name, mat &matrix)
void ShedSpectrum(const uword index)
VespucciDataset::ShedSpectrum.
mat AverageSpectrum(bool stats) const
VespucciDataset::AverageSpectrum Finds the average of the spectrum. This can be saved by the user...
void PLSCalibration(const QString &name, const QStringList &control_keys)
QStringList AnalysisResultsKeys() const
VespucciDataset::AnalysisResultsKeys.
The KMeansWrapper class mlpack relies heavily on template metaprogramming. This means that you only n...
void RollingBallBaseline(size_t wm, size_t ws)
VespucciDataset::RollingBallBaseline.
void CorrelationAnalysis(const QString &control_key, QString name)
VespucciDataset::CorrelationAnalysis.
void MinMaxNormalize()
VespucciDataset::MinMaxNormalize Normalizes each column of spectra_ so that the highest value is 1 an...
Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allo...
bool SaveSpectrum(QString filename, uword column, file_type type)
void SetName(QString new_name)
VespucciDataset::SetName.
VESPUCCI_EXPORT size_t HySime(const arma::mat &y, const arma::mat &n, arma::mat &Rn, arma::mat &Ek)
Vespucci::Math::DimensionReduction::HySime.
void SetParentDatasetIndices(mat parent_dataset_indices)
VespucciDataset::SetParentDatasetIndices.
void MedianFilter(unsigned int window_size)
VespucciDataset::MedianFilter performs median filtering on the spectral data. Entries near the bounda...
mat * abscissa_ptr()
VespucciDataset::abscissa_ptr.
QSharedPointer< AnalysisResults > GetAnalysisResult(const QString &key)
QStringList AuxiliaryMatrixKeys() const
VespucciDataset::AuxiliaryMatrixKeys.
void VectorNormalize(uword norm)
VespucciDataset::VectorNormalize.
void SingularValue(unsigned int singular_values)
VespucciDataset::SingularValue Denoises the spectra matrix using a truncated singular value decomposi...
QCPRange ValueRange() const
VespucciDataset::ValueRange Finds the minima and maxima of y variable to properly set axes of QCustom...
vec y() const
VespucciDataset::y.
VESPUCCI_EXPORT arma::mat InterpolateToNewAbscissa(const arma::mat &spectra, const arma::vec &old_abscissa, const arma::vec &new_abscissa, const int window_size, const int order)
InterpolateToNewAbscissa.
Continuous lightness from black over firey colors to white (suited for non-biased data representation...
Continuous lightness from black to white (suited for non-biased data representation) ...
int QUIC_SVD(double epsilon)
VespucciDataset::QUIC_SVD.
bool Undoable() const
VespucciDataset::Undoable.
QStringList CoreMatrixKeys() const
VespucciDataset::CoreMatrixKeys.
void AddAuxiliaryMatrix(const QString &name, mat &matrix)
VespucciDataset::AddAuxiliaryMatrix.
const mat & GetAuxiliaryMatrix(const QString &key) const
void SetMetric(std::string metric_type)
const mat & GetCoreMatrix(const QString &key) const
VESPUCCI_EXPORT arma::vec StandardScore(const arma::vec &X)
Vespucci::Math::Normalization::StandardScore.
bool IsCoreMatrix(const QString &key) const
VespucciDataset::IsCoreMatrix.
VESPUCCI_EXPORT arma::mat MedianFilterMat(const arma::mat &X, arma::uword window_size)
Vespucci::Math::Smoothing::MedianFilterMat.
int map_loading_count() const
VespucciDataset::map_names.
bool Contains(const QString &key) const
VespucciDataset::Contains.
void InterpolateToNewAbscissa(const vec &new_abscissa, unsigned int poly_order, unsigned int window_size)
VespucciDataset::InterpolateToNewAbscissa.
bool meta() const
VespucciDataset::meta.
mat * indices_ptr()
VespucciDataset::indices_ptr.
void RemoveMap(const QString &name)
mat ZScoreNormCopy()
VespucciDataset::ZScoreNormCopy For when you want to Z-score normalize without changing spectra_...
vec PointSpectrum(uword index) const
VespucciDataset::PointSpectrum.
int ValueSize() const
VespucciDataset::ValueSize Finds number of unique y values for properly setting QCPAxis.
VESPUCCI_EXPORT arma::vec FrequencyToEnergy(const arma::vec &x, double energy_factor, double freq_factor)
Vespucci::Math::FrequencyToEnergy.
VESPUCCI_EXPORT arma::vec FindPeakMaxMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::vec &positions)
Vespucci::Math::Quantification::FindPeakMaxMat.
VESPUCCI_EXPORT arma::vec FrequencyToWavenumber(const arma::vec &x, double wn_factor, double freq_factor)
Vespucci::Math::FrequencyToWavenumber.
bool Save(QString filename)
void Booleanize(double min, double max, bool keep_inside, bool oneify)
VespucciDataset::Booleanize.
void IModPolyBaseline(const uword poly_order, const uword max_it, double threshold)
vec indices() const
VespucciDataset::indices.
const QString last_operation() const
VespucciDataset::last_operation.
uvec FindRange(double start, double end) const
VespucciDataset::FindRange. Finds the index of the wavelength value closest to the specified waveleng...
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
VESPUCCI_EXPORT bool ImportWideText(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportWideText.
void FindPeaks(const QString &name, double sel, double threshold, uword poly_order, uword window_size)
VespucciDataset::FindPeaks.
void ClassicalLeastSquares(const QString &name, const QStringList &reference_keys)
void CreateMap(const QString &map_name, const QString &results_key, const QString &matrix_key, uword column, QCPColorGradient gradient)
VespucciDataset::CreateMap.
void TrainPLSDA(const QString &name, const QStringList &label_keys)
const mat & GetAnalysisResultMatrix(const QString &results_key, const QString &matrix_key) const
VespucciDataset::GetAnalysisResultMatrix.
QCPColorGradient GetClusterGradient(int clusters) const
VespucciDataset::GetClusterGradient Cluster gradients are slightly different from the continuous grad...
void BandRatio(const QString &name, double &first_left_bound, double &first_right_bound, double &second_left_bound, double &second_right_bound, uword bound_window)
VespucciDataset::BandRatio.
void FourierTransform(int n)
VespucciDataset::FourierTransform.
VESPUCCI_EXPORT bool ImportMultiplePoints(std::map< std::pair< int, int >, std::string > filenames, int rows, int cols, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y)
TextImport::ImportMultiplePoints.
void ImportAuxiliaryMatrix(const QString &name, const QString &filename)
VespucciDataset::ImportAuxiliaryMatrix.
VESPUCCI_EXPORT arma::mat SNVNorm(const arma::mat &X, const double offset, bool center)
Vespucci::Math::Normalization::SNVNorm.
VESPUCCI_EXPORT arma::mat QUICSVDDenoise(const arma::mat &X, double epsilon, arma::mat &U, arma::vec &s, arma::mat &V, arma::uword &rank)
VESPUCCI_EXPORT arma::mat SVDDenoise(const arma::mat &X, arma::uword k, arma::mat &U, arma::vec &s, arma::mat &V)
Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle ...
void CalculateRepresentativeSpectrum(const QString &name, QString statistic, QString metric)
VespucciDataset::CalculateRepresentativeSpectrum.
void ZeroSpectrum(const uword index)
const QString y_axis_description() const
VespucciDataset::y_axis_description.
void PeakIntensityNormalize(double peak_position)
uword FindOrigin() const
VespucciDataset::FindOrigin.
Continuous lightness from black over weak blueish colors to white (suited for non-biased data represe...
void SetIndices(vec indices)
VespucciDataset::SetIndices.
VespucciDataset(const QString &h5_filename, MainWindow *main_window, QSharedPointer< VespucciWorkspace > ws)
VespucciDataset::VespucciDataset.
void InverseFourierTransform(int n)
arma::mat Cluster(arma::uword k)
Vespucci::Math::Clustering::AHCA::Cluster Generate cluster assignments from tree. ...
~VespucciDataset()
VespucciDataset::~VespucciDataset.
QString last_save_filename() const
void ShedZeroWavelengths()
VESPUCCI_EXPORT arma::vec EnergyToWavenumber(const arma::vec &x, double wn_factor, double energy_factor)
Vespucci::Math::EnergyToWavenumber.
bool ShowMapViewer(const QString &map_key, bool show)
void DisplayWarning(const QString &title, const QString &text)
The VCAData class A class for performing and storing data from Vertex Components Analysis.
void LinearMovingAverage(unsigned int window_size)
VespucciDataset::LinearMovingAverage Performs moving average filtering on the spectral data...
void ZeroClippedSpectra(double threshold)
VespucciDataset::ZeroClippedSpectra.
void AgglomerativeClustering(const QString &name, const QString &linkage, const QString &metric)
VespucciDataset::AgglomerativeClustering.
VESPUCCI_EXPORT arma::mat RollingBallBaselineMat(const arma::mat &spectra, arma::mat &baselines, arma::uword wm, arma::uword ws)
VESPUCCI_EXPORT void EstimateAdditiveNoise(arma::mat &noise, arma::mat &noise_correlation, const arma::mat &sample)
Vespucci::Math::DimensionReduction::EstimateAdditiveNoise.
vec x() const
VespucciDataset::x.
VESPUCCI_EXPORT arma::vec CreateMovingAverageFilter(arma::uword window_size)
Vespucci::Math::Smoothing::CreateMovingAverageFilter.
double AbscissaMax() const
Defines a color gradient for use with e.g. QCPColorMap.
void SetYDescription(QString description)
VespucciDataset::SetYDescription.
Represents the range an axis is encompassing.
The MainWindow class The main window of the program, this is where the user performs most operations...
The AnalysisResults class A container for a mat object that allows a mat to be copied to a heap-alloc...
VESPUCCI_EXPORT arma::vec WavelengthToWavenumber(const arma::vec &x, double wl_factor, double wn_factor)
Vespucci::Math::WavelengthToWavenumber.
bool state_changed() const
void PartialLeastSquares(const QString &name, uword components)
VespucciDataset::PartialLeastSquares.
VESPUCCI_EXPORT arma::mat OrdinaryLeastSquares(const arma::mat &X, const arma::mat &y)
Vespucci::Math::LinLeastSq::OrdinaryLeastSquares Perform Squares.
Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and pha...
const vec & abscissa_ref()
VespucciDataset::abscissa_ref.
int KeySize() const
VespucciDataset::KeySize Finds the number of data points in x variable to properly set axes of QCusto...
VESPUCCI_EXPORT bool ImportLongText(std::string filename, arma::mat &spectra, arma::mat &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportLongText.
void AddMap(QSharedPointer< MapData > map)
VespucciDataset::AddMap Adds a map to the list of map pointers and adds its name to relevant lists...
void KMeans(const QString &name, const QString &metric_text, const QString &partition_policy, bool allow_empty, size_t clusters)
VespucciDataset::KMeans.
The AHCA class Handles agglomerative hierarchical clustering of data This class holds a tree which re...
VESPUCCI_EXPORT arma::vec FrequencyToWavelength(const arma::vec &x, double wl_factor, double freq_factor)
Vespucci::Math::FrequencyToWavelength.
QCPColorGradient GetGradient(int gradient_number) const
VespucciDataset::GetGradient Selects the color gradient from list of presets.
void SNVNormalize(double offset, bool center)
bool non_spatial() const
VespucciDataset::non_spatial.
void RemoveClippedSpectra(double threshold)
VespucciDataset::RemoveClippedSpectra.
mat * parent_dataset_indices()
int UnivariateCount() const
VespucciDataset::UnivariateCount.
void Scale(double scaling_factor)
void AddAnalysisResult(QSharedPointer< AnalysisResults > analysis_result)
QCPRange PointSpectrumRange(int i) const
VespucciDataset::PointSpectrumRange.
void FitPeak(const QString &name, const QString &peak_shape, double &left_bound, double &right_bound)
VESPUCCI_EXPORT arma::vec WavenumberToFrequency(const arma::vec &x, double freq_factor, double wn_factor)
Vespucci::Math::WavenumberToFrequency.