Merge branch 'rc178-still-results' into panel-s5

This commit is contained in:
leonarski_f committed 2026-10-21 13:18:14 +02:00
commit bb7c9c8fa3
1 file changed
+6 -5
+6 -5
View File
@@ -1,5 +1,5 @@
"""Data preparation for the still battery (not product code): copy a SwissFEL converted JUNGFRAU file, replacing /data/data (float32 keV) by int16 photon counts,
bitshuffle/LZ4, one chunk per frame. Everything else is copied unchanged. NaN -> 0 (what rugnux's reader makes of it).
bitshuffle/LZ4, one chunk per frame. Everything else is copied unchanged. Non-finite values (NaN, inf) -> -32768, the int16 error marker.
usage: float32_to_int16.py <in.h5> <out.h5> <photon_energy_keV>
Needs h5py and hdf5plugin. The copies are the alvra*_int16 sets of still_manifest.json; read them with --gain 1.
See docs/EXTERNAL_TEST_DATA_STILLS.md."""
@@ -27,16 +27,17 @@ with h5py.File(src, 'r') as fi, h5py.File(dst + '.part', 'w') as fo:
for k, v in d.attrs.items():
out.attrs[k] = v
out.attrs['photon_energy_keV_used_for_conversion'] = e_kev
out.attrs['conversion'] = 'int16 photons = round(float32 keV / photon_energy_keV), NaN -> 0, clipped to int16; original: ' + src
out.attrs['conversion'] = 'int16 photons = round(float32 keV / photon_energy_keV), non-finite -> -32768 (no measurement), others clipped to [-32767, 32767]; original: ' + src
nan = clipped = 0
hist = np.zeros(4, dtype=np.int64) # <0, 0, 1, >=2 photons
for i in range(n):
x = d[i]
bad = np.isnan(x)
bad = ~np.isfinite(x)
nan += int(bad.sum())
p = np.rint(np.where(bad, 0, x) / e_kev)
clipped += int(((p > 32767) | (p < -32768)).sum())
p = np.clip(p, -32768, 32767).astype(np.int16)
clipped += int(((p > 32767) | (p < -32767)).sum())
p = np.clip(p, -32767, 32767).astype(np.int16)
p[bad] = -32768
if i % 50 == 0:
hist += [(p < 0).sum(), (p == 0).sum(), (p == 1).sum(), (p >= 2).sum()]
out[i] = p