cdi-stools 0.3.3__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 (28) hide show
  1. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/CHANGELOG.md +59 -90
  2. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/PKG-INFO +56 -31
  3. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/README.md +53 -28
  4. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/pyproject.toml +6 -6
  5. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/__init__.py +1 -1
  6. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/bcdi_gui.py +32 -4
  7. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_infer.py +75 -62
  8. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_data_generator.py +4 -4
  9. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_demo.py +1 -1
  10. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_experimental_loader.py +62 -45
  11. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_gui_tabs.py +395 -630
  12. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_phase_model.py +3 -3
  13. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_phase_retrieval.py +4 -4
  14. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_train.py +3 -3
  15. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_visualize.py +4 -4
  16. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/recon.py +112 -33
  17. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/LICENSE +0 -0
  18. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/CDI_ST_logo.png +0 -0
  19. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/__main__.py +0 -0
  20. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/bcdi_core.py +0 -0
  21. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/facets.py +0 -0
  22. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_model.py +0 -0
  23. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_autophase_train.py +0 -0
  24. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/nn_dataset.py +0 -0
  25. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/ortho.py +0 -0
  26. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/requirements.txt +0 -0
  27. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/trainlog.py +0 -0
  28. {cdi_stools-0.3.3 → cdi_stools-0.3.4}/src/cdi_st/viz3d.py +0 -0
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
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
+
3
44
  ## [0.3.3] - 2026-11-17
4
45
 
5
46
  ### Fixed
@@ -25,24 +66,12 @@
25
66
  network.
26
67
  - **Render quality control in the 3D viewer**, chosen before rendering: Draft
27
68
  (15,000 points), Standard (60,000, the default), High (200,000) and Maximum
28
- (1,000,000). Higher settings also smooth the isosurface less, so density and
29
- strain stay distinguishable. Measured on a 128^3 reconstruction with 268,000
30
- support voxels: 0.4 s, 0.5 s, 1.4 s and 1.4 s respectively. The old viewer was
31
- fixed at 15,000 points and 4,000 interior points, with no way to change them.
32
- - **Auto-update view** toggle. With it on, changing any viewer setting re-renders
33
- without pressing "Update view". Changes are coalesced for 450 ms so dragging a
34
- slider does not start a render on every step.
69
+ (1,000,000).
35
70
 
36
71
  ### Changed
37
72
 
38
73
  - Turbo is the default colormap in the 3D viewer; magma and cividis added.
39
- - Reconstruction modes are named in plain language and name the networks:
40
- "AutoPhaseNet -> HIO/RAAR/ER refinement", "AutoPhaseNet alone (fast, rough)",
41
- "HIO/RAAR/ER only - no neural network", "Both networks averaged
42
- (AutoPhaseNet + PhaseUNet3D)". `nn_only` and `ensemble` are no longer shown to
43
- the user; the internal keys are unchanged so saved settings keep working.
44
74
  - The checkpoint field is disabled when a mode needs no network.
45
- - Simulation tabs are named "Material", "Beam", "Results" without numbering.
46
75
 
47
76
  ## [0.3.2] - 2026-11-08
48
77
 
@@ -58,9 +87,7 @@
58
87
 
59
88
  ### Fixed
60
89
 
61
- - `ModuleNotFoundError: No module named 'bcdi_core'` on launch. The modules
62
- imported each other as top-level names, which works when the files sit
63
- together in one folder but not from inside the `cdi_st` package. Imports are
90
+ - `ModuleNotFoundError: No module named 'bcdi_core'` on launch. Imports are
64
91
  now package-relative, with a fallback so the files still run directly from a
65
92
  plain folder.
66
93
 
@@ -101,40 +128,23 @@ the corrections to the noise model and colour-scale controls.
101
128
  - Separate simulation grid control, independent of the detector panel size.
102
129
  - Visualization controls (bonds, strain, dislocation) grouped together.
103
130
 
