Vespucci  1.0.0
vespuccidataset.cpp
Go to the documentation of this file.
1  /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
22 #include "Data/Import/textimport.h"
24 #include <H5Cpp.h>
26 #include <Math/Smoothing/denoise.h>
28 using namespace arma;
29 using namespace std;
30 
31 
36 {
37  for (auto key : MapKeys())
38  workspace_->GetMap(name_, key)->HideMapWindow();
39 
40 }
41 
42 bool VespucciDataset::Save(QString filename)
43 {
44  using namespace H5;
45  QStringList core_names = CoreMatrixKeys();
46  QStringList results_names = AnalysisResultsKeys();
47  try{
48  H5File file(filename.toStdString(), H5F_ACC_TRUNC);
49  DataSpace str_dataspace(H5S_SCALAR);
50  StrType str_type(PredType::C_S1, H5T_VARIABLE);
51 
52  Attribute str_attr;
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());
56 
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());
60 
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());
64 
65  for (auto core_name: core_names){
66  hsize_t dims[2];
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);
74  ds.close();
75  }
76 
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){
86  hsize_t dims[2];
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,
92  dataspace));
93  ds.write(results->GetMatrix(matrix_name).memptr(),
94  PredType::NATIVE_DOUBLE);
95  ds.close();
96  }
97  results_group.close();
98  }
99  file.close();
100  }
101  catch(FileIException error){
102  QString msg = QString::fromStdString(error.getDetailMsg());
103  main_window_->DisplayWarning("HDF5 FileIException", msg);
104  return false;
105  }
106  catch(DataSetIException error){
107  QString msg = QString::fromStdString(error.getDetailMsg());
108  main_window_->DisplayWarning("HDF5 DataSetIException", msg);
109  return false;
110  }
111  catch(AttributeIException error){
112  QString msg = QString::fromStdString(error.getDetailMsg());
113  main_window_->DisplayWarning("HDF5 AttributeIException", msg);
114  return false;
115  }
116 
117  last_save_filename_ = filename;
118  saved_ = true;
119  state_changed_ = false;
120  return true;
121 }
122 
123 bool VespucciDataset::SaveSpectrum(QString filename, uword column, file_type type)
124 {
125  std::string filename_stdstring = filename.toStdString();
126  vec spectrum;
127  bool success;
128  try{
129  spectrum = spectra_.col(column);
130  success = spectrum.save(filename_stdstring, type);
131  }
132  catch(exception e){
133  main_window_->DisplayExceptionWarning("VespucciDataset::SaveSpectrum", e);
134  success = false;
135  }
136  return success;
137 
138 }
139 
141 {
142  spectra_old_ = spectra_;
143  x_old_ = x_;
144  y_old_ = y_;
145  abscissa_old_ = abscissa_;
146 }
147 
156 bool VespucciDataset::Contains(const QString &key) const
157 {
158  return CoreMatrixKeys().contains(key) || AnalysisResultsKeys().contains(key)
159  || AuxiliaryMatrixKeys().contains(key) || key == "Auxiliary Matrices";
160 }
161 
163 {
164  bool has_spatial = x_.n_rows;
165  //x and y have same size
166  bool valid_spatial = has_spatial && (x_.n_rows == y_.n_rows);
167  //x and y have same number of rows as spectra has columns
168  bool spatial_match = valid_spatial && (x_.n_rows == spectra_.n_cols);
169  //spectra and abscissa have same number of rows
170  bool spectral_match = spectra_.n_elem && abscissa_.n_rows == spectra_.n_rows;
171  return spectral_match && (spatial_match || !has_spatial);
172 }
173 
175 {
176  return state_changed_;
177 }
178 
180 {
181  return filename_;
182 }
183 
185 {
186  return last_save_filename_;
187 }
188 
190 {
191  return saved_;
192 }
193 
194 
214 VespucciDataset::VespucciDataset(const QString &h5_filename,
215  MainWindow *main_window,
216  QSharedPointer<VespucciWorkspace> ws)
217  : auxiliary_matrices_(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"))
218 {
219  saved_ = true;
220  filename_ = h5_filename;
221  last_save_filename_ = h5_filename;
222  workspace_ = ws;
223  QString fallback_name = "Dataset";
224  directory_ = workspace_->directory_ptr();
225  int counter = 1;
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;
237  return;
238  }
239  using namespace H5;
240 
241  try{
242  H5File file(h5_filename.toStdString(), H5F_ACC_RDONLY);
243 
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);
250  }
251  else{
252  name_ = fallback_name;
253  }
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);
260  }
261  else{
262  x_axis_description_ = fallback_x_description;
263  }
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);
270  }
271  else{
272  y_axis_description_ = fallback_y_description;
273  }
274 
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);
278 
279  if (obj_type == H5G_DATASET){
280  DataSet ds = file.openDataSet(obj_name);
281  DataSpace dspace = ds.getSpace();
282  hsize_t dims[2];
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);
287  ds.close();
288  }
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);
296  }
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();
304  hsize_t dims[2];
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),
309  matrix);
310  ds.close();
311  }//if (subobj_type == H5G_DATASET
312  }//for objects in group
313  AddAnalysisResult(result);
314  group.close();
315  }//if (obj_type == H5G_GROUP)
316  }//for objects in file
317 
318  file.close();
319  if (AnalysisResultsKeys().contains("Auxiliary Matrices")){
320  auxiliary_matrices_ = GetAnalysisResult("Auxiliary Matrices");
321  }
322  else{
323  auxiliary_matrices_ = QSharedPointer<AnalysisResults>(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"));
324  AddAnalysisResult(auxiliary_matrices_);
325  }
326  constructor_canceled_ = false;
327  }//try
328  catch(H5::Exception error){
329  cerr << error.getDetailMsg() << "\n";
330  constructor_canceled_ = IsValid();
331  }
332  catch(std::exception e){
333  cerr << e.what() << "\n";
334  constructor_canceled_ = IsValid();
335  }
336 
337  if (!constructor_canceled_){
338  if (AnalysisResultsKeys().contains("Auxiliary Matrices")){
339  auxiliary_matrices_ = GetAnalysisResult("Auxiliary Matrices");
340  }
341  else{
342  AddAnalysisResult(auxiliary_matrices_);
343  }
344  }
345 
346 }
347 
360 VespucciDataset::VespucciDataset(QString text_filename,
361  MainWindow *main_window,
362  QString *directory,
363  QString name,
364  QString x_axis_description,
365  QString y_axis_description,
366  bool swap_spatial,
367  std::string format)
368  : auxiliary_matrices_(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"))
369 {
370  saved_ = false;
371  filename_ = text_filename;
372  workspace_ = main_window->workspace_ptr();
373  QDateTime datetime = QDateTime::currentDateTimeUtc();
374  state_changed_ = true;
375  AddAnalysisResult(auxiliary_matrices_);
376 
377  non_spatial_ = false;
378  meta_ = false;
379  //Set up variables unrelated to hyperspectral data:
380  //map_list_model_ = new MapListModel(main_window, this);
381  map_loading_count_ = 0;
382  z_scores_calculated_ = false;
383  directory_ = directory;
384  flipped_ = swap_spatial;
385 
386  QProgressDialog progress("Loading Dataset...", "Cancel", 0, 100, NULL);
387  vec indices_temp;
388 
389 
390  if (format == "WideTabDel"){
391  try{
392  constructor_canceled_ = TextImport::ImportWideText(text_filename.toStdString(),
393  spectra_,
394  abscissa_,
395  x_, y_, swap_spatial);
396  indices_ = linspace<vec>(0, x_.n_elem - 1, x_.n_elem);
397  }
398  catch(exception e){
399  string str = "Text import constructor:" + string(e.what());
400  throw std::runtime_error(str);
401  }
402  }
403  else if (format == "WideCSV"){
404  try{
405  constructor_canceled_ = TextImport::ImportWideText(text_filename.toStdString(),
406  spectra_,
407  abscissa_,
408  x_, y_, swap_spatial);
409  indices_ = linspace<vec>(0, x_.n_elem - 1, x_.n_elem);
410  }
411  catch(exception e){
412  string str = "Text import constructor: " + string(e.what());
413  throw std::runtime_error(str);
414  }
415  }
416  else if (format == "LongTabDel" || format == "LongCSV"){
417  try{
418 
419  constructor_canceled_ = TextImport::ImportLongText(text_filename.toStdString(),
420  spectra_,
421  abscissa_,
422  x_, y_,
423  swap_spatial);
424  indices_.set_size(x_.n_elem);
425  for (uword i = 0; i < indices_.n_elem; ++i)
426  indices_(i) = i;
427  }
428  catch(exception e){
429  string str = "Text import constructor: " + string(e.what());
430  throw std::runtime_error(str);
431  }
432  }
433  else{
434  throw std::runtime_error("Invalid file format for text import constructor");
435  }
436 
437  constructor_canceled_ = false;
438  name_ = name;
439  x_axis_description_ = x_axis_description;
440  y_axis_description_ = y_axis_description;
441  main_window_ = main_window;
442 }
443 
444 VespucciDataset::VespucciDataset(map<pair<int, int>, string> text_filenames,
445  MainWindow *main_window,
446  QString *directory,
447  QString name,
448  QString x_axis_description,
449  QString y_axis_description,
450  int rows, int cols)
451  : auxiliary_matrices_(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"))
452 {
453  saved_ = false;
454  text_filenames_ = text_filenames;
455  workspace_ = main_window->workspace_ptr();
456  AddAnalysisResult(auxiliary_matrices_);
457  QDateTime datetime = QDateTime::currentDateTimeUtc();
458  non_spatial_ = false;
459  meta_ = false;
460  //Set up variables unrelated to hyperspectral data:
461  //map_list_model_ = new MapListModel(main_window, this);
462  map_loading_count_ = 0;
463  z_scores_calculated_ = false;
464  directory_ = directory;
465  flipped_ = false;
466  try{
467  constructor_canceled_ = TextImport::ImportMultiplePoints(text_filenames,
468  rows, cols,
469  spectra_,
470  abscissa_,
471  x_,
472  y_);
473 
474  }
475  catch(exception e){
476  string reason = "Multi import constructor: " + string(e.what());
477  throw std::runtime_error(reason.c_str());
478  }
479  name_ = name;
480  x_axis_description_ = x_axis_description;
481  y_axis_description_ = y_axis_description;
482  main_window_ = main_window;
483 }
484 
495  MainWindow *main_window,
496  QString *directory,
497  QSharedPointer<VespucciDataset> original,
498  uvec indices)
499  : auxiliary_matrices_(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"))
500 
501 {
502  saved_ = false;
503  workspace_ = main_window->workspace_ptr();
504  AddAnalysisResult(auxiliary_matrices_);
505  state_changed_ = true;
506  non_spatial_ = true;
507  meta_ = original->meta();
508  map_loading_count_ = 0;
509  //principal_components_calculated_ = false;
510  //mlpack_pca_calculated_ = false;
511  //partial_least_squares_calculated_ = false;
512  //vertex_components_calculated_ = false;
513  z_scores_calculated_ = false;
514  directory_ = directory;
515  vec parent_indices;
516 
517  try{
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);
524  }
525  catch(exception e){
526  string str = "Extraction constructor: " + string(e.what());
527  throw std::runtime_error(str);
528  }
529 
530  name_ = name;
531  main_window_ = main_window;
532  directory_ = directory;
533 }
534 
545  MainWindow *main_window,
546  QString *directory)
547  : auxiliary_matrices_(new AnalysisResults("Auxiliary Matrices", "Auxiliary Matrices"))
548 {
549  workspace_ = main_window->workspace_ptr();
550  AddAnalysisResult(auxiliary_matrices_);
551  state_changed_ = true;
552  non_spatial_ = true;
553  meta_ = true;
554  map_loading_count_ = 0;
555  z_scores_calculated_ = false;
556  directory_ = directory;
557  name_ = name;
558  main_window_ = main_window;
559  directory_ = directory;
560  saved_ = false;
561 }
562 
563 // PRE-PROCESSING FUNCTIONS //
569 {
570 
571  try{
572  mat spectra_buffer = spectra_;
573  vec x_buffer = x_;
574  vec y_buffer = y_;
575  vec abscissa_buffer = abscissa_;
576 
577  spectra_.swap(spectra_old_);
578  x_.swap(x_old_);
579  y_.swap(y_old_);
580  abscissa_.swap(abscissa_old_);
581 
582  //spectra_ = spectra_old_;
583  //x_ = x_old_;
584  //y_ = y_old_;
585  //abscissa_ = abscissa_old_;
586 
587  //spectra_old_ = spectra_buffer;
588  //x_old_ = x_buffer;
589  //y_old_ = y_buffer;
590  //abscissa_old_ = abscissa_buffer;
591 
592 
593  }
594  catch(exception e){
595  string str = "Undo: " + string(e.what());
596  throw std::runtime_error(str);
597  }
598 
599  state_changed_ = true;
600  last_operation_ = "Undo";
601 }
602 
603 
613 void VespucciDataset::CropSpectra(double x_min, double x_max,
614  double y_min, double y_max,
615  double wl_min, double wl_max)
616 {
617 
618  SetOldCopies();
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));
621  try{
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);
629  }catch(exception e){
630  string str = "CropSpectra: " + string(e.what());
631  throw std::runtime_error(str);
632  }
633  }
634  if (!std::isnan(wl_min) && !std::isnan(wl_max)){
635  uvec valid_indices = find(abscissa_ >= wl_min && abscissa_ <= wl_max);
636  try{
637  spectra_ = spectra_.rows(valid_indices);
638  abscissa_ = abscissa_.rows(valid_indices);
639 
640  }catch(exception e){
641  string str = "CropSpectra: " + string(e.what());
642  throw std::runtime_error(str);
643  }
644  }
645 
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();
656 }
657 
658 
664 {
665  try{
666  SetOldCopies();
667  vec spectrum_buffer;
668  vec extrema_buffer;
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;
676  }
677  }
678  catch(exception e){
679  string str = "MinMaxNormalize: " + string(e.what());
680  throw std::runtime_error(str);
681  }
682  last_operation_ = "min/max normalize";
683  operations_ << "MinMaxNormalize()";
684  state_changed_ = true;
685 }
686 
692 {
693  if (!norm || norm > 2) return;
694  state_changed_ = true;
695 
696  SetOldCopies();
697  try{
698  spectra_ = normalise(spectra_, norm);
699  }
700  catch(exception e){
701  string str = "VectorNormalize()" + string(e.what());
702  throw std::runtime_error(str);
703  }
704  operations_ << "VectorNormalize(" + QString::number(norm) + ")";
705  last_operation_ = "vector normalize";
706 }
707 
713 {
714  state_changed_ = true;
715  SetOldCopies();
716  try{
717  vec mean_intensity = mean(spectra_, 1);
718  spectra_.each_col() -= mean_intensity;
719  }
720  catch(exception e){
721  throw std::runtime_error("MeanCenter");
722  }
723  last_operation_ = "mean centering";
724  operations_ << "MeanCenter()";
725 }
726 
732 void VespucciDataset::PeakIntensityNormalize(double left_bound, double right_bound)
733 {
734  SetOldCopies();
735  vec positions;
736  vec peak_maxes = Vespucci::Math::Quantification::FindPeakMaxMat(spectra_, abscissa_, left_bound, right_bound, positions);
737  for (uword j = 0; j < spectra_.n_cols; ++j){
738  spectra_.col(j) /= peak_maxes(j);
739  }
740  last_operation_ = "Peak intensity normalize";
741  operations_ << "PeakIntensityNormalize("
742  + QString::number(left_bound) + ", "
743  + QString::number(right_bound) + ")";
744 }
745 
753 void VespucciDataset::Booleanize(double min, double max, bool keep_inside, bool oneify)
754 {
755  SetOldCopies();
756  last_operation_ = "Booleanize";
757 
758  //set all values on the outside (or inside) of the range to zero
759  try{
760  if (keep_inside)
761  spectra_.elem(find(spectra_ <= min && spectra_ >= max) ).zeros();
762  else
763  spectra_.elem(find(spectra_ >= min && spectra_ <= max) ).zeros();
764 
765 
766  //set all non-zero values equal to one
767  if (oneify)
768  spectra_.elem( find(spectra_) ).ones();
769 
770  }
771  catch (exception e){
772  cerr << e.what();
773  runtime_error f("Booleanize");
774  main_window_->DisplayExceptionWarning(f);
775  }
776  operations_ << "Booleanize(" + QString::number(min) + ", "
777  + QString::number(max) + ", "
778  + (keep_inside ? "true" : "false") + ", "
779  + (oneify ? "true" : "false") + ")";
780 }
781 
787 void VespucciDataset::Clamp(double min, double max)
788 {
789  SetOldCopies();
790  last_operation_ = "Clamp";
791  state_changed_ = true;
792 
793 
794  try{
795  spectra_ = clamp(spectra_, min, max);
796  }
797  catch(exception e){
798  cerr << e.what();
799  runtime_error f("Clamp");
800  main_window_->DisplayExceptionWarning(f);
801  }
802  operations_ << "Clamp("
803  + QString::number(min) + ", "
804  + QString::number(max) + ")";
805 }
806 
808 {
809  SetOldCopies();
810  vec current_col;
811  uvec indices;
812  uvec indices_buffer;
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)
817  indices << i;
818  }
819  try{
820  spectra_ = spectra_.cols(indices);
821  x_ = x_.rows(indices);
822  y_ = y_.rows(indices);
823  }
824  catch(exception e){
825  main_window_->DisplayExceptionWarning("VespucciDataset::ShedZeroSpectra", e);
826  }
827 
828  workspace_->UpdateModel();
829  operations_ << "ShedZeroSpectra()";
830 }
831 
833 {
834  state_changed_ = true;
835 
836  SetOldCopies();
837  vec current_row;
838  uvec indices, indices_buffer;
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)
843  indices << i;
844  }
845  try{
846  spectra_ = spectra_.rows(indices);
847  abscissa_ = abscissa_.rows(indices);
848  }
849  catch(exception e){
850  main_window_->DisplayExceptionWarning("VespucciDataset::ShedZeroWavelengths", e);
851  }
852  workspace_->UpdateModel();
853  operations_ << "ShedZeroWavelengths()";
854 }
855 
862 {
863 
864  mat normalized;
865  //mat normalized_copy(num_rows, num_cols);
866  try{
867  normalized = Vespucci::Math::Normalization::StandardScore(spectra_);
868  }
869  catch(exception e){
870  string str = "ZScoreNormCopy: " + string(e.what());
871  throw std::runtime_error(str);
872  }
873  return trans(normalized);
874 
875 }
876 
882 {
883  state_changed_ = true;
884 
885  SetOldCopies();
886 
887  try{
889  }
890  catch(exception e){
891  string str = "ZScoreNormalize: " + string(e.what());
892  throw std::runtime_error(str);
893  }
894 
895  z_scores_calculated_ = true;
896  last_operation_ = "Z-score normalize";
897  operations_ << "ZScoreNormalize()";
898 
899 }
900 
901 
902 void VespucciDataset::SNVNormalize(double offset, bool center)
903 {
904  state_changed_ = true;
905 
906  SetOldCopies();
907  try{
908  spectra_ = Vespucci::Math::Normalization::SNVNorm(spectra_, offset, center);
909  }
910  catch(exception e){
911  string str = "SNVNormalize: " + string(e.what());
912  throw std::runtime_error(str);
913  }
914 
915  last_operation_ = "SNVNormalize";
916  operations_ << "SNVNormalize()";
917 }
918 
920 {
921  state_changed_ = true;
922 
923  SetOldCopies();
924 
925  try{
926  spectra_ = arma::abs(spectra_);
927  }
928  catch(exception e){
929  string str =
930  "AbsoluteValue: " + string(e.what());
931  throw std::runtime_error(str);
932  }
933 
934  last_operation_ = "Absolute value";
935  operations_ << "AbsoluteValue()";
936 }
937 
942 void VespucciDataset::SubtractBackground(const QStringList &data_keys)
943 {
944  mat background = workspace_->GetMatrix(data_keys);
945  state_changed_ = true;
946  SetOldCopies();
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");
953  return;
954  }
955  else{
956  try{
957  spectra_.each_col() -= background.col(0);
958  }
959  catch(exception e){
960  string str = "SubtractBackground: " + string(e.what());
961  throw std::runtime_error(str);
962  }
963  }
964  last_operation_ = "background correction";
965 }
966 
977 void VespucciDataset::MFBaseline(int window_size, int iterations)
978 {
979  state_changed_ = true;
980  SetOldCopies();
981  try{
982  baselines_ = spectra_;
983  for (uword i = 0; i < uword(iterations); ++i){
984  baselines_ = Vespucci::Math::Smoothing::MedianFilterMat(baselines_, window_size);
985  }
986  spectra_ -= baselines_;
987  }
988  catch(exception e){
989  string str = "MFBaseline: " + string(e.what());
990  throw std::runtime_error(str);
991  }
992 
993  last_operation_ = "baseline correction (median filter)";
994  operations_ << "MFBaseline("
995  + QString::number(window_size) + ", "
996  + QString::number(iterations) + ")";
997 }
998 
1004 void VespucciDataset::RollingBallBaseline(size_t wm, size_t ws)
1005 {
1006  state_changed_ = true;
1007  SetOldCopies();
1008  try{
1009  mat baselines;
1011  baselines,
1012  wm, ws);
1013  AddAuxiliaryMatrix("Rolling Ball Baselines", baselines);
1014  }catch(exception e){
1015  string str = "RollingBallBaseline " + string(e.what());
1016  throw std::runtime_error(str);
1017  }
1018  last_operation_ = "baseline correction (rolling ball)";
1019  operations_ << "RollingBallBaseline("
1020  + QString::number(wm) + ", "
1021  + QString::number(ws) + ")";
1022 }
1023 
1024 void VespucciDataset::CWTBaseline(int lambda, int penalty_order, double SNR_threshold, double peak_shape_threshold)
1025 {
1026 
1027 }
1028 
1029 void VespucciDataset::IModPolyBaseline(const uword poly_order, const uword max_it, double threshold)
1030 {
1031  state_changed_ = true;
1032  SetOldCopies();
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);
1042  progress->show();
1043  double err;
1044  try{
1045  for (uword i = 0; i < spectra_.n_cols; ++i){
1046  progress->setValue(i);
1047  progress->setLabelText("Spectrum " + QString::number(i+1) + colcount);
1048  Vespucci::Math::LinLeastSq::IModPoly(spectra_.col(i),
1049  abscissa_, baseline,
1050  corrected, err,
1051  poly_order, max_it, threshold);
1052  baselines.col(i) = baseline;
1053  spectra_.col(i) = corrected;
1054  if (progress->wasCanceled()){
1055  progress->close();
1056  break;
1057  Undo();
1058  }
1059  }
1060  }catch(exception e){
1061  main_window_->DisplayExceptionWarning("VespucciDataset::IModPolyBaseline", e);
1062  }
1063  progress->close();
1064  if (!progress->wasCanceled()){
1065  //AddAnalysisResult("IModPoly Baselines", baselines);
1066  }
1067  operations_ << "IModPolyBaseline("
1068  + QString::number(poly_order) + ", "
1069  + QString::number(max_it) + ", "
1070  + QString::number(threshold) + ")";
1071  last_operation_ = "IModPoly baseline";
1072 }
1073 
1079 {
1080  SetOldCopies();
1081  rowvec spectra_max = max(spectra_, 0);
1082 
1083  uvec valid_indices = find(spectra_max < threshold);
1084  if (valid_indices.n_elem == 0)
1085  return;
1086 
1087  try{
1088  spectra_ = spectra_.cols(valid_indices);
1089  x_ = x_.rows(valid_indices);
1090  y_ = y_.rows(valid_indices);
1091  }
1092  catch(exception e){
1093  string str = "RemoveClipped Spectra: " + string(e.what());
1094  throw std::runtime_error(str);
1095  }
1096 
1097  if (spectra_.n_rows != spectra_old_.n_rows)
1098  non_spatial_ = true;
1099 
1100  workspace_->UpdateModel();
1101  last_operation_ = "threshold";
1102  operations_ << "RemovedClippedSpectra(" + QString::number(threshold) + ")";
1103 }
1104 
1110 {
1111  SetOldCopies();
1112  rowvec spectra_max = max(spectra_, 0);
1113 
1114  uvec valid_indices = find(spectra_max > threshold);
1115  if (valid_indices.n_elem == 0)
1116  return;
1117 
1118  try{
1119  spectra_ = spectra_.cols(valid_indices);
1120  x_ = x_.rows(valid_indices);
1121  y_ = y_.rows(valid_indices);
1122  }
1123  catch(exception e){
1124  string str = "RemoveClipped Spectra: " + string(e.what());
1125  throw std::runtime_error(str);
1126  }
1127 
1128  if (spectra_.n_rows != spectra_old_.n_rows)
1129  non_spatial_ = true;
1130 
1131  workspace_->UpdateModel();
1132  last_operation_ = "threshold";
1133  operations_ << "RemoveFlatSpectra(" + QString::number(threshold) + ")";
1134 }
1135 
1141 {
1142  SetOldCopies();
1143  rowvec spectra_max = max(spectra_, 0);
1144  uvec invalid_indices = find(spectra_max > threshold);
1145  if (invalid_indices.n_elem == 0)
1146  return;
1147 
1148  try{
1149  for (uword i = 0; i < invalid_indices.n_rows; ++i)
1150  spectra_.col(invalid_indices(i)) = zeros(spectra_.n_rows);
1151  }
1152  catch(exception e){
1153  string str = "RemoveClipped Spectra: " + string(e.what());
1154  throw std::runtime_error(str);
1155  }
1156 
1157  if (spectra_.n_rows != spectra_old_.n_rows)
1158  non_spatial_ = true;
1159 
1160  workspace_->UpdateModel();
1161  last_operation_ = "threshold";
1162  operations_ << "ZeroClippedSpectra(" + QString::number(threshold) + ")";
1163 }
1164 
1169 void VespucciDataset::ZeroFlatSpectra(double threshold)
1170 {
1171  SetOldCopies();
1172  rowvec spectra_max = max(spectra_, 0);
1173  uvec invalid_indices = find(spectra_max < threshold);
1174  if (invalid_indices.n_elem == 0)
1175  return;
1176 
1177  try{
1178  for (uword i = 0; i < invalid_indices.n_rows; ++i)
1179  spectra_.col(invalid_indices(i)) = zeros(spectra_.n_rows);
1180  }
1181  catch(exception e){
1182  string str = "RemoveClipped Spectra: " + string(e.what());
1183  throw std::runtime_error(str);
1184  }
1185 
1186  if (spectra_.n_rows != spectra_old_.n_rows)
1187  non_spatial_ = true;
1188 
1189  workspace_->UpdateModel();
1190  last_operation_ = "threshold";
1191  operations_ << "ZeroFlatSpectra(" + QString::number(threshold) + ")";
1192 }
1193 
1194 //Filtering functions
1200 
1201 void VespucciDataset::MedianFilter(unsigned int window_size)
1202 {
1203  state_changed_ = true;
1204  mat processed;
1205  SetOldCopies();
1206  try{
1207  processed = Vespucci::Math::Smoothing::MedianFilterMat(spectra_, window_size);
1208  spectra_ = processed;
1209  }
1210  catch(exception e){
1211  string str = "MedianFilter: " + string(e.what());
1212  throw std::runtime_error(str);
1213  }
1214 
1215  last_operation_ = "median filter";
1216  operations_ << "MedianFilter(" + QString::number(window_size) + ")";
1217 }
1218 
1224 
1225 void VespucciDataset::LinearMovingAverage(unsigned int window_size)
1226 {
1227  state_changed_ = true;
1228  SetOldCopies();
1229  try{
1230  vec filter = Vespucci::Math::Smoothing::CreateMovingAverageFilter(window_size);
1231  for (uword j = 0; j < spectra_.n_cols; ++j){
1232  spectra_.col(j) = Vespucci::Math::Smoothing::ApplyFilter(spectra_.col(j), filter);
1233  }
1234  }
1235  catch(exception e){
1236  string str = "LinearMovingAverage: " + string(e.what());
1237  throw std::runtime_error(str);
1238  }
1239 
1240  last_operation_ = "moving average filter";
1241  operations_ << "LinearMovingAverage(" +QString::number(window_size) + ")";
1242 }
1243 
1252 void VespucciDataset::SingularValue(unsigned int singular_values)
1253 {
1254  state_changed_ = true;
1255  SetOldCopies();
1256  mat U;
1257  vec s;
1258  mat V;
1259  try{
1260  spectra_ = Vespucci::Math::Smoothing::SVDDenoise(spectra_, singular_values, U, s, V);
1261  }
1262  catch(exception e){
1263  string str = "SingularValue: " + string(e.what());
1264  throw std::runtime_error(str);
1265  }
1266 
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);
1273  AddAnalysisResult(results);
1274 
1275  last_operation_ = "truncated SVD de-noise";
1276  operations_ << "SingularValue(" + QString::number(singular_values) + ")";
1277 }
1278 
1279 
1285 int VespucciDataset::QUIC_SVD(double epsilon)
1286 {
1287  SetOldCopies();
1288  state_changed_ = true;
1289 
1290  uword rank;
1291  mat U, V;
1292  vec s;
1293  try{
1294  spectra_ = Vespucci::Math::Smoothing::QUICSVDDenoise(spectra_, epsilon, U, s, V, rank);
1295  }catch(exception e){
1296  string str = "QUIC_SVD: " + string(e.what());
1297  throw std::runtime_error(str);
1298  }
1299 
1300  vec SVD_vec({double(rank)});
1301 
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);
1307 
1308  last_operation_ = "QUIC_SVD de-noise";
1309  operations_ << "QUIC_SVD(" + QString::number(epsilon) + " )";
1310  return rank;
1311 }
1312 
1320 void VespucciDataset::SavitzkyGolay(unsigned int derivative_order,
1321  unsigned int polynomial_order,
1322  unsigned int window_size)
1323 {
1324  state_changed_ = true;
1325  SetOldCopies();
1326 
1327  try{
1328  spectra_ = Vespucci::Math::Smoothing::sgolayfilt(spectra_,
1329  polynomial_order,
1330  window_size,
1331  derivative_order,
1332  1);
1333  }
1334  catch(exception e){
1335  string str = "SavitzkyGolay: " + string(e.what());
1336  throw std::runtime_error(str);
1337  }
1338 
1339  last_operation_ = "Savitzky-Golay filtering";
1340  operations_ << "SavitzkyGolay("
1341  + QString::number(derivative_order) + ", "
1342  + QString::number(polynomial_order) + ", "
1343  + QString::number(window_size) + ")";
1344 }
1345 
1346 void VespucciDataset::Scale(double scaling_factor)
1347 {
1348  state_changed_ = true;
1349  SetOldCopies();
1350 
1351  try{
1352  spectra_ = spectra_ * scaling_factor;
1353  }catch(exception e){
1354  string str = "Scale(): " + string(e.what());
1355  throw std::runtime_error(str);
1356  }
1357 
1358  last_operation_ = "Scaling";
1359  operations_ << "Scale(" + QString::number(scaling_factor) + ")";
1360 }
1361 
1366 void VespucciDataset::ShedSpectrum(const uword index)
1367 {
1368  state_changed_ = true;
1369 
1370  SetOldCopies();
1371  try{
1372  spectra_.shed_col(index);
1373  x_.shed_row(index);
1374  y_.shed_row(index);
1375  indices_.shed_row(index);
1376  }
1377  catch(exception e){
1378  cout << e.what();
1379  std::runtime_error exc("VespucciDataset::ShedSpectrum");
1380  main_window_->DisplayExceptionWarning(exc);
1381  }
1382  cout << "spectra_ columns (post) = " << spectra_.n_cols;
1383  operations_ << "ShedSpectrum(" + QString::number(index) + ")";
1384  workspace_->UpdateModel();
1385 }
1386 
1387 void VespucciDataset::ZeroSpectrum(const uword index)
1388 {
1389  state_changed_ = true;
1390  SetOldCopies();
1391  try{
1392  spectra_.col(index).fill(0);
1393  }
1394  catch(exception e){
1395  cout << e.what();
1396  std::runtime_error exc("VespucciDataset::ShedSpectrum");
1397  main_window_->DisplayExceptionWarning(exc);
1398  }
1399  operations_ << "ZeroSpectrum(" + QString::number(index) + ")";
1400  workspace_->UpdateModel();
1401 }
1402 
1408 {
1409  cout << "VespucciDataset::HySime\n";
1410 
1411  wall_clock timer;
1412  mat noise, noise_correlation, subspace;
1413  cout << "call EstimateAdditiveNoise\n";
1414 
1415  timer.tic();
1416  Vespucci::Math::DimensionReduction::EstimateAdditiveNoise(noise, noise_correlation, spectra_);
1417  cout << "took " << timer.toc() << " seconds.\n";
1418 
1419  cout << "Call HySime\n";
1420 
1421  timer.tic();
1422  int k = Vespucci::Math::DimensionReduction::HySime(spectra_, noise, noise_correlation, subspace);
1423  cout << "Took " << timer.toc() << " seconds.\n";
1424 
1425  return k;
1426 }
1427 
1435 void VespucciDataset::TransformAbscissa(QString input_units, double input_factor, QString output_units, double output_factor, QString description)
1436 {
1437  state_changed_ = true;
1438  if (input_units == "Wavelength"){
1439  if (output_units == "Energy"){
1440  SetOldCopies();
1441  abscissa_ = Vespucci::Math::WavelengthToEnergy(abscissa_, output_factor, input_factor);
1442  x_axis_description_ = description;
1443  last_operation_ = "Abscissa Transform";
1444  }
1445  else if (output_units == "Wavenumber"){
1446  SetOldCopies();
1447  abscissa_ = Vespucci::Math::WavelengthToWavenumber(abscissa_, output_factor, input_factor);
1448  x_axis_description_ = description;
1449  last_operation_ = "Abscissa Transform";
1450  }
1451  else if (output_units == "Frequency"){
1452  SetOldCopies();
1453  abscissa_ = Vespucci::Math::WavelengthToFrequency(abscissa_, output_factor, input_factor);
1454  x_axis_description_ = description;
1455  last_operation_ = "Abscissa Transform";
1456  }
1457  else if (output_units == "Wavelength"){
1458  SetOldCopies();
1459  abscissa_ = (input_factor * output_factor) * abscissa_;
1460  x_axis_description_ = description;
1461  last_operation_ = "Abscissa Transform";
1462  }
1463  else{return;}
1464  }
1465  else if (input_units == "Energy"){
1466  if (output_units == "Energy"){
1467  SetOldCopies();
1468  abscissa_ = (input_factor * output_factor) * abscissa_;
1469  x_axis_description_ = description;
1470  last_operation_ = "Abscissa Transform";
1471  }
1472  else if (output_units == "Wavenumber"){
1473  SetOldCopies();
1474  abscissa_ = Vespucci::Math::EnergyToWavenumber(abscissa_, output_factor, input_factor);
1475  x_axis_description_ = description;
1476  last_operation_ = "Abscissa Transform";
1477  }
1478  else if (output_units == "Frequency"){
1479  SetOldCopies();
1480  abscissa_ = Vespucci::Math::EnergyToFrequency(abscissa_, output_factor, input_factor);
1481  x_axis_description_ = description;
1482  last_operation_ = "Abscissa Transform";
1483  }
1484  else if (output_units == "Wavelength"){
1485  SetOldCopies();
1486  abscissa_ = Vespucci::Math::EnergyToWavelength(abscissa_, output_factor, input_factor);
1487  x_axis_description_ = description;
1488  last_operation_ = "Abscissa Transform";
1489  }
1490  else{return;}
1491  }
1492  else if (input_units == "Wavenumber"){
1493  if (output_units == "Energy"){
1494  SetOldCopies();
1495  abscissa_ = Vespucci::Math::WavenumberToEnergy(abscissa_, output_factor, input_factor);
1496  x_axis_description_ = description;
1497  last_operation_ = "Abscissa Transform";
1498  }
1499  else if (output_units == "Wavenumber"){
1500  SetOldCopies();
1501  abscissa_ = (input_factor * output_factor) * abscissa_;
1502  x_axis_description_ = description;
1503  last_operation_ = "Abscissa Transform";
1504  }
1505  else if (output_units == "Frequency"){
1506  SetOldCopies();
1507  abscissa_ = Vespucci::Math::WavenumberToFrequency(abscissa_, output_factor, input_factor);
1508  x_axis_description_ = description;
1509  last_operation_ = "Abscissa Transform";
1510  }
1511  else if (output_units == "Wavelength"){
1512  SetOldCopies();
1513  abscissa_ = Vespucci::Math::WavenumberToWavelength(abscissa_, output_factor, input_factor);
1514  x_axis_description_ = description;
1515  last_operation_ = "Abscissa Transform";
1516  }
1517  else{return;}
1518  }
1519  else if (input_units == "Frequency"){
1520  if (output_units == "Energy"){
1521  SetOldCopies();
1522  abscissa_ = Vespucci::Math::FrequencyToEnergy(abscissa_, output_factor, input_factor);
1523  x_axis_description_ = description;
1524  last_operation_ = "Abscissa Transform";
1525  }
1526  else if (output_units == "Wavenumber"){
1527  SetOldCopies();
1528  abscissa_ = Vespucci::Math::FrequencyToWavenumber(abscissa_, output_factor, input_factor);
1529  x_axis_description_ = description;
1530  last_operation_ = "Abscissa Transform";
1531  }
1532  else if (output_units == "Frequency"){
1533  SetOldCopies();
1534  abscissa_ = (input_factor * output_factor) * abscissa_;
1535  x_axis_description_ = description;
1536  last_operation_ = "Abscissa Transform";
1537  }
1538  else if (output_units == "Wavelength"){
1539  SetOldCopies();
1540  abscissa_ = Vespucci::Math::FrequencyToWavelength(abscissa_, output_factor, input_factor);
1541  x_axis_description_ = description;
1542  last_operation_ = "Abscissa Transform";
1543  }
1544  else{return;}//do nothing for invalid input
1545  }
1546  else{return;}
1547 }
1548 
1555 void VespucciDataset::InterpolateToNewAbscissa(const vec &new_abscissa, unsigned int poly_order, unsigned int window_size)
1556 {
1557  state_changed_ = true;
1558  mat new_spectra;
1559  try{
1560  new_spectra = Vespucci::Math::Smoothing::InterpolateToNewAbscissa(spectra_, abscissa_, new_abscissa, window_size, poly_order);
1561  }catch(exception e){
1562  string str = "InterpolateToNewAbscissa(vec, uint, uint): " + string(e.what());
1563  throw std::runtime_error(str);
1564  }
1565  SetOldCopies();
1566  abscissa_ = new_abscissa;
1567  spectra_ = new_spectra;
1568  last_operation_ = "Abscissa Interpolation";
1569  workspace_->UpdateModel();
1570 }
1571 
1576 void VespucciDataset::InterpolateToNewAbscissa(const vec &new_abscissa)
1577 {
1578  state_changed_ = true;
1579  mat new_spectra;
1580  try{
1581  new_spectra = Vespucci::Math::Smoothing::InterpolateToNewAbscissa(spectra_, abscissa_, new_abscissa);
1582  }catch(exception e){
1583  string str = "InterpolateToNewAbscissa(vec): " + string(e.what());
1584  throw std::runtime_error(str);
1585  }
1586  SetOldCopies();
1587  abscissa_ = new_abscissa;
1588  spectra_ = new_spectra;
1589  last_operation_ = "Abscissa Interpolation";
1590  workspace_->UpdateModel();
1591 }
1592 
1598 {
1599  state_changed_ = true;
1600  cx_mat f_spectra(spectra_.n_rows, spectra_.n_cols);
1601  vec f_abscissa(abscissa_.n_rows);
1602  try{
1603  Vespucci::Math::Transform::fft_mat(spectra_, abscissa_,
1604  f_spectra, f_abscissa,
1605  n);
1606  }catch(exception e){
1607  string str = "FourierTransform: " + string(e.what());
1608  throw std::runtime_error(str);
1609  }
1610  SetOldCopies();
1611  spectra_ = real(f_spectra);
1612  spectra_imag_ = imag(f_spectra);
1613  abscissa_ = f_abscissa;
1614  x_axis_description_ = "Frequency (Hz)";
1615 }
1616 
1618 {
1619  state_changed_ = true;
1620  cx_mat t_spectra(spectra_.n_rows, spectra_.n_cols);
1621  vec t_abscissa(abscissa_.n_rows);
1622  try{
1624  abscissa_,
1625  t_spectra,
1626  t_abscissa,
1627  n);
1628  }catch(exception e){
1629  string str = "InverseFourierTransform: " + string(e.what());
1630  throw std::runtime_error(str);
1631  }
1632  SetOldCopies();
1633  spectra_ = real(t_spectra);
1634  spectra_imag_ = imag(t_spectra);
1635  abscissa_ = t_abscissa;
1636  x_axis_description_ = "Time (s)";
1637 }
1638 
1645  double param)
1646 {
1647  state_changed_ = true;
1648  SetOldCopies();
1649  string shape;
1650  if (type == "Exponential"){shape = "exp";}
1651  else{shape = "gaus";}
1652  try{
1653  spectra_ = Vespucci::Math::Transform::ApplyWeights(spectra_, abscissa_, shape, param);
1654  }catch(exception e){
1655  main_window_->DisplayExceptionWarning("VespucciDataset::ApplyFTWeight", e);
1656  }
1657 }
1658 
1666 void VespucciDataset::ApplyFTWeight(double start_offset,
1667  double end_offset,
1668  double power)
1669 {
1670  state_changed_ = true;
1671  SetOldCopies();
1672  try{
1673  spectra_ = Vespucci::Math::Transform::ApplySBWeights(spectra_,
1674  abscissa_,
1675  start_offset,
1676  end_offset,
1677  power);
1678  }catch(exception e){
1679  main_window_->DisplayExceptionWarning("VespucciDataset::ApplyFTWeight", e);
1680  }
1681 
1682 }
1683 
1684 
1691 void VespucciDataset::Univariate(const QString &name,
1692  double &left_bound, double &right_bound,
1693  uword bound_window)
1694 {
1695  state_changed_ = true;
1696  QSharedPointer<UnivariateData> univariate_data(new UnivariateData(name));
1697  try{
1698  univariate_data->Apply(left_bound, right_bound, bound_window, spectra_, abscissa_);
1699  }catch(exception e){
1700  main_window_->DisplayExceptionWarning(e);
1701  return;
1702  }
1703  AddAnalysisResult(univariate_data);
1704  workspace_->UpdateModel();
1705 
1706  operations_ << "Univariate("
1707  + name + ", "
1708  + QString::number(left_bound) + ", "
1709  + QString::number(right_bound) + ", "
1710  + QString::number(bound_window) + ")";
1711 
1712 }
1713 
1714 void VespucciDataset::FitPeak(const QString &name, const QString &peak_shape, double &left_bound, double &right_bound)
1715 {
1716  state_changed_ = true;
1717  QSharedPointer<UnivariateData> univariate_data(new UnivariateData(name));
1718  try{
1719  univariate_data->Apply(peak_shape, left_bound, right_bound, spectra_, abscissa_);
1720  }catch (exception e){
1721  main_window_->DisplayExceptionWarning(e);
1722  }
1723  AddAnalysisResult(univariate_data);
1724  workspace_->UpdateModel();
1725 }
1726 
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)
1736 {
1737  state_changed_ = true;
1738  QSharedPointer<UnivariateData> univariate_data(new UnivariateData(name));
1739  try{
1740  univariate_data->Apply(first_left_bound, first_right_bound,
1741  second_left_bound, second_right_bound,
1742  bound_window,
1743  spectra_, abscissa_);
1744  }catch(exception e){
1745  main_window_->DisplayExceptionWarning(e);
1746  return;
1747  }
1748  AddAnalysisResult(univariate_data);
1749  workspace_->UpdateModel();
1750  operations_ << "BandRatio("
1751  + name + ", "
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) + ")";
1757 
1758 
1759 }
1760 
1761 
1768 void VespucciDataset::PrincipalComponents(const QString &name, bool scale_data)
1769 {
1770  QSharedPointer<MlpackPCAData> mlpack_pca_data(new MlpackPCAData(name));
1771  state_changed_ = true;
1772 
1773  try{
1774  mlpack_pca_data->Apply(spectra_, scale_data);
1775  }
1776  catch(exception e){
1777  throw std::runtime_error("VespucciDataset::PrincipalComponents");
1778  }
1779  AddAnalysisResult(mlpack_pca_data);
1780  workspace_->UpdateModel();
1781 
1782 }
1783 
1788 {
1789  state_changed_ = true;
1790 
1791  QSharedPointer<PrincipalComponentsData> pca_data(new PrincipalComponentsData(name));
1792  try{
1793  pca_data->Apply(spectra_);
1794  }catch(exception e){
1795  string str = "PrincipalComponents: " + string(e.what());
1796  throw std::runtime_error(str);
1797  }
1798  AddAnalysisResult(pca_data);
1799  workspace_->UpdateModel();
1800  operations_ << "PrincipalComponents(" + name + ")";
1801 
1802 
1803 }
1804 
1812 void VespucciDataset::FindPeaks(const QString &name, double sel, double threshold, uword poly_order, uword window_size)
1813 {/*
1814 
1815  mat peak_magnitudes;
1816  mat peak_positions;
1817 
1818 
1819  try{
1820  peak_positions =
1821  Vespucci::Math::PeakFinding::FindPeaksMat(spectra_,
1822  sel, threshold,
1823  poly_order, window_size,
1824  peak_magnitudes);
1825  }catch(exception e){
1826  cerr << e.what();
1827  throw std::runtime_error("FindPeaks");
1828  }
1829  QSharedPointer<AnalysisResults> peak_mag(new AnalysisResults(peak_magnitudes));
1830  QSharedPointer<AnalysisResults> peak_pos(new AnalysisResults(peak_positions));
1831  analysis_results_.insert("Peak Positions", peak_pos);
1832  analysis_results_.insert("Peak Magnitudes", peak_mag);
1833 
1834 */}
1835 
1842 void VespucciDataset::AgglomerativeClustering(const QString &name, const QString &linkage, const QString &metric)
1843 {
1844  QSharedPointer<AnalysisResults> ahca_results(new AnalysisResults(name, "AHCA"));
1845  mat assignments;
1847  try{
1848  ahca.SetLinkage(linkage.toStdString());
1849  ahca.SetMetric(metric.toStdString());
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);
1855  }
1856 
1857  ahca_results->AddMatrix("Assignments", assignments);
1858  ahca_results->AddMatrix("Spectrum Distances", ahca.dist());
1859  ahca_results->AddMatrix("Cluster Distances", ahca.merge_data());
1860  AddAnalysisResult(ahca_results);
1861  state_changed_ = true;
1862  operations_ << "AgglomerativeClustering(" + name + ", " + linkage + ", " + metric + ")";
1863  workspace_->UpdateModel();
1864 }
1865 
1872 void VespucciDataset::CalculateRepresentativeSpectrum(const QString &name, QString statistic, QString metric)
1873 {
1874  uword index;
1875  vec rep;
1876  try{
1877  rep = Vespucci::Math::RepresentativeSpectrum(spectra_, index, metric.toStdString(), statistic.toStdString());
1878  }catch(exception e){
1879  string str = "CalculateRepresentativeSpectrum: " + string(e.what());
1880  throw runtime_error(str);
1881  }
1882  QString matrix_name = name;
1883  int i = 1;
1884  while (auxiliary_matrices_->HasMatrix(matrix_name))
1885  matrix_name = name + " (" + QString::number(i++) + ")";
1886  auxiliary_matrices_->AddMatrix(matrix_name, rep);
1887  workspace_->UpdateModel();
1888 }
1889 
1890 
1895 void VespucciDataset::VertexComponents(const QString &name, uword endmembers)
1896 {
1897  state_changed_ = true;
1898 
1899  if(endmembers == 0){
1900  QMessageBox alert;
1901  alert.setText("The HySime algorithm will take a long time.");
1902  alert.setInformativeText("OK to continue");
1903 
1904  alert.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1905  alert.setWindowTitle("Principal Components Analysis");
1906  alert.setIcon(QMessageBox::Question);
1907 
1908  int ret = alert.exec();
1909 
1910 
1911  if (ret == QMessageBox::Cancel){
1912  return;
1913  }
1914  endmembers = HySime();
1915  }
1916 
1917  QSharedPointer<VCAData> vertex_components_data(new VCAData(name));
1918 
1919  try{
1920  vertex_components_data->Apply(spectra_, endmembers);
1921  }catch(exception e){
1922  cerr << "VespucciDataset::VertexComponents()\n";
1923 
1924  throw std::runtime_error("VertexComponents: " + string(e.what()));
1925  }
1926  AddAnalysisResult(vertex_components_data);
1927  workspace_->UpdateModel();
1928  operations_ << "VertexComponents("
1929  + name + ", "
1930  + QString::number(endmembers) + ")";
1931 }
1932 
1933 
1934 
1935 
1940 void VespucciDataset::PartialLeastSquares(const QString &name, uword components)
1941 {
1942  state_changed_ = true;
1943  if(components == 0){
1944  components = HySime();
1945  }
1946 
1947  QSharedPointer<PLSData> pls_data(new PLSData(name));
1948 
1949 
1950  try{
1951  pls_data->Classify(spectra_, abscissa_, components);
1952  }catch(exception e){
1953  string str = "PartialLeastSquares: " + string(e.what());
1954  throw std::runtime_error(str);
1955  }
1956 
1957  AddAnalysisResult(pls_data);
1958  workspace_->UpdateModel();
1959  operations_ << "PartialLeastSquares("
1960  + name + ", "
1961  + QString::number(components) + ")";
1962 
1963 }
1964 
1965 void VespucciDataset::PLSCalibration(const QString &name, const QStringList &control_keys)
1966 {
1967  state_changed_ = true;
1968  QSharedPointer<PLSData> pls_data(new PLSData(name));
1969  mat controls = workspace_->GetMatrix(control_keys);
1970 
1971  try{
1972  pls_data->Calibrate(spectra_, controls);
1973  }catch(exception e){
1974  string str = "PartialLeastSquares: " + string(e.what());
1975  throw std::runtime_error(str);
1976  }
1977 
1978  AddAnalysisResult(pls_data);
1979  workspace_->UpdateModel();
1980 }
1981 
1982 void VespucciDataset::TrainPLSDA(const QString &name, const QStringList &label_keys)
1983 {
1984  state_changed_ = true;
1985  QSharedPointer<PLSData> pls_data(new PLSData(name));
1986  mat labels = workspace_->GetMatrix(label_keys);
1987 
1988  try{
1989  pls_data->Discriminate(spectra_, labels);
1990  }catch(exception e){
1991  string str = "PartialLeastSquares: " + string(e.what());
1992  throw std::runtime_error(str);
1993  }
1994 
1995  AddAnalysisResult(pls_data);
1996  workspace_->UpdateModel();
1997 }
1998 
2004 void VespucciDataset::CorrelationAnalysis(const QString &control_key, QString name)
2005 {
2006 
2007  if (!auxiliary_matrices_->HasMatrix(control_key)){
2008  main_window_->DisplayWarning("Object does not exit", "The object at the specified key does not exist!");
2009  return;
2010  }
2011  vec control;
2012  try{
2013  control = auxiliary_matrices_->GetMatrix(control_key).col(0);
2014  }catch(exception e){
2015  main_window_->DisplayExceptionWarning("VespucciDataset::CorrelationAnalysis", e);
2016  return;
2017  }
2018 
2019  QSharedPointer<UnivariateData> univariate_data(new UnivariateData(name));
2020  try{
2021  univariate_data->ApplyCorrelation(spectra_, control);
2022  }catch(exception e){
2023  main_window_->DisplayExceptionWarning("UnivariateData::apply", e);
2024  return;
2025  }
2026 
2027  state_changed_ = true;
2028  AddAnalysisResult(univariate_data);
2029  workspace_->UpdateModel();
2030 }
2031 
2032 
2041 void VespucciDataset::KMeans(const QString &name, const QString &metric_text, const QString &partition_policy, bool allow_empty, size_t clusters)
2042 {
2043  mat centroids;
2044  vec assignments;
2045  try{
2046  Vespucci::Math::KMeansWrapper k(partition_policy.toStdString(), metric_text.toStdString(), allow_empty);
2047  assignments = k.Cluster(spectra_, clusters, centroids);
2048  }catch(exception e){
2049  main_window_->DisplayExceptionWarning("KMeansWrapper: ", e);
2050  return;
2051  }
2052 
2053  QSharedPointer<AnalysisResults> results(new AnalysisResults(name, "k-Means Analysis"));
2054  results->AddMatrix("Assignments", assignments);
2055  results->AddMatrix("Centroids", centroids);
2056  AddAnalysisResult(results);
2057  workspace_->UpdateModel();
2058  operations_ << "KMeans("
2059  + name + ", "
2060  + QString::number(clusters) + ", "
2061  + metric_text + ", "
2062  + partition_policy + ", "
2063  + (allow_empty ? "true" : "false" ) + ")";
2064 }
2065 
2066 void VespucciDataset::ClassicalLeastSquares(const QString &name, const QStringList &reference_keys)
2067 {
2068  state_changed_ = true;
2069  mat reference = workspace_->GetMatrix(reference_keys);
2070  mat coefs;
2071  try{
2072  coefs = Vespucci::Math::LinLeastSq::OrdinaryLeastSquares(reference, spectra_);
2073  }catch(exception e){
2074  string str = "Vespucci::Math::LinLeastSq::OrdinaryLeastSquares" + string(e.what());
2075  throw runtime_error(str);
2076  }
2077  coefs = coefs.t(); //to make coefficients mappable
2078  QSharedPointer<AnalysisResults> results(new AnalysisResults(name, "CLS Analysis"));
2079  results->AddMatrix("Coefficients", coefs);
2080  AddAnalysisResult(results);
2081  workspace_->UpdateModel();
2082  QString operation = "ClassicalLeastSquares(" + name;
2083  for (auto param: reference_keys)
2084  operation = operation + ", " + param;
2085  operation = operation + ")";
2086  operations_ << operation;
2087 }
2088 
2089 
2090 // HELPER FUNCTIONS //
2091 
2100 uvec VespucciDataset::FindRange(double start, double end) const
2101 {
2102  uvec indices(2);
2103  indices(0) = FindIndex(start);
2104  indices(1) = FindIndex(end);
2105  return indices;
2106 }
2107 
2114 {
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));
2119 
2120  // If for some reason this doesn't work, also find the point halfway down.
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);
2123 }
2124 
2129 vec VespucciDataset::PointSpectrum(uword index) const
2130 {
2131  return spectra_.col((index < spectra_.n_cols ? index : spectra_.n_cols - 1));
2132 }
2133 
2134 QVector<double> VespucciDataset::WavelengthQVector() const
2135 {
2136  std::vector<double> abscissa_stdvector =
2137  conv_to< std::vector<double> >::from(abscissa_);
2138 
2139  QVector<double> abscissa_qvector =
2140  QVector<double>::fromStdVector(abscissa_stdvector);
2141 
2142  return abscissa_qvector;
2143 }
2144 
2145 uword VespucciDataset::FindIndex(double abscissa_value) const
2146 {
2147  double delta = std::fabs(abscissa_(1) - abscissa_(0));
2148  uvec indices = find((abscissa_value - delta) < abscissa_ <= (abscissa_value + delta));
2149  return indices(0);
2150 }
2151 
2159 {
2160  double lower = y_.min();
2161  double upper = y_.max();
2162  QCPRange range(upper, lower);
2163  return range;
2164 }
2172 {
2173  double lower = x_.min();
2174  double upper = x_.max();
2175  QCPRange range(upper, lower);
2176  return range;
2177 }
2178 
2186 {
2187  uword i;
2188  uword x_count=1;
2189  double x_buf;
2190 
2191  //loop through x until a value different then the first is met.
2192  if (!flipped_){
2193  x_count = 1; //this counts the first entry in x_
2194  x_buf = x_(0);
2195  for(i=0; i<x_.n_elem; ++i){
2196  if(x_(i)!=x_buf){
2197  ++x_count;
2198  x_buf=x_(i);
2199  }
2200  }
2201  } else{
2202  x_count = 0;
2203  for (i=0; i<x_.n_elem; ++i){
2204  if(y_(i)!=y_(0)){
2205  break;
2206  } else{
2207  ++x_count;
2208  }
2209  }
2210  }
2211 
2212  return x_count;
2213 }
2214 
2221 {
2222 
2223  uword i = 0;
2224  uword y_count;
2225 
2226 
2227  //long-text files hold x constant and vary y
2228  //until x is different, count y
2229  //reverse if flipped
2230  if (!flipped_){
2231  y_count = 0;
2232  for (i=0; i<x_.n_elem; ++i){
2233  if(x_(i)!=x_(0)){
2234  break;
2235  }
2236  else{
2237  ++y_count;
2238  }
2239  }
2240  } else{
2241  y_count = 1;
2242  double y_buf = y_(0);
2243  for(i=0; i<y_.n_elem; ++i){
2244  if(y_(i)!=y_buf){
2245  ++y_count;
2246  y_buf=y_(i);
2247  }
2248  }
2249  }
2250 
2251 
2252  return y_count;
2253 }
2254 
2255 
2256 // MEMBER ACCESS FUNCTIONS //
2262 {
2263  return abscissa_;
2264 }
2265 
2267 {
2268  return abscissa_;
2269 }
2270 
2272 {
2273  return abscissa_.rows(indices);
2274 }
2275 
2281 {
2282  return x_;
2283 }
2284 
2290 {
2291  return indices_;
2292 }
2293 
2299 {
2300  return (mat *) &indices_;
2301 }
2302 
2304 {
2305  return operations_;
2306 }
2307 
2313 {
2314  indices_ = indices;
2315 }
2316 
2323 {
2324  return x_(indices);
2325 }
2326 
2327 double VespucciDataset::x(uword index) const
2328 {
2329  if (index >= x_.n_rows)
2330  return x_(x_.n_rows - 1);
2331  else
2332  return x_(index);
2333 }
2334 
2335 
2336 
2342 {
2343  return y_;
2344 }
2345 
2352 {
2353  return y_(indices);
2354 }
2355 
2356 double VespucciDataset::y(uword index) const
2357 {
2358  if (index >= y_.n_rows)
2359  return y_(y_.n_rows - 1);
2360  else
2361  return y_(index);
2362 }
2363 
2369 {
2370  return spectra_;
2371 }
2372 
2374 {
2375  if (spectra_imag_.n_rows == spectra_.n_rows && spectra_imag_.n_cols == spectra_.n_cols)
2376  return cx_mat(spectra_, spectra_imag_);
2377  else
2378  return cx_mat(spectra_, zeros(spectra_.n_rows, spectra_.n_cols));
2379 }
2380 
2382 {
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));
2385  else
2386  return cx_mat(spectra_.cols(indices), zeros(spectra_.n_rows, indices.n_rows));
2387 }
2388 
2395 {
2396  return spectra_.cols(indices);
2397 }
2398 
2403 const QString VespucciDataset::name() const
2404 {
2405  return name_;
2406 }
2407 
2412 void VespucciDataset::SetName(QString new_name)
2413 {
2414  name_ = new_name;
2415 }
2416 
2424 void VespucciDataset::SetData(const mat &spectra, const vec &wavelength, const vec &x, const vec &y)
2425 {
2426  spectra_ = spectra;
2427  abscissa_ = wavelength;
2428  x_ = x;
2429  y_ = y;
2430 }
2431 
2432 //MAP HANDLING FUNCTIONS
2437 //QStringList VespucciDataset::map_names()
2438 //{
2439 // return map_names_;
2440 //}
2441 
2447 {
2448  return map_loading_count_;
2449 }
2450 
2451 
2457 void VespucciDataset::AddMap(QSharedPointer<MapData> map)
2458 {
2459  QString basename = map->name();
2460  int i = 0;
2461  while(MapKeys().contains(map->name()))
2462  map->SetName(basename + " (" + QString::number(++i) + ")", map->type());
2463  maps_.append(map);
2464  workspace_->UpdateModel();
2465 }
2466 
2467 void VespucciDataset::RemoveMap(const QString &name)
2468 {
2469  if (MapKeys().contains(name)){
2470  int i = maps_.size();
2471  while (i--){
2472  if (maps_[i]->name() == name)
2473  maps_.removeAt(i); //might be safe to break the while here
2474  }
2475  }
2476 }
2477 
2483 {
2484  double min = abscissa_.min();
2485  double max = abscissa_.max();
2486  QCPRange range(min, max);
2487  return range;
2488 }
2489 
2496 {
2497  vec row = spectra_.col(i);
2498  double min = row.min();
2499  double max = row.max();
2500 
2501  QCPRange range(min, max);
2502  return range;
2503 }
2504 
2512 {
2513  switch (gradient_number)
2514  {
2515  case 0: return QCPColorGradient::cbBuGn;
2516  case 1: return QCPColorGradient::cbBuPu;
2517  case 2: return QCPColorGradient::cbGnBu;
2518  case 3: return QCPColorGradient::cbOrRd;
2519  case 4: return QCPColorGradient::cbPuBu;
2520  case 5: return QCPColorGradient::cbPuBuGn;
2521  case 6: return QCPColorGradient::cbPuRd;
2522  case 7: return QCPColorGradient::cbRdPu;
2523  case 8: return QCPColorGradient::cbYlGn;
2524  case 9: return QCPColorGradient::cbYlGnBu;
2525  case 10: return QCPColorGradient::cbYlOrBr;
2526  case 11: return QCPColorGradient::cbYlOrRd;
2527  case 12: return QCPColorGradient::cbBlues;
2528  case 13: return QCPColorGradient::cbGreens;
2529  case 14: return QCPColorGradient::cbOranges;
2530  case 15: return QCPColorGradient::cbPurples;
2531  case 16: return QCPColorGradient::cbReds;
2532  case 17: return QCPColorGradient::cbGreys;
2533  case 18: return QCPColorGradient::gpGrayscale;
2534  case 19: return QCPColorGradient::gpNight;
2535  case 20: return QCPColorGradient::gpCandy;
2536  case 21: return QCPColorGradient::gpIon;
2537  case 22: return QCPColorGradient::gpThermal;
2538  case 23: return QCPColorGradient::gpPolar;
2539  case 24: return QCPColorGradient::gpSpectrum;
2540  case 25: return QCPColorGradient::gpJet;
2541  case 26: return QCPColorGradient::gpHues;
2542  case 27: return QCPColorGradient::gpHot;
2543  case 28: return QCPColorGradient::gpCold;
2544  case 29: return QCPColorGradient::cbBrBG;
2545  case 30: return QCPColorGradient::cbPiYG;
2546  case 31: return QCPColorGradient::cbPRGn;
2547  case 32: return QCPColorGradient::cbPuOr;
2548  case 33: return QCPColorGradient::cbRdBu;
2549  case 34: return QCPColorGradient::cbRdGy;
2550  case 35: return QCPColorGradient::cbRdYlBu;
2551  case 36: return QCPColorGradient::cbRdYlGn;
2552  case 37: return QCPColorGradient::cbSpectral;
2553  case 38: return QCPColorGradient::vSpectral;
2554  default: return QCPColorGradient::gpCold;
2555  }
2556 }
2557 
2566 {
2567  switch (clusters)
2568  {
2569  case 2: return QCPColorGradient::cbCluster2;
2570  case 3: return QCPColorGradient::cbCluster3;
2571  case 4: return QCPColorGradient::cbCluster4;
2572  case 5: return QCPColorGradient::cbCluster5;
2573  case 6: return QCPColorGradient::cbCluster6;
2574  case 7: return QCPColorGradient::cbCluster7;
2575  case 8: return QCPColorGradient::cbCluster8;
2576  case 9: return QCPColorGradient::cbCluster9;
2577  default: return QCPColorGradient::gpJet; //not as good, but should still be different
2578  }
2579 }
2580 
2588 {
2589  return constructor_canceled_;
2590 }
2591 
2601 {
2602  mat spec_mean = mean(spectra_, 1);
2603  vec spec_stddev;
2604  //insert stddevs on next line if requested
2605  if (stats){
2606  spec_stddev = stddev(spectra_, 0, 1);
2607  spec_mean.insert_cols(1, spec_stddev);
2608  }
2609  return spec_mean;
2610 }
2611 
2612 
2613 
2620 {
2621  return x_axis_description_;
2622 }
2623 
2629 void VespucciDataset::SetXDescription(QString description)
2630 {
2631  x_axis_description_ = description;
2632 }
2633 
2638 void VespucciDataset::SetYDescription(QString description)
2639 {
2640  y_axis_description_ = description;
2641 }
2642 
2648 {
2649  return y_axis_description_;
2650 }
2651 
2652 
2658 {
2659  return &spectra_;
2660 }
2661 
2667 {
2668  return spectra_;
2669 }
2670 
2676 {
2677  return abscissa_;
2678 }
2679 
2685 {
2686  return x_;
2687 }
2688 
2694 {
2695  return y_;
2696 }
2697 
2699 {
2700  return spectra_.n_cols;
2701 }
2702 
2704 {
2705  return abscissa_.min();
2706 }
2707 
2709 {
2710  return abscissa_.max();
2711 }
2712 
2713 
2719 {
2720  return (spectra_old_.n_elem > 0 ? true : false);
2721 }
2722 
2724 {
2725  vec unique_x = unique(x_);
2726  return unique_x.n_rows;
2727 }
2728 
2730 {
2731  vec unique_y = unique(y_);
2732  return unique_y.n_rows;
2733 }
2734 
2735 
2741 {
2742  return analysis_results_.size();
2743 }
2744 
2750 {
2751  return &abscissa_;
2752 }
2753 
2755 {
2756  return &abscissa_;
2757 }
2758 
2764 {
2765  return &x_;
2766 }
2767 
2773 {
2774  return &y_;
2775 }
2776 
2782 {
2783  return non_spatial_;
2784 }
2785 
2791 {
2792  return meta_;
2793 }
2794 
2800 {
2801  parent_dataset_indices_ = parent_dataset_indices;
2802 }
2803 
2805 {
2806  return &parent_dataset_indices_;
2807 }
2808 
2813 const QString VespucciDataset::last_operation() const
2814 {
2815  return last_operation_;
2816 }
2817 
2818 
2819 void VespucciDataset::AddAnalysisResult(QSharedPointer<AnalysisResults> analysis_result)
2820 {
2821  QString name = analysis_result->name();
2822  QString new_name = name;
2823  int i = 0;
2824  while (AnalysisResultsKeys().contains(new_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();
2831 }
2832 
2833 void VespucciDataset::AddAnalysisResult(QSharedPointer<AnalysisResults> analysis_result, uword start_row, uword end_row)
2834 {
2835  QString name = analysis_result->name();
2836  QString new_name = name;
2837  int i = 0;
2838  while (AnalysisResultsKeys().contains(new_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();
2845 }
2846 
2847 
2853 {
2854  QStringList keys;
2855  for (auto result: analysis_results_)
2856  keys << result->name();
2857  return keys;
2858 }
2859 
2864 QMap<QString, QStringList> VespucciDataset::AnalysisResultsTreeStructure() const
2865 {
2866  QMap<QString, QStringList> tree_structure;
2867  for (auto result: analysis_results_)
2868  tree_structure[result->name()] = result->KeyList();
2869  return tree_structure;
2870 }
2871 
2877 void VespucciDataset::ImportAuxiliaryMatrix(const QString &name, const QString &filename)
2878 {
2879  mat matrix;
2880  bool ok = matrix.load(filename.toStdString());
2881  if (ok)
2882  auxiliary_matrices_->AddMatrix(name, matrix);
2883  else
2884  main_window_->DisplayWarning("Matrix Not Loaded", "The file " + name + " could not be loaded");
2885 }
2886 
2892 void VespucciDataset::AddAuxiliaryMatrix(const QString &name, mat &matrix)
2893 {
2894  QString basename = name;
2895  QString new_name = name;
2896  int i = 0;
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;
2902 }
2903 
2904 void VespucciDataset::AddMatrix(const QString &name, mat &matrix)
2905 {
2906  if (name == "Spectra")
2907  spectra_ = matrix;
2908  else if (name == "x")
2909  x_ = matrix.col(0);
2910  else if (name == "y")
2911  y_ = matrix.col(0);
2912  else if (name == "Spectral Abscissa")
2913  abscissa_ = matrix.col(0);
2914  else
2915  AddAuxiliaryMatrix(name, matrix);
2916  state_changed_ = true;
2917  workspace_->UpdateModel();
2918 }
2919 
2925 {
2926  return auxiliary_matrices_->KeyList();
2927 }
2928 
2934 {
2935  return {"Spectra", "Spectral Abscissa", "x", "y"};
2936 }
2937 
2945 const mat & VespucciDataset::GetAnalysisResultMatrix(const QString &results_key, const QString &matrix_key) const
2946 {
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);
2951  }
2952 
2953  return empty_matrix_;
2954 }
2955 
2956 QSharedPointer<AnalysisResults> VespucciDataset::GetAnalysisResult(const QString &key)
2957 {
2958 
2959  for (auto result: analysis_results_){
2960  if (result->name() == key)
2961  return result;
2962  }
2963 
2964  QSharedPointer<AnalysisResults> dummy(new AnalysisResults("Dummy", "Dummy"));
2965  return dummy;
2966 }
2967 
2968 const mat & VespucciDataset::GetAuxiliaryMatrix(const QString &key) const
2969 {
2970  if (auxiliary_matrices_->HasMatrix(key)) return auxiliary_matrices_->GetMatrix(key);
2971  else
2972  return empty_matrix_;
2973 }
2974 
2975 const mat &VespucciDataset::GetCoreMatrix(const QString &key) const
2976 {
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_;}
2982 }
2983 
2990 bool VespucciDataset::IsCoreMatrix(const QString &key) const
2991 {
2992  return (key == "Spectra" || key == "Spectral Abscissa" || key == "x" || key == "y");
2993 }
2994 
2995 QSharedPointer<MapData> VespucciDataset::GetMapData(const QString &key)
2996 {
2997  for (auto map: maps_){
2998  if (map->name() == key) return map;
2999  }
3000  return QSharedPointer<MapData>(0); //return null mapdata
3001 }
3002 
3013 void VespucciDataset::CreateMap(const QString &map_name,
3014  const QString &results_key,
3015  const QString &matrix_key,
3016  uword column,
3017  QCPColorGradient gradient)
3018 {
3019  if (AnalysisResultsKeys().contains(results_key)
3020  && GetAnalysisResult(results_key)->HasMatrix(matrix_key)){
3021  QStringList data_keys = {name_, results_key, matrix_key};
3022  QString map_type = GetAnalysisResult(results_key)->type() + " Color Map";
3023  QSharedPointer<MapData> new_map(new MapData(map_name,
3024  map_type,
3025  data_keys,
3026  column,
3027  workspace_));
3028 
3029  new_map->setGradient(gradient);
3030  AddMap(new_map);
3031  workspace_->UpdateModel();
3032  }
3033 }
3034 
3035 void VespucciDataset::CreateMap(const QString &map_name,
3036  const QString &matrix_key,
3037  uword column,
3038  QCPColorGradient gradient)
3039 {
3040  if (auxiliary_matrices_->HasMatrix(matrix_key)){
3041  QStringList data_keys = {name_, matrix_key};
3042  QSharedPointer<MapData> new_map(new MapData(map_name,
3043  QString(),
3044  data_keys,
3045  column,
3046  workspace_));
3047  new_map->setGradient(gradient);
3048  AddMap(new_map);
3049  workspace_->UpdateModel();
3050  }
3051 }
3052 
3053 bool VespucciDataset::ShowMapViewer(const QString &map_key, bool show)
3054 {
3055  if (!MapKeys().contains(map_key)) return false;
3056  bool ok = MapKeys().contains(map_key);
3057  if (ok){
3058  for (auto map: maps_){
3059  if (map->name() == map_key){
3060  map->ShowMapWindow(show);
3061  }
3062  }
3063  }
3064  return ok;
3065 }
3066 
3067 QStringList VespucciDataset::MapKeys() const
3068 {
3069  QStringList map_keys;
3070  for (auto map: maps_)
3071  map_keys << map->name();
3072  return map_keys;
3073 }
3074 
3075 
VESPUCCI_EXPORT arma::vec WavenumberToWavelength(const arma::vec &x, double wn_factor, double wl_factor)
Vespucci::Math::WavenumberToWavelength.
Definition: accessory.cpp:701
The PLSData class A class for performing and storing data related to partial least squares determinan...
Definition: plsdata.h:29
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.
uword UniqueY() const
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.
VESPUCCI_EXPORT arma::mat ApplyWeights(const arma::mat &signal, const arma::vec &abscissa, const std::string &weight, const double &param)
Vespucci::Math::Transform::ApplyWeights.
Definition: fft.cpp:119
QVector< double > WavelengthQVector() const
arma::vec Cluster(const arma::mat &data, const size_t clusters, arma::mat &centroids)
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.
Definition: accessory.cpp:731
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.
Definition: FIR.cpp:126
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.
Definition: accessory.cpp:746
double AbscissaMin() const
QStringList MapKeys() const
uword UniqueX() 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
Definition: FIR.cpp:89
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.
Definition: mapdata.h:44
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.
Definition: qcustomplot.h:1930
void DisplayExceptionWarning(std::exception e)
MainWindow::DisplayExceptionWarning.
Definition: mainwindow.cpp:845
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...
Definition: linleastsq.cpp:35
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.
Definition: accessory.cpp:237
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.
vec abscissa() const
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.
Definition: accessory.cpp:657
QSharedPointer< VespucciWorkspace > workspace_ptr()
MainWindow::workspace_ptr.
Definition: mainwindow.cpp:794
VESPUCCI_EXPORT arma::vec RepresentativeSpectrum(const arma::mat &spectra, arma::uword &index, std::string metric_name="euclidean", std::string center="centroid")
Vespucci::Math::RepresentativeSpectrum.
Definition: accessory.cpp:953
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.
Definition: accessory.cpp:773
int FindIndex(int x_value, int y_value) const
QString filename() const
Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion ...
Definition: qcustomplot.h:1933
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)...
Definition: qcustomplot.h:1925
mat spectra() const
VespucciDataset::spectra.
An approximation of the visible light spectrum (creates banding illusion but allows more precise magn...
Definition: qcustomplot.h:1932
mat * x_ptr()
VespucciDataset::x_ptr.
VESPUCCI_EXPORT arma::vec WavelengthToFrequency(const arma::vec &x, double freq_factor, double wl_factor)
Vespucci::Math::WavelengthToFrequency.
Definition: accessory.cpp:614
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...
Definition: kmeanswrapper.h:33
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...
Definition: qcustomplot.h:1929
bool SaveSpectrum(QString filename, uword column, file_type type)
bool saved() const
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.
Definition: VCA.cpp:159
void SetParentDatasetIndices(mat parent_dataset_indices)
VespucciDataset::SetParentDatasetIndices.
VESPUCCI_EXPORT void ifft_mat(const arma::cx_mat &f_signal, const arma::vec f_abscissa, arma::cx_mat &t_signal, arma::vec &t_abscissa, arma::uword n)
Vespucci::Math::Transform::ifft_mat.
Definition: fft.cpp:72
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.
Definition: FIR.cpp:177
Continuous lightness from black over firey colors to white (suited for non-biased data representation...
Definition: qcustomplot.h:1924
Continuous lightness from black to white (suited for non-biased data representation) ...
Definition: qcustomplot.h:1923
int QUIC_SVD(double epsilon)
VespucciDataset::QUIC_SVD.
bool Undoable() const
VespucciDataset::Undoable.
Blue over pink to white.
Definition: qcustomplot.h:1927
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.
Definition: nonlinear.cpp:61
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.
Definition: accessory.cpp:643
VESPUCCI_EXPORT arma::vec FindPeakMaxMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::vec &positions)
Vespucci::Math::Quantification::FindPeakMaxMat.
Definition: maximum.cpp:50
VESPUCCI_EXPORT arma::vec FrequencyToWavenumber(const arma::vec &x, double wn_factor, double freq_factor)
Vespucci::Math::FrequencyToWavenumber.
Definition: accessory.cpp:686
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.
Definition: accessory.cpp:249
VESPUCCI_EXPORT bool ImportWideText(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportWideText.
Definition: textimport.cpp:97
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.
Definition: textimport.cpp:152
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)
Definition: denoise.cpp:28
VESPUCCI_EXPORT arma::mat SVDDenoise(const arma::mat &X, arma::uword k, arma::mat &U, arma::vec &s, arma::mat &V)
Definition: denoise.cpp:22
Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle ...
Definition: qcustomplot.h:1931
bool IsValid() const
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...
Definition: qcustomplot.h:1926
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
VESPUCCI_EXPORT arma::vec EnergyToWavenumber(const arma::vec &x, double wn_factor, double energy_factor)
Vespucci::Math::EnergyToWavenumber.
Definition: accessory.cpp:760
VESPUCCI_EXPORT arma::mat ApplySBWeights(const arma::mat &signal, const arma::vec &abscissa, const double &starting_offset, const double &ending_offset, const double &power)
Vespucci::Math::Transform::ApplyWeights.
Definition: fft.cpp:150
bool ShowMapViewer(const QString &map_key, bool show)
size_t columns() const
void DisplayWarning(const QString &title, const QString &text)
Definition: mainwindow.cpp:867
The VCAData class A class for performing and storing data from Vertex Components Analysis.
Definition: vcadata.h:28
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.
Definition: VCA.cpp:216
vec x() const
VespucciDataset::x.
VESPUCCI_EXPORT arma::vec CreateMovingAverageFilter(arma::uword window_size)
Vespucci::Math::Smoothing::CreateMovingAverageFilter.
Definition: FIR.cpp:160
double AbscissaMax() const
Defines a color gradient for use with e.g. QCPColorMap.
Definition: qcustomplot.h:1905
void SetYDescription(QString description)
VespucciDataset::SetYDescription.
Represents the range an axis is encompassing.
Definition: qcustomplot.h:481
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58
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.
Definition: accessory.cpp:716
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.
Definition: linleastsq.cpp:149
Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and pha...
Definition: qcustomplot.h:1934
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.
Definition: textimport.cpp:311
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.
Definition: accessory.cpp:629
QCPColorGradient GetGradient(int gradient_number) const
VespucciDataset::GetGradient Selects the color gradient from list of presets.
void SNVNormalize(double offset, bool center)
QStringList operations()
bool non_spatial() const
VespucciDataset::non_spatial.
void RemoveClippedSpectra(double threshold)
VespucciDataset::RemoveClippedSpectra.
mat * parent_dataset_indices()
int UnivariateCount() const
VespucciDataset::UnivariateCount.
VESPUCCI_EXPORT void fft_mat(const arma::mat &t_signal, const arma::vec &t_abscissa, arma::cx_mat &f_signal, arma::vec &f_abscissa, arma::uword n)
Vespucci::Math::Transform::fft_mat.
Definition: fft.cpp:29
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.
Definition: accessory.cpp:671