cdi-stools 0.3.2__tar.gz → 0.3.4__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 (29) hide show
  1. cdi_stools-0.3.4/CHANGELOG.md +229 -0
  2. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/PKG-INFO +85 -70
  3. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/README.md +82 -67
  4. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/pyproject.toml +6 -6
  5. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/__init__.py +1 -1
  6. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/bcdi_core.py +24 -18
  7. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/bcdi_gui.py +47 -8
  8. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_infer.py +75 -62
  9. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_data_generator.py +4 -4
  10. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_demo.py +1 -1
  11. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_experimental_loader.py +62 -45
  12. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_gui_tabs.py +517 -629
  13. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_phase_model.py +3 -3
  14. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_phase_retrieval.py +4 -4
  15. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_train.py +3 -3
  16. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_visualize.py +4 -4
  17. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/recon.py +112 -33
  18. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/viz3d.py +1 -1
  19. cdi_stools-0.3.2/CHANGELOG.md +0 -111
  20. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/LICENSE +0 -0
  21. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/CDI_ST_logo.png +0 -0
  22. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/__main__.py +0 -0
  23. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/facets.py +0 -0
  24. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_model.py +0 -0
  25. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_train.py +0 -0
  26. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/nn_dataset.py +0 -0
  27. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/ortho.py +0 -0
  28. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/requirements.txt +0 -0
  29. {cdi_stools-0.3.2 → cdi_stools-0.3.4}/src/cdi_st/trainlog.py +0 -0
