MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / verify_roi_output

Method verify_roi_output

pyxrf/core/tests/test_map_processing.py:764–824  ·  view source on GitHub ↗

Verify computated ROI. Computation of ROI is repeated in this function. Call with the same value of `snip_param` as the one sent to ROI computing function. It may be different from autogenerated `self.snip_param`. Parameters ---------- data_out: dict

(self, *, data_out, roi_dict, snip_param=None)

Source from the content-addressed store, hash-verified

762 )
763
764 def verify_roi_output(self, *, data_out, roi_dict, snip_param=None):
765 """
766 Verify computated ROI. Computation of ROI is repeated in this function.
767 Call with the same value of `snip_param` as the one sent to ROI computing function.
768 It may be different from autogenerated `self.snip_param`.
769
770 Parameters
771 ----------
772 data_out: dict
773 Dictionary: key - emission line, value - 2D array with ROI values
774 roi_dict: dict
775 Dictionary: key - emission line, value - tuple (left_val, right_val)
776 Energy values are in keV.
777 snip_param: dict
778 Parameters for SNIP algorithm for background subtraction. See `self.snip_param`
779 defined in the constructor for the example. The values are used for subtracting
780 baseline and for finding ranges of indices to define bands.
781 """
782
783 e_offset = snip_param["e_offset"]
784 e_linear = snip_param["e_linear"]
785
786 # Already truncated data (containing only selected region
787 _data = np.moveaxis(self.data_tmp, 0, 2)
788
789 if self.use_snip:
790 bg_sel = np.zeros(shape=_data.shape)
791 for ny in range(bg_sel.shape[0]):
792 for nx in range(bg_sel.shape[1]):
793 bg = snip_method_numba(
794 _data[ny, nx, :],
795 snip_param["e_offset"],
796 snip_param["e_linear"],
797 snip_param["e_quadratic"],
798 width=snip_param["b_width"],
799 )
800 bg_sel[ny, nx, :] = bg
801 _data = _data - bg_sel
802
803 data_expected = {}
804 for eline in roi_dict.keys():
805 vleft, vright = roi_dict[eline]
806 n_left = int(round((vleft - e_offset) / e_linear)) - self.add_pts_before
807 n_right = int(round((vright - e_offset) / e_linear)) - self.add_pts_before
808 n_left = int(np.clip(n_left, a_min=0, a_max=_data.shape[2] - 1))
809 n_right = int(np.clip(n_right, a_min=0, a_max=_data.shape[2] - 1))
810 if n_right > n_left:
811 data_expected[eline] = np.sum(_data[:, :, n_left:n_right], axis=2)
812 else:
813 data_expected[eline] = np.zeros(shape=_data.shape[0:2])
814
815 assert list(data_out.keys()) == list(
816 data_expected.keys()
817 ), "The list of output data keys is different from expected"
818
819 for key in data_out.keys():
820 npt.assert_array_almost_equal(
821 data_out[key],

Callers 3

test_compute_roiFunction · 0.80

Calls 2

snip_method_numbaFunction · 0.90
keysMethod · 0.80

Tested by

no test coverage detected