py4D-browser-flexloader 0.0.5__tar.gz → 0.1.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.
- {py4d_browser_flexloader-0.0.5/src/py4D_browser_flexloader.egg-info → py4d_browser_flexloader-0.1.0}/PKG-INFO +54 -4
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/README.md +51 -2
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/pyproject.toml +2 -1
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0/src/py4D_browser_flexloader.egg-info}/PKG-INFO +54 -4
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4D_browser_flexloader.egg-info/SOURCES.txt +1 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4D_browser_flexloader.egg-info/requires.txt +1 -1
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4d_browser_plugin/flexloader/__init__.py +1 -1
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4d_browser_plugin/flexloader/dialog.py +2 -5
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4d_browser_plugin/flexloader/flexloader.py +17 -24
- py4d_browser_flexloader-0.1.0/tests/test_plugin.py +175 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/tests/test_selection.py +42 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/LICENSE.txt +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/setup.cfg +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4D_browser_flexloader.egg-info/dependency_links.txt +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4D_browser_flexloader.egg-info/top_level.txt +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4d_browser_plugin/flexloader/backends.py +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/src/py4d_browser_plugin/flexloader/selection.py +0 -0
- {py4d_browser_flexloader-0.0.5 → py4d_browser_flexloader-0.1.0}/tests/test_backends.py +0 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py4D-browser-flexloader
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: py4D-browser plugin for flexible HDF5 and Zarr dataset loading
|
|
5
5
|
Author-email: Chia-Hao Lee <chia-hao.lee@cornell.edu>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/chiahao3/py4D-browser-flexloader
|
|
8
8
|
Project-URL: Repository, https://github.com/chiahao3/py4D-browser-flexloader
|
|
9
9
|
Project-URL: Bug Tracker, https://github.com/chiahao3/py4D-browser-flexloader/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/chiahao3/py4D-browser-flexloader/blob/main/CHANGELOG.md
|
|
10
11
|
Classifier: Programming Language :: Python :: 3
|
|
11
12
|
Classifier: Operating System :: OS Independent
|
|
12
13
|
Requires-Python: >=3.11
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
License-File: LICENSE.txt
|
|
15
|
-
Requires-Dist: py4d-browser
|
|
16
|
+
Requires-Dist: py4d-browser>=1.6.0
|
|
16
17
|
Requires-Dist: py4dstem>=0.14.9
|
|
17
18
|
Requires-Dist: numpy>=1.19
|
|
18
19
|
Requires-Dist: h5py
|
|
@@ -59,6 +60,33 @@ python -m pip cache purge
|
|
|
59
60
|
pip install py4d-browser-flexloader
|
|
60
61
|
```
|
|
61
62
|
|
|
63
|
+
### Compatibility
|
|
64
|
+
|
|
65
|
+
py4D-browser 1.6 introduced a versioned plugin API and only loads plugins that
|
|
66
|
+
declare the API version they were written for, so plugin and browser versions
|
|
67
|
+
must match:
|
|
68
|
+
|
|
69
|
+
| py4D-browser-flexloader | py4D-browser |
|
|
70
|
+
|---|---|
|
|
71
|
+
| 0.1.x | ≥ 1.6.0 |
|
|
72
|
+
| 0.0.x | 1.5.x (does **not** load in 1.6) |
|
|
73
|
+
|
|
74
|
+
To upgrade an existing environment, upgrade the plugin; pip pulls in
|
|
75
|
+
py4D-browser 1.6 with it:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install -U py4d-browser-flexloader
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
If you need to stay on py4D-browser 1.5.x, pin both packages:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "py4d-browser-flexloader<0.1" "py4d-browser<1.6"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
py4D-browser prints a "Skipping plugin 'chiahao3.flexloader' … does not declare
|
|
88
|
+
an `api_version`" line at startup when an older plugin is paired with 1.6.
|
|
89
|
+
|
|
62
90
|
## Usage
|
|
63
91
|
|
|
64
92
|
Start py4DGUI after activating the environment:
|
|
@@ -77,6 +105,8 @@ source:
|
|
|
77
105
|
- **Load Zarr Zip File...** for Zarr stores saved as `.zip` or `.zarr.zip`
|
|
78
106
|
files.
|
|
79
107
|
|
|
108
|
+

|
|
109
|
+
|
|
80
110
|
The loader dialog shows the internal hierarchy of the selected file or store,
|
|
81
111
|
including array paths, shapes, dtypes, chunks, and attributes. Once an array is
|
|
82
112
|
selected, assign its dimensions to:
|
|
@@ -99,11 +129,31 @@ preview reads only two 2D slices from the selected HDF5/Zarr dataset:
|
|
|
99
129
|
- an axial bright-field image from the central diffraction pixel
|
|
100
130
|
|
|
101
131
|
Click **Load** to create a `py4DSTEM.DataCube` from the selected 4D subset and
|
|
102
|
-
send it to py4DGUI. The raw source file is not modified.
|
|
103
|
-
|
|
132
|
+
send it to py4DGUI. The raw source file is not modified. The datacube starts
|
|
133
|
+
with a 1-pixel calibration in pixel units; set the real calibration after
|
|
134
|
+
loading using py4DGUI's calibration tools.
|
|
135
|
+
|
|
136
|
+
After loading, the status bar shows the loaded source as
|
|
137
|
+
`Loaded <file>:<dataset path>`. py4D-browser 1.6's plugin API cannot set the
|
|
138
|
+
window title, so the title is not updated, the same as for py4D-browser's own
|
|
139
|
+
**Open Raw...**.
|
|
104
140
|
|
|
105
141
|
Both grouped Zarr stores and root-level Zarr arrays are supported.
|
|
106
142
|
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
Install from source with the test extra and run the tests with pytest:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
git clone https://github.com/chiahao3/py4D-browser-flexloader.git
|
|
149
|
+
cd py4D-browser-flexloader
|
|
150
|
+
pip install -e '.[test]'
|
|
151
|
+
pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The plugin tests build real Qt widgets on Qt's `offscreen` platform, so no
|
|
155
|
+
display server is required.
|
|
156
|
+
|
|
107
157
|
## License
|
|
108
158
|
|
|
109
159
|
GNU GPLv3
|
|
@@ -35,6 +35,33 @@ python -m pip cache purge
|
|
|
35
35
|
pip install py4d-browser-flexloader
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Compatibility
|
|
39
|
+
|
|
40
|
+
py4D-browser 1.6 introduced a versioned plugin API and only loads plugins that
|
|
41
|
+
declare the API version they were written for, so plugin and browser versions
|
|
42
|
+
must match:
|
|
43
|
+
|
|
44
|
+
| py4D-browser-flexloader | py4D-browser |
|
|
45
|
+
|---|---|
|
|
46
|
+
| 0.1.x | ≥ 1.6.0 |
|
|
47
|
+
| 0.0.x | 1.5.x (does **not** load in 1.6) |
|
|
48
|
+
|
|
49
|
+
To upgrade an existing environment, upgrade the plugin; pip pulls in
|
|
50
|
+
py4D-browser 1.6 with it:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install -U py4d-browser-flexloader
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If you need to stay on py4D-browser 1.5.x, pin both packages:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install "py4d-browser-flexloader<0.1" "py4d-browser<1.6"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
py4D-browser prints a "Skipping plugin 'chiahao3.flexloader' … does not declare
|
|
63
|
+
an `api_version`" line at startup when an older plugin is paired with 1.6.
|
|
64
|
+
|
|
38
65
|
## Usage
|
|
39
66
|
|
|
40
67
|
Start py4DGUI after activating the environment:
|
|
@@ -53,6 +80,8 @@ source:
|
|
|
53
80
|
- **Load Zarr Zip File...** for Zarr stores saved as `.zip` or `.zarr.zip`
|
|
54
81
|
files.
|
|
55
82
|
|
|
83
|
+

|
|
84
|
+
|
|
56
85
|
The loader dialog shows the internal hierarchy of the selected file or store,
|
|
57
86
|
including array paths, shapes, dtypes, chunks, and attributes. Once an array is
|
|
58
87
|
selected, assign its dimensions to:
|
|
@@ -75,11 +104,31 @@ preview reads only two 2D slices from the selected HDF5/Zarr dataset:
|
|
|
75
104
|
- an axial bright-field image from the central diffraction pixel
|
|
76
105
|
|
|
77
106
|
Click **Load** to create a `py4DSTEM.DataCube` from the selected 4D subset and
|
|
78
|
-
send it to py4DGUI. The raw source file is not modified.
|
|
79
|
-
|
|
107
|
+
send it to py4DGUI. The raw source file is not modified. The datacube starts
|
|
108
|
+
with a 1-pixel calibration in pixel units; set the real calibration after
|
|
109
|
+
loading using py4DGUI's calibration tools.
|
|
110
|
+
|
|
111
|
+
After loading, the status bar shows the loaded source as
|
|
112
|
+
`Loaded <file>:<dataset path>`. py4D-browser 1.6's plugin API cannot set the
|
|
113
|
+
window title, so the title is not updated, the same as for py4D-browser's own
|
|
114
|
+
**Open Raw...**.
|
|
80
115
|
|
|
81
116
|
Both grouped Zarr stores and root-level Zarr arrays are supported.
|
|
82
117
|
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
Install from source with the test extra and run the tests with pytest:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
git clone https://github.com/chiahao3/py4D-browser-flexloader.git
|
|
124
|
+
cd py4D-browser-flexloader
|
|
125
|
+
pip install -e '.[test]'
|
|
126
|
+
pytest
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The plugin tests build real Qt widgets on Qt's `offscreen` platform, so no
|
|
130
|
+
display server is required.
|
|
131
|
+
|
|
83
132
|
## License
|
|
84
133
|
|
|
85
134
|
GNU GPLv3
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
"Operating System :: OS Independent",
|
|
19
19
|
]
|
|
20
20
|
dependencies = [
|
|
21
|
-
"py4d-browser",
|
|
21
|
+
"py4d-browser >= 1.6.0",
|
|
22
22
|
"py4dstem >= 0.14.9",
|
|
23
23
|
"numpy >= 1.19",
|
|
24
24
|
"h5py",
|
|
@@ -35,6 +35,7 @@ test = [
|
|
|
35
35
|
"Homepage" = "https://github.com/chiahao3/py4D-browser-flexloader"
|
|
36
36
|
"Repository" = "https://github.com/chiahao3/py4D-browser-flexloader"
|
|
37
37
|
"Bug Tracker" = "https://github.com/chiahao3/py4D-browser-flexloader/issues"
|
|
38
|
+
"Changelog" = "https://github.com/chiahao3/py4D-browser-flexloader/blob/main/CHANGELOG.md"
|
|
38
39
|
|
|
39
40
|
[tool.setuptools.packages.find]
|
|
40
41
|
where = ["src"]
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py4D-browser-flexloader
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: py4D-browser plugin for flexible HDF5 and Zarr dataset loading
|
|
5
5
|
Author-email: Chia-Hao Lee <chia-hao.lee@cornell.edu>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/chiahao3/py4D-browser-flexloader
|
|
8
8
|
Project-URL: Repository, https://github.com/chiahao3/py4D-browser-flexloader
|
|
9
9
|
Project-URL: Bug Tracker, https://github.com/chiahao3/py4D-browser-flexloader/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/chiahao3/py4D-browser-flexloader/blob/main/CHANGELOG.md
|
|
10
11
|
Classifier: Programming Language :: Python :: 3
|
|
11
12
|
Classifier: Operating System :: OS Independent
|
|
12
13
|
Requires-Python: >=3.11
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
License-File: LICENSE.txt
|
|
15
|
-
Requires-Dist: py4d-browser
|
|
16
|
+
Requires-Dist: py4d-browser>=1.6.0
|
|
16
17
|
Requires-Dist: py4dstem>=0.14.9
|
|
17
18
|
Requires-Dist: numpy>=1.19
|
|
18
19
|
Requires-Dist: h5py
|
|
@@ -59,6 +60,33 @@ python -m pip cache purge
|
|
|
59
60
|
pip install py4d-browser-flexloader
|
|
60
61
|
```
|
|
61
62
|
|
|
63
|
+
### Compatibility
|
|
64
|
+
|
|
65
|
+
py4D-browser 1.6 introduced a versioned plugin API and only loads plugins that
|
|
66
|
+
declare the API version they were written for, so plugin and browser versions
|
|
67
|
+
must match:
|
|
68
|
+
|
|
69
|
+
| py4D-browser-flexloader | py4D-browser |
|
|
70
|
+
|---|---|
|
|
71
|
+
| 0.1.x | ≥ 1.6.0 |
|
|
72
|
+
| 0.0.x | 1.5.x (does **not** load in 1.6) |
|
|
73
|
+
|
|
74
|
+
To upgrade an existing environment, upgrade the plugin; pip pulls in
|
|
75
|
+
py4D-browser 1.6 with it:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install -U py4d-browser-flexloader
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
If you need to stay on py4D-browser 1.5.x, pin both packages:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "py4d-browser-flexloader<0.1" "py4d-browser<1.6"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
py4D-browser prints a "Skipping plugin 'chiahao3.flexloader' … does not declare
|
|
88
|
+
an `api_version`" line at startup when an older plugin is paired with 1.6.
|
|
89
|
+
|
|
62
90
|
## Usage
|
|
63
91
|
|
|
64
92
|
Start py4DGUI after activating the environment:
|
|
@@ -77,6 +105,8 @@ source:
|
|
|
77
105
|
- **Load Zarr Zip File...** for Zarr stores saved as `.zip` or `.zarr.zip`
|
|
78
106
|
files.
|
|
79
107
|
|
|
108
|
+

