Skip to content

Commit 3c8aaca

Browse files
author
Arthur Glowacki
committed
Merge branch 'master' of github.com:aglowacki/XRF-Maps
2 parents 506b45f + a3e9172 commit 3c8aaca

13 files changed

Lines changed: 270 additions & 206 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,14 @@ IF (BUILD_WITH_PYBIND11)
385385
IF (WIN32)
386386
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared libzmq-static ws2_32.lib rpcrt4.lib iphlpapi.lib)
387387
ELSEIF (UNIX)
388-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared libzmq-static)
388+
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf libzmq-static)
389389
ENDIF()
390390
ELSE()
391-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared)
391+
IF (WIN32)
392+
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared)
393+
ELSEIF (UNIX)
394+
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf libzmq-static)
395+
ENDIF()
392396
ENDIF()
393397
ENDIF()
394398

@@ -514,8 +518,13 @@ ELSEIF (UNIX)
514518
ENDIF()
515519

516520
target_link_libraries(libxrf_fit PRIVATE NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
517-
target_link_libraries(libxrf_io PRIVATE libxrf_fit netCDF::netcdf hdf5::hdf5-shared yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
518-
target_link_libraries (xrf_maps PRIVATE libxrf_io libxrf_fit netCDF::netcdf hdf5::hdf5-shared yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
521+
IF (WIN32)
522+
target_link_libraries(libxrf_io PRIVATE libxrf_fit netCDF::netcdf hdf5::hdf5-shared yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
523+
target_link_libraries (xrf_maps PRIVATE libxrf_io libxrf_fit netCDF::netcdf hdf5::hdf5-shared yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
524+
ELSEIF (UNIX)
525+
target_link_libraries(libxrf_io PRIVATE libxrf_fit netCDF::netcdf yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
526+
target_link_libraries (xrf_maps PRIVATE libxrf_io libxrf_fit netCDF::netcdf yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
527+
ENDIF()
519528

520529
IF (BUILD_WITH_QT)
521530
target_link_libraries (libxrf_io LINK_PUBLIC ${Qt6Charts_LIBRARIES} )

reference/Scaler_to_PV_map.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ BeamLines:
1414
US_IC: 2idd:scaler1_cts1.C
1515
DS_IC:
1616
- 2idd:scaler1_cts1.B
17-
- 2iddtmm1:Current4:MeanValue_RBV
18-
- 2iddtmm1:Current4
1917
DS_IC_SCALE_FACTOR: 2iddtmm1:CurrentScale4
2018
ELT1: 2iddXMAP:mca1.ELTM
2119
ELT2: 2iddXMAP:mca2.ELTM

src/core/process_whole.cpp

Lines changed: 140 additions & 135 deletions
Large diffs are not rendered by default.

src/data_struct/detector.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void Detector<T_real>::update_element_quants(Fitting_Routines routine,
186186
// e_cal_ratio defined as 0 , add this value. If we have multiple standards
187187
// then we will normalize this later .
188188
eq_itr.e_cal_ratio += (T_real)1.0 / e_cal;
189+
logI<<"Ecal : "<<eq_itr.e_cal_ratio<<"\n";
189190

190191
}
191192
else
@@ -248,15 +249,15 @@ void Detector<T_real>::avg_element_quants(Fitting_Routines routine,
248249
template<typename T_real>
249250
void Detector<T_real>::generage_avg_quantification_scalers()
250251
{
251-
T_real avg_sr_current = 0.0;
252-
T_real avg_US_IC = 0.0;
253-
T_real avg_US_FM = 0.0;
254-
T_real avg_DS_IC = 0.0;
255-
256-
T_real crnt_cnt = 0.0;
257-
T_real us_cnt = 0.0;
258-
T_real us_fm_cnt = 0.0;
259-
T_real ds_cnt = 0.0;
252+
T_real avg_sr_current = (T_real)0.0;
253+
T_real avg_US_IC = (T_real)0.0;
254+
T_real avg_US_FM = (T_real)0.0;
255+
T_real avg_DS_IC = (T_real)0.0;
256+
257+
T_real crnt_cnt = (T_real)0.0;
258+
T_real us_cnt = (T_real)0.0;
259+
T_real us_fm_cnt = (T_real)0.0;
260+
T_real ds_cnt = (T_real)0.0;
260261

261262
//average quantification scalers
262263
for (const auto& itr : quantification_standards)

src/data_struct/fit_element_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ Fit_Element_Map<T_real>::Fit_Element_Map(std::string name, Element_Info<T_real>*
8181
else
8282
{
8383
std::string str_shell = _full_name.substr(idx);
84-
if (str_shell == "L")
84+
if (str_shell == "M")
8585
{
86-
_shell_type = Electron_Shell::L_SHELL;
86+
_shell_type = Electron_Shell::M_SHELL;
8787
}
8888
else if (str_shell == "L")
8989
{

src/data_struct/fit_parameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void Fit_Parameters<T_real>::from_array_d(const std::vector<double> &arr)
210210
{
211211
if (itr.second.opt_array_index != -1 && itr.second.opt_array_index < arr.size())
212212
{
213-
itr.second.value = arr[itr.second.opt_array_index];
213+
itr.second.value = static_cast<T_real>(arr[itr.second.opt_array_index]);
214214
}
215215
}
216216
}

src/io/file/aps/aps_roi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ DLL_EXPORT bool load_v10_rois(std::string path, std::map<std::string, std::vecto
129129
&& json_spectra.isMember(STR_ICR.c_str())
130130
&& json_spectra.isMember(STR_OCR.c_str()))
131131
{
132-
std::string filename = json_spectra[STR_MAP_ROI_INT_SPEC_FILENAME.c_str()].asString();
132+
std::string filename = json_spectra[STR_MAP_ROI_INT_SPEC_FILENAME.c_str()].asString() + roi_name;
133133
const Json::Value json_spectra_values = json_spectra[STR_SPECTRA.c_str()];
134134
int_specs[filename].resize(json_spectra_values.size());
135135
int_specs[filename].elapsed_livetime(json_spectra[STR_ELT.c_str()].asDouble());

src/io/file/hdf5_io.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,13 @@ class DLL_EXPORT HDF5_IO
16581658
ocr_array.setOnes();
16591659
}
16601660
}
1661+
else
1662+
{
1663+
elt_array.setOnes();
1664+
ert_array.setOnes();
1665+
icr_array.setOnes();
1666+
ocr_array.setOnes();
1667+
}
16611668
err = _read_h5d<T_real2>(energy_dset_id, H5S_ALL, energy_space_id, H5P_DEFAULT, energy_array.data());
16621669
if(err < 0)
16631670
{
@@ -1694,6 +1701,9 @@ class DLL_EXPORT HDF5_IO
16941701
int left_pol_idx = 0;
16951702
int right_pol_idx = 0;
16961703

1704+
int scaler_idx = 0;
1705+
int scaler_cntr = 0;
1706+
int scaler_inc = params_override->polarity_pattern.size();
16971707
for(size_t i = 0; i < dims3[0]; i++)
16981708
{
16991709
offset3[0] = i;
@@ -1774,11 +1784,21 @@ class DLL_EXPORT HDF5_IO
17741784
(*spec_vol)[polarity][idx].input_counts(icr_array[i]);
17751785
(*spec_vol)[polarity][idx].output_counts(ocr_array[i]);
17761786

1777-
energy_map.values(polarity, idx) = energy_array[i];
1778-
i0_map.values(polarity, idx) = i0_array[i];
1787+
1788+
energy_map.values(0, idx) = energy_array[scaler_idx];
1789+
energy_map.values(1, idx) = energy_array[scaler_idx];
1790+
i0_map.values(0, idx) = i0_array[scaler_idx];
1791+
i0_map.values(1, idx) = i0_array[scaler_idx];
17791792

1780-
dtf_map.values(polarity, idx) = dtf_array[i];
1781-
dtp_map.values(polarity, idx) = dtp_array[i];
1793+
scaler_cntr ++;
1794+
if(scaler_cntr > scaler_inc)
1795+
{
1796+
scaler_cntr = 0;
1797+
scaler_idx ++;
1798+
}
1799+
1800+
dtf_map.values(0, idx) = dtf_array[i];
1801+
dtp_map.values(0, idx) = dtp_array[i];
17821802
}
17831803

17841804
scan_info.scaler_maps.push_back(dtf_map);

src/io/file/hl_file_io.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -688,22 +688,24 @@ DLL_EXPORT bool load_and_integrate_spectra_volume(std::string dataset_directory,
688688
size_t spec_size = io::file::NetCDF_IO<T_real>::inst()->load_scalers_line(full_filename, "tetra2_", i, mda_io.get_scan_info(), params_override);
689689
}
690690
}
691-
T_real val = mda_io.get_scan_info()->scaler_avg_value(STR_US_IC);
692-
if(val > (T_real)0.0)
691+
if(params_override != nullptr)
693692
{
694-
params_override->US_IC = val;
695-
}
696-
val = mda_io.get_scan_info()->scaler_avg_value(STR_DS_IC);
697-
if(val > (T_real)0.0)
698-
{
699-
params_override->DS_IC = val;
700-
}
701-
val = mda_io.get_scan_info()->scaler_avg_value(STR_US_FM);
702-
if(val > (T_real)0.0)
703-
{
704-
params_override->US_FM = val;
693+
T_real val = mda_io.get_scan_info()->scaler_avg_value(STR_US_IC);
694+
if(val > (T_real)0.0)
695+
{
696+
params_override->US_IC = val;
697+
}
698+
val = mda_io.get_scan_info()->scaler_avg_value(STR_DS_IC);
699+
if(val > (T_real)0.0)
700+
{
701+
params_override->DS_IC = val;
702+
}
703+
val = mda_io.get_scan_info()->scaler_avg_value(STR_US_FM);
704+
if(val > (T_real)0.0)
705+
{
706+
params_override->US_FM = val;
707+
}
705708
}
706-
707709
}
708710
if (hasNetcdf)
709711
{
@@ -1232,13 +1234,14 @@ DLL_EXPORT bool load_spectra_volume(std::string dataset_directory,
12321234
}
12331235

12341236
// try to load spectra from mda file
1235-
if (false == mda_io.load_spectra_volume(dataset_directory + "mda" + DIR_END_CHAR + dataset_file, detector_num, spectra_volume, (hasNetcdf || hasBnpNetcdf || hasHdf || hasXspress), hasNetcdf))
1237+
auto mda_ret_val = mda_io.load_spectra_volume(dataset_directory + "mda" + DIR_END_CHAR + dataset_file, detector_num, spectra_volume, (hasNetcdf || hasBnpNetcdf || hasHdf || hasXspress), hasNetcdf);
1238+
if (Load_Status::Failed == mda_ret_val)
12361239
{
12371240
scan_type = STR_SCAN_TYPE_2D_MAP;
12381241
logE << "Load spectra " << dataset_directory + "mda" + DIR_END_CHAR + dataset_file << "\n";
12391242
return false;
12401243
}
1241-
else
1244+
else if (Load_Status::Half_need_spectra == mda_ret_val)
12421245
{
12431246
// tetramm is scalers only
12441247
if(hasTetraMM)

src/io/file/mda_io.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ bool MDA_IO<T_real>::load_quantification_scalers(std::string path, data_struct::
233233
//-----------------------------------------------------------------------------
234234

235235
template<typename T_real>
236-
bool MDA_IO<T_real>::load_spectra_volume(std::string path,
236+
Load_Status MDA_IO<T_real>::load_spectra_volume(std::string path,
237237
size_t detector_num,
238238
data_struct::Spectra_Volume<T_real>* vol,
239239
bool hasNetCDF,
@@ -252,22 +252,22 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
252252

253253
if (fptr == nullptr)
254254
{
255-
return false;
255+
return Load_Status::Failed;
256256
}
257257

258258

259259
_mda_file = mda_load(fptr);
260260
std::fclose(fptr);
261261
if (_mda_file == nullptr || vol == nullptr)
262262
{
263-
return false;
263+
return Load_Status::Failed;
264264
}
265265
logI<<"mda info ver:"<<_mda_file->header->version<<" data rank:"<<_mda_file->header->data_rank<<"\n";
266266

267267
if (_mda_file->header->data_rank == 1)
268268
{
269269
logE << "Cannot load mda file data rank == 1" << "\n";
270-
return false;
270+
return Load_Status::Failed;
271271
}
272272

273273
_load_scalers(false,hasNetCDF, subtract_two_cols);
@@ -311,7 +311,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
311311
}
312312

313313
vol->resize_and_zero(rows, cols, 2048);
314-
return true;
314+
return Load_Status::Half_need_spectra;
315315
}
316316
else
317317
{
@@ -322,7 +322,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
322322
{
323323
logE<<"Max detectors saved = "<<_mda_file->scan->sub_scans[0]->number_detectors<< "\n";
324324
unload();
325-
return false;
325+
return Load_Status::Failed;
326326
}
327327

328328
rows = 1;
@@ -347,7 +347,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
347347
//if not then we don't know what is dataset is.
348348
logE << "Don't understand this dataset layout. Can not load it.\n";
349349
unload();
350-
return false;
350+
return Load_Status::Failed;
351351
}
352352
}
353353
}
@@ -392,15 +392,15 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
392392
cols = 1;
393393
}
394394
vol->resize_and_zero(rows, cols, 2048);
395-
return true;
395+
return Load_Status::Half_need_spectra;
396396
}
397397
// TODO: might need to check if is XANES like above
398398
}
399399
if(_mda_file->scan->sub_scans[0]->sub_scans[0]->number_detectors-1 < (int)detector_num)
400400
{
401401
logE<<"Max detectors saved = "<<_mda_file->scan->sub_scans[0]->sub_scans[0]->number_detectors<< "\n";
402402
unload();
403-
return false;
403+
return Load_Status::Failed;
404404
}
405405

406406
if(_mda_file->scan->requested_points == 0 || _mda_file->scan->last_point == 0)
@@ -442,7 +442,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
442442
{
443443
logE<<" No support for data rank "<< _mda_file->header->data_rank <<"\n";
444444
unload();
445-
return false;
445+
return Load_Status::Failed;
446446
}
447447

448448
elt_arr = _scan_info.scaler_values(STR_ELT + std::to_string(detector_num + 1));
@@ -524,10 +524,10 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
524524
{
525525
logE<<"Caught exception loading mda file."<<"\n";
526526
std::cerr << "Exception catched : " << e.what() << "\n";
527-
return false;
527+
return Load_Status::Failed;
528528
}
529529

530-
return true;
530+
return Load_Status::Loaded;
531531
}
532532

533533

0 commit comments

Comments
 (0)