40 arma::field<arma::mat> dataset(4);
42 dataset(1) = abscissa;
45 success = dataset.save(filename, arma::arma_binary);
47 catch(std::exception e){
48 std::cerr <<
"See armadillo exception" << std::endl;
49 std::string str =
"Vespucci::SaveVespucciBinary: " + std::string(e.what());
50 throw std::runtime_error(str);
59 bool Vespucci::SaveText(std::string basename,
const arma::mat &spectra,
const arma::vec &x,
const arma::vec &y,
const arma::vec &abscissa, arma::file_type type)
61 std::string extension;
65 case arma::raw_ascii:
default:
68 bool x_success, y_success, spectra_success, abscissa_success;
69 spectra_success = spectra.save(basename +
"_spectra" + extension, type);
70 abscissa_success = abscissa.save(basename +
"_abscissa" + extension, type);
71 x_success = x.save(basename +
"_x" + extension, type);
72 y_success = y.save(basename +
"_y" + extension, type);
73 return (x_success && y_success && spectra_success && abscissa_success);
115 arma::mat &spectra, arma::vec &x, arma::vec &y,
120 abscissa = datasets(0,0)(1);
126 arma::mat first_x = datasets(0, 0)(2);
127 arma::mat first_y = datasets(0, 0)(3);
130 arma::vec unique_x = arma::unique(first_x);
131 arma::vec unique_y = arma::unique(first_y);
132 double spatial_resolution;
133 if (unique_x.n_rows < 2){
134 if (unique_y.n_rows > 1){
136 unique_y(unique_y.n_rows - 1)
137 - unique_y(unique_y.n_rows - 2);
143 unique_x(unique_x.n_rows - 1) - unique_x(unique_x.n_rows - 2);
146 arma::uword n_unique_y = 0;
147 arma::uword row_block_n_unique_y = 0;
149 for (
size_t i = datasets.n_rows - 1; i >= 0; --i){
150 row_block_n_unique_y = 0;
151 unique_x = arma::unique(datasets(i, 0)(2));
152 arma::uword n_unique_x = unique_x.n_rows;
153 arma::mat row_block_spc;
154 arma::vec row_block_x;
155 arma::vec row_block_y;
157 for (arma::uword j = 0; j < datasets.n_cols; ++j){
158 arma::uword abs_ct = datasets(i,j)(1).n_rows;
160 if (datasets(i,j)(0).n_rows != abs_ct){
165 unique_x = arma::unique(datasets(i,j)(2));
166 unique_y = arma::unique(datasets(i,j)(3));
167 if (unique_x.n_rows != n_unique_x){
171 row_block_n_unique_y += unique_y.n_rows;
176 arma::vec new_x = datasets(i,j)(2) - datasets(i,j)(2).
min()*arma::ones(datasets(i,j)(2).n_rows);
177 arma::vec new_y = datasets(i,j)(3) - datasets(i,j)(3).
min()*arma::ones(datasets(i,j)(3).n_rows);
180 double x_offset = (row_block_x.n_elem ?
181 row_block_x.max() + spatial_resolution :
183 new_x = datasets(i,j)(2) + x_offset*arma::ones(datasets(i,j)(2).n_rows);
186 if (!row_block_x.n_elem){row_block_x = new_x;}
187 else{row_block_x = arma::join_vert(row_block_x, new_x);}
188 if (!row_block_y.n_elem){row_block_y = new_y;}
189 else{row_block_y = arma::join_vert(row_block_y, new_y);}
190 if (!row_block_spc.n_elem){row_block_spc = datasets(i,j)(0);}
191 else{row_block_spc = arma::join_horiz(row_block_spc, datasets(i,j)(0));}
195 double y_offset = (y.n_elem ?
196 y.max() - row_block_y.min() + spatial_resolution :
198 row_block_y = row_block_y + y_offset*arma::ones(row_block_y.n_rows);
201 if (i == datasets.n_rows - 1){n_unique_y = row_block_n_unique_y;}
204 if (row_block_n_unique_y != n_unique_y){
210 if (!spectra.n_cols){spectra = row_block_spc;}
211 else{spectra = arma::join_horiz(spectra, row_block_spc);}
212 if (!x.n_rows){x = row_block_x;}
213 else{x = arma::join_vert(x, row_block_x);}
214 if (!y.n_rows){y = row_block_y;}
215 else{y = arma::join_vert(y, row_block_y);}
243 std::string::const_iterator it = in.begin();
244 for (
const char c : in){
245 if (c ==
'\t' || c ==
','){out.append(
" ");}
246 else{out.append(&c);}
VESPUCCI_EXPORT std::string CleanString(const std::string &in)
Vespucci::CleanString.
VESPUCCI_EXPORT bool StitchDatasets(const arma::field< arma::field< arma::mat > > &datasets, arma::mat &spectra, arma::vec &x, arma::vec &y, arma::vec &abscissa)
Vespucci::StitchDatasets.
VESPUCCI_EXPORT bool SaveOldVespucciBinary(std::string filename, const arma::mat &spectra, const arma::vec &x, const arma::vec &y, const arma::vec &abscissa)
Vespucci::SaveVespucciBinary.
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
VESPUCCI_EXPORT void ResetDataset(arma::mat &spectra, arma::vec &x, arma::vec &y, arma::vec &abscissa)
VESPUCCI_EXPORT bool SaveText(std::string basename, const arma::mat &spectra, const arma::vec &x, const arma::vec &y, const arma::vec &abscissa, arma::file_type type)