Skip to content
Snippets Groups Projects
Commit 8d1719a5 authored by Wout De Nolf's avatar Wout De Nolf
Browse files

split_bliss_scan: waiting for the end of the scan should be optional

parent c57ab07a
No related branches found
No related tags found
1 merge request!178Resolve "Workflow to split multi-XAS scan"
Pipeline #223979 passed
......@@ -6,7 +6,7 @@ from est.core.split_monotonic import split_bliss_scan
class SplitBlissScan(
Task,
input_names=["filename", "scan_number", "monotonic_channel", "out_filename"],
optional_input_names=["retry_timeout", "retry_period"],
optional_input_names=["wait_finished", "retry_timeout", "retry_period"],
output_names=["out_urls"],
):
"""Split a Bliss scan in subscans as determined by a channel which
......@@ -21,6 +21,7 @@ class SplitBlissScan(
:param optional_input_names:
* ``wait_finished``: Wait for the Bliss scan to be complete in HDF5.
* ``retry_timeout``: Timeout of waiting for the Bliss scan to be complete in HDF5.
* ``retry_period``: Check period of waiting for the Bliss scan to be complete in HDF5.
......
......@@ -18,6 +18,7 @@ def split_bliss_scan(
scan_number: int,
monotonic_channel: str,
out_filename: str,
wait_finished: bool = True,
**retry_args,
) -> List[str]:
"""Split a Bliss scan in subscans as determined by a channel which
......@@ -27,12 +28,15 @@ def split_bliss_scan(
:param scan_number: The Bliss scan number.
:param monotonic_channel: HDF5 path relative to the scan group.
:param out_filename: HDF5 file name to save subscans as a result of splitting the Bliss scan.
:param wait_finished: Wait for the Bliss scan to be complete in HDF5.
:param retry_timeout: Timeout of waiting for the Bliss scan to be complete in HDF5.
:param retry_period: Check period of waiting for the Bliss scan to be complete in HDF5.
:returns: HDF5 URL's of the subscans as a result of splitting the Bliss scan.
"""
entry_name = f"{scan_number}.1"
_wait_scan_finished(filename, entry_name, **retry_args)
if wait_finished:
_wait_scan_finished(filename, entry_name, **retry_args)
out_urls = []
with h5py_utils.File(filename) as nxroot_in:
......@@ -41,6 +45,10 @@ def split_bliss_scan(
monotonic_values = nxentry_in[monotonic_channel][()]
monotonic_slices = split_piecewise_monotonic(monotonic_values)
if monotonic_slices and not wait_finished:
# The last subscan might not be complete.
monotonic_slices = monotonic_slices[:-1]
for subscan_number, subscan_slice in enumerate(monotonic_slices, 1):
out_url = _save_subscan(
nxentry_in, scan_number, subscan_number, out_filename, subscan_slice
......
......@@ -90,6 +90,67 @@ def test_split_bliss_scan(tmp_path, split_function):
assert split_data == expected_split_data
@pytest.mark.parametrize("split_function", [split_bliss_scan, split_bliss_scan_task])
def test_split_unfinished_bliss_scan(tmp_path, split_function):
bliss_scan_data = {
"1.1": {
"end_time": "",
"@attr1": "value1",
"dataset1": "value1",
"group1": {
"@attr2": 10,
"dataset2": "value2",
"dataset3": [0, 1, 2, 2, 1, 0],
"dataset4": [0, 1, 2, 5, 4, 3],
"dataset5": 10,
"dataset6": [10, 20],
},
"group2": {
"@attr3": "value3",
">dataset3": "../group1/dataset3",
">dataset4": "/1.1/group1/dataset4",
},
}
}
expected_split_data = {
"1.1": {
"@attr1": "value1",
"dataset1": "value1",
"end_time": "",
"group1": {
"@attr2": 10,
"dataset2": "value2",
"dataset3": [0, 1, 2],
"dataset4": [0, 1, 2],
"dataset5": 10,
},
"group2": {
"@attr3": "value3",
"dataset3": [0, 1, 2],
"dataset4": [0, 1, 2],
},
}
}
in_file = str(tmp_path / "in.h5")
dictdump.dicttonx(bliss_scan_data, in_file, add_nx_class=False)
out_file = str(tmp_path / "out.h5")
out_urls = split_function(
filename=in_file,
scan_number=1,
monotonic_channel="group1/dataset3",
out_filename=out_file,
wait_finished=False,
)
assert out_urls == [f"silx://{out_file}::/1.1"]
split_data = _normalize_h5data(dictdump.nxtodict(out_file, asarray=False))
assert split_data == expected_split_data
@pytest.mark.parametrize("split_function", [split_bliss_scan, split_bliss_scan_task])
def test_split_bliss_scan_timeout(tmp_path, split_function):
bliss_scan_data = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment