danaroth commited on
Commit
8fc7967
·
1 Parent(s): 40abf7f

Initial commit

Browse files
Files changed (42) hide show
  1. .gitattributes +2 -0
  2. CITATION.cff +38 -0
  3. README.md +361 -0
  4. derived/edx/elemental_tilt_series/Ge_stack.tif +3 -0
  5. derived/edx/elemental_tilt_series/Sb_stack.tif +3 -0
  6. derived/edx/elemental_tilt_series/Si_stack.tif +3 -0
  7. derived/edx/elemental_tilt_series/Te_stack.tif +3 -0
  8. derived/edx/elemental_tilt_series/Ti_stack.tif +3 -0
  9. derived/haadf/HAADF_aligned.tiff +3 -0
  10. derived/haadf/HAADF_stack.tif +3 -0
  11. derived/haadf/alignment/ali_haadf.json +66 -0
  12. metadata/acquisition_manifest.csv +17 -0
  13. metadata/angles_deg.txt +16 -0
  14. metadata/audit/audit_summary.md +28 -0
  15. metadata/audit/checksums.sha256 +0 -0
  16. metadata/audit/emd_hdf5_summary.json +3 -0
  17. metadata/audit/file_inventory.csv +0 -0
  18. metadata/audit/hyperspy_summary.json +3 -0
  19. metadata/audit/json_summary.json +0 -0
  20. metadata/audit/tiff_summary.json +3 -0
  21. metadata/audit/tilt_manifest.csv +17 -0
  22. metadata/dataset.yaml +101 -0
  23. metadata/processing.yaml +58 -0
  24. previews/haadf_zero_tilt.png +3 -0
  25. raw/emd/D3_EDS-HAADF_0001_-40.emd +3 -0
  26. raw/emd/D3_EDS-HAADF_0002_-35.emd +3 -0
  27. raw/emd/D3_EDS-HAADF_0003_-30.emd +3 -0
  28. raw/emd/D3_EDS-HAADF_0004_-25.emd +3 -0
  29. raw/emd/D3_EDS-HAADF_0005_-20.emd +3 -0
  30. raw/emd/D3_EDS-HAADF_0006_-15.emd +3 -0
  31. raw/emd/D3_EDS-HAADF_0007_-10.emd +3 -0
  32. raw/emd/D3_EDS-HAADF_0008_-5.emd +3 -0
  33. raw/emd/D3_EDS-HAADF_0009_00.emd +3 -0
  34. raw/emd/D3_EDS-HAADF_0011_+10.emd +3 -0
  35. raw/emd/D3_EDS-HAADF_0012_+15.emd +3 -0
  36. raw/emd/D3_EDS-HAADF_0013_+20.emd +3 -0
  37. raw/emd/D3_EDS-HAADF_0014_+25.emd +3 -0
  38. raw/emd/D3_EDS-HAADF_0015_+30.emd +3 -0
  39. raw/emd/D3_EDS-HAADF_0016_+35.emd +3 -0
  40. raw/emd/D3_EDS-HAADF_0017_+40.emd +3 -0
  41. scripts/audit_themis_dataset.py +568 -0
  42. scripts/generate_haadf_preview.py +185 -0
.gitattributes CHANGED
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ *.tif filter=lfs diff=lfs merge=lfs -text
62
+ *.emd filter=lfs diff=lfs merge=lfs -text
CITATION.cff ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cff-version: 1.2.0
2
+ message: "Please cite this dataset and the associated publication."
3
+ title: "PFNC GST HAADF-STEM/EDS Tomography — Lamella b2_d3"
4
+ type: dataset
5
+ authors:
6
+ - family-names: "Picone"
7
+ given-names: "Daniele"
8
+ email: "daniele.picone@cea.fr"
9
+ - family-names: "Del Pozo Bueno"
10
+ given-names: "Daniel"
11
+ email: "daniel.delpozobueno@cea.fr"
12
+ - family-names: "Truong"
13
+ given-names: "Minh Thang"
14
+ - family-names: "Saghi"
15
+ given-names: "Zineb"
16
+ email: "zineb.saghi@cea.fr"
17
+ version: "1.0.0"
18
+ date-released: "TO FILL"
19
+ repository-code: "TO FILL"
20
+ license: "CC-BY-NC-ND-4.0"
21
+ references:
22
+ - type: article
23
+ title: "Unsupervised Deep Learning for Limited-Angle STEM-EDX Tomography -- Application to 3D Chemical Analysis of Phase-Change Memory Devices"
24
+ authors:
25
+ - family-names: "del Pozo Bueno"
26
+ given-names: "Daniel"
27
+ - family-names: "Brosset"
28
+ given-names: "Serge"
29
+ - family-names: "Monniez"
30
+ given-names: "Theo"
31
+ - family-names: "Navarro"
32
+ given-names: "Gabriele"
33
+ - family-names: "Ciuciu"
34
+ given-names: "Philippe"
35
+ - family-names: "Saghi"
36
+ given-names: "Zineb"
37
+ year: 2026
38
+ doi: "10.48550/arXiv.2606.10547"
README.md CHANGED
@@ -1,3 +1,364 @@
1
  ---
 
2
  license: cc-by-nc-nd-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pretty_name: "PFNC GST HAADF-STEM/EDS Tomography — b2_d3"
3
  license: cc-by-nc-nd-4.0
4
+ tags:
5
+ - electron-microscopy
6
+ - electron-tomography
7
+ - stem
8
+ - haadf
9
+ - eds
10
+ - edx
11
+ - spectrum-imaging
12
+ - materials-science
13
+ - semiconductor
14
+ - phase-change-memory
15
+ - gst
16
+ - limited-angle-tomography
17
+ size_categories:
18
+ - n<1K
19
  ---
20
+
21
+ # PFNC GST HAADF-STEM/EDS Tomography — Lamella `b2_d3`
22
+
23
+ ## Dataset summary
24
+
25
+ This dataset contains a limited-angle, multi-frame HAADF-STEM and EDS electron-tomography acquisition of a cross-sectional Ge-Sb-Te phase-change-memory lamella.
26
+
27
+ The data were acquired on a **Thermo Fisher Scientific Titan Themis** at the **Platform for Nanocharacterisation (PFNC), CEA Grenoble**, operated at **200 kV** and equipped with a four-detector **Super-X EDS** system.
28
+
29
+ The original lamella identifier is:
30
+
31
+ ```text
32
+ b2_d3
33
+ ```
34
+
35
+ The mapping of this lamella to the virgin or SET device described in the associated publication remains to be confirmed.
36
+
37
+ The dataset preserves:
38
+
39
+ - 16 original Velox EMD acquisition containers;
40
+ - 50 HAADF frames at each retained tilt;
41
+ - a 50-frame EDS spectrum stream at each retained tilt;
42
+ - integrated spectra and embedded elemental net-intensity maps;
43
+ - extracted HAADF and elemental tilt-series stacks;
44
+ - an aligned HAADF tilt series;
45
+ - per-projection pixel shifts referenced to the 0° acquisition;
46
+ - an explicit tilt-angle list.
47
+
48
+ ## Dataset name
49
+
50
+ Recommended public title:
51
+
52
+ ```text
53
+ PFNC GST HAADF-STEM/EDS Tomography — Lamella b2_d3
54
+ ```
55
+
56
+ Recommended Hugging Face repository slug:
57
+
58
+ ```text
59
+ pfnc-gst-haadf-stem-eds-tomography-b2-d3
60
+ ```
61
+
62
+ This name identifies the facility context, material system, acquisition modalities, tomography task, and original lamella identifier without making an unverified claim about the device state.
63
+
64
+ ## Provenance and credits
65
+
66
+ | Role | Person |
67
+ |---|---|
68
+ | Original acquisition operator | Le-Duc Minh Tran — `le-ducminh.tran@cea.fr` |
69
+ | Dataset curator | Daniele Picone — `daniele.picone@cea.fr` |
70
+ | Scientific contact | Daniel Del Pozo Bueno — `daniel.delpozobueno@cea.fr` |
71
+ | PFNC contact | Zineb Saghi — `zineb.saghi@cea.fr` |
72
+ | Dataset organization | CEA-Leti, Grenoble |
73
+ | Acquisition facility | PFNC, CEA Grenoble |
74
+
75
+ ## Instrument and acquisition
76
+
77
+ | Field | Value |
78
+ |---|---|
79
+ | Facility | Platform for Nanocharacterisation (PFNC), CEA Grenoble |
80
+ | Microscope | Thermo Fisher Scientific Titan Themis |
81
+ | Exact commercial generation/submodel | Not documented |
82
+ | Operating voltage | 200 kV |
83
+ | Corrector | Probe corrector |
84
+ | EDS system | Super-X, four silicon-drift detectors |
85
+ | Embedded detector identifier | `SuperXG1` |
86
+ | Acquisition software | Velox |
87
+ | Embedded Velox version | `3.17.0.967-b5399cab` |
88
+ | EMD format | Velox EMD version 11 |
89
+ | Acquisition date | 2025-07-07 |
90
+ | Beam current | 115 pA |
91
+ | Camera length | 110 mm |
92
+ | Pixel size | 10.67 Å/pixel |
93
+ | Frame size | 400 × 300 pixels |
94
+ | Dwell time | 40 µs |
95
+ | Frames per retained tilt | 50 |
96
+ | Time per frame | 5.57 s |
97
+ | Cumulative acquisition time per tilt | 278.5 s |
98
+ | Fluence per frame | 2.52 × 10² e⁻ Å⁻² |
99
+ | Fluence per tilt | 1.26 × 10⁴ e⁻ Å⁻² |
100
+ | Approximate total fluence | 2.0 × 10⁵ e⁻ Å⁻² |
101
+
102
+ ## Sample
103
+
104
+ | Field | Value |
105
+ |---|---|
106
+ | Lamella identifier | `b2_d3` |
107
+ | Filename identifier | `D3` |
108
+ | Material system | Ge-Sb-Te phase-change-memory device |
109
+ | Specimen form | Cross-sectional FIB lamella |
110
+ | Operational state | Unknown: virgin or SET |
111
+ | Approximate GST-region thickness | 50 nm, as reported for the associated study |
112
+ | Holder | Fischione single-axis tomography holder |
113
+ | Tilt-axis relation | Parallel to the GST layer |
114
+ | Wafer, die, and device lineage | Not available |
115
+
116
+ ## Tilt series
117
+
118
+ The intended acquisition contained 17 views from −40° to +40° at nominal 5° increments. One corrupted acquisition was discarded.
119
+
120
+ The 16 retained angles are:
121
+
122
+ ```text
123
+ -40, -35, -30, -25, -20, -15, -10, -5,
124
+ 0, +10, +15, +20, +25, +30, +35, +40 degrees
125
+ ```
126
+
127
+ The discarded acquisition is number `0010`, corresponding to nominal `+5°`.
128
+
129
+ Do not synthesize, duplicate, or interpolate the missing `+5°` projection in the archived data.
130
+
131
+ Public tilt-series arrays use:
132
+
133
+ ```text
134
+ (A, V, U) = (16, 400, 300)
135
+ ```
136
+
137
+ where `A` is tilt index, `V` is image row, and `U` is image column. `metadata/angles_deg.txt` is the authoritative angle coordinate.
138
+
139
+ ## Raw EMD acquisitions
140
+
141
+ The current raw filenames use the normalized convention:
142
+
143
+ ```text
144
+ D3_EDS-HAADF_0001_-40.emd
145
+ ...
146
+ D3_EDS-HAADF_0017_+40.emd
147
+ ```
148
+
149
+ The filename-to-angle mapping is recorded in `metadata/acquisition_manifest.csv`.
150
+
151
+ Each retained EMD contains:
152
+
153
+ ### HAADF-STEM frame series
154
+
155
+ ```text
156
+ shape: (400, 300, 50)
157
+ dtype: uint16
158
+ frames: 50
159
+ ```
160
+
161
+ ### EDS spectrum stream
162
+
163
+ ```text
164
+ spectral bins: 4096
165
+ frames: 50
166
+ stream dtype: uint16
167
+ detector identifier: SuperXG1
168
+ ```
169
+
170
+ An integrated spectrum of shape `(4096, 1)` and dtype `uint32` is also present.
171
+
172
+ ### Embedded elemental maps
173
+
174
+ Velox-rendered float32 net-intensity maps are present for:
175
+
176
+ ```text
177
+ N, O, Si, Ti, Ge, Sb, Te
178
+ ```
179
+
180
+ The embedded map-processing settings include a 3 × 3 mean filter. These maps are processed analytical products, not raw event data or calibrated concentrations.
181
+
182
+ ## Derived files
183
+
184
+ | File | Shape | Dtype | Interpretation |
185
+ |---|---:|---|---|
186
+ | `HAADF_stack.tif` | `(16, 400, 300)` | `uint16` | One extracted HAADF projection per retained tilt |
187
+ | `HAADF_aligned.tiff` | `(16, 400, 300)` | `float32` | HAADF tilt series aligned to the 0° acquisition |
188
+ | `Ge_stack.tif` | `(16, 400, 300)` | `float32` | Ge net-intensity tilt series |
189
+ | `Sb_stack.tif` | `(16, 400, 300)` | `float32` | Sb net-intensity tilt series |
190
+ | `Te_stack.tif` | `(16, 400, 300)` | `float32` | Te net-intensity tilt series |
191
+ | `Ti_stack.tif` | `(16, 400, 300)` | `float32` | Ti net-intensity tilt series |
192
+ | `Si_stack.tif` | `(16, 400, 300)` | `float32` | Si net-intensity tilt series |
193
+ | `ali_haadf.json` | 16 integer pairs | — | Pixel translations used to align each HAADF projection to the 0° acquisition |
194
+
195
+ The element-specific TIFF values are net intensities, not atomic concentrations.
196
+
197
+ ## HAADF alignment file
198
+
199
+ `ali_haadf.json` contains one pair of integer pixel shifts for each projection, in stack order. Each pair specifies the translation used to align that acquisition to the 0° HAADF projection.
200
+
201
+ Conceptually:
202
+
203
+ ```json
204
+ [
205
+ [9, 2],
206
+ ...
207
+ [0, 0],
208
+ ...
209
+ ]
210
+ ```
211
+
212
+ The `[0, 0]` entry corresponds to the 0° reference projection.
213
+
214
+ The following low-level convention remains undocumented:
215
+
216
+ - whether each pair is ordered as `[x, y]`, `[column, row]`, or `[row, column]`;
217
+ - whether values encode the applied shift or the measured displacement;
218
+ - interpolation and boundary handling used to produce `HAADF_aligned.tiff`.
219
+
220
+ The shift units are pixels.
221
+
222
+ ## Elemental lines and later preprocessing
223
+
224
+ The associated publication reports net-count extraction using:
225
+
226
+ | Element | Emission line |
227
+ |---|---|
228
+ | Ge | Kα |
229
+ | Te | Lα |
230
+ | Sb | Lα |
231
+ | Ti | Kα |
232
+
233
+ The publication workflow reports:
234
+
235
+ 1. translation-only alignment with Fiji MultiStackReg;
236
+ 2. transform estimation from Ge maps;
237
+ 3. application of the same transformations to Te, Sb, and Ti;
238
+ 4. later crop/resampling to `176 × 112`;
239
+ 5. binning factor 2;
240
+ 6. independent maximum normalization per element before reconstruction.
241
+
242
+ The distributed `(16, 400, 300)` TIFF stacks correspond to an earlier stage than the final reconstruction inputs.
243
+
244
+ `ali_haadf.json` describes HAADF-to-0° alignment and should not automatically be equated with the separate Ge-derived elemental-map transformations.
245
+
246
+ ## Repository organization
247
+
248
+ ```text
249
+ .
250
+ ├── README.md
251
+ ├── LICENSE
252
+ ├── CITATION.cff
253
+
254
+ ├── metadata/
255
+ │ ├── dataset.yaml
256
+ │ ├── acquisition_manifest.csv
257
+ │ ├── angles_deg.txt
258
+ │ ├── processing.yaml
259
+ │ ├── checksums.sha256
260
+ │ └── audit/
261
+
262
+ ├── raw/
263
+ │ └── emd/
264
+ │ ├── D3_EDS-HAADF_0001_-40.emd
265
+ │ ├── ...
266
+ │ └── D3_EDS-HAADF_0017_+40.emd
267
+
268
+ ├── derived/
269
+ │ ├── haadf/
270
+ │ │ ├── HAADF_stack.tif
271
+ │ │ ├── HAADF_aligned.tiff
272
+ │ │ └── alignment/
273
+ │ │ └── ali_haadf.json
274
+ │ └── eds/
275
+ │ └── elemental_tilt_series/
276
+ │ ├── Ge_stack.tif
277
+ │ ├── Sb_stack.tif
278
+ │ ├── Te_stack.tif
279
+ │ ├── Ti_stack.tif
280
+ │ └── Si_stack.tif
281
+
282
+ ├── previews/
283
+ └── scripts/
284
+ └── audit_themis_dataset.py
285
+ ```
286
+
287
+ ## Loading the derived data
288
+
289
+ ```python
290
+ from pathlib import Path
291
+
292
+ import json
293
+ import numpy as np
294
+ import tifffile
295
+
296
+ root = Path(".")
297
+
298
+ haadf = tifffile.imread(root / "derived/haadf/HAADF_aligned.tiff")
299
+ angles = np.loadtxt(root / "metadata/angles_deg.txt", dtype=np.float64)
300
+
301
+ with (root / "derived/haadf/alignment/ali_haadf.json").open() as handle:
302
+ haadf_pixel_shifts = np.asarray(json.load(handle), dtype=np.int64)
303
+
304
+ assert haadf.shape == (16, 400, 300)
305
+ assert angles.shape == (16,)
306
+ assert haadf_pixel_shifts.shape == (16, 2)
307
+ ```
308
+
309
+ ## Intended uses
310
+
311
+ Potential uses include:
312
+
313
+ - limited-angle HAADF-STEM tomography;
314
+ - STEM-EDS chemical tomography;
315
+ - multichannel reconstruction;
316
+ - raw spectrum-stream reprocessing;
317
+ - frame-aware denoising and registration;
318
+ - irregular-angle reconstruction;
319
+ - joint HAADF/EDS methods;
320
+ - semiconductor-device characterization.
321
+
322
+ The dataset does not contain an independently validated ground-truth reconstruction.
323
+
324
+ ## Known limitations
325
+
326
+ - The meaning of the internal lamella code `b2_d3` is undocumented.
327
+ - It remains unknown whether `b2_d3` is the virgin or SET device.
328
+ - The exact Titan Themis generation/submodel is undocumented.
329
+ - Wafer, die, and device lineage are unavailable.
330
+ - The exact 50-frame HAADF combination method is undocumented.
331
+ - The component order and sign convention in `ali_haadf.json` remain undocumented.
332
+ - N and O maps are retained inside the EMD files but not exported as public TIFF stacks.
333
+ - Net-intensity maps are not quantitative concentration maps.
334
+ - No independently validated 3D ground truth is included.
335
+
336
+ ## Associated publication
337
+
338
+ This dataset is the experimental dataset associated with:
339
+
340
+ > Daniel del Pozo Bueno, Serge Brosset, Theo Monniez, Gabriele Navarro, Philippe Ciuciu, and Zineb Saghi.
341
+ > **Unsupervised Deep Learning for Limited-Angle STEM-EDX Tomography — Application to 3D Chemical Analysis of Phase-Change Memory Devices.**
342
+ > arXiv:2606.10547, 2026. DOI: `10.48550/arXiv.2606.10547`.
343
+
344
+ ## License
345
+
346
+ This dataset is released under the **Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International** license:
347
+
348
+ ```text
349
+ CC BY-NC-ND 4.0
350
+ ```
351
+
352
+ You may share the unmodified dataset with attribution for non-commercial purposes. Distribution of adapted or modified versions is not permitted under this license. Consult the license text for the authoritative legal terms.
353
+
354
+ ## Citation
355
+
356
+ Use the dataset citation in `CITATION.cff` and cite the associated publication when using these data in scientific work.
357
+
358
+ ## Contacts
359
+
360
+ - **Dataset curator:** Daniele Picone — `daniele.picone@cea.fr`
361
+ - **Scientific contact:** Daniel Del Pozo Bueno — `daniel.delpozobueno@cea.fr`
362
+ - **PFNC contact:** Zineb Saghi — `zineb.saghi@cea.fr`
363
+ - **Original acquisition:** Le-Duc Minh Tran - `le-ducminh.tran@cea.fr`
364
+ - **Organization:** CEA-Leti, Grenoble
derived/edx/elemental_tilt_series/Ge_stack.tif ADDED