|
|
109
|
+
|
|
80
110
|
The loader dialog shows the internal hierarchy of the selected file or store,
|
|
81
111
|
including array paths, shapes, dtypes, chunks, and attributes. Once an array is
|
|
82
112
|
selected, assign its dimensions to:
|
|
@@ -99,11 +129,31 @@ preview reads only two 2D slices from the selected HDF5/Zarr dataset:
|
|
|
99
129
|
- an axial bright-field image from the central diffraction pixel
|
|
100
130
|
|
|
101
131
|
Click **Load** to create a `py4DSTEM.DataCube` from the selected 4D subset and
|
|
102
|
-
send it to py4DGUI. The raw source file is not modified.
|
|
103
|
-
|
|
132
|
+
send it to py4DGUI. The raw source file is not modified. The datacube starts
|
|
133
|
+
with a 1-pixel calibration in pixel units; set the real calibration after
|
|
134
|
+
loading using py4DGUI's calibration tools.
|
|
135
|
+
|
|
136
|
+
After loading, the status bar shows the loaded source as
|
|
137
|
+
`Loaded <file>:<dataset path>`. py4D-browser 1.6's plugin API cannot set the
|
|
138
|
+
window title, so the title is not updated, the same as for py4D-browser's own
|
|
139
|
+
**Open Raw...**.
|
|
104
140
|
|
|
105
141
|
Both grouped Zarr stores and root-level Zarr arrays are supported.
|
|
106
142
|
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
Install from source with the test extra and run the tests with pytest:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
git clone https://github.com/chiahao3/py4D-browser-flexloader.git
|
|
149
|
+
cd py4D-browser-flexloader
|
|
150
|
+
pip install -e '.[test]'
|
|
151
|
+
pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The plugin tests build real Qt widgets on Qt's `offscreen` platform, so no
|
|
155
|
+
display server is required.
|
|
156
|
+
|
|
107
157
|
## License
|
|
108
158
|
|
|
109
159
|
GNU GPLv3
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
5
4
|
|
|
6
5
|
import numpy as np
|
|
7
6
|
import pyqtgraph as pg
|
|
@@ -31,14 +30,12 @@ from .selection import ALL_ROLES, DATACUBE_ROLES, DimensionSelection, default_ro
|
|
|
31
30
|
from .selection import ROLE_FIXED, ROLE_FLATTENED_SCAN, default_scan_shape
|
|
32
31
|
from .selection import load_preview_arrays, validate_selection
|
|
33
32
|
|
|
34
|
-
if TYPE_CHECKING:
|
|
35
|
-
from py4D_browser import DataViewer
|
|
36
33
|
|
|
37
34
|
|
|
38
35
|
class FlexLoaderDialog(QDialog):
|
|
39
|
-
def __init__(self, filepath: str, parent:
|
|
36
|
+
def __init__(self, filepath: str, parent: QWidget | None = None):
|
|
37
|
+
# parent is the plugin API's dialog-parent widget (api.qt_window)
|
|
40
38
|
super().__init__(parent)
|
|
41
|
-
self.parent_viewer = parent
|
|
42
39
|
self.filepath = filepath
|
|
43
40
|
self.source: DataSource | None = None
|
|
44
41
|
self.root_node: DataNode | None = None
|
|
@@ -9,17 +9,21 @@ from .dialog import FlexLoaderDialog
|
|
|
9
9
|
from .selection import load_datacube_array
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
|
-
from py4D_browser import
|
|
12
|
+
from py4D_browser.plugin_api import PluginAPI1
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class FlexLoaderPlugin(QWidget):
|
|
16
16
|
plugin_id = "chiahao3.flexloader"
|
|
17
17
|
display_name = "Flex Loader"
|
|
18
18
|
uses_plugin_menu = True
|
|
19
|
+
# Versioned plugin API (py4D-browser 1.6). Everything this plugin needs
|
|
20
|
+
# (the datacube, dialog parenting, status messages) is on the API, so it
|
|
21
|
+
# does not ask for full access to the DataViewer.
|
|
22
|
+
api_version = (1, 6)
|
|
19
23
|
|
|
20
|
-
def __init__(self,
|
|
24
|
+
def __init__(self, api: "PluginAPI1", plugin_menu, **kwargs):
|
|
21
25
|
super().__init__()
|
|
22
|
-
self.
|
|
26
|
+
self.api = api
|
|
23
27
|
self.flexloader_menu = plugin_menu
|
|
24
28
|
|
|
25
29
|
self.load_action = QAction("Load HDF5 File...", self)
|
|
@@ -38,22 +42,22 @@ class FlexLoaderPlugin(QWidget):
|
|
|
38
42
|
pass
|
|
39
43
|
|
|
40
44
|
def launch_hdf5_file_loader(self) -> None:
|
|
41
|
-
filepath = FlexLoaderDialog.select_hdf5_file(self.
|
|
45
|
+
filepath = FlexLoaderDialog.select_hdf5_file(self.api.qt_window)
|
|
42
46
|
self.launch_loader(filepath)
|
|
43
47
|
|
|
44
48
|
def launch_zarr_directory_loader(self) -> None:
|
|
45
|
-
filepath = FlexLoaderDialog.select_zarr_directory(self.
|
|
49
|
+
filepath = FlexLoaderDialog.select_zarr_directory(self.api.qt_window)
|
|
46
50
|
self.launch_loader(filepath)
|
|
47
51
|
|
|
48
52
|
def launch_zarr_zip_loader(self) -> None:
|
|
49
|
-
filepath = FlexLoaderDialog.select_zarr_zip_file(self.
|
|
53
|
+
filepath = FlexLoaderDialog.select_zarr_zip_file(self.api.qt_window)
|
|
50
54
|
self.launch_loader(filepath)
|
|
51
55
|
|
|
52
56
|
def launch_loader(self, filepath: str | None) -> None:
|
|
53
57
|
if not filepath:
|
|
54
58
|
return
|
|
55
59
|
|
|
56
|
-
dialog = FlexLoaderDialog(filepath, parent=self.
|
|
60
|
+
dialog = FlexLoaderDialog(filepath, parent=self.api.qt_window)
|
|
57
61
|
if dialog.exec_() != dialog.Accepted:
|
|
58
62
|
dialog.close_source()
|
|
59
63
|
return
|
|
@@ -72,9 +76,13 @@ class FlexLoaderPlugin(QWidget):
|
|
|
72
76
|
array = np.asarray(array)
|
|
73
77
|
datacube = py4DSTEM.DataCube(array)
|
|
74
78
|
_set_default_pixel_calibration(datacube)
|
|
75
|
-
|
|
79
|
+
# set_datacube resets both views and emits signal_datacube_changed.
|
|
80
|
+
self.api.set_datacube(datacube)
|
|
81
|
+
# The plugin API cannot set the window title, so name the loaded
|
|
82
|
+
# source on the status bar instead.
|
|
83
|
+
self.api.status_bar.showMessage(f"Loaded {filepath}:{node.path}")
|
|
76
84
|
except Exception as exc:
|
|
77
|
-
QMessageBox.critical(self.
|
|
85
|
+
QMessageBox.critical(self.api.qt_window, "Could not load dataset", str(exc))
|
|
78
86
|
raise
|
|
79
87
|
finally:
|
|
80
88
|
dialog.close_source()
|
|
@@ -96,21 +104,6 @@ def _set_default_pixel_calibration(datacube) -> None:
|
|
|
96
104
|
method(value)
|
|
97
105
|
|
|
98
106
|
|
|
99
|
-
def _install_datacube(parent: "DataViewer", datacube, window_title: str) -> None:
|
|
100
|
-
if hasattr(parent, "set_datacube"):
|
|
101
|
-
parent.set_datacube(datacube, window_title)
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
parent.datacube = datacube
|
|
105
|
-
if hasattr(parent, "update_scalebars"):
|
|
106
|
-
parent.update_scalebars()
|
|
107
|
-
parent.update_diffraction_space_view(reset=True)
|
|
108
|
-
parent.update_real_space_view(reset=True)
|
|
109
|
-
parent.setWindowTitle(window_title)
|
|
110
|
-
if hasattr(parent, "signal_datacube_changed"):
|
|
111
|
-
parent.signal_datacube_changed.emit()
|
|
112
|
-
|
|
113
|
-
|
|
114
107
|
# TODO: Re-evaluate lazy HDF5/Zarr-backed loading after confirming that the
|
|
115
108
|
# current py4DSTEM.DataCube and py4DGUI view code fully support non-ndarray
|
|
116
109
|
# data through repeated slicing, summation, max projection, and transpose paths.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""The plugin glue against py4D-browser 1.6's versioned plugin API.
|
|
2
|
+
|
|
3
|
+
The API is faked: these tests pin what the plugin asks of the browser
|
|
4
|
+
(set_datacube, dialog parenting, status messages), not the browser itself.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
QtWidgets = pytest.importorskip("PyQt5.QtWidgets")
|
|
11
|
+
|
|
12
|
+
from py4d_browser_plugin.flexloader import flexloader as fl # noqa: E402
|
|
13
|
+
from py4d_browser_plugin.flexloader.selection import ( # noqa: E402
|
|
14
|
+
ROLE_DETECTOR_X,
|
|
15
|
+
ROLE_DETECTOR_Y,
|
|
16
|
+
ROLE_SCAN_X,
|
|
17
|
+
ROLE_SCAN_Y,
|
|
18
|
+
DimensionSelection,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture(scope="module")
|
|
23
|
+
def qapp():
|
|
24
|
+
return QtWidgets.QApplication.instance() or QtWidgets.QApplication([])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _StatusBar:
|
|
28
|
+
def __init__(self):
|
|
29
|
+
self.messages = []
|
|
30
|
+
|
|
31
|
+
def showMessage(self, message, timeout=0):
|
|
32
|
+
self.messages.append((message, timeout))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _API:
|
|
36
|
+
"""Just the PluginAPI1 surface flexloader may use."""
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
self.qt_window = QtWidgets.QWidget()
|
|
40
|
+
self.status_bar = _StatusBar()
|
|
41
|
+
self.set_datacube_calls = []
|
|
42
|
+
|
|
43
|
+
def set_datacube(self, datacube, refresh=True):
|
|
44
|
+
self.set_datacube_calls.append((datacube, refresh))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _Node:
|
|
48
|
+
def __init__(self, path, shape):
|
|
49
|
+
self.path = path
|
|
50
|
+
self.shape = shape
|
|
51
|
+
self.is_array = True
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class _Source:
|
|
55
|
+
def __init__(self, arrays):
|
|
56
|
+
self.arrays = arrays
|
|
57
|
+
|
|
58
|
+
def get_array(self, path):
|
|
59
|
+
return self.arrays[path]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _AcceptedDialog:
|
|
63
|
+
"""Stand-in for FlexLoaderDialog that has already picked a 4D dataset."""
|
|
64
|
+
|
|
65
|
+
Accepted = 1
|
|
66
|
+
created_with = []
|
|
67
|
+
|
|
68
|
+
def __init__(self, filepath, parent=None):
|
|
69
|
+
_AcceptedDialog.created_with.append((filepath, parent))
|
|
70
|
+
self.data = np.arange(2 * 3 * 4 * 5, dtype=np.float32).reshape(2, 3, 4, 5)
|
|
71
|
+
self.selected_node = _Node("/entry/data", self.data.shape)
|
|
72
|
+
self.source = _Source({"/entry/data": self.data})
|
|
73
|
+
self.closed = False
|
|
74
|
+
|
|
75
|
+
def exec_(self):
|
|
76
|
+
return self.Accepted
|
|
77
|
+
|
|
78
|
+
def get_selection(self):
|
|
79
|
+
return DimensionSelection(
|
|
80
|
+
(ROLE_SCAN_Y, ROLE_SCAN_X, ROLE_DETECTOR_Y, ROLE_DETECTOR_X), (0, 0, 0, 0)
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def close_source(self):
|
|
84
|
+
self.closed = True
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _plugin(api):
|
|
88
|
+
return fl.FlexLoaderPlugin(api=api, plugin_menu=QtWidgets.QMenu())
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_declares_plugin_api_1_6_without_full_access():
|
|
92
|
+
assert fl.FlexLoaderPlugin.api_version == (1, 6)
|
|
93
|
+
assert not getattr(fl.FlexLoaderPlugin, "full_access", False)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_loads_with_the_1_6_loader_kwargs(qapp):
|
|
97
|
+
# py4D-browser 1.6 calls Plugin(api=..., plugin_menu=..., plugin_action=None)
|
|
98
|
+
api = _API()
|
|
99
|
+
menu = QtWidgets.QMenu()
|
|
100
|
+
plugin = fl.FlexLoaderPlugin(api=api, plugin_menu=menu, plugin_action=None)
|
|
101
|
+
assert plugin.api is api
|
|
102
|
+
assert [a.text() for a in menu.actions()] == [
|
|
103
|
+
"Load HDF5 File...",
|
|
104
|
+
"Load Zarr Directory...",
|
|
105
|
+
"Load Zarr Zip File...",
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_file_pickers_are_parented_on_the_api_window(qapp, monkeypatch):
|
|
110
|
+
api = _API()
|
|
111
|
+
plugin = _plugin(api)
|
|
112
|
+
seen = []
|
|
113
|
+
for picker in ("select_hdf5_file", "select_zarr_directory", "select_zarr_zip_file"):
|
|
114
|
+
monkeypatch.setattr(
|
|
115
|
+
fl.FlexLoaderDialog, picker, classmethod(lambda cls, parent: seen.append(parent))
|
|
116
|
+
)
|
|
117
|
+
plugin.launch_hdf5_file_loader()
|
|
118
|
+
plugin.launch_zarr_directory_loader()
|
|
119
|
+
plugin.launch_zarr_zip_loader()
|
|
120
|
+
assert seen == [api.qt_window] * 3
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_loading_installs_the_datacube_through_the_api(qapp, monkeypatch):
|
|
124
|
+
api = _API()
|
|
125
|
+
plugin = _plugin(api)
|
|
126
|
+
_AcceptedDialog.created_with = []
|
|
127
|
+
monkeypatch.setattr(fl, "FlexLoaderDialog", _AcceptedDialog)
|
|
128
|
+
|
|
129
|
+
plugin.launch_loader("/data/scan.h5")
|
|
130
|
+
|
|
131
|
+
assert _AcceptedDialog.created_with == [("/data/scan.h5", api.qt_window)]
|
|
132
|
+
assert len(api.set_datacube_calls) == 1
|
|
133
|
+
datacube, refresh = api.set_datacube_calls[0]
|
|
134
|
+
assert refresh is True # the browser resets both views and emits the change signal
|
|
135
|
+
np.testing.assert_array_equal(
|
|
136
|
+
datacube.data, np.arange(2 * 3 * 4 * 5, dtype=np.float32).reshape(2, 3, 4, 5)
|
|
137
|
+
)
|
|
138
|
+
assert datacube.calibration.get_R_pixel_units() == "pixels"
|
|
139
|
+
assert datacube.calibration.get_Q_pixel_units() == "pixels"
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_loading_reports_the_source_on_the_status_bar(qapp, monkeypatch):
|
|
143
|
+
# The API cannot set the window title, so the loaded source goes to the status bar.
|
|
144
|
+
api = _API()
|
|
145
|
+
plugin = _plugin(api)
|
|
146
|
+
monkeypatch.setattr(fl, "FlexLoaderDialog", _AcceptedDialog)
|
|
147
|
+
|
|
148
|
+
plugin.launch_loader("/data/scan.h5")
|
|
149
|
+
|
|
150
|
+
assert any("/data/scan.h5:/entry/data" in m for m, _ in api.status_bar.messages)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_load_errors_are_shown_on_the_api_window(qapp, monkeypatch):
|
|
154
|
+
api = _API()
|
|
155
|
+
plugin = _plugin(api)
|
|
156
|
+
monkeypatch.setattr(fl, "FlexLoaderDialog", _AcceptedDialog)
|
|
157
|
+
|
|
158
|
+
def _reject(datacube, refresh=True):
|
|
159
|
+
raise ValueError("bad cube")
|
|
160
|
+
|
|
161
|
+
api.set_datacube = _reject
|
|
162
|
+
shown = []
|
|
163
|
+
monkeypatch.setattr(
|
|
164
|
+
fl.QMessageBox, "critical", staticmethod(lambda parent, *a: shown.append(parent))
|
|
165
|
+
)
|
|
166
|
+
with pytest.raises(ValueError):
|
|
167
|
+
plugin.launch_loader("/data/scan.h5")
|
|
168
|
+
assert shown == [api.qt_window]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_cancelled_pick_does_nothing(qapp):
|
|
172
|
+
api = _API()
|
|
173
|
+
plugin = _plugin(api)
|
|
174
|
+
plugin.launch_loader(None)
|
|
175
|
+
assert api.set_datacube_calls == []
|
|
@@ -16,6 +16,21 @@ from py4d_browser_plugin.flexloader.selection import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
class RecordingArray:
|
|
20
|
+
def __init__(self, shape):
|
|
21
|
+
self.shape = shape
|
|
22
|
+
self.requests = []
|
|
23
|
+
|
|
24
|
+
def __getitem__(self, index):
|
|
25
|
+
self.requests.append(index)
|
|
26
|
+
result_shape = tuple(
|
|
27
|
+
size
|
|
28
|
+
for size, axis_index in zip(self.shape, index)
|
|
29
|
+
if isinstance(axis_index, slice)
|
|
30
|
+
)
|
|
31
|
+
return np.zeros(result_shape)
|
|
32
|
+
|
|
33
|
+
|
|
19
34
|
def test_default_roles_use_last_four_axes():
|
|
20
35
|
assert default_roles(5) == [
|
|
21
36
|
ROLE_FIXED,
|
|
@@ -60,6 +75,19 @@ def test_preview_plain_4d_dataset_reads_central_dp_and_axial_bf():
|
|
|
60
75
|
assert "scan center" in previews.description
|
|
61
76
|
|
|
62
77
|
|
|
78
|
+
def test_preview_plain_4d_dataset_uses_two_2d_slice_reads():
|
|
79
|
+
array = RecordingArray((64, 64, 128, 128))
|
|
80
|
+
selection = DimensionSelection(
|
|
81
|
+
(ROLE_SCAN_Y, ROLE_SCAN_X, ROLE_DETECTOR_Y, ROLE_DETECTOR_X),
|
|
82
|
+
(0, 0, 0, 0),
|
|
83
|
+
)
|
|
84
|
+
load_preview_arrays(array, selection)
|
|
85
|
+
assert array.requests == [
|
|
86
|
+
(32, 32, slice(None), slice(None)),
|
|
87
|
+
(slice(None), slice(None), 64, 64),
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
|
|
63
91
|
def test_load_5d_dataset_with_fixed_index():
|
|
64
92
|
array = np.arange(2 * 3 * 4 * 5 * 6).reshape(2, 3, 4, 5, 6)
|
|
65
93
|
selection = DimensionSelection(
|
|
@@ -114,6 +142,20 @@ def test_preview_flattened_scan_reads_single_dp_and_axial_bf():
|
|
|
114
142
|
np.testing.assert_array_equal(previews.axial_bf, array[:, 2, 2].reshape(2, 3))
|
|
115
143
|
|
|
116
144
|
|
|
145
|
+
def test_preview_flattened_scan_uses_two_source_slice_reads():
|
|
146
|
+
array = RecordingArray((4096, 128, 128))
|
|
147
|
+
selection = DimensionSelection(
|
|
148
|
+
(ROLE_FLATTENED_SCAN, ROLE_DETECTOR_Y, ROLE_DETECTOR_X),
|
|
149
|
+
(0, 0, 0),
|
|
150
|
+
((64, 64), None, None),
|
|
151
|
+
)
|
|
152
|
+
load_preview_arrays(array, selection)
|
|
153
|
+
assert array.requests == [
|
|
154
|
+
(2080, slice(None), slice(None)),
|
|
155
|
+
(slice(None), 64, 64),
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
|
|
117
159
|
def test_flattened_scan_axis_can_follow_fixed_dimensions():
|
|
118
160
|
array = np.arange(2 * 6 * 4 * 5).reshape(2, 6, 4, 5)
|
|
119
161
|
selection = DimensionSelection(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|