From e23aefde69579638b9b9c75657605148f6a7a7dd Mon Sep 17 00:00:00 2001 From: Garrett Bischof Date: Tue, 9 Jun 2026 17:02:09 -0400 Subject: [PATCH] fix(config): compute vit_normalization inline, not via ptychoml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config_from_tiled's vit_normalization auto-detect was changed in the H6b decomposition PR to call ptychoml.compute_intensity_normalization. But config_from_tiled runs in the `client` and `replay` pixi envs, which deliberately do NOT depend on ptychoml (the replay env dropped it on purpose). So the import raised ModuleNotFoundError, the broad except swallowed it, and vit_normalization silently came out unset — both for `config-from-tiled` and for `replay --hp-start` (which builds its config via build_full_config -> load_config_from_tiled). Revert to the inline hot-pixel-masked max (numpy only). Verified against scan 405820: vit_normalization now resolves to 1150.0, matching the operator's known-good config. (The ptychoml-reuse was well-intentioned but I only tested it in the default env, which has ptychoml; the failure only shows in the client/replay envs.) Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com> --- scripts/config_from_tiled.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/config_from_tiled.py b/scripts/config_from_tiled.py index de47b2b..3e78b4c 100644 --- a/scripts/config_from_tiled.py +++ b/scripts/config_from_tiled.py @@ -565,21 +565,20 @@ def load_config_from_tiled( slice=[slice(0, n_sample), slice(None), slice(None)] ) import numpy as _np - from ptychoml import compute_intensity_normalization # Max raw intensity with hot pixels excluded — the same constant - # hxn_to_vit writes per scan. compute_intensity_normalization - # raises ValueError when every sampled pixel exceeds the threshold. - try: - vit_normalization = compute_intensity_normalization( - _np.asarray(sample), - hot_pixel_count_threshold=HOT_PIXEL_THRESHOLD, - ) + # hxn_to_vit writes per scan. Kept inline (not + # ptychoml.compute_intensity_normalization) because config_from_tiled + # runs in the client/replay pixi envs, which deliberately do NOT + # depend on ptychoml. + mask = sample <= HOT_PIXEL_THRESHOLD + if mask.any(): + vit_normalization = float(_np.asarray(sample)[mask].max()) print( f"[config_from_tiled] vit_normalization={vit_normalization:.1f} " f"(max of {n_sample} frames, hot_pixel_threshold={HOT_PIXEL_THRESHOLD})", file=sys.stderr, ) - except ValueError: + else: print( "WARNING: all sampled pixels exceed hot_pixel_threshold " f"({HOT_PIXEL_THRESHOLD}); vit_normalization not set",