Git LFS Details

  • SHA256: 71aa33b0358caf5898b927b773e4cd3c190e9ec28ff34939c18f9d2886b49922
  • Pointer size: 132 Bytes
  • Size of remote file: 7.69 MB
derived/edx/elemental_tilt_series/Sb_stack.tif ADDED

Git LFS Details

  • SHA256: 23023e88daf4750d12c3139acbedaefd175f057725dc048a4dcf8103b0c68ae8
  • Pointer size: 132 Bytes
  • Size of remote file: 7.69 MB
derived/edx/elemental_tilt_series/Si_stack.tif ADDED

Git LFS Details

  • SHA256: 0e048be2775c3db3123d0bf829a35f1a37d84bc68440d39417493fbe686e0d65
  • Pointer size: 132 Bytes
  • Size of remote file: 7.69 MB
derived/edx/elemental_tilt_series/Te_stack.tif ADDED

Git LFS Details

  • SHA256: 2e6908117e633e683b0c354d794ee1c3b505fa2460434dcc558be23b634db5c6
  • Pointer size: 132 Bytes
  • Size of remote file: 7.69 MB
derived/edx/elemental_tilt_series/Ti_stack.tif ADDED

Git LFS Details

  • SHA256: 9c45f220ad941b32614021bb0d8276801e6088009d76e0775daf424cce99bf79
  • Pointer size: 132 Bytes
  • Size of remote file: 7.69 MB
derived/haadf/HAADF_aligned.tiff ADDED

Git LFS Details

  • SHA256: 3d114c93a93df50ecb4e537230c2ebac7a0b2eb26a2607d657865cf23bf12dbd
  • Pointer size: 132 Bytes
  • Size of remote file: 7.76 MB
derived/haadf/HAADF_stack.tif ADDED

Git LFS Details

  • SHA256: a7820f4a043ff7ab66c6f4bdd4becd47f6fdf092c044b3477f024391abb51412
  • Pointer size: 132 Bytes
  • Size of remote file: 3.85 MB
derived/haadf/alignment/ali_haadf.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ [
3
+ 9,
4
+ 2
5
+ ],
6
+ [
7
+ -7,
8
+ 5
9
+ ],
10
+ [
11
+ -2,
12
+ -1
13
+ ],
14
+ [
15
+ 2,
16
+ 7
17
+ ],
18
+ [
19
+ -14,
20
+ 4
21
+ ],
22
+ [
23
+ -6,
24
+ -7
25
+ ],
26
+ [
27
+ -1,
28
+ -14
29
+ ],
30
+ [
31
+ 3,
32
+ -1
33
+ ],
34
+ [
35
+ 0,
36
+ 0
37
+ ],
38
+ [
39
+ -20,
40
+ -3
41
+ ],
42
+ [
43
+ -16,
44
+ 6
45
+ ],
46
+ [
47
+ -23,
48
+ 9
49
+ ],
50
+ [
51
+ 8,
52
+ -15
53
+ ],
54
+ [
55
+ -4,
56
+ -11
57
+ ],
58
+ [
59
+ 1,
60
+ 6
61
+ ],
62
+ [
63
+ 0,
64
+ 13
65
+ ]
66
+ ]
metadata/acquisition_manifest.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ stack_index,acquisition_number,nominal_tilt_deg,emd_file,haadf_present,eds_present,included_in_derived_stacks,status,notes
2
+ 0,1,-40,raw/emd/D3_EDS-HAADF_0001_-40.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
3
+ 1,2,-35,raw/emd/D3_EDS-HAADF_0002_-35.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
4
+ 2,3,-30,raw/emd/D3_EDS-HAADF_0003_-30.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
5
+ 3,4,-25,raw/emd/D3_EDS-HAADF_0004_-25.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
6
+ 4,5,-20,raw/emd/D3_EDS-HAADF_0005_-20.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
7
+ 5,6,-15,raw/emd/D3_EDS-HAADF_0006_-15.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
8
+ 6,7,-10,raw/emd/D3_EDS-HAADF_0007_-10.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
9
+ 7,8,-5,raw/emd/D3_EDS-HAADF_0008_-5.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
10
+ 8,9,0,raw/emd/D3_EDS-HAADF_0009_00.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
11
+ 9,11,10,raw/emd/D3_EDS-HAADF_0011_+10.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
12
+ 10,12,15,raw/emd/D3_EDS-HAADF_0012_+15.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
13
+ 11,13,20,raw/emd/D3_EDS-HAADF_0013_+20.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
14
+ 12,14,25,raw/emd/D3_EDS-HAADF_0014_+25.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
15
+ 13,15,30,raw/emd/D3_EDS-HAADF_0015_+30.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
16
+ 14,16,35,raw/emd/D3_EDS-HAADF_0016_+35.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
17
+ 15,17,40,raw/emd/D3_EDS-HAADF_0017_+40.emd,yes,yes,yes,retained,Retained projection. EMD contains 50 HAADF frames and a 50-frame EDS spectrum stream. Filename normalized to remove spaces.
metadata/angles_deg.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -40
2
+ -35
3
+ -30
4
+ -25
5
+ -20
6
+ -15
7
+ -10
8
+ -5
9
+ 0
10
+ 10
11
+ 15
12
+ 20
13
+ 25
14
+ 30
15
+ 35
16
+ 40
metadata/audit/audit_summary.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dataset audit summary
2
+
3
+ - Dataset root: `/home/deck/Documents/code/scitomo/data/raw/D3_Tomography`
4
+ - Total files: 9259
5
+ - EMD files: 16
6
+ - TIFF files: 7
7
+ - JSON files: 19
8
+ - Angle files: 1
9
+ - Parsed filename angles: [-40.0, -35.0, -30.0, -25.0, -20.0, -15.0, -10.0, -5.0, 0.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0]
10
+ - Inferred common angular step: 5.0
11
+ - Missing angles within filename range: [5.0]
12
+ - Missing acquisition numbers: [10]
13
+ - Parsed angles file values: [-40.0, -35.0, -30.0, -25.0, -20.0, -15.0, -10.0, -5.0, 0.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0]
14
+ - Angle-file parse error: none
15
+
16
+ ## TIFF series shapes
17
+
18
+ ```json
19
+ {}
20
+ ```
21
+
22
+ ## Required manual checks
23
+
24
+ - Confirm that the manifest order equals the plane order in every TIFF stack.
25
+ - Resolve every mismatch between filename angles and `angles.txt`.
26
+ - Inspect `hyperspy_summary.json` to identify HAADF and EDS signals.
27
+ - Review exported metadata for confidential identifiers before publication.
28
+ - Document alignment and elemental-map extraction.
metadata/audit/checksums.sha256 ADDED
The diff for this file is too large to render. See raw diff
 
