Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit f8c3db8

Browse files
authored
Merge pull request #324 from carterbox/log-affine-backport
REL: Backport affine transform logging
2 parents 4ae2596 + 3a00a34 commit f8c3db8

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/tike/ptycho/position.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def fromarray(self, T: np.ndarray) -> AffineTransform:
180180
scale1=float(scale1),
181181
shear1=float(shear1),
182182
angle=float(angle),
183-
t0=T[2, 0],
184-
t1=T[2, 1],
183+
t0=T[2, 0] if T.shape[0] > 2 else 0,
184+
t1=T[2, 1] if T.shape[0] > 2 else 0,
185185
)
186186

187187
def asarray(self, xp=np) -> np.ndarray:

src/tike/ptycho/ptycho.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ def reconstruct(
228228
use_mpi,
229229
) as context:
230230
context.iterate(parameters.algorithm_options.num_iter)
231+
232+
if (
233+
logger.getEffectiveLevel() <= logging.INFO
234+
) and context.parameters.position_options:
235+
mean_scaling = 0.5 * (
236+
context.parameters.position_options.transform.scale0
237+
+ context.parameters.position_options.transform.scale1
238+
)
239+
logger.info(
240+
f"Global scaling of {mean_scaling:.3e} detected from position correction."
241+
" Probably your estimate of photon energy and/or sample to detector "
242+
"distance is off by that amount."
243+
)
244+
t = context.parameters.position_options.transform.asarray()
245+
logger.info(f"""Affine transform parameters:
246+
247+
{t[0,0]: .3e}, {t[0,1]: .3e}
248+
{t[1,0]: .3e}, {t[1,1]: .3e}
249+
""")
250+
231251
return context.parameters
232252

233253

@@ -923,6 +943,24 @@ def reconstruct_multigrid(
923943
context.iterate(resampled_parameters.algorithm_options.num_iter)
924944

925945
if level == 0:
946+
if (
947+
logger.getEffectiveLevel() <= logging.INFO
948+
) and context.parameters.position_options:
949+
mean_scaling = 0.5 * (
950+
context.parameters.position_options.transform.scale0
951+
+ context.parameters.position_options.transform.scale1
952+
)
953+
logger.info(
954+
f"Global scaling of {mean_scaling:.3e} detected from position correction."
955+
" Probably your estimate of photon energy and/or sample to detector "
956+
"distance is off by that amount."
957+
)
958+
t = context.parameters.position_options.transform.asarray()
959+
logger.info(f"""Affine transform parameters:
960+
961+
{t[0,0]: .3e}, {t[0,1]: .3e}
962+
{t[1,0]: .3e}, {t[1,1]: .3e}
963+
""")
926964
return context.parameters
927965

928966
# Upsample result to next grid

0 commit comments

Comments
 (0)