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

Function test_compute_roi

pyxrf/core/tests/test_map_processing.py:1022–1072  ·  view source on GitHub ↗

Basic functionality of `_compute_roi` function

(dataset_params, add_pts_before, add_pts_after, use_snip)

Source from the content-addressed store, hash-verified

1020@pytest.mark.parametrize("use_snip", [False, True])
1021# fmt: on
1022def test_compute_roi(dataset_params, add_pts_before, add_pts_after, use_snip):
1023 """Basic functionality of `_compute_roi` function"""
1024
1025 ft = _FitXRFMapTesting(
1026 dataset_params=dataset_params,
1027 use_snip=use_snip,
1028 add_pts_before=add_pts_before,
1029 add_pts_after=add_pts_after,
1030 )
1031
1032 n_pts = ft.n_spectrum_points
1033 energy_min, energy_max = 3.1, 12.2 # Energy range for the 'selected' data, keV
1034 energy_step = (energy_max - energy_min) / (n_pts - 1)
1035
1036 # 'e_offset' - the offset for the 0th element of the array, not the selected range
1037 snip_param = {
1038 "e_offset": energy_min - energy_step * add_pts_before,
1039 "e_linear": energy_step,
1040 "e_quadratic": 0,
1041 "b_width": 2.0,
1042 }
1043
1044 roi_dict = {
1045 "roi-1": (2.5, 3.5), # Outside the range
1046 "roi-2": (3.5, 4.8),
1047 "roi-3": (5.2, 7.4),
1048 "roi-4": (6.0, 6.0), # No data points
1049 "roi-5": (6.0, 5.5), # No data points
1050 "roi-6": (10.1, 15.0), # Outside the range
1051 }
1052
1053 roi_bands = [_ for _ in roi_dict.values()]
1054
1055 # We don't use autogenerated 'ft.snip_param', because we want to use specific
1056 # values to make sure that computations are done correctly.
1057
1058 data_out = _compute_roi(
1059 ft.data_input,
1060 data_sel_indices=ft.data_sel_indices,
1061 roi_bands=roi_bands,
1062 snip_param=snip_param,
1063 use_snip=use_snip,
1064 )
1065
1066 roi_keys = list(roi_dict.keys())
1067 assert data_out.shape == (*ft.data_input.shape[0:2], len(roi_keys)), "Output data has unexpected shape"
1068
1069 # Convert data from numpy array to dictionary
1070 data_out = {roi_keys[_]: data_out[:, :, _] for _ in range(len(roi_keys))}
1071 # Verify the dictionary
1072 ft.verify_roi_output(data_out=data_out, roi_dict=roi_dict, snip_param=snip_param)
1073
1074
1075@pytest.mark.usefixtures("_start_dask_client")

Callers

nothing calls this directly

Calls 5

_compute_roiFunction · 0.90
_FitXRFMapTestingClass · 0.85
valuesMethod · 0.80
keysMethod · 0.80
verify_roi_outputMethod · 0.80

Tested by

no test coverage detected