@@ -0,0 +1,229 @@
1
+ # Changelog
2
+
3
+ ## [0.3.4] - 2026-11-23
4
+
5
+ ### Fixed
6
+
7
+ - **R-factor was not comparable between modes, and could look good for a failed reconstruction.**
8
+ - **R is now shown with two references**, so a number such as 0.12 can be judged:
9
+ the noise level (the R this result would reach if it were exactly right, from
10
+ Poisson statistics of the data) and the R of a featureless sphere (no phase
11
+ retrieval at all). The result is labelled *fits the data to the noise level*,
12
+ *partial fit*, *not reconstructed*, or *data too noisy to judge* when even a
13
+ featureless sphere fits within the noise. Checked on 56 cases from 10^2 counts to
14
+ noise-free data with no wrong label.
15
+ - **Crash after an HIO/RAAR/ER only reconstruction** (`cannot convert float NaN to integer`).
16
+ The object was centred but its support was not, so the two could stop
17
+ overlapping. They now move together, and the display falls back to the array
18
+ centre when there is nothing to weigh. Phase-ramp removal in the classical path
19
+ is now exact.
20
+ - **AutoPhase_NN alone lost most of the network's phase.** Centring the object
21
+ shifted the amplitude first and then masked the phase with the already shifted
22
+ box, so wherever the network placed the object off centre its phase was set to
23
+ zero (36 to 100 % of the object in tests). The refinement modes started from this
24
+ flat phase too. The object is now moved as one complex array by whole voxels,
25
+ which leaves |F| unchanged. Refined results are as good as before.
26
+
27
+ ### Changed
28
+
29
+ - 3D viewer render styles: **Point cloud** (default), **Isosurface**, a smooth
30
+ solid whose cut face, with the clip plane, shows the field inside; **Surface
31
+ only**, the outer skin, hollow when cut.
32
+ - **Render quality changes only how finely the object is drawn.** The values, the
33
+ colour scale, the iso level and the smoothing are identical at every level;
34
+ quality sets the mesh resolution and, for very large reconstructions, how many
35
+ points are drawn.
36
+ - **Live preview** replaces Auto-update view: a quick draft while you drag, full
37
+ quality when you stop, rotation and zoom kept.
38
+ - Reconstruction modes name the networks as their tabs do: AutoPhase_NN, CDI_NN.
39
+
40
+ ### Known issues
41
+
42
+ - Some real P10 scans are converting incorrectly; under investigation...
43
+
44
+ ## [0.3.3] - 2026-11-17
45
+
46
+ ### Fixed
47
+
48
+ - **Some missing reflections for hexagonal and rhombohedral materials.**
49
+
50
+ - A reflection typed as any member of its family is now found. Previously only
51
+ the stored representative and its Friedel mate matched, so `(0 -1 10)` in
52
+ corundum reported "not found" even though the peak was in the table under
53
+ another label.
54
+ - Window no longer open larger than the screen.
55
+ - The Beam tab's control column scrolls instead of being squeezed
56
+ - `BCDISimulator.simulate()` returned `None` when called without a progress
57
+ callback: `if progress_cb: progress_cb(100);return ...etc` put the `return` inside
58
+ the `if`. Present since 0.2.2 and invisible from the GUI, which always passes a
59
+ callback, but it made the simulator unusable from a script.
60
+
61
+ ### Added
62
+
63
+ - **Reconstruction without a neural network.** A `HIO/RAAR/ER only` mode runs the
64
+ standard iterative algorithms from a random start with no checkpoint file, and
65
+ without importing PyTorch at all, so it works on a machine that cannot run a
66
+ network.
67
+ - **Render quality control in the 3D viewer**, chosen before rendering: Draft
68
+ (15,000 points), Standard (60,000, the default), High (200,000) and Maximum
69
+ (1,000,000).
70
+
71
+ ### Changed
72
+
73
+ - Turbo is the default colormap in the 3D viewer; magma and cividis added.
74
+ - The checkpoint field is disabled when a mode needs no network.
75
+
76
+ ## [0.3.2] - 2026-11-08
77
+
78
+ ### Fixed
79
+
80
+ - The launcher window was missing: `main()` opened the simulation window
81
+ directly, so the data-analysis tabs were unreachable from the installed
82
+ package. The v0.3.0 rewrite of `bcdi_gui.py` had dropped `Launcher`,
83
+ `CDIStSplash`, `MW_Analysis` and `ReportsDialog`. All four are restored, and
84
+ `MW_Sim` keeps its Reports & Suggestions button.
85
+
86
+ ## [0.3.1] - 2026-11-08
87
+
88
+ ### Fixed
89
+
90
+ - `ModuleNotFoundError: No module named 'bcdi_core'` on launch. Imports are
91
+ now package-relative, with a fallback so the files still run directly from a
92
+ plain folder.
93
+
94
+ ## [0.3.0] - 2026-11-08
95
+
96
+ Faceted particles, photon-budget noise, detector/sample space, standalone phase
97
+ retrieval and training diagnostics.
98
+
99
+ With thanks to **Dr. Gerards Hinsley**, whose review of v0.2.2 prompted most of
100
+ the changes in this release: the facet options, the photon-count control, the
101
+ detector-space toggle, the standalone reconstruction path, the training log, and
102
+ the corrections to the noise model and colour-scale controls.
103
+
104
+ ### Added
105
+
106
+ **Simulation**
107
+ - Crystallographic facet shapes built from a Wulff half-space construction
108
+ (`facets.py`): octahedron, cuboctahedron, truncated octahedron, truncated cube,
109
+ rhombic dodecahedron, tunable Wulff, and hexagonal prism / bipyramid /
110
+ truncated bipyramid. Facet normals come from the reciprocal lattice, so the
111
+ construction is correct for every crystal system.
112
+ - Facet multiplicities control: a ratio of facet distances, off by default,
113
+ enabled by a tick box, with a plain-language tooltip giving the shape each
114
+ value produces.
115
+ - Particle size entered directly in nm; supercell multiples follow from the
116
+ lattice vectors. Cell limit raised from 2500 to 100000 per axis, with a size
117
+ notice above 2M atoms and a confirmation above 10M.
118
+ - Photon number: the pattern is scaled to a chosen number of photons before
119
+ Poisson sampling, so the counting statistics mean something. The field accepts
120
+ scientific notation (1e9, 2.5e12).
121
+ - Detector / sample space toggle. `ortho.det_matrix` builds the real
122
+ (dq/dpx, dq/dpy, dq/drocking) transform; the Results tab switches between the
123
+ orthogonal lab q grid and the raw skewed detector grid and reports the skew.
124
+ - Custom 2theta with a live readout: the offset from the nearest reflection, the
125
+ resulting dq, and the peak shift in both simulation voxels and real detector
126
+ pixels, with a warning when the peak leaves the frame.
127
+ - Prismatic dislocation loop alongside the existing line dislocations.
128
+ - Separate simulation grid control, independent of the detector panel size.
129
+ - Visualization controls (bonds, strain, dislocation) grouped together.
130
+
131
+ ### Changed
132
+
133
+ - Read noise is applied only to integrating detectors. Hybrid photon-counting
134
+ detectors (EIGER, PILATUS, MAXIPIX, MERLIN, TIMEPIX) have Poisson statistics
135
+ only, and the Readout option disables itself when one is selected.
136
+ - Noise controls are named per effect.
137
+ - Default simulation grid raised from 128 to 192, giving 2.25x the pixels in the
138
+ 2D slices for about 2 s per simulation.
139
+ - Frame transform uses cubic interpolation (0.7% round-trip error, against 3.6%
140
+ for linear).
141
+
142
+ ### Fixed
143
+
144
+ - The simulation grid was capped by the detector panel size, so a 128 x 128
145
+ panel forced 128^3 slices regardless of the grid setting.
146
+ - Reflections are labelled by their canonical Friedel mate, so selecting (1 1 1)
147
+ no longer displays (-1 -1 -1).
148
+ - `select_reflection` returns full-precision d, 2theta, q, |F|^2 and LP. It
149
+ previously used the four-decimal values rounded for the table.
150
+ - Half-voxel registration error in the detector/lab transform. An orthogonal
151
+ transform is now an exact no-op for any q-grid convention.
152
+ - Shrinkwrap could inflate the support until the algorithm fit the noise (89% of
153
+ the array at 1e5 counts). An absolute cap keeps reconstructions stable from
154
+ 1e3 to 1e8 photons.
155
+ - Selecting a large detector preset set the transform size to the full panel:
156
+ Eiger2 4M attempted a 2068^3 complex FFT, about 140 GB.
157
+ - The facet ratio control was not read when building, and the large-supercell
158
+ notice was missing.
159
+
160
+ ## [0.2.2] - 2026-06-18
161
+
162
+ ### Fixed
163
+ - **ID01 SPEC+EDF conversion now tolerates missing edge frames.**
164
+ Acquisitions are sometimes started a frame late or stopped a frame
165
+ early, so a SPEC scan can list frames 262–662 (401 points) while the
166
+ EDF directory only has 263–661 (399 files). The converter now probes
167
+ the disk first, loads only the EDF files that actually exist, and
168
+ trims the per-frame motor arrays (`eta`, `phi`, `nu`, `delta`,
169
+ `mpx4inr`) to stay in lock-step with the loaded data. A clear note
170
+ identifies which leading / trailing / interior frames were skipped.
171
+ New helper `_filter_existing_edf_frames()` exposes this filtering for
172
+ programmatic use.
173
+
174
+ ## [0.2.1] - 2026-06-15
175
+
176
+ ### Added
177
+ - **PETRA III P10 / DESY Eiger compressed-data support.** Auto-imports
178
+ `hdf5plugin` at module load so bitshuffle + LZ4 compressed datasets
179
+ (the Eiger default at DESY P10 and many other beamlines) read
180
+ transparently. `hdf5plugin>=4.0` is now a runtime dependency.
181
+ - **HDF5 external-link resolution.** The P10 loader now enumerates and
182
+ resolves external links in master files instead of relying on h5py's
183
+ default link-following, which was unreliable on Windows.
184
+ - **Scan range selection for P10** (new in the P10 converter dialog)
185
+ similar to the ID01 SPEC+EDF scan browser. Avoids loading 49 GB of
186
+ detector frames into RAM when you only need the rocking-curve maximum
187
+
188
+ ### Fixed
189
+ - AutoPhase_NN tab missing `_on_epoch` slot..
190
+ - Training Stop button no longer crashes the program.
191
+
192
+ ### Changed
193
+ - Live training curve in AutoPhase_NN and CDI_NN.
194
+ - `inspect_h5()` now properly shows external links with their target
195
+ files and `[OK]` / `[MISSING]` markers.
196
+
197
+ ## [0.1.0] - Alpha - 2026-05-08
198
+
199
+ ### Added
200
+ - **Initial public release** of CDI-ST as a packaged Python application.
201
+ - BCDI Simulation module (Material → Beam → Results)
202
+ - Material presets: Si, Ge, Pt, Au, SiC, GaAs, and more
203
+ - CIF import for arbitrary crystals
204
+ - Particle shapes: cube, sphere, cylinder, hexagonal prism, octahedron, dodecahedron
205
+ - Strain fields: radial gradient, edge dislocation, random
206
+ - Configurable line dislocations: edge / screw / mixed with arbitrary Burgers vector
207
+ - 3D atomic lattice viewer (Plotly)
208
+ - Detector presets: Maxipix 2×2, Eiger 2M, custom rectangular
209
+ - Analytical and FFT simulation paths
210
+ - BCDI Data Analysis module (Generate Data → AutoPhase_NN → CDI_NN → Reconstruction → 3D Viewer)
211
+ - Training-data generator with random material/shape/size/strain/dislocation
212
+ - Toggles for randomized strain and dislocations
213
+ - AutoPhaseNN (unsupervised, dual-decoder, physics-driven loss)
214
+ - CDI_NN (supervised, BCDI loss with α/β/γ weights)
215
+ - Inference: NN-only, refined (HIO+RAAR+ER), ensemble, compare
216
+ - Iterative phase retrieval: HIO (β=0.9), RAAR (β=0.9), ER, with shrink-wrap
217
+ - Experimental data loader: HDF5, ID01 SPEC+EDF, q-space orthogonalization
218
+ - Detector chip-gap masking, hot pixel removal, beamstop streak removal
219
+ - 3D viewer with point cloud / isosurface / surface-only modes
220
+ - Per-voxel opacity weighted by intensity
221
+ - VTI export for ParaView
222
+ - Splash screen and theme-matched launcher
223
+ - Cross-platform support (Linux, macOS, Windows) via PyQt6
224
+
225
+ ### Known limitations (alpha)
226
+ - Q-space orthogonalization is only ID01-specific
227
+ - Some checkpoints from earlier prototypes lack `grid_size` metadata
228
+ - Mask-aware modulus constraint not yet implemented (gaps are filled instead)
229
+ - VTI export is exporting a 2D slice, will be fixed.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cdi-stools
3
- Version: 0.3.2
4
- Summary: Coherent Diffraction Imaging Simulation Tools — BCDI simulation and NN-based phase retrieval
3
+ Version: 0.3.4
4
+ Summary: Coherent Diffraction Imaging Simulation Tools: BCDI simulation and NN-based phase retrieval
5
5
  Project-URL: Homepage, https://github.com/SAIDIsoufiane/CDI-St
