ewoksdata 2.0.1__tar.gz → 2.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ewoksdata-2.0.1/src/ewoksdata.egg-info → ewoksdata-2.0.3}/PKG-INFO +1 -1
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/pyproject.toml +1 -1
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/bliss.py +65 -10
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/test_data_bliss.py +6 -2
- {ewoksdata-2.0.1 → ewoksdata-2.0.3/src/ewoksdata.egg-info}/PKG-INFO +1 -1
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/LICENSE.md +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/README.md +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/setup.cfg +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/blissdata/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/blissdata/blissdatav0.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/blissdata/blissdatav1.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/blissdata/blissdatav2.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/contextiterator.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/hdf5/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/hdf5/config.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/hdf5/dataset_writer.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/hdf5/types.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/nexus.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/url.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/data/utils.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/conftest.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/data/__init__.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/data/bliss_scans.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/test_contextiterator.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/test_data_hdf5.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/test_data_nexus.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata/tests/test_dataset_writer.py +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata.egg-info/SOURCES.txt +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata.egg-info/dependency_links.txt +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata.egg-info/requires.txt +0 -0
- {ewoksdata-2.0.1 → ewoksdata-2.0.3}/src/ewoksdata.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ewoksdata"
|
|
7
|
-
version = "2.0.
|
|
7
|
+
version = "2.0.3"
|
|
8
8
|
authors = [{ name = "ESRF", email = "dau-pydev@esrf.fr" }]
|
|
9
9
|
description = "Ewoks tasks for data access"
|
|
10
10
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
@@ -3,7 +3,9 @@ or from memory (Redis or device servers).
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
6
7
|
import sys
|
|
8
|
+
import time
|
|
7
9
|
from numbers import Integral
|
|
8
10
|
from numbers import Number
|
|
9
11
|
from typing import Any
|
|
@@ -39,21 +41,49 @@ logger = logging.getLogger(__name__)
|
|
|
39
41
|
|
|
40
42
|
def get_data(
|
|
41
43
|
data: Union[str, DataUrl, ArrayLike, Number],
|
|
44
|
+
retry_timeout: Optional[float] = None,
|
|
45
|
+
retry_period: Optional[float] = None,
|
|
42
46
|
**hdf5_options: Any,
|
|
43
47
|
) -> Union[numpy.ndarray, Number, Sequence]:
|
|
44
48
|
"""
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
Retrieve numerical data from a data source and return it as a NumPy array or scalar.
|
|
50
|
+
|
|
51
|
+
This function accepts various data representations, including data URLs,
|
|
52
|
+
array-like objects, and scalar numbers. The data source may not be
|
|
53
|
+
immediately available so a retry mechanism is used.
|
|
54
|
+
|
|
55
|
+
:param data: The input data source. May be:
|
|
56
|
+
- A string or :class:`DataUrl` referencing a dataset (e.g., HDF5),
|
|
57
|
+
- An array-like object convertible to a NumPy array,
|
|
58
|
+
- A scalar numerical value.
|
|
59
|
+
:param retry_timeout: Maximum time in seconds to wait for the data to become
|
|
60
|
+
available. If ``None`` (default), no timeout is applied.
|
|
61
|
+
:param retry_period: Interval in seconds between availability checks when
|
|
62
|
+
retrying. If ``None`` (default), a period of 0.1 seconds is used.
|
|
63
|
+
:param hdf5_options: Additional keyword arguments forwarded to
|
|
64
|
+
:class:`silx.io.h5py_utils.File` when opening HDF5 resources.
|
|
65
|
+
|
|
66
|
+
:returns: The resolved data. Array-like inputs are returned as NumPy arrays,
|
|
67
|
+
while scalar inputs are returned as numbers.
|
|
68
|
+
|
|
69
|
+
:raises TimeoutError: If the data does not become available within ``retry_timeout``.
|
|
70
|
+
:raises ValueError: If the input type is unsupported or the data cannot be resolved.
|
|
50
71
|
"""
|
|
51
72
|
if isinstance(data, (str, DataUrl)):
|
|
52
73
|
data_url = url.as_dataurl(data)
|
|
53
74
|
filename, h5path, idx = url.h5dataset_url_parse(data_url)
|
|
54
75
|
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
_wait_for_file(filename, retry_timeout=retry_timeout, retry_period=retry_period)
|
|
77
|
+
|
|
78
|
+
if _is_hdf5_filename(filename):
|
|
79
|
+
return _get_hdf5_data(
|
|
80
|
+
filename,
|
|
81
|
+
h5path,
|
|
82
|
+
idx=idx,
|
|
83
|
+
retry_timeout=retry_timeout,
|
|
84
|
+
retry_period=retry_period,
|
|
85
|
+
**hdf5_options,
|
|
86
|
+
)
|
|
57
87
|
|
|
58
88
|
if not data_url.scheme():
|
|
59
89
|
for scheme in ("fabio", "silx"):
|
|
@@ -73,16 +103,41 @@ def get_data(
|
|
|
73
103
|
raise TypeError(f"Unsupported data type: {type(data)!r}")
|
|
74
104
|
|
|
75
105
|
|
|
106
|
+
def _wait_for_file(
|
|
107
|
+
filename: str,
|
|
108
|
+
retry_timeout: Optional[float] = None,
|
|
109
|
+
retry_period: Optional[float] = None,
|
|
110
|
+
**_,
|
|
111
|
+
) -> None:
|
|
112
|
+
if retry_period is None:
|
|
113
|
+
retry_period = 0.1
|
|
114
|
+
t0 = time.time()
|
|
115
|
+
while True:
|
|
116
|
+
if os.path.exists(filename):
|
|
117
|
+
return
|
|
118
|
+
if retry_timeout is not None:
|
|
119
|
+
if (time.time() - t0) > retry_timeout:
|
|
120
|
+
raise TimeoutError(
|
|
121
|
+
f"File {filename} is not created within {retry_timeout} sec"
|
|
122
|
+
)
|
|
123
|
+
time.sleep(retry_period)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _is_hdf5_filename(filename: str) -> bool:
|
|
127
|
+
_, ext = os.path.splitext(filename)
|
|
128
|
+
return ext in (".h5", ".hdf5", ".nx", ".nxs", ".nexus")
|
|
129
|
+
|
|
130
|
+
|
|
76
131
|
def get_image(
|
|
77
132
|
data: Union[str, DataUrl, ArrayLike, Number], **hdf5_options: Any
|
|
78
133
|
) -> numpy.ndarray:
|
|
79
134
|
"""
|
|
80
135
|
Return a NumPy array or a scalar from *data*.
|
|
81
136
|
|
|
137
|
+
Retry options, such as `retry_timeout` and `retry_period` are forwarded to the internal HDF5 data reader.
|
|
138
|
+
|
|
82
139
|
:param data: Either a data-URL, an array-like object or a scalar number.
|
|
83
|
-
:param
|
|
84
|
-
:param retry_period: Interval between retries.
|
|
85
|
-
:param **hdf5_options: Additional options forwarded to :class:`silx.io.h5py_utils.File`.
|
|
140
|
+
:param hdf5_options: Additional options forwarded to :class:`silx.io.h5py_utils.File`.
|
|
86
141
|
:return: A 2-D image.
|
|
87
142
|
"""
|
|
88
143
|
data = get_data(data, **hdf5_options)
|
|
@@ -28,8 +28,12 @@ def test_get_data_hdf5(tmpdir):
|
|
|
28
28
|
numpy.testing.assert_array_equal(img1, img3)
|
|
29
29
|
|
|
30
30
|
filename_non_existing = str(tmpdir / "data_non_existing.h5")
|
|
31
|
-
with pytest.raises(
|
|
32
|
-
_ = bliss.get_data(f"{filename_non_existing}?path=/img")
|
|
31
|
+
with pytest.raises(TimeoutError):
|
|
32
|
+
_ = bliss.get_data(f"{filename_non_existing}?path=/img", retry_timeout=0)
|
|
33
|
+
|
|
34
|
+
filename_non_existing = str(tmpdir / "data_non_existing.edf")
|
|
35
|
+
with pytest.raises(TimeoutError):
|
|
36
|
+
_ = bliss.get_data(filename_non_existing, retry_timeout=0)
|
|
33
37
|
|
|
34
38
|
|
|
35
39
|
@pytest.mark.parametrize("lima_names", [(), ("p3",), ("p3", "p4")])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|