Skip to content

Commit e0e4fd1

Browse files
authored
Merge pull request #235 from aglowacki/master
Polar updates
2 parents 364cf2b + a8c3cfd commit e0e4fd1

10 files changed

Lines changed: 166 additions & 61 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ ELSE()
373373
)
374374
ENDIF()
375375

376-
set(HDF5_LIB_LEN 0)
377-
list(LENGTH HDF5_LIBRARIES HDF5_LIB_LEN)
378376

379377
#--------------- start pyxrf-maps lib -----------------
380378
IF (BUILD_WITH_PYBIND11)
@@ -385,24 +383,16 @@ IF (BUILD_WITH_PYBIND11)
385383
pybind11_add_module(pyxrfmaps src/pybindings/main.cpp)
386384
IF (BUILD_WITH_ZMQ)
387385
IF (WIN32)
388-
IF(${HDF5_LIB_LEN} LESS 1)
389-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf libzmq-static ws2_32.lib rpcrt4.lib iphlpapi.lib)
390-
ELSE()
391386
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared libzmq-static ws2_32.lib rpcrt4.lib iphlpapi.lib)
392-
ENDIF()
393387
ELSEIF (UNIX)
394-
IF(${HDF5_LIB_LEN} LESS 1)
395-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf libzmq-static)
396-
ELSE()
397-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared libzmq-static)
398-
ENDIF()
388+
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf libzmq-static)
399389
ENDIF()
400390
ELSE()
401-
IF(${HDF5_LIB_LEN} LESS 1)
402-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf)
403-
ELSE()
404-
target_link_libraries(pyxrfmaps PRIVATE libxrf_fit libxrf_io netCDF::netcdf hdf5::hdf5-shared)
405-
ENDIF()
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()
406396
ENDIF()
407397
ENDIF()
408398

@@ -527,15 +517,13 @@ ELSEIF (UNIX)
527517
ENDIF()
528518
ENDIF()
529519

530-
# Building on theta doesn't need hdf5 and it is empty os need a check
531-
IF(${HDF5_LIB_LEN} LESS 1)
532-
target_link_libraries (libxrf_fit PRIVATE NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
533-
target_link_libraries(libxrf_io PRIVATE libxrf_fit netCDF::netcdf yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
534-
target_link_libraries (xrf_maps PRIVATE libxrf_io libxrf_fit netCDF::netcdf yaml-cpp::yaml-cpp JsonCpp::JsonCpp NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
535-
ELSE()
536-
target_link_libraries(libxrf_fit PRIVATE NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
520+
target_link_libraries(libxrf_fit PRIVATE NLopt::nlopt ${CMAKE_THREAD_LIBS_INIT} )
521+
IF (WIN32)
537522
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} )
538523
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} )
539527
ENDIF()
540528

541529
IF (BUILD_WITH_QT)

src/core/defines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ const std::string STR_LIMITED_LO = "limit_lo";
337337
const std::string STR_LIMITED_HI = "limit_hi";
338338
const std::string STR_FIT = "fit";
339339

340+
const std::string STR_CUSTOM_EL_REGION = "CUSTOM_ELEMENT_REGION";
341+
340342
// ROI
341343
const std::string STR_MAPS_ROIS = "MAPS_ROIS";
342344
const std::string STR_MAP_ROI_NAME = "Name";

src/data_struct/fit_element_map.cpp