metadata/audit/emd_hdf5_summary.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "error": "Install h5py to inspect EMD/HDF5 files."
3
+ }
metadata/audit/file_inventory.csv ADDED
The diff for this file is too large to render. See raw diff
 
metadata/audit/hyperspy_summary.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "error": "Install hyperspy, rosettasciio, and sparse."
3
+ }
metadata/audit/json_summary.json ADDED
The diff for this file is too large to render. See raw diff
 
metadata/audit/tiff_summary.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "error": "Install tifffile to inspect TIFF files."
3
+ }
metadata/audit/tilt_manifest.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ stack_index_candidate,acquisition_number,filename_angle_deg,angles_file_value_deg,angle_match,emd_file,status,notes
2
+ 0,1,-40.0,-40.0,True,raw/emd/D3_EDS-HAADF_0001_-40.emd,unknown,
3
+ 1,2,-35.0,-35.0,True,raw/emd/D3_EDS-HAADF_0002_-35.emd,unknown,
4
+ 2,3,-30.0,-30.0,True,raw/emd/D3_EDS-HAADF_0003_-30.emd,unknown,
5
+ 3,4,-25.0,-25.0,True,raw/emd/D3_EDS-HAADF_0004_-25.emd,unknown,
6
+ 4,5,-20.0,-20.0,True,raw/emd/D3_EDS-HAADF_0005_-20.emd,unknown,
7
+ 5,6,-15.0,-15.0,True,raw/emd/D3_EDS-HAADF_0006_-15.emd,unknown,
8
+ 6,7,-10.0,-10.0,True,raw/emd/D3_EDS-HAADF_0007_-10.emd,unknown,
9
+ 7,8,-5.0,-5.0,True,raw/emd/D3_EDS-HAADF_0008_-5.emd,unknown,
10
+ 8,9,0.0,0.0,True,raw/emd/D3_EDS-HAADF_0009_00.emd,unknown,
11
+ 9,11,10.0,10.0,True,raw/emd/D3_EDS-HAADF_0011_+10.emd,unknown,
12
+ 10,12,15.0,15.0,True,raw/emd/D3_EDS-HAADF_0012_+15.emd,unknown,
13
+ 11,13,20.0,20.0,True,raw/emd/D3_EDS-HAADF_0013_+20.emd,unknown,
14
+ 12,14,25.0,25.0,True,raw/emd/D3_EDS-HAADF_0014_+25.emd,unknown,
15
+ 13,15,30.0,30.0,True,raw/emd/D3_EDS-HAADF_0015_+30.emd,unknown,
16
+ 14,16,35.0,35.0,True,raw/emd/D3_EDS-HAADF_0016_+35.emd,unknown,
17
+ 15,17,40.0,40.0,True,raw/emd/D3_EDS-HAADF_0017_+40.emd,unknown,
metadata/dataset.yaml ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ dataset:
2
+ title: "PFNC GST HAADF-STEM/EDS Tomography — Lamella b2_d3"
3
+ repository_slug_recommended: "pfnc-gst-haadf-stem-eds-tomography-b2-d3"
4
+ version: "1.0.0-release-candidate"
5
+ license: "cc-by-nc-nd-4.0"
6
+ release_authorization:
7
+ cea: true
8
+ sample_owner: true
9
+
10
+ provenance:
11
+ lamella_identifier: "b2_d3"
12
+ filename_identifier: "D3"
13
+ dataset_provider: "Daniel Del Pozo Bueno"
14
+ original_acquisition_operator:
15
+ name: "Le-Duc Minh Tran"
16
+ email: "le-ducminh.tran@cea.fr"
17
+ curator:
18
+ name: "Daniele Picone"
19
+ email: "daniele.picone@cea.fr"
20
+ scientific_contact:
21
+ name: "Daniel Del Pozo Bueno"
22
+ email: "daniel.delpozobueno@cea.fr"
23
+ pfnc_contact:
24
+ name: "Zineb Saghi"
25
+ email: "zineb.saghi@cea.fr"
26
+ dataset_organization: "CEA-Leti, Grenoble"
27
+ acquisition_facility: "PFNC, CEA Grenoble"
28
+ acquisition_institute_context: "CEA-Liten"
29
+
30
+ instrument:
31
+ manufacturer: "Thermo Fisher Scientific"
32
+ model_family: "Titan Themis"
33
+ exact_generation_or_submodel: "UNKNOWN"
34
+ operating_voltage_kv: 200
35
+ probe_corrected: true
36
+ eds_system:
37
+ name: "Super-X"
38
+ detector_type: "silicon drift detector"
39
+ detector_count: 4
40
+ embedded_identifier: "SuperXG1"
41
+ software:
42
+ name: "Velox"
43
+ version: "3.17.0.967-b5399cab"
44
+ emd:
45
+ format: "Velox EMD"
46
+ format_version: 11
47
+
48
+ sample:
49
+ identifier: "b2_d3"
50
+ filename_identifier: "D3"
51
+ system: "Ge-Sb-Te phase-change-memory device"
52
+ specimen: "cross-sectional FIB lamella"
53
+ operational_state: "UNKNOWN: virgin or SET"
54
+ approximate_gst_region_thickness_nm: 50
55
+ holder: "Fischione single-axis tomography holder"
56
+ tilt_axis_relation: "parallel to GST layer"
57
+
58
+ acquisition:
59
+ date: "2025-07-07"
60
+ accelerating_voltage_kv: 200
61
+ beam_current_pa: 115
62
+ camera_length_mm: 110
63
+ pixel_size_angstrom: 10.67
64
+ frame_shape_vu: [400, 300]
65
+ dwell_time_us: 40
66
+ frames_per_tilt: 50
67
+ time_per_frame_s: 5.57
68
+ cumulative_time_per_tilt_s: 278.5
69
+ intended_angles_deg: [-40, -35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40]
70
+ retained_angles_deg: [-40, -35, -30, -25, -20, -15, -10, -5, 0, 10, 15, 20, 25, 30, 35, 40]
71
+ discarded_angle_deg: 5
72
+ discarded_acquisition_number: 10
73
+ discarded_reason: "acquisition corruption"
74
+
75
+ raw_data:
76
+ filename_pattern: "D3_EDS-HAADF_<acquisition>_<signed-angle>.emd"
77
+ haadf:
78
+ shape_per_tilt: [400, 300, 50]
79
+ dtype: uint16
80
+ eds:
81
+ spectral_bins: 4096
82
+ frames_per_tilt: 50
83
+ stream_dtype: uint16
84
+ integrated_spectrum_dtype: uint32
85
+ rendered_map_mode: NetIntensity
86
+ embedded_elements: [N, O, Si, Ti, Ge, Sb, Te]
87
+
88
+ derived_data:
89
+ haadf_alignment:
90
+ reference_angle_deg: 0
91
+ shift_units: pixels
92
+ parameter_shape: [16, 2]
93
+ component_order: UNKNOWN
94
+ sign_convention: UNKNOWN
95
+ elemental_stacks: [Ge, Sb, Te, Ti, Si]
96
+
97
+ associated_study:
98
+ title: "Unsupervised Deep Learning for Limited-Angle STEM-EDX Tomography -- Application to 3D Chemical Analysis of Phase-Change Memory Devices"
99
+ arxiv: "2606.10547"
100
+ doi: "10.48550/arXiv.2606.10547"
101
+ association_status: "confirmed by dataset provider"
metadata/processing.yaml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ haadf_projection_export:
2
+ source: "50-frame HAADF series in each Velox EMD"
3
+ source_shape_per_tilt: [400, 300, 50]
4
+ source_dtype: uint16
5
+ output: derived/haadf/HAADF_stack.tif
6
+ frame_selection: UNKNOWN
7
+ rejected_frames: UNKNOWN
8
+ combination: UNKNOWN
9
+ drift_correction: UNKNOWN
10
+ normalization: UNKNOWN
11
+ crop: UNKNOWN
12
+ binning: UNKNOWN
13
+
14
+ haadf_alignment:
15
+ input: derived/haadf/HAADF_stack.tif
16
+ output: derived/haadf/HAADF_aligned.tiff
17
+ parameters: derived/haadf/alignment/ali_haadf.json
18
+ reference_angle_deg: 0
19
+ parameter_count: 16
20
+ parameter_shape: [16, 2]
21
+ parameter_units: pixels
22
+ parameter_meaning: "translation used to align each HAADF projection to the 0-degree acquisition"
23
+ zero_degree_entry: [0, 0]
24
+ component_order: UNKNOWN
25
+ sign_convention: UNKNOWN
26
+ interpolation: UNKNOWN
27
+ boundary_handling: UNKNOWN
28
+
29
+ eds_map_extraction:
30
+ source: "50-frame EDS spectrum stream in each Velox EMD"
31
+ detector: "Super-X, four SDDs"
32
+ map_mode: NetIntensity
33
+ lines:
34
+ Ge: "Kα"
35
+ Te: "Lα"
36
+ Sb: "Lα"
37
+ Ti: "Kα"
38
+ embedded_additional_elements: [N, O, Si]
39
+ rendered_map_filter:
40
+ enabled: true
41
+ type: Mean
42
+ kernel_size: 3
43
+ spectral_filter:
44
+ enabled: false
45
+ type: Gaussian
46
+ absorption_correction:
47
+ enabled: false
48
+
49
+ publication_elemental_alignment:
50
+ software: Fiji
51
+ plugin: MultiStackReg
52
+ transform: translation-only
53
+ reference_channel_for_transform_estimation: Ge
54
+ applied_to_channels: [Ge, Te, Sb, Ti]
55
+ later_output_shape: [176, 112]
56
+ binning_factor: 2
57
+ normalization: "independent maximum normalization per channel"
58
+ note: "The distributed 400x300 TIFFs precede this later reconstruction preprocessing."
previews/haadf_zero_tilt.png ADDED

