ewoksdata 0.4.3__tar.gz → 0.5.0__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.
Files changed (41) hide show
  1. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/PKG-INFO +2 -9
  2. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/README.md +0 -8
  3. ewoksdata-0.5.0/pyproject.toml +5 -0
  4. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/setup.cfg +1 -0
  5. ewoksdata-0.5.0/src/ewoksdata/__init__.py +1 -0
  6. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/bliss.py +3 -0
  7. ewoksdata-0.5.0/src/ewoksdata/data/contextiterator.py +35 -0
  8. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/hdf5/dataset_writer.py +41 -0
  9. ewoksdata-0.5.0/src/ewoksdata/tests/conftest.py +29 -0
  10. ewoksdata-0.5.0/src/ewoksdata/tests/test_data_bliss.py +66 -0
  11. ewoksdata-0.5.0/src/ewoksdata/tests/test_data_hdf5.py +14 -0
  12. ewoksdata-0.5.0/src/ewoksdata/tests/test_dataset_writer.py +89 -0
  13. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata.egg-info/PKG-INFO +2 -9
  14. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata.egg-info/SOURCES.txt +1 -0
  15. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata.egg-info/requires.txt +1 -0
  16. ewoksdata-0.4.3/pyproject.toml +0 -6
  17. ewoksdata-0.4.3/src/ewoksdata/__init__.py +0 -1
  18. ewoksdata-0.4.3/src/ewoksdata/tests/conftest.py +0 -23
  19. ewoksdata-0.4.3/src/ewoksdata/tests/test_data_bliss.py +0 -49
  20. ewoksdata-0.4.3/src/ewoksdata/tests/test_data_hdf5.py +0 -13
  21. ewoksdata-0.4.3/src/ewoksdata/tests/test_dataset_writer.py +0 -113
  22. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/LICENSE.md +0 -0
  23. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/setup.py +0 -0
  24. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/__init__.py +0 -0
  25. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/blissdata/__init__.py +0 -0
  26. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/blissdata/blissdatav0.py +0 -0
  27. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/blissdata/blissdatav1.py +0 -0
  28. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/blissdata/blissdatavid31.py +0 -0
  29. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/blissdata/exceptions.py +0 -0
  30. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/hdf5/__init__.py +0 -0
  31. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/hdf5/config.py +0 -0
  32. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/hdf5/types.py +0 -0
  33. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/nexus.py +0 -0
  34. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/url.py +0 -0
  35. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/data/utils.py +0 -0
  36. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/tests/__init__.py +0 -0
  37. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/tests/data/__init__.py +0 -0
  38. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/tests/data/bliss_scans.py +0 -0
  39. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata/tests/test_data_nexus.py +0 -0
  40. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata.egg-info/dependency_links.txt +0 -0
  41. {ewoksdata-0.4.3 → ewoksdata-0.5.0}/src/ewoksdata.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ewoksdata
3
- Version: 0.4.3
3
+ Version: 0.5.0
4
4
  Summary: Ewoks tasks for data access
5
5
  Home-page: https://gitlab.esrf.fr/workflow/ewoksapps/ewoksdata/
6
6
  Author: ESRF
@@ -36,19 +36,12 @@ Requires-Dist: blissdata[tango]; extra == "doc"
36
36
  Requires-Dist: pytest>=7; extra == "doc"
37
37
  Requires-Dist: sphinx>=4.5; extra == "doc"
38
38
  Requires-Dist: sphinx-autodoc-typehints>=1.16; extra == "doc"
39
+ Requires-Dist: pydata-sphinx-theme<0.15; extra == "doc"
39
40
 
40
41
  # ewoksdata
41
42
 