104
- **Data processing**
105
- - read reconstructions from `.npz`, `.npy`, `.h5`, `.cxi`,
106
- `.nxs` and `.mat`, including PyNX `/entry_1/image_1/data` and amplitude/phase
107
- pairs, so work reconstructed outside CDI-St can be loaded.
108
- - per-step training log (`.log` + `.jsonl`) that flags NaN/Inf
109
- losses, non-finite gradients and weights, and loss spikes, then dumps input
110
- statistics and the likely cause. `scan_dataset()` pre-flights a training set.
111
-
112
131
  ### Changed
113
132
 
114
133
  - Read noise is applied only to integrating detectors. Hybrid photon-counting
115
134
  detectors (EIGER, PILATUS, MAXIPIX, MERLIN, TIMEPIX) have Poisson statistics
116
135
  only, and the Readout option disables itself when one is selected.
117
- - Noise controls are named per effect (Poisson / Readout / Air / Dead px /
118
- Hot px) instead of a single "Add noise", and all are off by default, so the
119
- ideal pattern is what you see until you ask for noise.
136
+ - Noise controls are named per effect.
120
137
  - Default simulation grid raised from 128 to 192, giving 2.25x the pixels in the
121
138
  2D slices for about 2 s per simulation.
122
- - The simulation panel is resizable; the fixed 520 px left column is a splitter.
123
139
  - Frame transform uses cubic interpolation (0.7% round-trip error, against 3.6%
124
140
  for linear).
125
141
 
126
142
  ### Fixed
127
143
 
128
- - Poisson noise was on by default and applied the photon budget unconditionally,
129
- which quantised 83% of the volume to zero counts and erased the weak fringes
130
- in the 3D peak and the 2D slices. Noise is now opt-in.
131
144
  - The simulation grid was capped by the detector panel size, so a 128 x 128
132
- panel forced 128^3 slices regardless of the grid setting. Panel geometry
133
- (exported as metadata) and simulation grid are now independent.
145
+ panel forced 128^3 slices regardless of the grid setting.
134
146
  - Reflections are labelled by their canonical Friedel mate, so selecting (1 1 1)
135
- no longer displays (-1 -1 -1). Both label the same physical peak; the hkl
136
- search simply reached the negative representative first. The raw index is kept
137
- as `hkl_raw`.
147
+ no longer displays (-1 -1 -1).
138
148
  - `select_reflection` returns full-precision d, 2theta, q, |F|^2 and LP. It
139
149
  previously used the four-decimal values rounded for the table.
140
150
  - Half-voxel registration error in the detector/lab transform. An orthogonal
@@ -147,7 +157,7 @@ the corrections to the noise model and colour-scale controls.
147
157
  - The facet ratio control was not read when building, and the large-supercell
148
158
  notice was missing.
149
159
 
150
- ## [0.2.2] — 2026-06-18
160
+ ## [0.2.2] - 2026-06-18
151
161
 
152
162
  ### Fixed
153
163
  - **ID01 SPEC+EDF conversion now tolerates missing edge frames.**
@@ -161,7 +171,7 @@ the corrections to the noise model and colour-scale controls.
161
171
  New helper `_filter_existing_edf_frames()` exposes this filtering for
162
172
  programmatic use.
163
173
 
164
- ## [0.2.1] — 2026-06-15
174
+ ## [0.2.1] - 2026-06-15
165
175
 
166
176
  ### Added
167
177
  - **PETRA III P10 / DESY Eiger compressed-data support.** Auto-imports
@@ -170,61 +180,21 @@ the corrections to the noise model and colour-scale controls.
170
180
  transparently. `hdf5plugin>=4.0` is now a runtime dependency.
171
181
  - **HDF5 external-link resolution.** The P10 loader now enumerates and
172
182
  resolves external links in master files instead of relying on h5py's
173
- default link-following, which was unreliable on Windows. Each chunk is
174
- opened directly to bypass any path-mangling. Master files with hundreds
175
- of external links to chunk files (the standard Eiger layout) work out
176
- of the box.
183
+ default link-following, which was unreliable on Windows.
177
184
  - **Scan range selection for P10** (new in the P10 converter dialog)