Git LFS Details

  • SHA256: d6e6aed23d81c970d9b920887edb3b468e1a20d009d52b707dbb76c75231bf57
  • Pointer size: 130 Bytes
  • Size of remote file: 97.2 kB
raw/emd/D3_EDS-HAADF_0001_-40.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df39dc52b422096ae56d5138dd4a004da53a841b9c079d55af9a6c8958b62aba
3
+ size 44686558
raw/emd/D3_EDS-HAADF_0002_-35.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84c505ccb715eca48e142bdf0fde67646d1ebf1b10761ca26be4452fbf8e1410
3
+ size 43410877
raw/emd/D3_EDS-HAADF_0003_-30.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e44979f37679429a42140f71e0da080b1b2fea18dc8f25b85fc38e18cf0269a1
3
+ size 42351831
raw/emd/D3_EDS-HAADF_0004_-25.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17034cc8120405965f7328dcfb1a6d7b84a31a3b96787727573d619f3d2c7b5e
3
+ size 41675026
raw/emd/D3_EDS-HAADF_0005_-20.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25bb549801f90d71c41bfe1cf11a0ae49e0bc30e19017053ea1c56d3f67f86fe
3
+ size 41493710
raw/emd/D3_EDS-HAADF_0006_-15.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbd7f761519d659e8b38a07590a5d194fb7951c9bf128754525003830eb3bc8a
3
+ size 41019680
raw/emd/D3_EDS-HAADF_0007_-10.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc4124ee3e52df65a2a72ffda013c917f05731a8b7691c6e566b191f65b45dde
3
+ size 40621713
raw/emd/D3_EDS-HAADF_0008_-5.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91ac9efc693919e8172cd3349917c79e47419fea436d258497dab969beb89730
3
+ size 40470559
raw/emd/D3_EDS-HAADF_0009_00.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82524989e90641cea9279560dcd458edd02042a7a5ca1a3c70c49c6308ad6c27
3
+ size 40397526
raw/emd/D3_EDS-HAADF_0011_+10.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4ddce2f8c6d825616c5bcd45a20db3260c63ae074fb2cd58f0e4fb5dbf05c14
3
+ size 41440088
raw/emd/D3_EDS-HAADF_0012_+15.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00c55f807c099f3c9b8cebf321558c65905341be9497956e66e551354c296812
3
+ size 41168660
raw/emd/D3_EDS-HAADF_0013_+20.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e997baf5bde89680c63a0fa2f81310c16b0803ab1abcd594e4cec5cee8bad6ff
3
+ size 41705397
raw/emd/D3_EDS-HAADF_0014_+25.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b468fe1401bd8c8f04f7ac70ed43516b440c1fa3bf3222c2282c4d89da0c1639
3
+ size 41867313
raw/emd/D3_EDS-HAADF_0015_+30.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b8cc93d77591bdabcdb0ccb2fe53046ec318f671a24a1fd3f150605b9d6064c
3
+ size 42982493
raw/emd/D3_EDS-HAADF_0016_+35.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9274cffa7af1df827b36aa1d01c8fddbeedca78a4e288bbb9017c529412f0d22
3
+ size 44237637
raw/emd/D3_EDS-HAADF_0017_+40.emd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e59d5814b0ad818a3ece787cb2d6dae58d9e9e4f08b5b21a69cb427a20026057
3
+ size 46312973
scripts/audit_themis_dataset.py ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Audit a NEOARM/EMD tomography directory without modifying source files.
3
+
4
+ Outputs:
5
+ _audit/file_inventory.csv
6
+ _audit/checksums.sha256
7
+ _audit/tilt_manifest.csv
8
+ _audit/tiff_summary.json
9
+ _audit/json_summary.json
10
+ _audit/emd_hdf5_summary.json
11
+ _audit/hyperspy_summary.json (only with --hyperspy-files)
12
+ _audit/audit_summary.md
13
+
14
+ The script reads HDF5/EMD structure and TIFF metadata but does not load full
15
+ numeric arrays unless optional HyperSpy inspection is requested.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import csv
22
+ import hashlib
23
+ import json
24
+ import math
25
+ import re
26
+ import statistics
27
+ import sys
28
+ from collections import Counter
29
+ from pathlib import Path
30
+ from typing import Any, Iterable
31
+
32
+ ANGLE_RE = re.compile(r"(?P<angle>[+-]?\d+(?:\.\d+)?)\.emd$", re.IGNORECASE)
33
+ ACQ_RE = re.compile(r"(?P<number>\d{4})(?=_[+-]?\d+(?:\.\d+)?\.emd$)", re.IGNORECASE)
34
+ FLOAT_RE = re.compile(r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?")
35
+
36
+
37
+ def sha256_file(path: Path, chunk_size: int = 8 * 1024 * 1024) -> str:
38
+ digest = hashlib.sha256()
39
+ with path.open("rb") as handle:
40
+ while chunk := handle.read(chunk_size):
41
+ digest.update(chunk)
42
+ return digest.hexdigest()
43
+
44
+
45
+ def safe_value(value: Any, max_chars: int = 2000) -> Any:
46
+ """Convert metadata values to bounded JSON-safe representations."""
47
+ if value is None or isinstance(value, (bool, int, float, str)):
48
+ text = value
49
+ elif isinstance(value, bytes):
50
+ text = value.decode("utf-8", errors="replace")
51
+ elif hasattr(value, "tolist"):
52
+ try:
53
+ converted = value.tolist()
54
+ if isinstance(converted, list) and len(converted) > 100:
55
+ return {
56
+ "type": type(value).__name__,
57
+ "length": len(converted),
58
+ "preview": converted[:10],
59
+ }
60
+ return safe_value(converted, max_chars=max_chars)
61
+ except Exception:
62
+ text = repr(value)
63
+ elif isinstance(value, dict):
64
+ return {
65
+ str(k): safe_value(v, max_chars=max_chars)
66
+ for k, v in list(value.items())[:200]
67
+ }
68
+ elif isinstance(value, (list, tuple)):
69
+ if len(value) > 100:
70
+ return {
71
+ "length": len(value),
72
+ "preview": [safe_value(v, max_chars=max_chars) for v in value[:10]],
73
+ }
74
+ return [safe_value(v, max_chars=max_chars) for v in value]
75
+ else:
76
+ text = repr(value)
77
+
78
+ if isinstance(text, str) and len(text) > max_chars:
79
+ return text[:max_chars] + "...<truncated>"
80
+ return text
81
+
82
+
83
+ def parse_angles_file(path: Path) -> list[float]:
84
+ text = path.read_text(encoding="utf-8", errors="replace")
85
+ return [float(token) for token in FLOAT_RE.findall(text)]
86
+
87
+
88
+ def emd_records(files: Iterable[Path], root: Path) -> list[dict[str, Any]]:
89
+ records = []
90
+ for path in files:
91
+ angle_match = ANGLE_RE.search(path.name)
92
+ number_match = ACQ_RE.search(path.name)
93
+ records.append(
94
+ {
95
+ "path": path,
96
+ "relative_path": path.relative_to(root).as_posix(),
97
+ "filename": path.name,
98
+ "acquisition_number": (
99
+ int(number_match.group("number")) if number_match else None
100
+ ),
101
+ "filename_angle_deg": (
102
+ float(angle_match.group("angle")) if angle_match else None
103
+ ),
104
+ }
105
+ )
106
+ return sorted(
107
+ records,
108
+ key=lambda row: (
109
+ row["acquisition_number"] is None,
110
+ row["acquisition_number"] or math.inf,
111
+ row["filename"],
112
+ ),
113
+ )
114
+
115
+
116
+ def infer_missing(values: list[float]) -> tuple[float | None, list[float]]:
117
+ unique = sorted(set(values))
118
+ if len(unique) < 3:
119
+ return None, []
120
+
121
+ positive_diffs = [
122
+ round(b - a, 12) for a, b in zip(unique, unique[1:]) if b > a
123
+ ]
124
+ if not positive_diffs:
125
+ return None, []
126
+
127
+ counts = Counter(positive_diffs)
128
+ step = counts.most_common(1)[0][0]
129
+ if step <= 0:
130
+ return None, []
131
+
132
+ missing: list[float] = []
133
+ value = unique[0]
134
+ while value <= unique[-1] + step / 2:
135
+ if not any(abs(value - observed) < 1e-8 for observed in unique):
136
+ missing.append(round(value, 10))
137
+ value += step
138
+ return step, missing
139
+
140
+
141
+ def inspect_tiffs(paths: list[Path], root: Path) -> dict[str, Any]:
142
+ try:
143
+ import tifffile
144
+ except ImportError:
145
+ return {"error": "Install tifffile to inspect TIFF files."}
146
+
147
+ output: dict[str, Any] = {}
148
+ for path in paths:
149
+ key = path.relative_to(root).as_posix()
150
+ try:
151
+ with tifffile.TiffFile(path) as tif:
152
+ series = []
153
+ for item in tif.series:
154
+ series.append(
155
+ {
156
+ "shape": list(item.shape),
157
+ "dtype": str(item.dtype),
158
+ "axes": getattr(item, "axes", None),
159
+ "page_count": len(item.pages),
160
+ }
161
+ )
162
+ first_page = tif.pages[0] if tif.pages else None
163
+ tags = {}
164
+ if first_page is not None:
165
+ for tag_name in (
166
+ "ImageWidth",
167
+ "ImageLength",
168
+ "BitsPerSample",
169
+ "SampleFormat",
170
+ "XResolution",
171
+ "YResolution",
172
+ "ResolutionUnit",
173
+ "ImageDescription",
174
+ "Software",
175
+ "DateTime",
176
+ ):
177
+ tag = first_page.tags.get(tag_name)
178
+ if tag is not None:
179
+ tags[tag_name] = safe_value(tag.value)
180
+ output[key] = {
181
+ "series": series,
182
+ "page_count": len(tif.pages),
183
+ "is_imagej": bool(tif.is_imagej),
184
+ "is_ome": bool(tif.is_ome),
185
+ "imagej_metadata": safe_value(tif.imagej_metadata),
186
+ "first_page_tags": tags,
187
+ }
188
+ except Exception as exc:
189
+ output[key] = {"error": f"{type(exc).__name__}: {exc}"}
190
+ return output
191
+
192
+
193
+ def inspect_json_files(paths: list[Path], root: Path) -> dict[str, Any]:
194
+ output: dict[str, Any] = {}
195
+ for path in paths:
196
+ key = path.relative_to(root).as_posix()
197
+ try:
198
+ data = json.loads(path.read_text(encoding="utf-8", errors="strict"))
199
+ summary: dict[str, Any] = {"root_type": type(data).__name__}
200
+ if isinstance(data, dict):
201
+ summary["keys"] = list(data.keys())[:200]
202
+ summary["content_preview"] = safe_value(data)
203
+ elif isinstance(data, list):
204
+ summary["length"] = len(data)
205
+ summary["content_preview"] = safe_value(data[:10])
206
+ else:
207
+ summary["content_preview"] = safe_value(data)
208
+ output[key] = summary
209
+ except Exception as exc:
210
+ output[key] = {"error": f"{type(exc).__name__}: {exc}"}
211
+ return output
212
+
213
+
214
+ def inspect_hdf5_emd(
215
+ paths: list[Path],
216
+ root: Path,
217
+ max_objects_per_file: int = 5000,
218
+ ) -> dict[str, Any]:
219
+ try:
220
+ import h5py
221
+ except ImportError:
222
+ return {"error": "Install h5py to inspect EMD/HDF5 files."}
223
+
224
+ output: dict[str, Any] = {}
225
+ for path in paths:
226
+ key = path.relative_to(root).as_posix()
227
+ objects: list[dict[str, Any]] = []
228
+ truncated = False
229
+ try:
230
+ with h5py.File(path, "r") as handle:
231
+ root_attrs = {
232
+ str(k): safe_value(v) for k, v in handle.attrs.items()
233
+ }
234
+
235
+ def visitor(name: str, obj: Any) -> None:
236
+ nonlocal truncated
237
+ if len(objects) >= max_objects_per_file:
238
+ truncated = True
239
+ return
240
+
241
+ record: dict[str, Any] = {
242
+ "path": name,
243
+ "kind": type(obj).__name__,
244
+ }
245
+ if hasattr(obj, "shape"):
246
+ record["shape"] = list(obj.shape)
247
+ if hasattr(obj, "dtype"):
248
+ record["dtype"] = str(obj.dtype)
249
+ attrs = {
250
+ str(k): safe_value(v)
251
+ for k, v in list(obj.attrs.items())[:50]
252
+ }
253
+ if attrs:
254
+ record["attributes"] = attrs
255
+
256
+ # Read only small scalar/string datasets, never large arrays.
257
+ if (
258
+ hasattr(obj, "shape")
259
+ and hasattr(obj, "dtype")
260
+ and (
261
+ obj.shape == ()
262
+ or (
263
+ getattr(obj.dtype, "kind", "") in {"S", "U", "O"}
264
+ and getattr(obj, "size", 0) <= 64
265
+ )
266
+ )
267
+ ):
268
+ try:
269
+ record["value"] = safe_value(obj[()])
270
+ except Exception:
271
+ pass
272
+ objects.append(record)
273
+
274
+ handle.visititems(visitor)
275
+ output[key] = {
276
+ "root_attributes": root_attrs,
277
+ "objects": objects,
278
+ "truncated": truncated,
279
+ }
280
+ except Exception as exc:
281
+ output[key] = {"error": f"{type(exc).__name__}: {exc}"}
282
+ return output
283
+
284
+
285
+ def metadata_to_dict(node: Any) -> Any:
286
+ if node is None:
287
+ return None
288
+ if hasattr(node, "as_dictionary"):
289
+ try:
290
+ return safe_value(node.as_dictionary())
291
+ except Exception:
292
+ pass
293
+ return safe_value(node)
294
+
295
+
296
+ def inspect_with_hyperspy(
297
+ paths: list[Path],
298
+ root: Path,
299
+ count: int,
300
+ ) -> dict[str, Any]:
301
+ if count <= 0:
302
+ return {}
303
+ try:
304
+ import hyperspy.api as hs
305
+ except ImportError:
306
+ return {"error": "Install hyperspy, rosettasciio, and sparse."}
307
+
308
+ output: dict[str, Any] = {}
309
+ for path in paths[:count]:
310
+ key = path.relative_to(root).as_posix()
311
+ try:
312
+ loaded = hs.load(path, lazy=True)
313
+ signals = loaded if isinstance(loaded, list) else [loaded]
314
+ summaries = []
315
+ for signal in signals:
316
+ axes = []
317
+ raw_axes = list(getattr(signal.axes_manager, "_axes", []))
318
+ if not raw_axes:
319
+ raw_axes = list(signal.axes_manager.navigation_axes) + list(
320
+ signal.axes_manager.signal_axes
321
+ )
322
+ for axis in raw_axes:
323
+ # Some HyperSpy versions expose grouped axes as tuples.
324
+ grouped_axes = axis if isinstance(axis, (tuple, list)) else (axis,)
325
+ for item in grouped_axes:
326
+ axes.append(
327
+ {
328
+ "name": getattr(item, "name", None),
329
+ "size": int(getattr(item, "size", 0)),
330
+ "scale": safe_value(getattr(item, "scale", None)),
331
+ "offset": safe_value(getattr(item, "offset", None)),
332
+ "units": getattr(item, "units", None),
333
+ "navigate": bool(getattr(item, "navigate", False)),
334
+ }
335
+ )
336
+ summaries.append(
337
+ {
338
+ "class": type(signal).__name__,
339
+ "title": signal.metadata.get_item(
340
+ "General.title", default=None
341
+ ),
342
+ "data_shape": list(signal.data.shape),
343
+ "data_dtype": str(signal.data.dtype),
344
+ "axes": axes,
345
+ "metadata": metadata_to_dict(signal.metadata),
346
+ "original_metadata": metadata_to_dict(
347
+ signal.original_metadata
348
+ ),
349
+ }
350
+ )
351
+ output[key] = summaries
352
+ except Exception as exc:
353
+ output[key] = {"error": f"{type(exc).__name__}: {exc}"}
354
+ return output
355
+
356
+
357
+ def write_json(path: Path, value: Any) -> None:
358
+ path.write_text(
359
+ json.dumps(value, indent=2, ensure_ascii=False),
360
+ encoding="utf-8",
361
+ )
362
+
363
+
364
+ def main() -> int:
365
+ parser = argparse.ArgumentParser()
366
+ parser.add_argument("dataset_root", type=Path)
367
+ parser.add_argument(
368
+ "--output",
369
+ type=Path,
370
+ default=None,
371
+ help="Default: DATASET_ROOT/_audit",
372
+ )
373
+ parser.add_argument(
374
+ "--hyperspy-files",
375
+ type=int,
376
+ default=0,
377
+ help="Inspect this many EMD files with HyperSpy. Start with 1.",
378
+ )
379
+ args = parser.parse_args()
380
+
381
+ root = args.dataset_root.expanduser().resolve()
382
+ if not root.is_dir():
383
+ print(f"Not a directory: {root}", file=sys.stderr)
384
+ return 2
385
+
386
+ output = (
387
+ args.output.expanduser().resolve()
388
+ if args.output is not None
389
+ else root / "_audit"
390
+ )
391
+ output.mkdir(parents=True, exist_ok=True)
392
+
393
+ files = sorted(
394
+ path for path in root.rglob("*")
395
+ if path.is_file() and output not in path.parents
396
+ )
397
+ emd_files = [p for p in files if p.suffix.lower() == ".emd"]
398
+ tiff_files = [
399
+ p for p in files if p.suffix.lower() in {".tif", ".tiff"}
400
+ ]
401
+ json_files = [p for p in files if p.suffix.lower() == ".json"]
402
+ angle_files = [
403
+ p for p in files if p.name.lower() in {"angles.txt", "angles_deg.txt"}
404
+ ]
405
+
406
+ inventory_path = output / "file_inventory.csv"
407
+ checksum_path = output / "checksums.sha256"
408
+ with inventory_path.open("w", newline="", encoding="utf-8") as csv_handle, \
409
+ checksum_path.open("w", encoding="utf-8") as checksum_handle:
410
+ writer = csv.DictWriter(
411
+ csv_handle,
412
+ fieldnames=["relative_path", "size_bytes", "suffix", "sha256"],
413
+ )
414
+ writer.writeheader()
415
+ for path in files:
416
+ digest = sha256_file(path)
417
+ relative = path.relative_to(root).as_posix()
418
+ writer.writerow(
419
+ {
420
+ "relative_path": relative,
421
+ "size_bytes": path.stat().st_size,
422
+ "suffix": path.suffix.lower(),
423
+ "sha256": digest,
424
+ }
425
+ )
426
+ checksum_handle.write(f"{digest} {relative}\n")
427
+
428
+ records = emd_records(emd_files, root)
429
+ angle_values: list[float] = []
430
+ angle_parse_error: str | None = None
431
+ if angle_files:
432
+ try:
433
+ angle_values = parse_angles_file(angle_files[0])
434
+ except Exception as exc:
435
+ angle_parse_error = f"{type(exc).__name__}: {exc}"
436
+
437
+ manifest_path = output / "tilt_manifest.csv"
438
+ with manifest_path.open("w", newline="", encoding="utf-8") as handle:
439
+ fieldnames = [
440
+ "stack_index_candidate",
441
+ "acquisition_number",
442
+ "filename_angle_deg",
443
+ "angles_file_value_deg",
444
+ "angle_match",
445
+ "emd_file",
446
+ "status",
447
+ "notes",
448
+ ]
449
+ writer = csv.DictWriter(handle, fieldnames=fieldnames)
450
+ writer.writeheader()
451
+ max_count = max(len(records), len(angle_values))
452
+ for index in range(max_count):
453
+ record = records[index] if index < len(records) else None
454
+ text_angle = angle_values[index] if index < len(angle_values) else None
455
+ filename_angle = (
456
+ record["filename_angle_deg"] if record is not None else None
457
+ )
458
+ match = (
459
+ filename_angle is not None
460
+ and text_angle is not None
461
+ and abs(filename_angle - text_angle) < 1e-8
462
+ )
463
+ writer.writerow(
464
+ {
465
+ "stack_index_candidate": index,
466
+ "acquisition_number": (
467
+ record["acquisition_number"] if record else ""
468
+ ),
469
+ "filename_angle_deg": (
470
+ filename_angle if filename_angle is not None else ""
471
+ ),
472
+ "angles_file_value_deg": (
473
+ text_angle if text_angle is not None else ""
474
+ ),
475
+ "angle_match": match if (
476
+ filename_angle is not None and text_angle is not None
477
+ ) else "",
478
+ "emd_file": record["relative_path"] if record else "",
479
+ "status": "unknown",
480
+ "notes": "",
481
+ }
482
+ )
483
+
484
+ filename_angles = [
485
+ row["filename_angle_deg"]
486
+ for row in records
487
+ if row["filename_angle_deg"] is not None
488
+ ]
489
+ step, missing_angles = infer_missing(filename_angles)
490
+ acquisition_numbers = [
491
+ row["acquisition_number"]
492
+ for row in records
493
+ if row["acquisition_number"] is not None
494
+ ]
495
+ missing_numbers: list[int] = []
496
+ if acquisition_numbers:
497
+ missing_numbers = sorted(
498
+ set(range(min(acquisition_numbers), max(acquisition_numbers) + 1))
499
+ - set(acquisition_numbers)
500
+ )
501
+
502
+ tiff_summary = inspect_tiffs(tiff_files, root)
503
+ json_summary = inspect_json_files(json_files, root)
504
+ emd_summary = inspect_hdf5_emd(emd_files, root)
505
+ hyperspy_summary = inspect_with_hyperspy(
506
+ emd_files, root, args.hyperspy_files
507
+ )
508
+
509
+ write_json(output / "tiff_summary.json", tiff_summary)
510
+ write_json(output / "json_summary.json", json_summary)
511
+ write_json(output / "emd_hdf5_summary.json", emd_summary)
512
+ if args.hyperspy_files > 0:
513
+ write_json(output / "hyperspy_summary.json", hyperspy_summary)
514
+
515
+ tiff_shapes = {}
516
+ for key, value in tiff_summary.items():
517
+ if isinstance(value, dict) and "series" in value:
518
+ tiff_shapes[key] = [
519
+ item.get("shape") for item in value.get("series", [])
520
+ ]
521
+
522
+ summary_lines = [
523
+ "# Dataset audit summary",
524
+ "",
525
+ f"- Dataset root: `{root}`",
526
+ f"- Total files: {len(files)}",
527
+ f"- EMD files: {len(emd_files)}",
528
+ f"- TIFF files: {len(tiff_files)}",
529
+ f"- JSON files: {len(json_files)}",
530
+ f"- Angle files: {len(angle_files)}",
531
+ f"- Parsed filename angles: {filename_angles}",
532
+ f"- Inferred common angular step: {step}",
533
+ f"- Missing angles within filename range: {missing_angles}",
534
+ f"- Missing acquisition numbers: {missing_numbers}",
535
+ f"- Parsed angles file values: {angle_values}",
536
+ f"- Angle-file parse error: {angle_parse_error or 'none'}",
537
+ "",
538
+ "## TIFF series shapes",
539
+ "",
540
+ "```json",
541
+ json.dumps(tiff_shapes, indent=2),
542
+ "```",
543
+ "",
544
+ "## Required manual checks",
545
+ "",
546
+ "- Confirm that the manifest order equals the plane order in every TIFF stack.",
547
+ "- Resolve every mismatch between filename angles and `angles.txt`.",
548
+ "- Inspect `hyperspy_summary.json` to identify HAADF and EDS signals.",
549
+ "- Review exported metadata for confidential identifiers before publication.",
550
+ "- Document alignment and elemental-map extraction.",
551
+ ]
552
+ (output / "audit_summary.md").write_text(
553
+ "\n".join(summary_lines) + "\n",
554
+ encoding="utf-8",
555
+ )
556
+
557
+ print(f"Audit complete: {output}")
558
+ print(f"EMD files: {len(emd_files)}")
559
+ print(f"TIFF files: {len(tiff_files)}")
560
+ print(f"Missing filename-derived angles: {missing_angles}")
561
+ print(f"Missing acquisition numbers: {missing_numbers}")
562
+ if args.hyperspy_files == 0:
563
+ print("HyperSpy inspection skipped. Use --hyperspy-files 1 to inspect one EMD.")
564
+ return 0
565
+
566
+
567
+ if __name__ == "__main__":
568
+ raise SystemExit(main())
scripts/generate_haadf_preview.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate a display PNG from the HAADF projection closest to 0 degrees.
3
+
4
+ This creates a visualization only. It does not modify the TIFF source data.
5
+
6
+ Dependencies:
7
+ python -m pip install numpy tifffile pillow
8
+
9
+ Example:
10
+ python scripts/generate_haadf_preview.py .
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import argparse
16
+ from pathlib import Path
17
+
18
+ import numpy as np
19
+ import tifffile
20
+ from PIL import Image, PngImagePlugin
21
+
22
+
23
+ def find_tilt_axis(shape: tuple[int, ...], n_angles: int) -> int:
24
+ matches = [axis for axis, size in enumerate(shape) if size == n_angles]
25
+ if not matches:
26
+ raise ValueError(
27
+ f"No TIFF axis has length {n_angles}; TIFF shape is {shape}."
28
+ )
29
+ if len(matches) > 1:
30
+ raise ValueError(
31
+ f"More than one TIFF axis has length {n_angles}: {matches}. "
32
+ "Specify a stack with an unambiguous tilt axis."
33
+ )
34
+ return matches[0]
35
+
36
+
37
+ def normalize_to_uint8(
38
+ image: np.ndarray,
39
+ lower_percentile: float,
40
+ upper_percentile: float,
41
+ invert: bool,
42
+ ) -> np.ndarray:
43
+ image = np.asarray(image, dtype=np.float32)
44
+ finite = np.isfinite(image)
45
+
46
+ if not finite.any():
47
+ raise ValueError("The selected projection contains no finite values.")
48
+
49
+ values = image[finite]
50
+ low = float(np.percentile(values, lower_percentile))
51
+ high = float(np.percentile(values, upper_percentile))
52
+
53
+ if not high > low:
54
+ low = float(values.min())
55
+ high = float(values.max())
56
+
57
+ if not high > low:
58
+ return np.zeros(image.shape, dtype=np.uint8)
59
+
60
+ normalized = np.clip((image - low) / (high - low), 0.0, 1.0)
61
+ normalized[~finite] = 0.0
62
+
63
+ if invert:
64
+ normalized = 1.0 - normalized
65
+
66
+ return np.rint(normalized * 255.0).astype(np.uint8)
67
+
68
+
69
+ def main() -> int:
70
+ parser = argparse.ArgumentParser(
71
+ description="Create a PNG preview from the HAADF projection nearest 0°."
72
+ )
73
+ parser.add_argument(
74
+ "dataset_root",
75
+ type=Path,
76
+ nargs="?",
77
+ default=Path("."),
78
+ help="Dataset root directory. Default: current directory.",
79
+ )
80
+ parser.add_argument(
81
+ "--stack",
82
+ type=Path,
83
+ default=Path("derived/haadf/HAADF_aligned.tiff"),
84
+ help="HAADF TIFF path relative to the dataset root.",
85
+ )
86
+ parser.add_argument(
87
+ "--angles",
88
+ type=Path,
89
+ default=Path("metadata/angles_deg.txt"),
90
+ help="Angle-list path relative to the dataset root.",
91
+ )
92
+ parser.add_argument(
93
+ "--output",
94
+ type=Path,
95
+ default=Path("previews/haadf_zero_tilt.png"),
96
+ help="Output PNG path relative to the dataset root.",
97
+ )
98
+ parser.add_argument(
99
+ "--lower-percentile",
100
+ type=float,
101
+ default=1.0,
102
+ help="Lower display percentile. Default: 1.0.",
103
+ )
104
+ parser.add_argument(
105
+ "--upper-percentile",
106
+ type=float,
107
+ default=99.8,
108
+ help="Upper display percentile. Default: 99.8.",
109
+ )
110
+ parser.add_argument(
111
+ "--invert",
112
+ action="store_true",
113
+ help="Invert grayscale in the PNG preview.",
114
+ )
115
+ parser.add_argument(
116
+ "--upscale",
117
+ type=int,
118
+ default=2,
119
+ help="Integer nearest-neighbor upscale factor. Default: 2.",
120
+ )
121
+ args = parser.parse_args()
122
+
123
+ root = args.dataset_root.expanduser().resolve()
124
+ stack_path = root / args.stack
125
+ angles_path = root / args.angles
126
+ output_path = root / args.output
127
+
128
+ if not stack_path.is_file():
129
+ raise FileNotFoundError(f"HAADF stack not found: {stack_path}")
130
+ if not angles_path.is_file():
131
+ raise FileNotFoundError(f"Angle list not found: {angles_path}")
132
+ if not 0.0 <= args.lower_percentile < args.upper_percentile <= 100.0:
133
+ raise ValueError("Percentiles must satisfy 0 <= lower < upper <= 100.")
134
+ if args.upscale < 1:
135
+ raise ValueError("--upscale must be at least 1.")
136
+
137
+ angles = np.atleast_1d(np.loadtxt(angles_path, dtype=np.float64))
138
+ stack = tifffile.imread(stack_path)
139
+
140
+ if stack.ndim != 3:
141
+ raise ValueError(f"Expected a 3D tilt stack, got shape {stack.shape}.")
142
+
143
+ tilt_axis = find_tilt_axis(stack.shape, len(angles))
144
+ stack = np.moveaxis(stack, tilt_axis, 0)
145
+
146
+ index = int(np.argmin(np.abs(angles)))
147
+ angle = float(angles[index])
148
+ projection = stack[index]
149
+
150
+ preview = normalize_to_uint8(
151
+ projection,
152
+ lower_percentile=args.lower_percentile,
153
+ upper_percentile=args.upper_percentile,
154
+ invert=args.invert,
155
+ )
156
+
157
+ image = Image.fromarray(preview, mode="L")
158
+ if args.upscale > 1:
159
+ image = image.resize(
160
+ (image.width * args.upscale, image.height * args.upscale),
161
+ resample=Image.Resampling.NEAREST,
162
+ )
163
+
164
+ output_path.parent.mkdir(parents=True, exist_ok=True)
165
+
166
+ metadata = PngImagePlugin.PngInfo()
167
+ metadata.add_text("Source", args.stack.as_posix())
168
+ metadata.add_text("Tilt angle (degrees)", f"{angle:g}")
169
+ metadata.add_text("Stack index", str(index))
170
+ metadata.add_text(
171
+ "Display normalization",
172
+ f"{args.lower_percentile:g}–{args.upper_percentile:g} percentiles",
173
+ )
174
+
175
+ image.save(output_path, pnginfo=metadata)
176
+
177
+ print(f"Saved: {output_path}")
178
+ print(f"Selected stack index: {index}")
179
+ print(f"Selected angle: {angle:g} degrees")
180
+ print(f"Original projection shape: {projection.shape}")
181
+ return 0
182
+
183
+
184
+ if __name__ == "__main__":
185
+ raise SystemExit(main())