Lines changed: 33 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
{
@@ -118,6 +118,33 @@ Fit_Element_Map<T_real>::Fit_Element_Map(std::string name, Element_Info<T_real>*
118118

119119
//-----------------------------------------------------------------------------
120120

121+
template<typename T_real>
122+
Fit_Element_Map<T_real>::Fit_Element_Map(std::string name, T_real center, T_real width_multi)
123+
{
124+
_full_name = name;
125+
126+
_element_info = nullptr;
127+
128+
_pileup_element_info = nullptr;
129+
130+
_width_multi = width_multi;
131+
132+
_center = center;
133+
134+
_width = int( std::sqrt( std::pow(ENERGY_RES_OFFSET, 2) + std::pow( (_center * ENERGY_RES_SQRT), 2) ) );
135+
_width /= 2000.0;
136+
_width *= _width_multi;
137+
138+
size_t num_ratios = 1;
139+
_energy_ratios.push_back(Element_Energy_Ratio<T_real>(_center, 1.0, 0.0, Element_Param_Type::Ka1_Line));
140+
for(size_t i=0; i<num_ratios; i++)
141+
{
142+
_energy_ratio_custom_multipliers.push_back(1.0);
143+
}
144+
}
145+
146+
//-----------------------------------------------------------------------------
147+
121148
template<typename T_real>
122149
Fit_Element_Map<T_real>::~Fit_Element_Map()
123150
{
@@ -135,6 +162,10 @@ void Fit_Element_Map<T_real>::init_energy_ratio_for_detector_element(const Eleme
135162

136163
if(_element_info == nullptr)
137164
{
165+
_width = int( std::sqrt( std::pow(ENERGY_RES_OFFSET, 2) + std::pow( (_center * ENERGY_RES_SQRT), 2) ) );
166+
_width /= 2000.0;
167+
_width *= _width_multi;
168+
138169
//Don't log because we can have non elements such as Compton that doesn't have element properties
139170
//logE<<"Element info was not properly loaded. Variable is null! Can't initialize energy ratios!\n";
140171
return;

src/data_struct/fit_element_map.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class DLL_EXPORT Fit_Element_Map
159159
public:
160160
Fit_Element_Map(std::string name, Element_Info<T_real>* element_info);
161161

162+
Fit_Element_Map(std::string name, T_real center, T_real width_multi);
163+
162164
~Fit_Element_Map();
163165

164166
const T_real& center() const { return _center; }
@@ -194,6 +196,8 @@ class DLL_EXPORT Fit_Element_Map
194196
std::unordered_map<std::string, T_real> generate_roi_centers_per_shell();
195197

196198
bool check_binding_energy(T_real incident_energy, size_t energy_ratio_idx) const;
199+
200+
bool has_element_info() { return !(_element_info==nullptr);}
197201
protected:
198202

199203
void generate_energy_ratio(T_real energy, T_real ratio, Element_Param_Type et, const Element_Info<T_real> * const detector_element);

src/io/file/aps/aps_fit_params_import.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,31 @@ DLL_EXPORT bool load_parameters_override(std::string path, Params_Override<T_rea
468468
fit_map->set_width_multi(factor);
469469
}
470470
}
471+
else if (tag == STR_CUSTOM_EL_REGION)
472+
{
473+
std::string element_symb;
474+
std::string energy_value;
475+
std::string width_value;
476+
477+
std::getline(strstream, element_symb, ',');
478+
element_symb.erase(std::remove_if(element_symb.begin(), element_symb.end(), ::isspace), element_symb.end());
479+
480+
T_real center = 1.0;
481+
std::getline(strstream, energy_value, ',');
482+
center = parse_input_real<T_real>(energy_value);
483+
484+
T_real width_multi = 1.0;
485+
std::getline(strstream, width_value, ',');
486+
width_multi = parse_input_real<T_real>(width_value);
487+
488+
Fit_Element_Map<T_real>* fit_map;
489+
if (params_override->elements_to_fit.count(element_symb) < 1)
490+
{
491+
492+
fit_map = new Fit_Element_Map<T_real>(element_symb, center, width_multi);
493+
params_override->elements_to_fit[element_symb] = fit_map;
494+
}
495+
}
471496
else if (tag == "BRANCHING_FAMILY_ADJUSTMENT_L" || tag == "BRANCHING_RATIO_ADJUSTMENT_L" || tag == "BRANCHING_RATIO_ADJUSTMENT_K" || tag == "BRANCHING_RATIO_ADJUSTMENT_M")
472497
{
473498
unsigned int cnt = 0;
@@ -954,12 +979,24 @@ DLL_EXPORT bool save_parameters_override(std::string path, Params_Override<T_rea
954979
for (const auto& itr : params_override->elements_to_fit)
955980
{
956981
// if not pileup
957-
if (itr.second->pileup_element() == nullptr && (itr.first != "COHERENT_SCT_AMPLITUDE" || itr.first != "COMPTON_AMPLITUDE"))
982+
if (itr.second->pileup_element() == nullptr && itr.second->has_element_info())
958983
{
959984
out_stream << itr.first << " , ";
960985
}
961986
}
962987
out_stream << "\n";
988+
for (const auto& itr : params_override->elements_to_fit)
989+
{
990+
// if not pileup
991+
if (itr.second->pileup_element() == nullptr && false == itr.second->has_element_info())
992+
{
993+
if(itr.first == STR_COHERENT_SCT_AMPLITUDE || itr.first == STR_COMPTON_AMPLITUDE)
994+
{
995+
continue;
996+
}
997+
out_stream << STR_CUSTOM_EL_REGION<<": "<< itr.first << "," << itr.second->center() << "," << itr.second->width_multi() << "\n";
998+
}
999+
}
9631000
out_stream << " list the element combinations you want to fit for pileup, e.g., Si_Si, Si_Si_Si, Si_Cl, etc\n";
9641001
out_stream << "ELEMENTS_WITH_PILEUP: ";
9651002
for (const auto& itr : params_override->elements_to_fit)

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)

0 commit comments

Comments
 (0)