178
185
  similar to the ID01 SPEC+EDF scan browser. Avoids loading 49 GB of
179
- detector frames into RAM when you only need the rocking-curve maximum:
180
- - **Probe scan** button reads chunk metadata only (no decompression),
181
- instantly reporting total frame count, detector shape, and estimated
182
- full-load memory footprint.
183
- - **Frame range** (`from`, `to`) reads only the requested global frame
184
- range across all chunks. Loaded chunk-by-chunk so memory scales with
185
- the chosen range, not the total dataset size.
186
- - **Detector ROI** reads a centered square ROI from each frame instead
187
- of the full detector. For BCDI you typically only need ~256×256
188
- around the Bragg peak — cuts memory by `(2167*2070)/(roi²)` for
189
- Eiger 4M data.
190
- - **Memory budget** (default 8 GB) the loader refuses reads that
191
- would exceed this and tells you which `frame_range` would fit,
192
- instead of crashing the Python process with an OOM error.
193
- - **Programmatic API additions** to `nn_experimental_loader`:
194
- `p10_scan_info()` for cheap metadata previews, plus new
195
- `frame_range`, `detector_roi`, `memory_budget_gb` parameters on
196
- `load_p10_from_external_links()` and `p10_h5_to_npz()`.
186
+ detector frames into RAM when you only need the rocking-curve maximum
197
187
 
198
188
  ### Fixed
199
- - Cryptic "Can't synchronously read data (can't open directory)" error
200
- on P10 / Eiger files. The message was HDF5 looking for the compression
201
- plugin DLL in a non-existent directory — now caught and converted to
202
- a clear "install hdf5plugin" instruction.
203
- - AutoPhase_NN tab missing `_on_epoch` slot (introduced in 0.2.0 during
204
- the live-curve refactor; AutoPhase_NN's `epoch_done` signal had no
205
- receiver and emitted unhandled errors). Restored.
206
- - CDI_NN `KeyError: 'phase_true'` — `BCDIDataset.__getitem__` now exposes
207
- the GUI's expected keys (`phase_true`, `amplitude`) alongside the legacy
208
- ones (`target_phase`, `input`).
209
- - `BCDIPhaseLoss` accepts both the GUI's descriptive kwargs (`alpha_amp`,
210
- `beta_phase`, `gamma_diff`, `diff_amp`) and the original short ones
211
- (`alpha`, `beta`, `gamma`, `amplitude`). Either spelling now works.
212
- - Training Stop button no longer crashes the program. `QThread.terminate()`
213
- was killing PyTorch mid-`backward()` and corrupting CUDA / autograd
214
- state — replaced with a cooperative `request_stop()` flag that the
215
- training loop checks at batch / epoch boundaries, then exits cleanly
216
- with a saved checkpoint.
189
+ - AutoPhase_NN tab missing `_on_epoch` slot..
190
+ - Training Stop button no longer crashes the program.
217
191
 
218
192
  ### Changed
219
- - Live training curve in AutoPhase_NN and CDI_NN the dashed "running"
220
- line updates every ~2 s during training so users can see progress
221
- immediately on slow CPU runs (rather than staring at a blank plot
222
- for an entire epoch).
193
+ - Live training curve in AutoPhase_NN and CDI_NN.
223
194
  - `inspect_h5()` now properly shows external links with their target
224
- files and `[OK]` / `[MISSING]` markers. The empty-looking `/entry/data/`
225
- group on Eiger masters is no longer misleading.
195
+ files and `[OK]` / `[MISSING]` markers.
226
196
 
227
- ## [0.1.0] — Alpha — 2026-05-08
197
+ ## [0.1.0] - Alpha - 2026-05-08
228
198
 
229
199
  ### Added
230
200
  - **Initial public release** of CDI-ST as a packaged Python application.
@@ -240,8 +210,8 @@ the corrections to the noise model and colour-scale controls.
240
210
  - BCDI Data Analysis module (Generate Data → AutoPhase_NN → CDI_NN → Reconstruction → 3D Viewer)
