The class implements methods for testing of XRF fitting algorithm. Used for testing `_fit_xrf_block` and `fit_xrf_map` functions. See the respective tests for examples
| 646 | |
| 647 | |
| 648 | class _FitXRFMapTesting: |
| 649 | """ |
| 650 | The class implements methods for testing of XRF fitting algorithm. |
| 651 | Used for testing `_fit_xrf_block` and `fit_xrf_map` functions. |
| 652 | See the respective tests for examples |
| 653 | """ |
| 654 | |
| 655 | def __init__(self, *, dataset_params, use_snip, add_pts_before, add_pts_after): |
| 656 | self.use_snip = use_snip |
| 657 | self.add_pts_before = add_pts_before |
| 658 | self.add_pts_after = add_pts_after |
| 659 | |
| 660 | self.fitting_data = DataForFittingTest(**dataset_params) |
| 661 | |
| 662 | # 'spectra' has dimensions (n_spec_points, n_lines), which is correct |
| 663 | self.spectra = self.fitting_data.spectra |
| 664 | self.n_spectrum_points, self.n_lines = self.spectra.shape |
| 665 | |
| 666 | # 'data_tmp' has dimensions (n_spec_points, ny, nx), so it needs to be rearranged |
| 667 | self.data_tmp = self.fitting_data.data_input |
| 668 | |
| 669 | # Add some small background if snip is used |
| 670 | if self.use_snip: |
| 671 | self.data_tmp += 1.0 |
| 672 | |
| 673 | # We want to also add points at the beginning and the end of the spectra |
| 674 | # The original data is filled with random values. Those values should be either |
| 675 | # overwritten by actual spectral data or ignored during fitting. |
| 676 | self.data_input = np.random.random( |
| 677 | size=( |
| 678 | self.data_tmp.shape[1], |
| 679 | self.data_tmp.shape[2], |
| 680 | self.data_tmp.shape[0] + self.add_pts_before + self.add_pts_after, |
| 681 | ) |
| 682 | ) |
| 683 | |
| 684 | # Range of indices of the experimental spectrum that should be used for fitting |
| 685 | # (it contains the spectrum data). The rest of the points should be ignored |
| 686 | ne_start = self.add_pts_before |
| 687 | ne_stop = self.add_pts_before + self.data_tmp.shape[0] |
| 688 | self.data_sel_indices = (ne_start, ne_stop) |
| 689 | |
| 690 | for ny in range(self.data_tmp.shape[1]): |
| 691 | for nx in range(self.data_tmp.shape[2]): |
| 692 | ne_start = self.add_pts_before |
| 693 | ne_stop = self.add_pts_before + self.data_tmp.shape[0] |
| 694 | self.data_input[ny, nx, ne_start:ne_stop] = self.data_tmp[:, ny, nx] |
| 695 | |
| 696 | # The snip parameters are set so that the snip width is about 10 points |
| 697 | self.snip_param = {"e_offset": 0.0, "e_linear": 0.1, "e_quadratic": 0.0, "b_width": 1} |
| 698 | |
| 699 | def verify_fit_output(self, *, data_out, snip_param=None): |
| 700 | assert data_out.shape == ( |
| 701 | self.data_tmp.shape[1], |
| 702 | self.data_tmp.shape[2], |
| 703 | self.n_lines + 4, |
| 704 | ), f"The shape of 'data_out' is incorrect: data_out.shape={data_out.shape}" |
| 705 |
no outgoing calls