42
43
  Data access utilities for [ewoks](https://ewoks.readthedocs.io/) workflows.
43
44
 
44
- ## Installation
45
-
46
- Until `silx>1.0.0` is released:
47
-
48
- ```bash
49
- python -m pip install git+https://github.com/silx-kit/silx.git
50
- ```
51
-
52
45
  ## Documentation
53
46
 
54
47
  https://ewoksdata.readthedocs.io
@@ -2,14 +2,6 @@
2
2
 
3
3
  Data access utilities for [ewoks](https://ewoks.readthedocs.io/) workflows.
4
4
 
5
- ## Installation
6
-
7
- Until `silx>1.0.0` is released:
8
-
9
- ```bash
10
- python -m pip install git+https://github.com/silx-kit/silx.git
11
- ```
12
-
13
5
  ## Documentation
14
6
 
15
7
  https://ewoksdata.readthedocs.io
@@ -0,0 +1,5 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=46.4"
4
+ ]
5
+ build-backend = "setuptools.build_meta"
@@ -47,6 +47,7 @@ doc =
47
47
  %(test)s
48
48
  sphinx >=4.5
49
49
  sphinx-autodoc-typehints >=1.16
50
+ pydata-sphinx-theme < 0.15
50
51
 
51
52
  [flake8]
52
53
  ignore = E501, E203, W503
@@ -0,0 +1 @@
1
+ __version__ = "0.5.0"
@@ -15,6 +15,7 @@ from .blissdata import iter_bliss_scan_data_from_memory # noqa F401
15
15
  from .blissdata import last_lima_image # noqa F401
16
16
  from .blissdata import dynamic_hdf5
17
17
 
18
+ from .contextiterator import contextiterator
18
19
  from . import hdf5
19
20
  from . import nexus
20
21
  from . import url
@@ -59,6 +60,7 @@ def _get_hdf5_data(filename: str, h5path: str, idx=None, **options) -> numpy.nda
59
60
  return dset[idx]
60
61
 
61
62
 
63
+ @contextiterator
62
64
  def iter_bliss_scan_data(
63
65
  filename: str,
64
66
  scan_nr: Integral,
@@ -96,6 +98,7 @@ def iter_bliss_scan_data(
96
98
  yield dict(zip(names, values))
97
99
 
98
100
 
101
+ @contextiterator
99
102
  def iter_bliss_data(
100
103
  filename: str,
101
104
  scan_nr: Integral,
@@ -0,0 +1,35 @@
1
+ from collections.abc import Generator
2
+
3
+
4
+ class ContextIterator(Generator):
5
+ def __init__(self, it):
6
+ self._it = it
7
+
8
+ def __iter__(self):
9
+ return self
10
+
11
+ def __next__(self):
12
+ return next(self._it)
13
+
14
+ def __enter__(self):
15
+ return self
16
+
17
+ def __exit__(self, *_):
18
+ self._it.close()
19
+
20
+ def send(self):
21
+ return next(self._it)
22
+
23
+ def throw(self):
24
+ raise StopIteration
25
+
26
+
27
+ def contextiterator(iterator):
28
+ """Decorator that allows to use an iterator as a context manager.
29
+ This ensures that the iterator is closed when exiting the context manager.
30
+ """
31
+
32
+ def wrapper(*args, **kw):
33
+ return ContextIterator(iterator(*args, **kw))
34
+
35
+ return wrapper
@@ -55,6 +55,21 @@ class _DatasetWriterBase:
55
55
 
56
56
 
57
57
  class DatasetWriter(_DatasetWriterBase):
58
+ """Append arrays of the same shape to a new HDF5 dataset in a sequential manner.
59
+
60
+ .. code-block::python
61
+
62
+ with DatasetWriter(parent, "mydataset") as writer:
63
+ writer.add_point([1,2,3])
64
+ writer.add_points([[4,5,6], [7,8,9]])
65
+
66
+ This is equivalent to
67
+
68
+ .. code-block::python
69
+
70
+ parent["mydataset"] = [[1,2,3], [4,5,6], [7,8,9]]
71
+ """
72
+
58
73
  def __init__(
59
74
  self,
60
75
  parent: h5py.Group,
@@ -103,6 +118,7 @@ class DatasetWriter(_DatasetWriterBase):
103
118
  return self._npoints_added
104
119
 
105
120
  def add_point(self, data: ArrayLike) -> bool:
121
+ """Append one array to the dataset."""
106
122
  if self._dataset is None:
107
123
  self._dataset = self._create_dataset(data)
108
124
  self._buffer.append(data)
@@ -110,6 +126,7 @@ class DatasetWriter(_DatasetWriterBase):
110
126
  return self.flush_buffer(align=True)
111
127
 
112
128
  def add_points(self, data: ArrayLike) -> bool:
129
+ """Append several arrays at once to the dataset."""
113
130
  if self._dataset is None:
114
131
  self._dataset = self._create_dataset(data[0])
115
132
  self._buffer.extend(data)
@@ -147,6 +164,27 @@ class DatasetWriter(_DatasetWriterBase):
147
164
 
148
165
 
149
166
  class StackDatasetWriter(_DatasetWriterBase):
167
+ """Append arrays of the same shape to each item of a new HDF5 dataset
168
+ in a sequential manner per item. So each item of the HDF5 dataset is a
169
+ stack to which we can append data in a sequential manner.
170
+
171
+ .. code-block::python
172
+
173
+ with DatasetWriter(parent, "mydataset") as writer:
174
+ writer.add_point([1,2,3], 0)
175
+ writer.add_point([10,11,12], 1)
176
+ writer.add_points([[4,5,6], [7,8,9]], 0)
177
+ writer.add_points([[13,14,15], [16,17,18]], 1)
178
+
179
+ This is equivalent to
180
+
181
+ .. code-block::python
182
+
183
+ stack0 = [[1,2,3], [4,5,6], [7,8,9]]
184
+ stack1 = [[10,11,12], [13,14,15], [16,17,18]]
185
+ parent["mydataset"] = [stack0, stack1]
186
+ """
187
+
150
188
  def __init__(
151
189
  self,
152
190
  parent: h5py.Group,
@@ -194,12 +232,14 @@ class StackDatasetWriter(_DatasetWriterBase):
194
232
  return dset
195
233
 
196
234
  def _get_buffer(self, stack_index: int) -> List[ArrayLike]:
235
+ # Add stack buffers when needed
197
236
  for _ in range(max(stack_index - len(self._buffers) + 1, 0)):
198
237
  self._buffers.append(list())
199
238
  self._nflushed = numpy.append(self._nflushed, 0)
200
239
  return self._buffers[stack_index]
201
240
 
202
241
  def add_point(self, data: ArrayLike, stack_index: int) -> bool:
242
+ """Append one array to one stack of the dataset."""
203
243
  if self._dataset is None:
204
244
  self._dataset = self._create_dataset(data, stack_index)
205
245
  buffer = self._get_buffer(stack_index)
@@ -207,6 +247,7 @@ class StackDatasetWriter(_DatasetWriterBase):
207
247
  return self.flush_buffer(align=True)
208
248
 
209
249
  def add_points(self, data: ArrayLike, stack_index: int) -> bool:
250
+ """Append several arrays at once to one stack of the dataset."""
210
251
  if self._dataset is None:
211
252
  self._dataset = self._create_dataset(data[0], stack_index)
212
253
  buffer = self._get_buffer(stack_index)
@@ -0,0 +1,29 @@
1
+ import numpy
2
+ import pytest
3
+ from . import data
4
+
5
+
6
+ @pytest.fixture(scope="session")
7
+ def bliss_scan(tmpdir_factory):
8
+ tmpdir = tmpdir_factory.mktemp("sample_dataset")
9
+ npoints_per_file = 3
10
+ npoints = 31
11
+ scannr = 2
12
+ image = numpy.zeros((10, 12))
13
+ return (
14
+ str(
15
+ data.save_bliss_scan(
16
+ tmpdir,
17
+ image,
18
+ npoints_per_file,
19
+ npoints,
20
+ scannr,
21
+ subscannr=1,
22
+ lima_names=("p3", "p4"),
23
+ counter_names=("diode1", "diode2"),
24
+ sequence="add",
25
+ )
26
+ ),
27
+ npoints,
28
+ scannr,
29
+ )
@@ -0,0 +1,66 @@
1
+ import numpy
2
+ import h5py
3
+ from fabio.edfimage import edfimage
4
+ import pytest
5
+ from ..data import bliss
6
+
7
+
8
+ def test_get_data_edf(tmpdir):
9
+ filename = str(tmpdir / "data.edf")
10
+ img1 = numpy.random.uniform(((10, 12)))
11
+ edf = edfimage(data=img1)
12
+ edf.write(filename)
13
+ img2 = bliss.get_data(filename)
14
+ numpy.testing.assert_array_equal(img1, img2)
15
+
16
+
17
+ def test_get_data_hdf5(tmpdir):
18
+ filename = str(tmpdir / "data.h5")
19
+ img1 = numpy.random.uniform(((10, 12)))
20
+ with h5py.File(filename, "w") as f:
21
+ f["img"] = img1
22
+ img2 = bliss.get_data(f"{filename}::/img")
23
+ numpy.testing.assert_array_equal(img1, img2)
24
+ img3 = bliss.get_data(f"{filename}?path=/img")
25
+ numpy.testing.assert_array_equal(img1, img3)
26
+
27
+
28
+ @pytest.mark.parametrize("lima_names", [(), ("p3",), ("p3", "p4")])
29
+ @pytest.mark.parametrize("counter_names", [(), ("diode1",), ("diode1", "diode2")])
30
+ def test_iter_bliss_data(lima_names, counter_names, bliss_scan):
31
+ nexpected = len(lima_names) + len(counter_names)
32
+ index = None
33
+ filename, npoints, scan_nb = bliss_scan
34
+ with bliss.iter_bliss_data(
35
+ filename, scan_nb, lima_names=lima_names, counter_names=counter_names
36
+ ) as bliss_data_iterator:
37
+ for index, data in bliss_data_iterator:
38
+ assert len(data) == nexpected
39
+ if "diode1" in counter_names:
40
+ assert data["diode1"] == index
41
+ if "diode2" in counter_names:
42
+ assert data["diode2"] == index
43
+ if "p3" in lima_names:
44
+ assert (data["p3"] == index).all()
45
+ if "p4" in lima_names:
46
+ assert (data["p4"] == index).all()
47
+
48
+ if nexpected:
49
+ assert index == npoints - 1
50
+ else:
51
+ assert index is None
52
+
53
+
54
+ def test_closure_of_iter_bliss_data(bliss_scan):
55
+ filename, npoints, scan_nb = bliss_scan
56
+
57
+ # This opens filename with `locking=False`
58
+ with bliss.iter_bliss_data(
59
+ filename, scan_nb, counter_names=[], lima_names=("p3",)
60
+ ) as lima_iterator:
61
+ for i in range(npoints):
62
+ next(lima_iterator)
63
+
64
+ # Make sure that the file is closed and can be reopened with a different locking flag
65
+ with h5py.File(filename, "r", locking=True):
66
+ pass
@@ -0,0 +1,14 @@
1
+ from ..data import hdf5
2
+
3
+
4
+ def test_bliss_data(bliss_scan):
5
+ filename, nb_points, scan_nb = bliss_scan
6
+ with hdf5.h5context(filename) as f:
7
+ values = f[f"/{scan_nb}.1/measurement/diode1"][()]
8
+ assert values.tolist() == list(range(nb_points))
9
+ values = f[f"/{scan_nb}.1/measurement/diode2"][()]
10
+ assert values.tolist() == list(range(nb_points))
11
+ values = f[f"/{scan_nb}.1/measurement/p3"][:, 0, 0]
12
+ assert values.tolist() == list(range(nb_points))
13
+ values = f[f"/{scan_nb}.1/measurement/p3"][:, -1, -1]
14
+ assert values.tolist() == list(range(nb_points))
@@ -0,0 +1,89 @@
1
+ import time
2
+ import itertools
3
+
4
+ import h5py
5
+ import numpy
6
+ import pytest
7
+ from ..data.hdf5 import dataset_writer
8
+
9
+
10
+ @pytest.mark.parametrize("npoints", (1, 3, 1000))
11
+ @pytest.mark.parametrize("flush_period", (None, 0.1))
12
+ @pytest.mark.parametrize("known_npoints", (True, False))
13
+ def test_dataset_writer(tmpdir, npoints, flush_period, known_npoints):
14
+ expected = list()
15
+ filename = str(tmpdir / "test.h5")
16
+ if flush_period is None:
17
+ sleep_time = None
18
+ else:
19
+ sleep_time = flush_period + 0.1
20
+ isleep = npoints // 3
21
+
22
+ kwargs = {"flush_period": flush_period}
23
+ if known_npoints:
24
+ kwargs["npoints"] = npoints
25
+
26
+ with h5py.File(filename, mode="w") as f:
27
+ with dataset_writer.DatasetWriter(f, "data", **kwargs) as writer:
28
+ for ipoint in range(npoints):
29
+ data = numpy.random.random((10, 20))
30
+ writer.add_point(data)
31
+ expected.append(data)
32
+ if sleep_time and ipoint == isleep:
33
+ time.sleep(sleep_time)
34
+
35
+ with h5py.File(filename, mode="r") as f:
36
+ data = f["data"][()]
37
+ numpy.testing.assert_allclose(data, expected)
38
+
39
+
40
+ @pytest.mark.parametrize("nstack", (1, 4))
41
+ @pytest.mark.parametrize("npoints", (1, 3, 1000))
42
+ @pytest.mark.parametrize("flush_period", (None, 0.1))
43
+ @pytest.mark.parametrize("known_npoints", (True, False))
44
+ @pytest.mark.parametrize("known_nstack", (True, False))
45
+ @pytest.mark.parametrize("append_stacks_in_parallel", (True, False))
46
+ def test_stack_dataset_writer(
47
+ tmpdir,
48
+ nstack,
49
+ npoints,
50
+ flush_period,
51
+ known_npoints,
52
+ known_nstack,
53
+ append_stacks_in_parallel,
54
+ ):
55
+ expected = [list() for _ in range(nstack)]
56
+ filename = str(tmpdir / "test.h5")
57
+ if flush_period is None:
58
+ sleep_time = None
59
+ else:
60
+ sleep_time = flush_period + 0.1
61
+ isleep = (nstack * npoints) // 3
62
+
63
+ kwargs = {"flush_period": flush_period}
64
+ if known_npoints:
65
+ kwargs["npoints"] = npoints
66
+ if known_nstack:
67
+ kwargs["nstack"] = nstack
68
+
69
+ if append_stacks_in_parallel:
70
+ itpoints = itertools.product(range(npoints), range(nstack))
71
+ else:
72
+ itpoints = itertools.product(range(nstack), range(npoints))
73
+
74
+ with h5py.File(filename, mode="w") as f:
75
+ with dataset_writer.StackDatasetWriter(f, "data", **kwargs) as writer:
76
+ for tpl in itpoints:
77
+ if append_stacks_in_parallel:
78
+ ipoint, istack = tpl
79
+ else:
80
+ istack, ipoint = tpl
81
+ data = numpy.random.random((10, 20))
82
+ writer.add_point(data, istack)
83
+ expected[istack].append(data)
84
+ if sleep_time and (ipoint * nstack + istack) == isleep:
85
+ time.sleep(sleep_time)
86
+
87
+ with h5py.File(filename, mode="r") as f:
88
+ data = f["data"][()]
89
+ numpy.testing.assert_allclose(data, expected)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ewoksdata
3
- Version: 0.4.3
3
+ Version: 0.5.0
4
4
  Summary: Ewoks tasks for data access
5
5
  Home-page: https://gitlab.esrf.fr/workflow/ewoksapps/ewoksdata/
6
6
  Author: ESRF
@@ -36,19 +36,12 @@ Requires-Dist: blissdata[tango]; extra == "doc"
36
36
  Requires-Dist: pytest>=7; extra == "doc"
37
37
  Requires-Dist: sphinx>=4.5; extra == "doc"
38
38
  Requires-Dist: sphinx-autodoc-typehints>=1.16; extra == "doc"
39
+ Requires-Dist: pydata-sphinx-theme<0.15; extra == "doc"
39
40
 
40
41
  # ewoksdata
41
42
 
42
43
  Data access utilities for [ewoks](https://ewoks.readthedocs.io/) workflows.
43
44
 
44
- ## Installation
45
-
46
- Until `silx>1.0.0` is released:
47
-
48
- ```bash
49
- python -m pip install git+https://github.com/silx-kit/silx.git
50
- ```
51
-
52
45
  ## Documentation
53
46
 
54
47
  https://ewoksdata.readthedocs.io
@@ -11,6 +11,7 @@ src/ewoksdata.egg-info/requires.txt
11
11
  src/ewoksdata.egg-info/top_level.txt
12
12
  src/ewoksdata/data/__init__.py
13
13
  src/ewoksdata/data/bliss.py
14
+ src/ewoksdata/data/contextiterator.py
14
15
  src/ewoksdata/data/nexus.py
15
16
  src/ewoksdata/data/url.py
16
17
  src/ewoksdata/data/utils.py
@@ -20,6 +20,7 @@ blissdata[tango]
20
20
  pytest>=7
21
21
  sphinx>=4.5
22
22
  sphinx-autodoc-typehints>=1.16
23
+ pydata-sphinx-theme<0.15
23
24
 
24
25
  [online]
25
26
  blissdata[tango]
@@ -1,6 +0,0 @@
1
- [build-system]
2
- requires = [
3
- "setuptools>=46.4,<63",
4
- "wheel",
5
- ]
6
- build-backend = "setuptools.build_meta"
@@ -1 +0,0 @@
1
- __version__ = "0.4.3"
@@ -1,23 +0,0 @@
1
- import numpy
2
- import pytest
3
- from . import data
4
-
5
-
6
- @pytest.fixture(scope="session")
7
- def bliss_scan(tmpdir_factory):
8
- tmpdir = tmpdir_factory.mktemp("sample_dataset")
9
- npoints_per_file = 3
10
- npoints = 31
11
- scannr = 2
12
- image = numpy.zeros((10, 12))
13
- return data.save_bliss_scan(
14
- tmpdir,
15
- image,
16
- npoints_per_file,
17
- npoints,
18
- scannr,
19
- subscannr=1,
20
- lima_names=("p3", "p4"),
21
- counter_names=("diode1", "diode2"),
22
- sequence="add",
23
- )
@@ -1,49 +0,0 @@
1
- import numpy
2
- import h5py
3
- from fabio.edfimage import edfimage
4
- import pytest
5
- from ..data import bliss
6
-
7
-
8
- def test_get_data_edf(tmpdir):
9
- filename = str(tmpdir / "data.edf")
10
- img1 = numpy.random.uniform(((10, 12)))
11
- edf = edfimage(data=img1)
12
- edf.write(filename)
13
- img2 = bliss.get_data(filename)
14
- numpy.testing.assert_array_equal(img1, img2)
15
-
16
-
17
- def test_get_data_hdf5(tmpdir):
18
- filename = str(tmpdir / "data.h5")
19
- img1 = numpy.random.uniform(((10, 12)))
20
- with h5py.File(filename, "w") as f:
21
- f["img"] = img1
22
- img2 = bliss.get_data(f"{filename}::/img")
23
- numpy.testing.assert_array_equal(img1, img2)
24
- img3 = bliss.get_data(f"{filename}?path=/img")
25
- numpy.testing.assert_array_equal(img1, img3)
26
-
27
-
28
- @pytest.mark.parametrize("lima_names", [(), ("p3",), ("p3", "p4")])
29
- @pytest.mark.parametrize("counter_names", [(), ("diode1",), ("diode1", "diode2")])
30
- def test_iter_bliss_data(lima_names, counter_names, bliss_scan):
31
- nexpected = len(lima_names) + len(counter_names)
32
- index = None
33
- for index, data in bliss.iter_bliss_data(
34
- str(bliss_scan), 2, lima_names=lima_names, counter_names=counter_names
35
- ):
36
- assert len(data) == nexpected
37
- if "diode1" in counter_names:
38
- assert data["diode1"] == index
39
- if "diode2" in counter_names:
40
- assert data["diode2"] == index
41
- if "p3" in counter_names:
42
- assert (data["p3"] == index).all()
43
- if "p4" in counter_names:
44
- assert (data["p4"] == index).all()
45
-
46
- if nexpected:
47
- assert index == 30
48
- else:
49
- assert index is None
@@ -1,13 +0,0 @@
1
- from ..data import hdf5
2
-
3
-
4
- def test_bliss_data(bliss_scan):
5
- with hdf5.h5context(bliss_scan) as f:
6
- values = f["/2.1/measurement/diode1"][()]
7
- assert values.tolist() == list(range(31))
8
- values = f["/2.1/measurement/diode2"][()]
9
- assert values.tolist() == list(range(31))
10
- values = f["/2.1/measurement/p3"][:, 0, 0]
11
- assert values.tolist() == list(range(31))
12
- values = f["/2.1/measurement/p3"][:, -1, -1]
13
- assert values.tolist() == list(range(31))
@@ -1,113 +0,0 @@
1
- import time
2
- import h5py
3
- import numpy
4
- import pytest
5
- from ..data.hdf5 import dataset_writer
6
-
7
-
8
- @pytest.mark.parametrize("npoints", (1, 3, 1000))
9
- @pytest.mark.parametrize("flush_period", (None, 0.1))
10
- def test_dataset_writer_variable_points(tmpdir, npoints, flush_period):
11
- expected = list()
12
- filename = str(tmpdir / "test.h5")
13
- if flush_period is None:
14
- sleep_time = None
15
- else:
16
- sleep_time = flush_period + 0.1
17
- isleep = npoints // 3
18
-
19
- with h5py.File(filename, mode="w") as f:
20
- with dataset_writer.DatasetWriter(
21
- f, "data", flush_period=flush_period
22
- ) as writer:
23
- for ipoint in range(npoints):
24
- data = numpy.random.random((10, 20))
25
- writer.add_point(data)
26
- expected.append(data)
27
- if sleep_time and ipoint == isleep:
28
- time.sleep(sleep_time)
29
- with h5py.File(filename, mode="r") as f:
30
- data = f["data"][()]
31
- numpy.testing.assert_allclose(data, expected)
32
-
33
-
34
- @pytest.mark.parametrize("npoints", (1, 3, 1000))
35
- @pytest.mark.parametrize("flush_period", (None, 0.1))
36
- def test_dataset_writer_fixed_points(tmpdir, npoints, flush_period):
37
- expected = list()
38
- filename = str(tmpdir / "test.h5")
39
- if flush_period is None:
40
- sleep_time = None
41
- else:
42
- sleep_time = flush_period + 0.1
43
- isleep = npoints // 3
44
-
45
- with h5py.File(filename, mode="w") as f:
46
- with dataset_writer.DatasetWriter(
47
- f, "data", flush_period=flush_period, npoints=npoints
48
- ) as writer:
49
- for ipoint in range(npoints):
50
- data = numpy.random.random((10, 20))
51
- writer.add_point(data)
52
- expected.append(data)
53
- if sleep_time and ipoint == isleep:
54
- time.sleep(sleep_time)
55
- with h5py.File(filename, mode="r") as f:
56
- data = f["data"][()]
57
- numpy.testing.assert_allclose(data, expected)
58
-
59
-
60
- @pytest.mark.parametrize("nstack", (1, 4))
61
- @pytest.mark.parametrize("npoints", (1, 3, 1000))
62
- @pytest.mark.parametrize("flush_period", (None, 0.1))
63
- def test_stack_dataset_writer_variable_points(tmpdir, nstack, npoints, flush_period):
64
- expected = [list() for _ in range(nstack)]
65
- filename = str(tmpdir / "test.h5")
66
- if flush_period is None:
67
- sleep_time = None
68
- else:
69
- sleep_time = flush_period + 0.1
70
- isleep = (nstack * npoints) // 3
71
-
72
- with h5py.File(filename, mode="w") as f:
73
- with dataset_writer.StackDatasetWriter(
74
- f, "data", flush_period=flush_period
75
- ) as writer:
76
- for ipoint in range(npoints):
77
- for istack in range(nstack):
78
- data = numpy.random.random((10, 20))
79
- writer.add_point(data, istack)
80
- expected[istack].append(data)
81
- if sleep_time and (ipoint * nstack + istack) == isleep:
82
- time.sleep(sleep_time)
83
- with h5py.File(filename, mode="r") as f:
84
- data = f["data"][()]
85
- numpy.testing.assert_allclose(data, expected)
86
-
87
-
88
- @pytest.mark.parametrize("nstack", (1, 4))
89
- @pytest.mark.parametrize("npoints", (1, 3, 1000))
90
- @pytest.mark.parametrize("flush_period", (None, 0.1))
91
- def test_stack_dataset_writer_fixed_points(tmpdir, nstack, npoints, flush_period):
92
- expected = [list() for _ in range(nstack)]
93
- filename = str(tmpdir / "test.h5")
94
- if flush_period is None:
95
- sleep_time = None
96
- else:
97
- sleep_time = flush_period + 0.1
98
- isleep = npoints // 3
99
-
100
- with h5py.File(filename, mode="w") as f:
101
- with dataset_writer.StackDatasetWriter(
102
- f, "data", flush_period=flush_period, npoints=npoints, nstack=nstack
103
- ) as writer:
104
- for ipoint in range(npoints):
105
- for istack in range(nstack):
106
- data = numpy.random.random((10, 20))
107
- writer.add_point(data, istack)
108
- expected[istack].append(data)
109
- if sleep_time and (ipoint * nstack + istack) == isleep:
110
- time.sleep(sleep_time)
111
- with h5py.File(filename, mode="r") as f:
112
- data = f["data"][()]
113
- numpy.testing.assert_allclose(data, expected)
File without changes
File without changes