241
211
  - Training-data generator with random material/shape/size/strain/dislocation
242
212
  - Toggles for randomized strain and dislocations
243
- - AutoPhaseNet3D (unsupervised, dual-decoder, physics-driven loss)
244
- - PhaseUNet3D (supervised, BCDI loss with α/β/γ weights)
213
+ - AutoPhaseNN (unsupervised, dual-decoder, physics-driven loss)
214
+ - CDI_NN (supervised, BCDI loss with α/β/γ weights)
245
215
  - Inference: NN-only, refined (HIO+RAAR+ER), ensemble, compare
246
216
  - Iterative phase retrieval: HIO (β=0.9), RAAR (β=0.9), ER, with shrink-wrap
247
217
  - Experimental data loader: HDF5, ID01 SPEC+EDF, q-space orthogonalization
@@ -250,11 +220,10 @@ the corrections to the noise model and colour-scale controls.
250
220
  - Per-voxel opacity weighted by intensity
251
221
  - VTI export for ParaView
252
222
  - Splash screen and theme-matched launcher
253
- - In-app Reports & Suggestions feature
254
223
  - Cross-platform support (Linux, macOS, Windows) via PyQt6
255
- - MIT license, full source on GitHub
256
224
 
257
225
  ### Known limitations (alpha)
258
- - Q-space orthogonalization is ID01-specific (can be extended)
226
+ - Q-space orthogonalization is only ID01-specific
259
227
  - Some checkpoints from earlier prototypes lack `grid_size` metadata
260
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.3
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,7 +53,7 @@ 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
58
  **Coherent Diffraction Imaging - Simulation Tools**
59
59
 
@@ -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
 
@@ -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
  |---|---|---|
@@ -162,7 +162,7 @@ The 3D lattice view (powered by Plotly) shows every atom in the supercell.
162
162
 
163
163
  Select a reflection (h k l) from the auto-computed list of allowed peaks. The
164
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
165
+ c axis keep their high-l reflections: `(0 0 6)` for Fe3GeTe2, `(0 0 8)` for
166
166
  4H-SiC, `(0 0 6)` and `(0 -1 10)` for corundum. Typing any member of a family
167
167
  finds that family, whichever member the table happens to list.
168
168
  The Beam tab also lets you set:
@@ -175,7 +175,7 @@ Detector preset auto-fills the geometry parameters.
175
175
 
176
176
  ### 3. Results : run the simulation
177
177
 
178
- CDI-ST computes the diffraction in **two paths**:
178
+ CDI-St computes the diffraction in **two paths**:
179
179
 
180
180
  - **Analytical path** (cube/rectangular shapes, no strain): closed-form Fourier transform of the support
181
181
  - **FFT path** (any shape, any strain field): full 3D FFT of the complex object
@@ -218,38 +218,52 @@ et al. npj Computational Materials 8.1 (2022) ) reimplemented for this codebase.
218
218
  Training is GPU-accelerated (CUDA preferred) and converges in a few dozen
219
219
  epochs on 2,000+ samples. The best checkpoint is saved automatically.
220
220
 
221
- ### 6. CDI_NN : supervised PhaseUNet3D
221
+ ### 6. CDI_NN : supervised 3D U-Net
222
222
 
223
223
  A 3D U-Net that predicts the phase field from the diffraction magnitude, trained
224
224
  against the ground-truth phase from the data generator.
225
225
 
226
226
  Use AutoPhase_NN when you don't trust your simulator's ground truth (or have
227
227
  none). Use CDI_NN when you have a high-fidelity simulator and want a direct
228
- mapping. Use both via the **ensemble** mode in the Reconstruction tab.
228
+ mapping. Use both via **Both networks averaged** in the Reconstruction tab.
229
229
 
230
230
  ### 7. Reconstruction : invert experimental or simulated data
231
231
 
232
232
  Load any `.npz` (simulated) or `.h5` (experimental) BCDI file, or convert a
233
233
  SPEC + EDF scan from ID01 directly via the dialog. Choose:
234
234
 