6
6
  Project-URL: Documentation, https://github.com/SAIDIsoufiane/CDI-St#readme
7
7
  Project-URL: Repository, https://github.com/SAIDIsoufiane/CDI-St
@@ -11,7 +11,7 @@ Author-email: Soufiane SAIDI <saidisoufiane@hotmail.com>
11
11
  License-Expression: MIT
12
12
  License-File: LICENSE
13
13
  Keywords: BCDI,Bragg coherent diffraction imaging,ID01,X-ray diffraction,crystallography,neural network,phase retrieval,synchrotron
14
- Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Development Status :: 4 - Beta
15
15
  Classifier: Environment :: X11 Applications :: Qt
16
16
  Classifier: Intended Audience :: Science/Research
17
17
  Classifier: License :: OSI Approved :: MIT License
@@ -53,9 +53,9 @@ Description-Content-Type: text/markdown
53
53
 
54
54
  <img src="docs/screenshots/CDI_ST_logo.png" alt="CDI-ST" width="600"/>
55
55
 
56
- # CDI-ST
56
+ # CDI-St
57
57
 
58
- **Coherent Diffraction Imaging — Simulation Tools**
58
+ **Coherent Diffraction Imaging - Simulation Tools**
59
59
 
60
60
  An end-to-end Bragg Coherent Diffraction Imaging (BCDI) Python application using low computational resources with an easy to learn GUI:
61
61
  crystal lattice construction, X-ray scattering simulation, neural-network phase retrieval,
@@ -64,7 +64,7 @@ and 3D visualization, in a single GUI.
64
64
  [![PyPI version](https://img.shields.io/pypi/v/cdi-stools.svg)](https://pypi.org/project/cdi-stools/)
65
65
  [![Python](https://img.shields.io/pypi/pyversions/cdi-stools.svg)](https://pypi.org/project/cdi-stools/)
66
66
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
67
- [![Status](https://img.shields.io/badge/status-alpha-orange.svg)]()
67
+ [![Status](https://img.shields.io/badge/status-beta-blue.svg)]()
68
68
 
69
69
  </div>
70
70
 
@@ -78,8 +78,8 @@ and 3D visualization, in a single GUI.
78
78
  </tr>
79
79
  <tr>
80
80
  <td align="center"><sub>Launcher</sub></td>
81
- <td align="center"><sub>Material — crystal builder</sub></td>
82
- <td align="center"><sub>Results — simulated Bragg peak</sub></td>
81
+ <td align="center"><sub>Material - crystal builder</sub></td>
82
+ <td align="center"><sub>Results - simulated Bragg peak</sub></td>
83
83
  </tr>
84
84
  <tr>
85
85
  <td><img src="docs/screenshots/3d_viewer.png" width="280"/></td>
@@ -87,9 +87,9 @@ and 3D visualization, in a single GUI.
87
87
  <td><img src="docs/screenshots/reconstruction.png" width="280"/></td>
88
88
  </tr>
89
89
  <tr>
90
- <td align="center"><sub>3D Viewer — diffraction simulation</sub></td>
90
+ <td align="center"><sub>3D Viewer - diffraction simulation</sub></td>
91
91
  <td align="center"><sub>2D reconstruction</sub></td>
92
- <td align="center"><sub>3D Viewer — reconstruction</sub></td>
92
+ <td align="center"><sub>3D Viewer - reconstruction</sub></td>
93
93
  </tr>
94
94
  </table>
95
95
 
@@ -125,7 +125,7 @@ intensity around a Bragg peak. The intensity gives only |F(q)|², so reconstruct
125
125
  must recover the missing phase by iterative algorithms (HIO, RAAR, ER),
126
126
  more recently by neural networks.
127
127
 
128
- **CDI-ST integrates the entire workflow into one tool:**
128
+ **CDI-St integrates the entire workflow into one tool:**
129
129
 
130
130
  | Step | What you do | Where in the GUI |
131
131
  |---|---|---|
@@ -134,18 +134,18 @@ more recently by neural networks.
134
134
  | 3. Simulate diffraction | Compute the 3D Bragg peak | **BCDI Simulation → Results** |
135
135
  | 4. Generate training data | Build a labeled dataset of (object, diffraction) pairs | **BCDI Data Analysis → Generate Data** |
136
136
  | 5. Train an unsupervised NN | AutoPhase_NN: physics-driven, no ground truth | **BCDI Data Analysis → AutoPhase_NN** |
137
- | 6. Train a supervised NN | CDI_NN: PhaseUNet3D learning the phase mapping | **BCDI Data Analysis → CDI_NN** |
138
- | 7. Reconstruct | NN → optionally refine with HIO/RAAR/ER | **BCDI Data Analysis → Reconstruction** |
137
+ | 6. Train a supervised NN | CDI_NN: learning the phase mapping | **BCDI Data Analysis → CDI_NN** |
138
+ | 7. Reconstruct | HIO/RAAR/ER on their own, or a network seed refined by them | **BCDI Data Analysis → Reconstruction** |
139
139
  | 8. Visualize and export | Interactive 3D viewer, ParaView VTI export | **BCDI Data Analysis → 3D Viewer** |
140
140
 
141
141
  ---
142
142
 
143
143
  ## The simulation pipeline
144
144
 
145
- ### 1. Material — build the crystal
145
+ ### 1. Material : build the crystal
146
146
 
147
- Choose from preset materials (Si, Ge, Pt, Au, SiC, GaAs, ...) or import a custom
148
- CIF file. The crystal is built atom-by-atom from the unit cell, replicated to the
147
+ Choose from the preset materials (Al, Cu, Au, Pt, W, Fe, Si, Ge, SiC (3C and 4H),
148
+ ZnO, GaN, Te, Fe3GeTe2, Fe5GeTe2) or import any CIF file. The crystal is built atom-by-atom from the unit cell, replicated to the
149
149
  requested supercell size.
150
150
 
151
151
  You can:
@@ -158,9 +158,13 @@ You can:
158
158
 
159
159
  The 3D lattice view (powered by Plotly) shows every atom in the supercell.
160
160
 
161
- ### 2. Beam — define the X-ray geometry
161
+ ### 2. Beam : define the X-ray geometry
162
162
 
163
- Select a reflection (h k l) from the auto-computed list of allowed peaks.
163
+ Select a reflection (h k l) from the auto-computed list of allowed peaks. The
164
+ search bounds each index separately from the geometry, so materials with a long
165
+ c axis keep their high-l reflections: `(0 0 6)` for Fe3GeTe2, `(0 0 8)` for
166
+ 4H-SiC, `(0 0 6)` and `(0 -1 10)` for corundum. Typing any member of a family
167
+ finds that family, whichever member the table happens to list.
164
168
  The Beam tab also lets you set:
165
169
  - **Beam energy** (and the resulting wavelength)
166
170
  - **Detector geometry**: pixel pitch, sample-to-detector distance, detector size
@@ -169,9 +173,9 @@ The Beam tab also lets you set:
169
173
 
170
174
  Detector preset auto-fills the geometry parameters.
171
175
 
172
- ### 3. Results — run the simulation
176
+ ### 3. Results : run the simulation
173
177
 
174
- CDI-ST computes the diffraction in **two paths**:
178
+ CDI-St computes the diffraction in **two paths**:
175
179
 
176
180
  - **Analytical path** (cube/rectangular shapes, no strain): closed-form Fourier transform of the support
177
181
  - **FFT path** (any shape, any strain field): full 3D FFT of the complex object
@@ -186,7 +190,7 @@ or for use as ground truth when training NNs.
186
190
 
187
191
  ## The data-analysis pipeline
188
192
 
189
- ### 4. Generate Data — create training samples
193
+ ### 4. Generate Data : create training samples
190
194
 
191
195
  Generates a dataset of synthetic BCDI samples for NN training. Each sample
192
196
  contains the ground-truth phase, support, and the simulated diffraction
@@ -202,7 +206,7 @@ intensity. You control:
202
206
  Samples save as `sample_XXXXX.npz` and a `manifest.json`. Generation is
203
207
  parallelizable and resumable.
204
208
 
205
- ### 5. AutoPhase_NN — unsupervised physics-driven NN
209
+ ### 5. AutoPhase_NN : unsupervised physics-driven NN
206
210
 
207
211
  AutoPhase_NN is a 3D dual-decoder convolutional network that learns to invert the
208
212
  Fourier modulus constraint **without ground truth**. It predicts the object's
@@ -214,93 +218,104 @@ et al. npj Computational Materials 8.1 (2022) ) reimplemented for this codebase.
214
218
  Training is GPU-accelerated (CUDA preferred) and converges in a few dozen
215
219
  epochs on 2,000+ samples. The best checkpoint is saved automatically.
216
220
 
217
- ### 6. CDI_NN — supervised PhaseUNet3D
221
+ ### 6. CDI_NN : supervised 3D U-Net
218
222
 
219
223
  A 3D U-Net that predicts the phase field from the diffraction magnitude, trained
220
224
  against the ground-truth phase from the data generator.
221
225
 
222
226
  Use AutoPhase_NN when you don't trust your simulator's ground truth (or have
223
227
  none). Use CDI_NN when you have a high-fidelity simulator and want a direct
224
- mapping. Use both via the **ensemble** mode in the Reconstruction tab.
228
+ mapping. Use both via **Both networks averaged** in the Reconstruction tab.
225
229
 
226
- ### 7. Reconstruction — invert experimental or simulated data
230
+ ### 7. Reconstruction : invert experimental or simulated data
227
231
 
228
232
  Load any `.npz` (simulated) or `.h5` (experimental) BCDI file, or convert a
229
233
  SPEC + EDF scan from ID01 directly via the dialog. Choose:
230
234
 
231
- - **NN-only (Autophase_NN)**: forward pass, twin-image suppression, COM centering
232
- - **Refined**: NN seed → HIO + RAAR + ER iterative phase retrieval
233
- - **Ensemble**: AutoPhase_NN + CDI_NN combined, optionally refined
234
- - **Compare**: runs both modes side-by-side
235
+ - **AutoPhase_NN → HIO/RAAR/ER refinement**: network seed, then the classical
236
+ algorithms polish it. The default and best choice.
237
+ - **AutoPhase_NN alone**: one forward pass (~100 ms), with twin-image
238
+ suppression and centring. The result is the network's object, its largest
239
+ connected region above 10 % of its maximum. A quick look.
240
+ - **HIO/RAAR/ER only (no neural network)**: the standard iterative algorithms
241
+ from a random start. No checkpoint, no PyTorch, nothing trained - this is the
242
+ option to use if you cannot run a network, and it is what most published BCDI
243
+ work uses.
244
+ - **Both networks averaged (AutoPhase_NN + CDI_NN)**, optionally refined:
245
+ averaging two independent guesses cancels some of the error each makes alone.
246
+ Needs the second checkpoint. (still in need of further work)
247
+
248
+ If refinement comes out worse than the network alone, the network output is kept.
235
249
 
236
250
  The output is a complex object (amplitude + phase), a binary support, the
237
251
  R-factor convergence curve, and 2D slices at the COM of the reconstruction.
252
+ Every mode reports the same R-factor, R = sum| k|F| - sqrt(I) | / sum sqrt(I), with
253
+ k chosen so the model and the data hold the same total intensity. R alone cannot
254
+ say whether a value is good, because its floor depends on the counting statistics,
255
+ so it is shown with two references from the same data: the **noise level** (the R
256
+ the result would reach if it were exactly right) and the R of a **featureless
257
+ sphere** (no phase retrieval at all). The result is then labelled *fits the data to
258
+ the noise level*, *partial fit*, *not reconstructed*, or *data too noisy to judge*
259
+ when the counts are too low for any reconstruction to be told apart from a
260
+ featureless object. R measures how well a result explains the measured
261
+ intensities, not whether it is the unique right object.
238
262
 
239
263
  For experimental data, the loader handles:
264
+ - Invalid-pixel flags: EIGER and other counting detectors write the largest
265
+ integer (4294967295 for 32-bit data) into gap, dead and saturated pixels; these
266
+ are zeroed as each frame is read, so they cannot be mistaken for the Bragg peak
240
267
  - Detector chip-gap masking (Maxipix, Eiger)
241
268
  - Hot-pixel removal
242
269
  - Beamstop / direct-beam streak removal
243
270
  - Bragg-peak-centered cropping
244
271
  - Optional q-space orthogonalization via xrayutilities (with `[id01]` extra)
245
272
 
246
- ### 8. 3D Viewer — interactive visualization
273
+ ### 8. 3D Viewer : interactive visualization
247
274
 
248
275
  The viewer renders the reconstruction in three modes:
249
276
 
250
277
  - **Point cloud**: every voxel above threshold, colored by amplitude / phase / strain,
251
278
  with per-voxel opacity weighted by intensity
252
- - **Isosurface**: smoothed iso-shell with internal data points showing through
253
- - **Surface only**: bare iso-mesh with edges visible
279
+ - **Isosurface**: the object as a smooth solid, coloured by the chosen field. Cut
280
+ it with the clip plane and the cut face is filled with the field inside, so a
281
+ dislocation or a strained region shows where the cut passes.
282
+ - **Surface only**: the outer skin alone, coloured by the field just beneath it;
283
+ hollow when cut
284
+
285
+ On both surfaces each point shows the outermost voxels of the object, as ParaView
286
+ colours a thresholded volume (on the surface itself the density equals the
287
+ threshold everywhere). The colour range comes from the voxels inside the surface
288
+ and is the same for all three styles.
289
+
290
+ Strain is computed from neighbour phase differences, so a 2π phase jump (for
291
+ example the branch cut around a dislocation) is not shown as false strain.
292
+
293
+ **Render quality** changes only how finely the object is drawn, never the data:
294
+ values, colour scale, iso level and smoothing are identical at every level. Draft
295
+ builds the surface from every second voxel, Standard at the reconstruction's own
296
+ resolution, High and Maximum on a 2× and 3× finer trilinear grid (capped at
297
+ 256³). The point cloud always draws the reconstruction's own voxels.
254
298
 
255
299
  Controls:
256
- - Threshold (% of peak amplitude), voxel size, opacity, colormap
300
+ - Threshold (% of peak amplitude), voxel size, opacity, colormap (Turbo by default)
257
301
  - Color scale auto / manual (`vmin` / `vmax`)
258
302
  - Clip plane on any axis
303
+ - **Live preview**: when on, the render follows every change of threshold,
304
+ voxel size, opacity, colormap, clip plane or field. A quick draft is drawn while
305
+ you drag and full quality follows when you stop; rotation and zoom are kept.
259
306
  - Mouse: left-drag rotate, right-drag pan, wheel zoom, double-click reset
260
307
  - Export PNG snapshot or VTI (ParaView)
261
308
 
262
309
  ---
263
310
 
264
- ## Project structure
265
-
266
- ```
267
- cdi-st/
268
- ├── src/cdi_st/
269
- │ ├── __init__.py
270
- │ ├── __main__.py # python -m cdi_st
271
- │ ├── bcdi_gui.py # main entry point + launcher + splash
272
- │ ├── bcdi_core.py # crystal builder, simulator, reflection calculator
273
- │ ├── nn_gui_tabs.py # all NN-related GUI tabs
274
- │ ├── nn_data_generator.py # training-data generator
275
- │ ├── nn_dataset.py # PyTorch Dataset wrapper
276
- │ ├── nn_phase_model.py # PhaseUNet3D (supervised)
277
- │ ├── nn_autophase_model.py # AutoPhaseNet3D (unsupervised)
278
- │ ├── nn_train.py # supervised training CLI
279
- │ ├── nn_autophase_train.py # unsupervised training CLI
280
- │ ├── nn_phase_retrieval.py # HIO / RAAR / ER iterative algorithms
281
- │ ├── nn_autophase_infer.py # inference: nn_only / refined / ensemble
282
- │ ├── nn_experimental_loader.py # h5/spec/edf loading + preprocessing
283
- │ ├── nn_demo.py
284
- │ ├── nn_visualize.py
285
- │ └── CDI_ST_logo.png
286
- ├── tests/
287
- ├── docs/
288
- ├── pyproject.toml
289
- ├── README.md
290
- ├── LICENSE
291
- └── CHANGELOG.md
292
- ```
293
-
294
- ---
295
-
296
311
  ## Citing
297
312
 
298
- If you use CDI-ST in published research, please cite:
313
+ If you use CDI-St in published research, please cite:
299
314
 
300
315
  ```bibtex
301
316
  @software{saidi_cdi_st_2026,
302
317
  author = {Saidi, Soufiane},
303
- title = {CDI-ST: Coherent Diffraction Imaging — Simulation Tools},
318
+ title = {CDI-St: Coherent Diffraction Imaging - Simulation Tools},
304
319
  year = {2026},
305
320
  publisher = {GitHub},
306
321
  url = {https://github.com/Refze/CDI-St}
@@ -311,11 +326,11 @@ If you use CDI-ST in published research, please cite:
311
326
 
312
327
  ## License
313
328
 
314
- MIT — see [LICENSE](LICENSE).
329
+ MIT, see [LICENSE](LICENSE).
315
330
 
316
331
  ## Author
317
332
 
318
- **Soufiane SAIDI** — saidisoufiane@hotmail.com
333
+ **Soufiane SAIDI** - saidisoufiane@hotmail.com
319
334
 
320
335
  We heavily encourage you to use the in-app **Reports & Suggestions** button to send any type of feedback.
321
336
 
@@ -327,4 +342,4 @@ Built on the shoulders of the BCDI and python community:
327
342
  [PyNX](https://pynx.esrf.fr/), [BCDI-Utilities](https://github.com/carnisj/bcdi),
328
343
  [cdiutils](https://github.com/clatlan/cdiutils), [Atomsk](https://atomsk.univ-lille.fr/) , [xrayutilities](https://xrayutilities.sourceforge.io/),
329
344
  [scikit-image](https://scikit-image.org/), [PyQt6](https://www.riverbankcomputing.com/software/pyqt/),
330
- and the AutoPhaseNN paper by Yao et al. (2022).
345
+ and the AutoPhaseNN paper by Yao et al.(2022) (https://doi.org/10.1038/s41524-022-00803-w).