Source code for ewoksfluo.tests.tutorials.test_mosaic_scan_multi_detector
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
from . import assert_results
[docs]
def test_mosaic_scan_multi_detector_without_qt(tmp_path):
assert_results.assert_without_qt(
"mosaic_mesh_multi_detector.ows",
get_inputs(tmp_path),
get_expected_outputs(tmp_path),
get_expected_hdf5(tmp_path),
)
[docs]
def test_mosaic_scan_multi_detector_with_qt(ewoks_orange_canvas, tmp_path):
assert_results.assert_with_qt(
ewoks_orange_canvas,
"mosaic_mesh_multi_detector.ows",
get_inputs(tmp_path),
get_expected_outputs(tmp_path),
get_expected_hdf5(tmp_path),
)
[docs]
def get_inputs(tmp_path) -> List[Dict[str, Any]]:
return [
{
"label": "Mosaic Mesh (multi detector)",
"name": "output_filename",
"value": str(tmp_path / "input.h5"),
},
{
"label": "Concat BLISS scans",
"name": "bliss_scan_uri",
"value": str(tmp_path / "concat.h5::/1.1"),
},
{
"label": "Fit scan (multi detector)",
"name": "output_root_uri",
"value": str(tmp_path / "output.h5::/1.1"),
},
]
[docs]
def get_expected_outputs(tmp_path) -> Dict[str, Dict[str, Any]]:
bliss_scan_uri = str(tmp_path / "concat.h5::/1.1")
output_root_uri = str(tmp_path / "output.h5::/1.1")
return {
"Mosaic Mesh (multi detector)": {
"config": str(tmp_path / "input.h5::/1.1/theory/configuration/data"),
"configs": [str(tmp_path / "input.h5::/1.1/theory/configuration/data")] * 2,
"detector_names": ["mca0", "mca1"],
"detector_normalization_template": "0.1/<instrument/{}/live_time>",
"expo_time": 0.1,
"filenames": [str(tmp_path / "input.h5")],
"monitor_name": "I0",
"monitor_normalization_template": "1000000/<instrument/{}/data>",
"scan_ranges": [(1, 6)],
},
"Pick scans": {
"bliss_scan_uris": [
str(tmp_path / f"input.h5::/{i+1}.1") for i in range(6)
],
},
"Concat BLISS scans": {
"bliss_scan_uri": bliss_scan_uri,
},
"Fit scan (multi detector)": {
"bliss_scan_uri": bliss_scan_uri,
"detector_names": ["mca0", "mca1"],
"output_root_uri": output_root_uri,
"output_root_group": None,
"xrf_results_uris": [
str(tmp_path / "output.h5::/1.1/fit/mca0/results"),
str(tmp_path / "output.h5::/1.1/fit/mca1/results"),
],
},
"Sum Fit Results": {
"xrf_results_uri": str(tmp_path / "output.h5::/1.1/sum/results"),
"bliss_scan_uri": bliss_scan_uri,
"output_root_uri": output_root_uri,
"output_root_group": None,
},
"Normalize": {
"bliss_scan_uri": bliss_scan_uri,
"output_root_uri": output_root_uri,
"output_root_group": None,
"xrf_results_uri": str(tmp_path / "output.h5::/1.1/norm/results"),
},
"Raw Counters": {
"bliss_scan_uri": bliss_scan_uri,
"output_root_uri": output_root_uri,
"output_root_group": None,
"xrf_results_uri": str(tmp_path / "output.h5::/1.1/merge/results"),
},
"Regrid": {
"bliss_scan_uri": bliss_scan_uri,
"output_root_uri": output_root_uri,
"output_root_group": None,
"xrf_results_uri": str(tmp_path / "output.h5::/1.1/regrid/results"),
},
}
[docs]
def get_expected_hdf5(tmp_path) -> Tuple[str, Dict[str, Any]]:
output_path = tmp_path / "output.h5"
expected = {
"@NX_class": "NXroot",
"@extra_attrs": {"default"},
"1.1": {
"@NX_class": "NXentry",
"@extra_attrs": {"default"},
"end_time@shape": (),
"fit": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"mca0": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"derivatives": {
"@NX_class": "NXdata",
"@axes": ["energy"],
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (1024,),
"Ce_L@shape": (1024,),
"Fe_K@shape": (1024,),
"Scatter_Compton000@shape": (1024,),
"Scatter_Peak000@shape": (1024,),
"Si_K@shape": (1024,),
"energy@shape": (1024,),
"energy@units": "keV",
},
"diagnostics": {
"@NX_class": "NXdata",
"@signals": {"nObservations", "nFreeParameters"},
"nFreeParameters@shape": (3000,),
"nObservations@shape": (3000,),
},
"fit": {
"@NX_class": "NXdata",
"@axes": [".", "energy"],
"@signals": {"data", "model", "residuals"},
"data@shape": (3000, 1024),
"energy@shape": (1024,),
"energy@units": "keV",
"model@shape": (3000, 1024),
"residuals@shape": (3000, 1024),
},
"massfractions": {
"@NX_class": "NXdata",
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Si_K@shape": (3000,),
},
"parameters": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
"uncertainties": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
},
"version@shape": (),
},
"mca1": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"derivatives": {
"@NX_class": "NXdata",
"@axes": ["energy"],
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (1024,),
"Ce_L@shape": (1024,),
"Fe_K@shape": (1024,),
"Scatter_Compton000@shape": (1024,),
"Scatter_Peak000@shape": (1024,),
"Si_K@shape": (1024,),
"energy@shape": (1024,),
"energy@units": "keV",
},
"diagnostics": {
"@NX_class": "NXdata",
"@signals": {"nObservations", "nFreeParameters"},
"nFreeParameters@shape": (3000,),
"nObservations@shape": (3000,),
},
"fit": {
"@NX_class": "NXdata",
"@axes": [".", "energy"],
"@signals": {"data", "model", "residuals"},
"data@shape": (3000, 1024),
"energy@shape": (1024,),
"energy@units": "keV",
"model@shape": (3000, 1024),
"residuals@shape": (3000, 1024),
},
"massfractions": {
"@NX_class": "NXdata",
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Si_K@shape": (3000,),
},
"parameters": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
"uncertainties": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Si_K",
"Scatter_Peak000",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
},
"version@shape": (),
},
},
"merge": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"massfractions": {
"@NX_class": "NXdata",
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Si_K@shape": (3000,),
},
"parameters": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
"rawcounters": {
"@NX_class": "NXdata",
"@signals": {
"mca1_roi2",
"mca1_triggers",
"mca0_live_time",
"mca1_events",
"sampy",
"sampz",
"mca1_event_count_rate",
"mca1_roi1",
"mca0_roi1",
"mca1_trigger_live_time",
"mca1_trigger_count_rate",
"mca0_trigger_count_rate",
"I0",
"mca0_event_count_rate",
"mca0_triggers",
"mca1_live_time",
"mca0_roi2",
"mca0_elapsed_time",
"mca1_fractional_dead_time",
"mca1_elapsed_time",
"mca0_events",
"mca0_fractional_dead_time",
"mca0_trigger_live_time",
},
"I0@shape": (3000,),
"mca0_elapsed_time@shape": (3000,),
"mca0_event_count_rate@shape": (3000,),
"mca0_events@shape": (3000,),
"mca0_fractional_dead_time@shape": (3000,),
"mca0_live_time@shape": (3000,),
"mca0_roi1@shape": (3000,),
"mca0_roi2@shape": (3000,),
"mca0_trigger_count_rate@shape": (3000,),
"mca0_trigger_live_time@shape": (3000,),
"mca0_triggers@shape": (3000,),
"mca1_elapsed_time@shape": (3000,),
"mca1_event_count_rate@shape": (3000,),
"mca1_events@shape": (3000,),
"mca1_fractional_dead_time@shape": (3000,),
"mca1_live_time@shape": (3000,),
"mca1_roi1@shape": (3000,),
"mca1_roi2@shape": (3000,),
"mca1_trigger_count_rate@shape": (3000,),
"mca1_trigger_live_time@shape": (3000,),
"mca1_triggers@shape": (3000,),
"sampy@shape": (3000,),
"sampy@units": "um",
"sampz@shape": (3000,),
"sampz@units": "um",
},
"uncertainties": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
},
"version@shape": (),
},
"norm": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"massfractions": {
"@NX_class": "NXdata",
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Si_K@shape": (3000,),
},
"parameters": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
"uncertainties": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
},
"version@shape": (),
},
"regrid": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"coordinates": {
"@NX_class": "NXcollection",
"closest_grid_distance": {
"@NX_class": "NXdata",
"@axes": ["sampy", "sampz"],
"@signals": {"distance"},
"distance@shape": (3000,),
"sampy@shape": (3000,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampz@shape": (3000,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"title@shape": (),
},
"closest_scatter_distance": {
"@NX_class": "NXdata",
"@axes": ["sampy", "sampz"],
"@signals": {"distance"},
"distance@shape": (3456,),
"sampy@shape": (3456,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampz@shape": (3456,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"title@shape": (),
},
"coordinates": {
"@NX_class": "NXdata",
"@axes": ["sampy", "sampz"],
"@signals": {"coordinate_type"},
"coordinate_type@shape": (6456,),
"sampy@shape": (6456,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampz@shape": (6456,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"title@shape": (),
},
"grid_coordinates": {
"@NX_class": "NXdata",
"@axes": ["sampy", "sampz"],
"@signals": {"has_data"},
"has_data@shape": (3456,),
"sampy@shape": (3456,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampz@shape": (3456,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"title@shape": (),
},
"scatter_coordinates": {
"@NX_class": "NXdata",
"@axes": ["sampy", "sampz"],
"@signals": {"indices"},
"indices@shape": (3000,),
"sampy@shape": (3000,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampz@shape": (3000,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"title@shape": (),
},
},
"massfractions": {
"@NX_class": "NXdata",
"@axes": ["sampz", "sampy"],
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (54, 64),
"Ce_L@shape": (54, 64),
"Fe_K@shape": (54, 64),
"Si_K@shape": (54, 64),
"sampy@shape": (64,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampy_indices@shape": (),
"sampz@shape": (54,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"sampz_indices@shape": (),
},
"parameters": {
"@NX_class": "NXdata",
"@axes": ["sampz", "sampy"],
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (54, 64),
"Ce_L@shape": (54, 64),
"Fe_K@shape": (54, 64),
"Scatter_Compton000@shape": (54, 64),
"Scatter_Peak000@shape": (54, 64),
"Si_K@shape": (54, 64),
"sampy@shape": (64,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampy_indices@shape": (),
"sampz@shape": (54,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"sampz_indices@shape": (),
},
"rawcounters": {
"@NX_class": "NXdata",
"@axes": ["sampz", "sampy"],
"@signals": {
"mca1_roi2",
"mca1_triggers",
"mca0_live_time",
"mca1_events",
"mca1_event_count_rate",
"mca1_roi1",
"mca0_roi1",
"mca1_trigger_live_time",
"mca1_trigger_count_rate",
"mca0_trigger_count_rate",
"I0",
"mca0_event_count_rate",
"mca0_triggers",
"mca1_live_time",
"mca0_roi2",
"mca0_elapsed_time",
"mca1_fractional_dead_time",
"mca1_elapsed_time",
"mca0_events",
"mca0_fractional_dead_time",
"mca0_trigger_live_time",
},
"I0@shape": (54, 64),
"mca0_elapsed_time@shape": (54, 64),
"mca0_event_count_rate@shape": (54, 64),
"mca0_events@shape": (54, 64),
"mca0_fractional_dead_time@shape": (54, 64),
"mca0_live_time@shape": (54, 64),
"mca0_roi1@shape": (54, 64),
"mca0_roi2@shape": (54, 64),
"mca0_trigger_count_rate@shape": (54, 64),
"mca0_trigger_live_time@shape": (54, 64),
"mca0_triggers@shape": (54, 64),
"mca1_elapsed_time@shape": (54, 64),
"mca1_event_count_rate@shape": (54, 64),
"mca1_events@shape": (54, 64),
"mca1_fractional_dead_time@shape": (54, 64),
"mca1_live_time@shape": (54, 64),
"mca1_roi1@shape": (54, 64),
"mca1_roi2@shape": (54, 64),
"mca1_trigger_count_rate@shape": (54, 64),
"mca1_trigger_live_time@shape": (54, 64),
"mca1_triggers@shape": (54, 64),
"sampy@shape": (64,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampy_indices@shape": (),
"sampz@shape": (54,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"sampz_indices@shape": (),
},
"title@shape": (),
"uncertainties": {
"@NX_class": "NXdata",
"@axes": ["sampz", "sampy"],
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (54, 64),
"Ce_L@shape": (54, 64),
"Fe_K@shape": (54, 64),
"Scatter_Compton000@shape": (54, 64),
"Scatter_Peak000@shape": (54, 64),
"Si_K@shape": (54, 64),
"sampy@shape": (64,),
"sampy@long_name": "sampy (um)",
"sampy@units": "um",
"sampy_indices@shape": (),
"sampz@shape": (54,),
"sampz@long_name": "sampz (um)",
"sampz@units": "um",
"sampz_indices@shape": (),
},
},
"version@shape": (),
},
"start_time@shape": (),
"sum": {
"@NX_class": "NXprocess",
"@extra_attrs": {"default"},
"configuration": {
"@NX_class": "NXnote",
"data@shape": (),
"date@shape": (),
"type@shape": (),
},
"program@shape": (),
"results": {
"@NX_class": "NXcollection",
"@extra_attrs": {"default"},
"massfractions": {
"@NX_class": "NXdata",
"@signals": {"Ce_L", "Fe_K", "Ca_K", "Si_K"},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Si_K@shape": (3000,),
},
"parameters": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
"uncertainties": {
"@NX_class": "NXdata",
"@signals": {
"Scatter_Compton000",
"Fe_K",
"Ca_K",
"Scatter_Peak000",
"Si_K",
"Ce_L",
},
"Ca_K@shape": (3000,),
"Ce_L@shape": (3000,),
"Fe_K@shape": (3000,),
"Scatter_Compton000@shape": (3000,),
"Scatter_Peak000@shape": (3000,),
"Si_K@shape": (3000,),
},
},
"version@shape": (),
},
},
}
return output_path, expected