235
- - **HIO/RAAR/ER only — no neural network**: the standard iterative algorithms
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
236
241
  from a random start. No checkpoint, no PyTorch, nothing trained - this is the
237
242
  option to use if you cannot run a network, and it is what most published BCDI
238
243
  work uses.
239
- - **AutoPhaseNet alone**: one forward pass (~100 ms), with twin-image
240
- suppression and COM centering. A quick look.
241
- - **AutoPhaseNet → HIO/RAAR/ER refinement**: network seed, then the classical
242
- algorithms polish it. The usual choice.
243
- - **Both networks averaged (AutoPhaseNet + PhaseUNet3D)**, optionally refined:
244
+ - **Both networks averaged (AutoPhase_NN + CDI_NN)**, optionally refined:
244
245
  averaging two independent guesses cancels some of the error each makes alone.
245
- Needs the second checkpoint.
246
+ Needs the second checkpoint. (still in need of further work)
246
247
 
247
248
  If refinement comes out worse than the network alone, the network output is kept.
248
249
 
249
250
  The output is a complex object (amplitude + phase), a binary support, the
250
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.
251
262
 
252
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
253
267
  - Detector chip-gap masking (Maxipix, Eiger)
254
268
  - Hot-pixel removal
255
269
  - Beamstop / direct-beam streak removal
@@ -262,22 +276,33 @@ The viewer renders the reconstruction in three modes:
262
276
 
263
277
  - **Point cloud**: every voxel above threshold, colored by amplitude / phase / strain,
264
278
  with per-voxel opacity weighted by intensity
265
- - **Isosurface**: smoothed iso-shell with internal data points showing through
266
- - **Surface only**: bare iso-mesh with edges visible
267
-
268
- **Render quality** is chosen before rendering - Draft (15,000 points), Standard
269
- (60,000, the default), High (200,000) or Maximum (1,000,000). Higher settings also
270
- smooth the isosurface less, so density and strain stay distinguishable. On a 128³
271
- reconstruction with 268,000 support voxels these take roughly 0.4 s, 0.5 s, 1.4 s
272
- and 1.4 s.
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.
273
298
 
274
299
  Controls:
275
300
  - Threshold (% of peak amplitude), voxel size, opacity, colormap (Turbo by default)
276
301
  - Color scale auto / manual (`vmin` / `vmax`)
277
302
  - Clip plane on any axis
278
- - **Auto-update view**: re-renders as soon as a setting changes, instead of
279
- pressing "Update view". Changes are coalesced briefly so dragging a slider does
280
- not start a render on every step.
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.
281
306
  - Mouse: left-drag rotate, right-drag pan, wheel zoom, double-click reset
282
307
  - Export PNG snapshot or VTI (ParaView)
283
308
 
@@ -285,12 +310,12 @@ Controls:
285
310
 
286
311
  ## Citing
287
312
 
288
- If you use CDI-ST in published research, please cite:
313
+ If you use CDI-St in published research, please cite:
289
314
 
