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

Function _compute_roi

pyxrf/core/map_processing.py:913–981  ·  view source on GitHub ↗

Compute intensity for ROIs (energy bands) in XRF datasets. The function is intended to be called using `map_blocks` function for parallel processing using Dask distributed package. Parameters ---------- data : ndarray block of an XRF dataset. Shape=(ny, nx, ne).

(data, data_sel_indices, roi_bands, snip_param, use_snip)

Source from the content-addressed store, hash-verified

911
912
913def _compute_roi(data, data_sel_indices, roi_bands, snip_param, use_snip):
914 """
915 Compute intensity for ROIs (energy bands) in XRF datasets. The function is intended to be
916 called using `map_blocks` function for parallel processing using Dask distributed
917 package.
918
919 Parameters
920 ----------
921 data : ndarray
922 block of an XRF dataset. Shape=(ny, nx, ne).
923 data_sel_indices: tuple
924 tuple `(n_start, n_end)` which defines the indices along axis 2 of `data` array
925 that are used for fitting. Note that `ne` (in `data`). Indexes
926 `n_start .. n_end - 1` will be selected from each pixel.
927 roi_bands: list(tuple)
928 list of ROI bands, elements are tuples `(left_val, right_val)`, where `left_val` and
929 `right_val` are energy values in keV that define the ROI band. If `left_val >= right_val`,
930 then the width of the band is considered zero and and ROI will be zero.
931 snip_param: dict
932 Dictionary of parameters forwarded to 'snip' method for background removal.
933 Keys: `e_offset`, `e_linear`, `e_quadratic` (parameters of the energy axis approximation),
934 `b_width` (width of the window that defines resolution of the snip algorithm).
935 The values of `e_offset` and `e_linear` are used to compute indices for ROIs, so they
936 need to be always provided.
937 use_snip: bool, optional
938 enable/disable background removal using snip algorithm
939
940 Returns
941 -------
942 data_out: ndarray
943 array with ROI counts. Shape: `(ny, nx, len(roi_bands))`. For each pixel
944 the output data contains `len(roi_bands)` values that represent area under
945 the experimental spectrum inside the band.
946 """
947 spec = data
948 spec_sel = spec[:, :, data_sel_indices[0] : data_sel_indices[1]]
949
950 e_offset = snip_param["e_offset"]
951 e_linear = snip_param["e_linear"]
952 e_quadratic = snip_param["e_quadratic"]
953
954 if use_snip:
955 bg_sel = np.apply_along_axis(
956 snip_method_numba, 2, spec_sel, e_offset, e_linear, e_quadratic, width=snip_param["b_width"]
957 )
958 y = spec_sel - bg_sel
959
960 else:
961 y = spec_sel
962
963 # The number of available spectrum points
964 ny, nx, n_pts = y.shape
965 n_sel_start = data_sel_indices[0]
966
967 def _energy_to_index(energy):
968 # 'y' is truncated array, and energy axis is aligned with the full array
969 n_index = int(round((energy - e_offset) / e_linear)) - n_sel_start
970 n_index = int(np.clip(n_index, a_min=0, a_max=n_pts - 1))

Callers 1

test_compute_roiFunction · 0.90

Calls 1

_energy_to_indexFunction · 0.85

Tested by 1

test_compute_roiFunction · 0.72