Skip to content

Commit 88f6d12

Browse files
authored
Merge pull request #231 from aglowacki/master
Merge with dev
2 parents 0d29a1b + b05ae0d commit 88f6d12

File tree

10 files changed

+105
-39
lines changed

10 files changed

+105
-39
lines changed

src/core/defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ const std::string STR_CFG_3 = "CFG_3";
224224
const std::string STR_CFG_4 = "CFG_4";
225225
const std::string STR_CFG_5 = "CFG_5";
226226

227+
const std::string STR_POLARITY_PATTERN = "POLARITY_PATTERN";
227228

228229
const std::string STR_K_A_LINES = "K Alpha";
229230
const std::string STR_K_B_LINES = "K Beta";

src/data_struct/params_override.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DLL_EXPORT Params_Override
9393
ge_dead_layer = "0.0";
9494
airpath = "0";
9595
theta_pv = "";
96+
polarity_pattern = "";
9697
}
9798

9899
Params_Override(std::string dir, int detector)
@@ -116,6 +117,7 @@ class DLL_EXPORT Params_Override
116117
dataset_directory = dir;
117118
detector_num = detector;
118119
detector_element = "Si";
120+
polarity_pattern = "";
119121
}
120122

121123
~Params_Override()
@@ -245,6 +247,8 @@ class DLL_EXPORT Params_Override
245247
T_real ds_amp_sens_num;
246248
std::string ds_amp_sens_unit;
247249

250+
std::string polarity_pattern;
251+
248252
};
249253

250254
TEMPLATE_CLASS_DLL_EXPORT Params_Override<float>;

src/data_struct/scan_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct Scan_Meta_Info
9292
std::string name;
9393
std::string scan_time_stamp;
9494
std::string scan_type;
95+
std::string polarity_pattern;
9596
ArrayTr<T_real> x_axis;
9697
ArrayTr<T_real> y_axis;
9798
int requested_cols;