290
315
  ```bibtex
291
316
  @software{saidi_cdi_st_2026,
292
317
  author = {Saidi, Soufiane},
293
- title = {CDI-ST: Coherent Diffraction Imaging — Simulation Tools},
318
+ title = {CDI-St: Coherent Diffraction Imaging - Simulation Tools},
294
319
  year = {2026},
295
320
  publisher = {GitHub},
296
321
  url = {https://github.com/Refze/CDI-St}
@@ -301,7 +326,7 @@ If you use CDI-ST in published research, please cite:
301
326
 
302
327
  ## License
303
328
 
304
- MIT — see [LICENSE](LICENSE).
329
+ MIT, see [LICENSE](LICENSE).
305
330
 
306
331
  ## Author
307
332
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  <img src="docs/screenshots/CDI_ST_logo.png" alt="CDI-ST" width="600"/>
4
4
 
5
- # CDI-ST
5
+ # CDI-St
6
6
 
7
7
  **Coherent Diffraction Imaging - Simulation Tools**
8
8
 
@@ -13,7 +13,7 @@ and 3D visualization, in a single GUI.
13
13
  [![PyPI version](https://img.shields.io/pypi/v/cdi-stools.svg)](https://pypi.org/project/cdi-stools/)
14
14
  [![Python](https://img.shields.io/pypi/pyversions/cdi-stools.svg)](https://pypi.org/project/cdi-stools/)
15
15
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
16
- [![Status](https://img.shields.io/badge/status-alpha-orange.svg)]()
16
+ [![Status](https://img.shields.io/badge/status-beta-blue.svg)]()
17
17
 
18
18
  </div>
19
19
 
@@ -74,7 +74,7 @@ intensity around a Bragg peak. The intensity gives only |F(q)|², so reconstruct
74
74
  must recover the missing phase by iterative algorithms (HIO, RAAR, ER),
75
75
  more recently by neural networks.
76
76
 
77
- **CDI-ST integrates the entire workflow into one tool:**
77
+ **CDI-St integrates the entire workflow into one tool:**
78
78
 
79
79
  | Step | What you do | Where in the GUI |
80
80
  |---|---|---|
@@ -111,7 +111,7 @@ The 3D lattice view (powered by Plotly) shows every atom in the supercell.
111
111
 
112
112
  Select a reflection (h k l) from the auto-computed list of allowed peaks. The
113
113
  search bounds each index separately from the geometry, so materials with a long
114
- c axis keep their high-l reflections — `(0 0 6)` for Fe3GeTe2, `(0 0 8)` for
114
+ c axis keep their high-l reflections: `(0 0 6)` for Fe3GeTe2, `(0 0 8)` for
115
115
  4H-SiC, `(0 0 6)` and `(0 -1 10)` for corundum. Typing any member of a family
116
116
  finds that family, whichever member the table happens to list.
117
117
  The Beam tab also lets you set:
@@ -124,7 +124,7 @@ Detector preset auto-fills the geometry parameters.
124
124
 
125
125
  ### 3. Results : run the simulation
126
126
 
127
- CDI-ST computes the diffraction in **two paths**:
127
+ CDI-St computes the diffraction in **two paths**:
128
128
 
129
129
  - **Analytical path** (cube/rectangular shapes, no strain): closed-form Fourier transform of the support
130
130
  - **FFT path** (any shape, any strain field): full 3D FFT of the complex object
@@ -167,38 +167,52 @@ et al. npj Computational Materials 8.1 (2022) ) reimplemented for this codebase.
167
167
  Training is GPU-accelerated (CUDA preferred) and converges in a few dozen
168
168
  epochs on 2,000+ samples. The best checkpoint is saved automatically.
169
169
 
170
- ### 6. CDI_NN : supervised PhaseUNet3D
170
+ ### 6. CDI_NN : supervised 3D U-Net
171
171
 
172
172
  A 3D U-Net that predicts the phase field from the diffraction magnitude, trained
173
173
  against the ground-truth phase from the data generator.
174
174
 
175
175
  Use AutoPhase_NN when you don't trust your simulator's ground truth (or have
176
176
  none). Use CDI_NN when you have a high-fidelity simulator and want a direct
177
- mapping. Use both via the **ensemble** mode in the Reconstruction tab.
177
+ mapping. Use both via **Both networks averaged** in the Reconstruction tab.
178
178
 
179
179
  ### 7. Reconstruction : invert experimental or simulated data
180
180
 
181
181
  Load any `.npz` (simulated) or `.h5` (experimental) BCDI file, or convert a
182
182
  SPEC + EDF scan from ID01 directly via the dialog. Choose:
183
183
 
184
- - **HIO/RAAR/ER only — no neural network**: the standard iterative algorithms
184
+ - **AutoPhase_NN → HIO/RAAR/ER refinement**: network seed, then the classical
185
+ algorithms polish it. The default and best choice.
186
+ - **AutoPhase_NN alone**: one forward pass (~100 ms), with twin-image
187
+ suppression and centring. The result is the network's object, its largest
188
+ connected region above 10 % of its maximum. A quick look.
189
+ - **HIO/RAAR/ER only (no neural network)**: the standard iterative algorithms
185
190
  from a random start. No checkpoint, no PyTorch, nothing trained - this is the
186
191
  option to use if you cannot run a network, and it is what most published BCDI
187
192
  work uses.
188
- - **AutoPhaseNet alone**: one forward pass (~100 ms), with twin-image
189
- suppression and COM centering. A quick look.
190
- - **AutoPhaseNet → HIO/RAAR/ER refinement**: network seed, then the classical
191
- algorithms polish it. The usual choice.
192
- - **Both networks averaged (AutoPhaseNet + PhaseUNet3D)**, optionally refined:
193
+ - **Both networks averaged (AutoPhase_NN + CDI_NN)**, optionally refined:
193
194
  averaging two independent guesses cancels some of the error each makes alone.
194
- Needs the second checkpoint.
195
+ Needs the second checkpoint. (still in need of further work)
195
196
 
196
197
  If refinement comes out worse than the network alone, the network output is kept.
197
198
 
198
199
  The output is a complex object (amplitude + phase), a binary support, the
199
200
  R-factor convergence curve, and 2D slices at the COM of the reconstruction.
201
+ Every mode reports the same R-factor, R = sum| k|F| - sqrt(I) | / sum sqrt(I), with
202
+ k chosen so the model and the data hold the same total intensity. R alone cannot
203
+ say whether a value is good, because its floor depends on the counting statistics,
204
+ so it is shown with two references from the same data: the **noise level** (the R
205
+ the result would reach if it were exactly right) and the R of a **featureless
206
+ sphere** (no phase retrieval at all). The result is then labelled *fits the data to
207
+ the noise level*, *partial fit*, *not reconstructed*, or *data too noisy to judge*
208
+ when the counts are too low for any reconstruction to be told apart from a
209
+ featureless object. R measures how well a result explains the measured
210
+ intensities, not whether it is the unique right object.
200
211
 
201
212
  For experimental data, the loader handles:
213
+ - Invalid-pixel flags: EIGER and other counting detectors write the largest
214
+ integer (4294967295 for 32-bit data) into gap, dead and saturated pixels; these
215
+ are zeroed as each frame is read, so they cannot be mistaken for the Bragg peak
202
216
  - Detector chip-gap masking (Maxipix, Eiger)
203
217
  - Hot-pixel removal
204
218
  - Beamstop / direct-beam streak removal
@@ -211,22 +225,33 @@ The viewer renders the reconstruction in three modes:
211
225
 
212
226
  - **Point cloud**: every voxel above threshold, colored by amplitude / phase / strain,
213
227
  with per-voxel opacity weighted by intensity
214
- - **Isosurface**: smoothed iso-shell with internal data points showing through
215
- - **Surface only**: bare iso-mesh with edges visible
216
-
217
- **Render quality** is chosen before rendering - Draft (15,000 points), Standard
218
- (60,000, the default), High (200,000) or Maximum (1,000,000). Higher settings also
219
- smooth the isosurface less, so density and strain stay distinguishable. On a 128³
220
- reconstruction with 268,000 support voxels these take roughly 0.4 s, 0.5 s, 1.4 s
221
- and 1.4 s.
228
+ - **Isosurface**: the object as a smooth solid, coloured by the chosen field. Cut
229
+ it with the clip plane and the cut face is filled with the field inside, so a
230
+ dislocation or a strained region shows where the cut passes.
231
+ - **Surface only**: the outer skin alone, coloured by the field just beneath it;
232
+ hollow when cut
233
+
234
+ On both surfaces each point shows the outermost voxels of the object, as ParaView
235
+ colours a thresholded volume (on the surface itself the density equals the
236
+ threshold everywhere). The colour range comes from the voxels inside the surface
237
+ and is the same for all three styles.
238
+
239
+ Strain is computed from neighbour phase differences, so a 2π phase jump (for
240
+ example the branch cut around a dislocation) is not shown as false strain.
241
+
242
+ **Render quality** changes only how finely the object is drawn, never the data:
243
+ values, colour scale, iso level and smoothing are identical at every level. Draft
244
+ builds the surface from every second voxel, Standard at the reconstruction's own
245
+ resolution, High and Maximum on a 2× and 3× finer trilinear grid (capped at
246
+ 256³). The point cloud always draws the reconstruction's own voxels.
222
247
 
223
248
  Controls:
224
249
  - Threshold (% of peak amplitude), voxel size, opacity, colormap (Turbo by default)
225
250
  - Color scale auto / manual (`vmin` / `vmax`)
226
251
  - Clip plane on any axis
227
- - **Auto-update view**: re-renders as soon as a setting changes, instead of
228
- pressing "Update view". Changes are coalesced briefly so dragging a slider does
229
- not start a render on every step.
252
+ - **Live preview**: when on, the render follows every change of threshold,
253
+ voxel size, opacity, colormap, clip plane or field. A quick draft is drawn while
254
+ you drag and full quality follows when you stop; rotation and zoom are kept.
230
255
  - Mouse: left-drag rotate, right-drag pan, wheel zoom, double-click reset
231
256
  - Export PNG snapshot or VTI (ParaView)
232
257
 
@@ -234,12 +259,12 @@ Controls:
234
259
 
235
260
  ## Citing
236
261
 
237
- If you use CDI-ST in published research, please cite:
262
+ If you use CDI-St in published research, please cite:
238
263
 
239
264
  ```bibtex
