cdi-stools 0.3.3__tar.gz → 0.4.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.
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/CHANGELOG.md +98 -90
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/PKG-INFO +101 -31
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/README.md +98 -28
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/pyproject.toml +6 -6
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/__init__.py +1 -1
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/bcdi_core.py +90 -90
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/bcdi_gui.py +118 -34
- cdi_stools-0.4.0/src/cdi_st/cxi.py +55 -0
- cdi_stools-0.4.0/src/cdi_st/defects.py +143 -0
- cdi_stools-0.4.0/src/cdi_st/geometry.py +92 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_autophase_infer.py +113 -68
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_data_generator.py +135 -34
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_dataset.py +46 -74
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_demo.py +3 -3
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_experimental_loader.py +121 -88
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_gui_tabs.py +657 -695
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_phase_model.py +105 -93
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_phase_retrieval.py +8 -5
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_train.py +34 -31
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_visualize.py +4 -4
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/ortho.py +35 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/recon.py +118 -35
- cdi_stools-0.4.0/src/cdi_st/strain.py +40 -0
- cdi_stools-0.4.0/src/cdi_st/theme.py +275 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/LICENSE +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/CDI_ST_logo.png +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/__main__.py +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/facets.py +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_autophase_model.py +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/nn_autophase_train.py +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/requirements.txt +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/trainlog.py +0 -0
- {cdi_stools-0.3.3 → cdi_stools-0.4.0}/src/cdi_st/viz3d.py +0 -0
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-12-04
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **Phase convention: φ = -G·u**, as numpy's FFT requires (Carnis et al., Sci. Rep. 9, 17357, 2019). Strain from experimental data now has the right sign, and simulated patterns are the true patterns of the given displacement.
|
|
8
|
+
- Every simulated strain field uses the vector G = h b1 + k b2 + l b3, not |G|.
|
|
9
|
+
- The strain type `edge_dislocation` is now `screw_dislocation`, which is what it always computed. The old name still works.
|
|
10
|
+
- Radial strain model: u(r) = ε0·(|r|/R)·r.
|
|
11
|
+
- Training data: dislocations use lattice Burgers vectors and slip-plane line directions. Each sample records b, the line direction and g·b.
|
|
12
|
+
- CDI_NN predicts density and phase and is trained with L = α‖ρ̂-ρ‖² + β‖φ̂-φ‖² + γ‖|F[ψ̂]|-|F_meas|‖²: linear diffraction amplitude, wrapped phase difference that ignores a global offset and the twin image, and augmentations that keep input and targets consistent. Defaults (α, β, γ) = (1.0, 0.5, 0.1), batch size 4. Phase-only checkpoints still load.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- Full isotropic dislocation field (Hirth & Lothe) with any Burgers vector and line direction, in the diffraction and in the atom view.
|
|
17
|
+
- ID01 SPEC/EDF: energy read from the SPEC header; direct beam, distance and pixel size as inputs; voxel size from the full 3D sampling geometry.
|
|
18
|
+
- Real-space orthogonalisation of detector-frame reconstructions (Maddali et al., J. Appl. Cryst. 53, 393, 2020).
|
|
19
|
+
- Signed strain along G in the 3D viewer, the 2D slices and the VTI export. |∇φ| is now given in rad/nm.
|
|
20
|
+
- Diffractometer presets for ID01 and P10.
|
|
21
|
+
- CXI export, a light theme for exported figures, and an optional dead-time model.
|
|
22
|
+
- Checkpoints load at the width they were trained with.
|
|
23
|
+
- `tests/test_physics.py`, `scripts/benchmark_hybrid.py`, and a class-fraction report for training sets.
|
|
24
|
+
- **Light mode is available !** Light mode for the whole interface, exported figures follow the chosen theme.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Prismatic loops: the solid angle is exact, with no jump at the loop radius.
|
|
29
|
+
- The random strain field was the same in every sample.
|
|
30
|
+
- Command-line dataset generation failed on every sample.
|
|
31
|
+
- Resampling to the model grid no longer changes the voxel size.
|
|
32
|
+
- The simulation grid matches the FFT sampling.
|
|
33
|
+
- Angular offset with a strained or shaped crystal no longer crashes.
|
|
34
|
+
- CDI_NN did not learn: the log-scaled input was used as the measured amplitude and the predicted phase collapsed to a constant.
|
|
35
|
+
|
|
36
|
+
### Known issues
|
|
37
|
+
|
|
38
|
+
- P10 conversion does not compute the voxel size yet.
|
|
39
|
+
- Loops use the solid-angle term of the displacement only.
|
|
40
|
+
- Some VTI export in 2D.
|
|
41
|
+
|
|
42
|
+
## [0.3.4] - 2026-11-23
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- **R-factor was not comparable between modes, and could look good for a failed reconstruction.**
|
|
47
|
+
- **R is now shown with two references**, so a number such as 0.12 can be judged:
|
|
48
|
+
the noise level (the R this result would reach if it were exactly right, from
|
|
49
|
+
Poisson statistics of the data) and the R of a featureless sphere (no phase
|
|
50
|
+
retrieval at all). The result is labelled *fits the data to the noise level*,
|
|
51
|
+
*partial fit*, *not reconstructed*, or *data too noisy to judge* when even a
|
|
52
|
+
featureless sphere fits within the noise. Checked on 56 cases from 10^2 counts to
|
|
53
|
+
noise-free data with no wrong label.
|
|
54
|
+
- **Crash after an HIO/RAAR/ER only reconstruction** (`cannot convert float NaN to integer`).
|
|
55
|
+
The object was centred but its support was not, so the two could stop
|
|
56
|
+
overlapping. They now move together, and the display falls back to the array
|
|
57
|
+
centre when there is nothing to weigh. Phase-ramp removal in the classical path
|
|
58
|
+
is now exact.
|
|
59
|
+
- **AutoPhase_NN alone lost most of the network's phase.** Centring the object
|
|
60
|
+
shifted the amplitude first and then masked the phase with the already shifted
|
|
61
|
+
box, so wherever the network placed the object off centre its phase was set to
|
|
62
|
+
zero (36 to 100 % of the object in tests). The refinement modes started from this
|
|
63
|
+
flat phase too. The object is now moved as one complex array by whole voxels,
|
|
64
|
+
which leaves |F| unchanged. Refined results are as good as before.
|
|
65
|
+
|
|
66
|
+
### Changed
|
|
67
|
+
|
|
68
|
+
- 3D viewer render styles: **Point cloud** (default), **Isosurface**, a smooth
|
|
69
|
+
solid whose cut face, with the clip plane, shows the field inside; **Surface
|
|
70
|
+
only**, the outer skin, hollow when cut.
|
|
71
|
+
- **Render quality changes only how finely the object is drawn.** The values, the
|
|
72
|
+
colour scale, the iso level and the smoothing are identical at every level;
|
|
73
|
+
quality sets the mesh resolution and, for very large reconstructions, how many
|
|
74
|
+
points are drawn.
|
|
75
|
+
- **Live preview** replaces Auto-update view: a quick draft while you drag, full
|
|
76
|
+
quality when you stop, rotation and zoom kept.
|
|
77
|
+
- Reconstruction modes name the networks as their tabs do: AutoPhase_NN, CDI_NN.
|
|
78
|
+
|
|
79
|
+
### Known issues
|
|
80
|
+
|
|
81
|
+
- Some real P10 scans are converting incorrectly; under investigation...
|
|
82
|
+
|
|
3
83
|
## [0.3.3] - 2026-11-17
|
|
4
84
|
|
|
5
85
|
### Fixed
|
|
@@ -25,24 +105,12 @@
|
|
|
25
105
|
network.
|
|
26
106
|
- **Render quality control in the 3D viewer**, chosen before rendering: Draft
|
|
27
107
|
(15,000 points), Standard (60,000, the default), High (200,000) and Maximum
|
|
28
|
-
(1,000,000).
|
|
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.
|
|
108
|
+
(1,000,000).
|
|
35
109
|
|
|
36
110
|
### Changed
|
|
37
111
|
|
|
38
112
|
- 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
113
|
- The checkpoint field is disabled when a mode needs no network.
|
|
45
|
-
- Simulation tabs are named "Material", "Beam", "Results" without numbering.
|
|
46
114
|
|
|
47
115
|
## [0.3.2] - 2026-11-08
|
|
48
116
|
|
|
@@ -58,9 +126,7 @@
|
|
|
58
126
|
|
|
59
127
|
### Fixed
|
|
60
128
|
|
|
61
|
-
- `ModuleNotFoundError: No module named 'bcdi_core'` on launch.
|
|
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
|
|
129
|
+
- `ModuleNotFoundError: No module named 'bcdi_core'` on launch. Imports are
|
|
64
130
|
now package-relative, with a fallback so the files still run directly from a
|
|
65
131
|
plain folder.
|
|
66
132
|
|
|
@@ -101,40 +167,23 @@ the corrections to the noise model and colour-scale controls.
|
|
|
101
167
|
- Separate simulation grid control, independent of the detector panel size.
|
|
102
168
|
- Visualization controls (bonds, strain, dislocation) grouped together.
|
|
103
169
|
|
|
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
170
|
### Changed
|
|
113
171
|
|
|
114
172
|
- Read noise is applied only to integrating detectors. Hybrid photon-counting
|
|
115
173
|
detectors (EIGER, PILATUS, MAXIPIX, MERLIN, TIMEPIX) have Poisson statistics
|
|
116
174
|
only, and the Readout option disables itself when one is selected.
|
|
117
|
-
- Noise controls are named per effect
|
|
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.
|
|
175
|
+
- Noise controls are named per effect.
|
|
120
176
|
- Default simulation grid raised from 128 to 192, giving 2.25x the pixels in the
|
|
121
177
|
2D slices for about 2 s per simulation.
|
|
122
|
-
- The simulation panel is resizable; the fixed 520 px left column is a splitter.
|
|
123
178
|
- Frame transform uses cubic interpolation (0.7% round-trip error, against 3.6%
|
|
124
179
|
for linear).
|
|
125
180
|
|
|
126
181
|
### Fixed
|
|
127
182
|
|
|
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
183
|
- 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.
|
|
133
|
-
(exported as metadata) and simulation grid are now independent.
|
|
184
|
+
panel forced 128^3 slices regardless of the grid setting.
|
|
134
185
|
- Reflections are labelled by their canonical Friedel mate, so selecting (1 1 1)
|
|
135
|
-
no longer displays (-1 -1 -1).
|
|
136
|
-
search simply reached the negative representative first. The raw index is kept
|
|
137
|
-
as `hkl_raw`.
|
|
186
|
+
no longer displays (-1 -1 -1).
|
|
138
187
|
- `select_reflection` returns full-precision d, 2theta, q, |F|^2 and LP. It
|
|
139
188
|
previously used the four-decimal values rounded for the table.
|
|
140
189
|
- Half-voxel registration error in the detector/lab transform. An orthogonal
|
|
@@ -147,7 +196,7 @@ the corrections to the noise model and colour-scale controls.
|
|
|
147
196
|
- The facet ratio control was not read when building, and the large-supercell
|
|
148
197
|
notice was missing.
|
|
149
198
|
|
|
150
|
-
## [0.2.2]
|
|
199
|
+
## [0.2.2] - 2026-06-18
|
|
151
200
|
|
|
152
201
|
### Fixed
|
|
153
202
|
- **ID01 SPEC+EDF conversion now tolerates missing edge frames.**
|
|
@@ -161,7 +210,7 @@ the corrections to the noise model and colour-scale controls.
|
|
|
161
210
|
New helper `_filter_existing_edf_frames()` exposes this filtering for
|
|
162
211
|
programmatic use.
|
|
163
212
|
|
|
164
|
-
## [0.2.1]
|
|
213
|
+
## [0.2.1] - 2026-06-15
|
|
165
214
|
|
|
166
215
|
### Added
|
|
167
216
|
- **PETRA III P10 / DESY Eiger compressed-data support.** Auto-imports
|
|
@@ -170,61 +219,21 @@ the corrections to the noise model and colour-scale controls.
|
|
|
170
219
|
transparently. `hdf5plugin>=4.0` is now a runtime dependency.
|
|
171
220
|
- **HDF5 external-link resolution.** The P10 loader now enumerates and
|
|
172
221
|
resolves external links in master files instead of relying on h5py's
|
|
173
|
-
default link-following, which was unreliable on Windows.
|
|
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.
|
|
222
|
+
default link-following, which was unreliable on Windows.
|
|
177
223
|
- **Scan range selection for P10** (new in the P10 converter dialog)
|
|
178
224
|
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()`.
|
|
225
|
+
detector frames into RAM when you only need the rocking-curve maximum
|
|
197
226
|
|
|
198
227
|
### Fixed
|
|
199
|
-
-
|
|
200
|
-
|
|
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.
|
|
228
|
+
- AutoPhase_NN tab missing `_on_epoch` slot..
|
|
229
|
+
- Training Stop button no longer crashes the program.
|
|
217
230
|
|
|
218
231
|
### Changed
|
|
219
|
-
- Live training curve in AutoPhase_NN and CDI_NN
|
|
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).
|
|
232
|
+
- Live training curve in AutoPhase_NN and CDI_NN.
|
|
223
233
|
- `inspect_h5()` now properly shows external links with their target
|
|
224
|
-
files and `[OK]` / `[MISSING]` markers.
|
|
225
|
-
group on Eiger masters is no longer misleading.
|
|
234
|
+
files and `[OK]` / `[MISSING]` markers.
|
|
226
235
|
|
|
227
|
-
## [0.1.0]
|
|
236
|
+
## [0.1.0] - Alpha - 2026-05-08
|
|
228
237
|
|
|
229
238
|
### Added
|
|
230
239
|
- **Initial public release** of CDI-ST as a packaged Python application.
|
|
@@ -240,8 +249,8 @@ the corrections to the noise model and colour-scale controls.
|
|
|
240
249
|
- BCDI Data Analysis module (Generate Data → AutoPhase_NN → CDI_NN → Reconstruction → 3D Viewer)
|
|
241
250
|
- Training-data generator with random material/shape/size/strain/dislocation
|
|
242
251
|
- Toggles for randomized strain and dislocations
|
|
243
|
-
-
|
|
244
|
-
-
|
|
252
|
+
- AutoPhaseNN (unsupervised, dual-decoder, physics-driven loss)
|
|
253
|
+
- CDI_NN (supervised, BCDI loss with α/β/γ weights)
|
|
245
254
|
- Inference: NN-only, refined (HIO+RAAR+ER), ensemble, compare
|
|
246
255
|
- Iterative phase retrieval: HIO (β=0.9), RAAR (β=0.9), ER, with shrink-wrap
|
|
247
256
|
- Experimental data loader: HDF5, ID01 SPEC+EDF, q-space orthogonalization
|
|
@@ -250,11 +259,10 @@ the corrections to the noise model and colour-scale controls.
|
|
|
250
259
|
- Per-voxel opacity weighted by intensity
|
|
251
260
|
- VTI export for ParaView
|
|
252
261
|
- Splash screen and theme-matched launcher
|
|
253
|
-
- In-app Reports & Suggestions feature
|
|
254
262
|
- Cross-platform support (Linux, macOS, Windows) via PyQt6
|
|
255
|
-
- MIT license, full source on GitHub
|
|
256
263
|
|
|
257
264
|
### Known limitations (alpha)
|
|
258
|
-
- Q-space orthogonalization is ID01-specific
|
|
265
|
+
- Q-space orthogonalization is only ID01-specific
|
|
259
266
|
- Some checkpoints from earlier prototypes lack `grid_size` metadata
|
|
260
267
|
- Mask-aware modulus constraint not yet implemented (gaps are filled instead)
|
|
268
|
+
- 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.
|
|
4
|
-
Summary: Coherent Diffraction Imaging Simulation Tools
|
|
3
|
+
Version: 0.4.0
|
|
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 ::
|
|
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-
|
|
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
|
[](https://pypi.org/project/cdi-stools/)
|
|
65
65
|
[](https://pypi.org/project/cdi-stools/)
|
|
66
66
|
[](https://opensource.org/licenses/MIT)
|
|
67
|
-
[]()
|
|
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-
|
|
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
|
|
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-
|
|
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,57 @@ 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
|
|
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
|
+
Since v0.4.0 it predicts the density as well as the phase and is trained with
|
|
227
|
+
L = α‖ρ̂-ρ‖² + β‖φ̂-φ‖² + γ‖|F[ψ̂]|-|F_meas|‖² (defaults 1.0, 0.5, 0.1). The phase term
|
|
228
|
+
is wrapped and ignores a global phase offset and the twin image; the Fourier term
|
|
229
|
+
compares linear diffraction amplitudes.
|
|
230
|
+
|
|
226
231
|
Use AutoPhase_NN when you don't trust your simulator's ground truth (or have
|
|
227
232
|
none). Use CDI_NN when you have a high-fidelity simulator and want a direct
|
|
228
|
-
mapping. Use both via
|
|
233
|
+
mapping. Use both via **Both networks averaged** in the Reconstruction tab.
|
|
229
234
|
|
|
230
235
|
### 7. Reconstruction : invert experimental or simulated data
|
|
231
236
|
|
|
232
237
|
Load any `.npz` (simulated) or `.h5` (experimental) BCDI file, or convert a
|
|
233
238
|
SPEC + EDF scan from ID01 directly via the dialog. Choose:
|
|
234
239
|
|
|
235
|
-
- **HIO/RAAR/ER
|
|
240
|
+
- **AutoPhase_NN → HIO/RAAR/ER refinement**: network seed, then the classical
|
|
241
|
+
algorithms polish it. The default and best choice.
|
|
242
|
+
- **AutoPhase_NN alone**: one forward pass (~100 ms), with twin-image
|
|
243
|
+
suppression and centring. The result is the network's object, its largest
|
|
244
|
+
connected region above 10 % of its maximum. A quick look.
|
|
245
|
+
- **HIO/RAAR/ER only (no neural network)**: the standard iterative algorithms
|
|
236
246
|
from a random start. No checkpoint, no PyTorch, nothing trained - this is the
|
|
237
247
|
option to use if you cannot run a network, and it is what most published BCDI
|
|
238
248
|
work uses.
|
|
239
|
-
- **
|
|
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:
|
|
249
|
+
- **Both networks averaged (AutoPhase_NN + CDI_NN)**, optionally refined:
|
|
244
250
|
averaging two independent guesses cancels some of the error each makes alone.
|
|
245
|
-
Needs the second checkpoint.
|
|
251
|
+
Needs the second checkpoint. (still in need of further work)
|
|
246
252
|
|
|
247
253
|
If refinement comes out worse than the network alone, the network output is kept.
|
|
248
254
|
|
|
249
255
|
The output is a complex object (amplitude + phase), a binary support, the
|
|
250
256
|
R-factor convergence curve, and 2D slices at the COM of the reconstruction.
|
|
257
|
+
Every mode reports the same R-factor, R = sum| k|F| - sqrt(I) | / sum sqrt(I), with
|
|
258
|
+
k chosen so the model and the data hold the same total intensity. R alone cannot
|
|
259
|
+
say whether a value is good, because its floor depends on the counting statistics,
|
|
260
|
+
so it is shown with two references from the same data: the **noise level** (the R
|
|
261
|
+
the result would reach if it were exactly right) and the R of a **featureless
|
|
262
|
+
sphere** (no phase retrieval at all). The result is then labelled *fits the data to
|
|
263
|
+
the noise level*, *partial fit*, *not reconstructed*, or *data too noisy to judge*
|
|
264
|
+
when the counts are too low for any reconstruction to be told apart from a
|
|
265
|
+
featureless object. R measures how well a result explains the measured
|
|
266
|
+
intensities, not whether it is the unique right object.
|
|
251
267
|
|
|
252
268
|
For experimental data, the loader handles:
|
|
269
|
+
- Invalid-pixel flags: EIGER and other counting detectors write the largest
|
|
270
|
+
integer (4294967295 for 32-bit data) into gap, dead and saturated pixels; these
|
|
271
|
+
are zeroed as each frame is read, so they cannot be mistaken for the Bragg peak
|
|
253
272
|
- Detector chip-gap masking (Maxipix, Eiger)
|
|
254
273
|
- Hot-pixel removal
|
|
255
274
|
- Beamstop / direct-beam streak removal
|
|
@@ -262,35 +281,86 @@ The viewer renders the reconstruction in three modes:
|
|
|
262
281
|
|
|
263
282
|
- **Point cloud**: every voxel above threshold, colored by amplitude / phase / strain,
|
|
264
283
|
with per-voxel opacity weighted by intensity
|
|
265
|
-
- **Isosurface**:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
284
|
+
- **Isosurface**: the object as a smooth solid, coloured by the chosen field. Cut
|
|
285
|
+
it with the clip plane and the cut face is filled with the field inside, so a
|
|
286
|
+
dislocation or a strained region shows where the cut passes.
|
|
287
|
+
- **Surface only**: the outer skin alone, coloured by the field just beneath it;
|
|
288
|
+
hollow when cut
|
|
289
|
+
|
|
290
|
+
On both surfaces each point shows the outermost voxels of the object, as ParaView
|
|
291
|
+
colours a thresholded volume (on the surface itself the density equals the
|
|
292
|
+
threshold everywhere). The colour range comes from the voxels inside the surface
|
|
293
|
+
and is the same for all three styles.
|
|
294
|
+
|
|
295
|
+
Strain is computed from neighbour phase differences, so a 2π phase jump (for
|
|
296
|
+
example the branch cut around a dislocation) is not shown as false strain.
|
|
297
|
+
|
|
298
|
+
**Render quality** changes only how finely the object is drawn, never the data:
|
|
299
|
+
values, colour scale, iso level and smoothing are identical at every level. Draft
|
|
300
|
+
builds the surface from every second voxel, Standard at the reconstruction's own
|
|
301
|
+
resolution, High and Maximum on a 2× and 3× finer trilinear grid (capped at
|
|
302
|
+
256³). The point cloud always draws the reconstruction's own voxels.
|
|
273
303
|
|
|
274
304
|
Controls:
|
|
275
305
|
- Threshold (% of peak amplitude), voxel size, opacity, colormap (Turbo by default)
|
|
276
306
|
- Color scale auto / manual (`vmin` / `vmax`)
|
|
277
307
|
- Clip plane on any axis
|
|
278
|
-
- **
|
|
279
|
-
|
|
280
|
-
|
|
308
|
+
- **Live preview**: when on, the render follows every change of threshold,
|
|
309
|
+
voxel size, opacity, colormap, clip plane or field. A quick draft is drawn while
|
|
310
|
+
you drag and full quality follows when you stop; rotation and zoom are kept.
|
|
281
311
|
- Mouse: left-drag rotate, right-drag pan, wheel zoom, double-click reset
|
|
282
312
|
- Export PNG snapshot or VTI (ParaView)
|
|
283
313
|
|
|
314
|
+
### Conventions and experimental geometry
|
|
315
|
+
|
|
316
|
+
**Phase and strain.** CDI-St uses numpy's FFT, whose kernel is exp(-iq·r), so the
|
|
317
|
+
reconstructed object is ρ(r)·exp(-iG·u(r)): the phase is φ = -G·u (Carnis et al.,
|
|
318
|
+
Sci. Rep. 9, 17357, 2019). The strain shown along G is ε = ∂u_G/∂s = -(1/|G|)·∂φ/∂s,
|
|
319
|
+
with s the coordinate along G. It is unchanged by the twin solution. Phase
|
|
320
|
+
differences are taken from neighbour products of the complex object, so no
|
|
321
|
+
unwrapping is needed; the surface layer is excluded.
|
|
322
|
+
|
|
323
|
+
**Simulated strain fields** (all φ = -G·u, G = h b1 + k b2 + l b3):
|
|
324
|
+
- radial gradient: u(r) = ε0·(|r|/R)·r, R half the mean particle size
|
|
325
|
+
- screw dislocation along z: b the shortest lattice translation along z
|
|
326
|
+
- line dislocations: isotropic infinite-medium field (Hirth & Lothe, 1982) for any
|
|
327
|
+
Burgers vector and line direction, given in lattice units [u v w] or by the
|
|
328
|
+
axis options
|
|
329
|
+
- prismatic loops: solid-angle term (b/4π)·Ω·n, with the exact solid angle
|
|
330
|
+
|
|
331
|
+
**ID01 SPEC/EDF data.** Give the direct-beam pixel and the detector distance from
|
|
332
|
+
your detector calibration; the energy is read from the SPEC header (`nrj`, keV)
|
|
333
|
+
unless you set it. Defaults from an old experiment are used with a warning. The
|
|
334
|
+
converted .npz stores the sampling matrix B (∂q per index, at the Bragg peak), the
|
|
335
|
+
real-space steps A = 2π·(B·diag(N))^(-T) and q at the Bragg peak. After a
|
|
336
|
+
reconstruction, the object is resampled from the sheared basis A onto an
|
|
337
|
+
orthogonal grid (Maddali et al., J. Appl. Cryst. 53, 393, 2020), so voxel size,
|
|
338
|
+
shape and strain are in real space. Resampling to the model grid keeps the voxel
|
|
339
|
+
size: the same q range on more or fewer points changes the field of view, and the
|
|
340
|
+
oversampling with it.
|
|
341
|
+
|
|
342
|
+
**Exports.** VTI (ParaView) holds |ρ|, φ, |∇φ| in rad/nm and, when G is known, the
|
|
343
|
+
signed strain. CXI holds the complex object, its support, the voxel size and the
|
|
344
|
+
basis, in the layout PyNX and cdiutils read. Exported figures follow the interface
|
|
345
|
+
theme, dark or light, chosen on the start screen.
|
|
346
|
+
|
|
347
|
+
### Pretrained weights
|
|
348
|
+
|
|
349
|
+
Trained AutoPhase_NN and CDI_NN checkpoints can be found in here : https://doi.org/10.5281/zenodo.24826193
|
|
350
|
+
(it is recommended to use AutoPhase_NN for better results)
|
|
351
|
+
Load one with *Resume from checkpoint* in either network tab, or as the model in
|
|
352
|
+
the Reconstruction tab; the network width is read from the checkpoint.
|
|
353
|
+
|
|
284
354
|
---
|
|
285
355
|
|
|
286
356
|
## Citing
|
|
287
357
|
|
|
288
|
-
If you use CDI-
|
|
358
|
+
If you use CDI-St in published research, please cite:
|
|
289
359
|
|
|
290
360
|
```bibtex
|
|
291
361
|
@software{saidi_cdi_st_2026,
|
|
292
362
|
author = {Saidi, Soufiane},
|
|
293
|
-
title = {CDI-
|
|
363
|
+
title = {CDI-St: Coherent Diffraction Imaging - Simulation Tools},
|
|
294
364
|
year = {2026},
|
|
295
365
|
publisher = {GitHub},
|
|
296
366
|
url = {https://github.com/Refze/CDI-St}
|
|
@@ -301,7 +371,7 @@ If you use CDI-ST in published research, please cite:
|
|
|
301
371
|
|
|
302
372
|
## License
|
|
303
373
|
|
|
304
|
-
MIT
|
|
374
|
+
MIT, see [LICENSE](LICENSE).
|
|
305
375
|
|
|
306
376
|
## Author
|
|
307
377
|
|