src/fitting/optimizers/nlopt_optimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ double quantification_residuals_nlopt(const std::vector<double> &x, [[maybe_unus
165165
double sum = 0.0;
166166
for(auto& itr : ud->quant_map)
167167
{
168-
sum += pow((itr.second.e_cal_ratio - result_map[itr.first]), 2.0);
169-
168+
//sum += pow((itr.second.e_cal_ratio - result_map[itr.first]), 2.0);
169+
sum += pow(1.0 - (itr.second.e_cal_ratio / result_map[itr.first]), 2.0);
170170
if (std::isfinite(result_map[itr.first]) == false)
171171
{
172172
logE<<"Quantification reuslted in NaN or Inf! "<< itr.first<<" : "<<result_map[itr.first]<<"\n";

src/io/file/aps/aps_fit_params_import.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ namespace aps
126126
{"fwhm_fanoprime", STR_FWHM_FANOPRIME},
127127
{"COHERENT_SCT_ENERGY", STR_COHERENT_SCT_ENERGY},
128128
{"coherent_sct_energy", STR_COHERENT_SCT_ENERGY},
129+
{"COHERENT_SCT_AMPLITUDE", STR_COHERENT_SCT_AMPLITUDE},
129130
{"coherent_sct_amplitude", STR_COHERENT_SCT_AMPLITUDE},
130131
{"COMPTON_ANGLE", STR_COMPTON_ANGLE},
131132
{"compton_angle", STR_COMPTON_ANGLE},
132133
{"COMPTON_FWHM_CORR", STR_COMPTON_FWHM_CORR},
133134
{"compton_fwhm_corr", STR_COMPTON_FWHM_CORR},
135+
{"COMPTON_AMPLITUDE", STR_COMPTON_AMPLITUDE},
134136
{"compton_amplitude", STR_COMPTON_AMPLITUDE},
135137
{"COMPTON_STEP", STR_COMPTON_F_STEP},
136138
{"compton_f_step", STR_COMPTON_F_STEP},
@@ -818,6 +820,16 @@ DLL_EXPORT bool load_parameters_override(std::string path, Params_Override<T_rea
818820

819821
params_override->scaling_factors[scaler_name] = factor;
820822
}
823+
else if (tag == STR_POLARITY_PATTERN)
824+
{
825+
std::string value;
826+
std::getline(strstream, value);
827+
value.erase(std::remove(value.begin(), value.end(), '\n'), value.end());
828+
value.erase(std::remove(value.begin(), value.end(), '\r'), value.end());
829+
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
830+
params_override->polarity_pattern = value;
831+
}
832+
821833
}
822834
catch (std::exception& e)
823835
{

src/io/file/hdf5_io.h

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ class DLL_EXPORT HDF5_IO
10361036
//-----------------------------------------------------------------------------
10371037
// load spectra volume as float (T_real) but scan_info as double (T_real2)
10381038
template<typename T_real, typename T_real2>
1039-
bool load_spectra_vol_polar_energy_scan(std::string path, std::string filename, size_t detector_num, data_struct::Spectra_Volume<T_real>* spec_vol, data_struct::Scan_Info<T_real2> &scan_info, bool logerr = true)
1039+
bool load_spectra_vol_polar_energy_scan(std::string path, std::string filename, size_t detector_num, data_struct::Spectra_Volume<T_real>* spec_vol, data_struct::Scan_Info<T_real2> &scan_info, data_struct::Params_Override<T_real>* params_override, bool logerr = true)
10401040
{
10411041
std::stack<std::pair<hid_t, H5_OBJECTS> > close_map;
10421042
hid_t file_id, dset_id, space_id;
@@ -1247,9 +1247,10 @@ class DLL_EXPORT HDF5_IO
12471247
scan_info.meta_info.scan_type = STR_SCAN_TYPE_POLAR_XANES;
12481248
// Take 1 spectra per magnetic polarization, divide them by 2 and store in each row
12491249
scan_info.meta_info.requested_cols = dims3[0] / 2;
1250-
scan_info.meta_info.requested_rows = 2;
1250+
scan_info.meta_info.requested_rows = 2; // two polarities
12511251
scan_info.meta_info.x_axis.resize(scan_info.meta_info.requested_cols);
12521252
scan_info.meta_info.y_axis.resize(scan_info.meta_info.requested_rows);
1253+
scan_info.meta_info.polarity_pattern = params_override->polarity_pattern;
12531254
spec_vol->resize_and_zero(scan_info.meta_info.requested_rows, scan_info.meta_info.requested_cols, dims3[2]);
12541255

12551256
struct data_struct::Scaler_Map<T_real2> energy_map;
@@ -1314,58 +1315,90 @@ class DLL_EXPORT HDF5_IO
13141315
int polarity = 0;
13151316
int idx = 0;
13161317

1317-
if(use_pr1 && (pr1_array.size() != dims3[0]))
1318+
if (params_override != nullptr && params_override->polarity_pattern.size() == 0)
13181319
{
1319-
logE<<str_pr1_path<<" is not the same size as spectra data. Can not load properly.\n";
1320-
_close_h5_objects(close_map);
1321-
return false;
1322-
}
1323-
else if(use_pr1 == false && (pr2_array.size() != dims3[0]))
1324-
{
1325-
logE<<str_pr2_path<<" is not the same size as spectra data. Can not load properly.\n";
1326-
_close_h5_objects(close_map);
1327-
return false;
1320+
if (use_pr1 && (pr1_array.size() != dims3[0]))
1321+
{
1322+
logE << str_pr1_path << " is not the same size as spectra data. Can not load properly.\n";
1323+
_close_h5_objects(close_map);
1324+
return false;
1325+
}
1326+
else if (use_pr1 == false && (pr2_array.size() != dims3[0]))
1327+
{
1328+
logE << str_pr2_path << " is not the same size as spectra data. Can not load properly.\n";
1329+
_close_h5_objects(close_map);
1330+
return false;
1331+
}
13281332
}
1333+
int polarity_str_idx = 0;
1334+
int left_pol_idx = 0;
1335+
int right_pol_idx = 0;
13291336

13301337
for(size_t i = 0; i < dims3[0]; i++)
13311338
{
13321339
offset3[0] = i;
13331340
H5Sselect_hyperslab(space_id, H5S_SELECT_SET, offset3, nullptr, count3, nullptr);
13341341

1335-
if(i > 0)
1342+
if (params_override != nullptr && params_override->polarity_pattern.size() > 0)
1343+
{
1344+
if (polarity_str_idx >= params_override->polarity_pattern.size())
1345+
{
1346+
polarity_str_idx = 0;
1347+
}
1348+
if (params_override->polarity_pattern.at(polarity_str_idx) == 'L')
1349+
{
1350+
polarity = 0;
1351+
idx = left_pol_idx;
1352+
left_pol_idx++;
1353+
}
1354+
else if (params_override->polarity_pattern.at(polarity_str_idx) == 'R')
1355+
{
1356+
polarity = 1;
1357+
idx = right_pol_idx;
1358+
right_pol_idx++;
1359+
}
1360+
else
1361+
{
1362+
logW << "Unknown polarity override " << params_override->polarity_pattern[polarity_str_idx] << " in override string : " << params_override->polarity_pattern << "\n";
1363+
}
1364+
}
1365+
else
13361366
{
1337-
if(use_pr1)
1367+
if (i > 0)
13381368
{
1339-
if(pr1_array[i] != pr1_array[i-1])
1369+
if (use_pr1)
13401370
{
1341-
if(polarity == 1)
1342-
{
1343-
polarity = 0;
1344-
idx++;
1345-
}
1346-
else
1371+
if (pr1_array[i] != pr1_array[i - 1])
13471372
{
1348-
polarity = 1;
1373+
if (polarity == 1)
1374+
{
1375+
polarity = 0;
1376+
idx++;
1377+
}
1378+
else
1379+
{
1380+
polarity = 1;
1381+
}
13491382
}
13501383
}
1351-
}
1352-
else
1353-
{
1354-
if(pr2_array[i] != pr2_array[i-1])
1384+
else
13551385
{
1356-
if(polarity == 1)
1386+
if (pr2_array[i] != pr2_array[i - 1])
13571387
{
1358-
polarity = 0;
1388+
if (polarity == 1)
1389+
{
1390+
polarity = 0;
1391+
}
1392+
else
1393+
{
1394+
polarity = 1;
1395+
}
13591396
}
13601397
else
13611398
{
1362-
polarity = 1;
1399+
idx++;
13631400
}
13641401
}
1365-
else
1366-
{
1367-
idx++;
1368-
}
13691402
}
13701403
}
13711404

@@ -8468,6 +8501,18 @@ class DLL_EXPORT HDF5_IO
84688501
}
84698502
}
84708503

8504+
//Save polarity pattern
8505+
if (_open_h5_dataset(STR_POLARITY_PATTERN, filetype, scan_grp_id, 1, count, count, dset_id, dataspace_id))
8506+
{
8507+
char tmp_char[255] = { 0 };
8508+
meta_info->polarity_pattern.copy(tmp_char, 254);
8509+
status = H5Dwrite(dset_id, memtype, memoryspace_id, dataspace_id, H5P_DEFAULT, (void*)tmp_char);
8510+
if (status < 0)
8511+
{
8512+
logE << "failed to write " << STR_POLARITY_PATTERN << "\n";
8513+
}
8514+
}
8515+
84718516
if (_open_h5_dataset(STR_SCAN_TIME_STAMP, filetype, scan_grp_id, 1, count, count, dset_id, dataspace_id))
84728517
{
84738518
char tmp_char[255] = { 0 };

src/io/file/hl_file_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ DLL_EXPORT bool load_spectra_volume(std::string dataset_directory,
916916
{
917917
// try to load polar hdf master file
918918
data_struct::Scan_Info<double> scan_info;
919-
if(true == io::file::HDF5_IO::inst()->load_spectra_vol_polar_energy_scan(dataset_directory, dataset_file, detector_num, spectra_volume, scan_info))
919+
if(true == io::file::HDF5_IO::inst()->load_spectra_vol_polar_energy_scan(dataset_directory, dataset_file, detector_num, spectra_volume, scan_info, params_override))
920920
{
921921
scan_type = STR_SCAN_TYPE_POLAR_XANES;
922922
if(io::file::HDF5_IO::inst()->start_save_seq(true))

src/io/file/mda_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class DLL_EXPORT MDA_IO
127127

128128
void unload();
129129

130-
void search_and_update_amps(std::string us_amp_pv_str, std::string ds_amp_pv_str, T_real& out_us_amp, T_real& out_ds_amp);
130+
//void search_and_update_amps(std::string us_amp_pv_str, std::string ds_amp_pv_str, T_real& out_us_amp, T_real& out_ds_amp);
131131

132132
data_struct::Scan_Info<T_real>* get_scan_info() { return &_scan_info; }
133133

src/io/file/netcdf_io.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,11 @@ bool NetCDF_IO<T_real>::load_spectra_line_with_callback(const std::string& path,
476476
bool val = true;
477477
for (auto &detector : detector_num_arr)
478478
{
479-
val &= _load_spectra(E_load_type::CALLBACKF, path, detector, nullptr, max_cols, nullptr, row, max_rows, &callback_fun, nullptr);
479+
size_t loaded_cols = _load_spectra(E_load_type::CALLBACKF, path, detector, nullptr, max_cols, nullptr, row, max_rows, &callback_fun, nullptr);
480+
if (loaded_cols == 0)
481+
{
482+
val = false;
483+
}
480484
}
481485
return val;
482486
}

src/pybindings/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define _STL_CRT_SECURE_INVALID_PARAMETER(expr) _CRT_SECURE_INVALID_PARAMETER(expr)
21

32
#include <pybind11/pybind11.h>
43
#include <pybind11/numpy.h>

0 commit comments

Comments
 (0)