240
265
  @software{saidi_cdi_st_2026,
241
266
  author = {Saidi, Soufiane},
242
- title = {CDI-ST: Coherent Diffraction Imaging — Simulation Tools},
267
+ title = {CDI-St: Coherent Diffraction Imaging - Simulation Tools},
243
268
  year = {2026},
244
269
  publisher = {GitHub},
245
270
  url = {https://github.com/Refze/CDI-St}
@@ -250,7 +275,7 @@ If you use CDI-ST in published research, please cite:
250
275
 
251
276
  ## License
252
277
 
253
- MIT — see [LICENSE](LICENSE).
278
+ MIT, see [LICENSE](LICENSE).
254
279
 
255
280
  ## Author
256
281
 
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cdi-stools"
7
- version = "0.3.3"
8
- description = "Coherent Diffraction Imaging Simulation Tools — BCDI simulation and NN-based phase retrieval"
7
+ version = "0.3.4"
8
+ description = "Coherent Diffraction Imaging Simulation Tools: BCDI simulation and NN-based phase retrieval"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = "MIT"
@@ -24,7 +24,7 @@ keywords = [
24
24
  "ID01",
25
25
  ]
26
26
  classifiers = [
27
- "Development Status :: 3 - Alpha",
27
+ "Development Status :: 4 - Beta",
28
28
  "Intended Audience :: Science/Research",
29
29
  "Topic :: Scientific/Engineering :: Physics",
30
30
  "Topic :: Scientific/Engineering :: Image Processing",
@@ -108,11 +108,11 @@ line-length = 100
108
108
  target-version = "py39"
109
109
 
110
110
  [tool.ruff.lint]
111
- # Pragmatic linting — most existing code already breaks heavy strict mode
111
+ # Pragmatic linting: most existing code already breaks heavy strict mode
112
112
  select = ["E", "F", "W", "I", "UP"]
113
113
  ignore = [
114
- "E501", # line too long — many scientific lines exceed 100
115
- "E402", # module-level import not at top — common with conditional Qt imports
114
+ "E501", # line too long: many scientific lines exceed 100
115
+ "E402", # module-level import not at top: common with conditional Qt imports
116
116
  "E731", # don't assign a lambda
117
117
  ]
118
118
 
@@ -1,4 +1,4 @@
1
- __version__ = "0.3.3"
1
+ __version__ = "0.3.4"
2
2
  __author__ = "Soufiane SAIDI"
3
3
  __email__ = "saidisoufiane@hotmail.com"
4
4
  __license__ = "MIT"