Skip to content

Commit

Permalink
Merge pull request #324 from carterbox/log-affine-backport
Browse files Browse the repository at this point in the history
REL: Backport affine transform logging
  • Loading branch information
carterbox authored Jul 1, 2024
2 parents 4ae2596 + 3a00a34 commit f8c3db8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tike/ptycho/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def fromarray(self, T: np.ndarray) -> AffineTransform:
scale1=float(scale1),
shear1=float(shear1),
angle=float(angle),
t0=T[2, 0],
t1=T[2, 1],
t0=T[2, 0] if T.shape[0] > 2 else 0,
t1=T[2, 1] if T.shape[0] > 2 else 0,
)

def asarray(self, xp=np) -> np.ndarray:
Expand Down
38 changes: 38 additions & 0 deletions src/tike/ptycho/ptycho.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ def reconstruct(
use_mpi,
) as context:
context.iterate(parameters.algorithm_options.num_iter)

if (
logger.getEffectiveLevel() <= logging.INFO
) and context.parameters.position_options:
mean_scaling = 0.5 * (
context.parameters.position_options.transform.scale0
+ context.parameters.position_options.transform.scale1
)
logger.info(
f"Global scaling of {mean_scaling:.3e} detected from position correction."
" Probably your estimate of photon energy and/or sample to detector "
"distance is off by that amount."
)
t = context.parameters.position_options.transform.asarray()
logger.info(f"""Affine transform parameters:
{t[0,0]: .3e}, {t[0,1]: .3e}
{t[1,0]: .3e}, {t[1,1]: .3e}
""")

return context.parameters


Expand Down Expand Up @@ -923,6 +943,24 @@ def reconstruct_multigrid(
context.iterate(resampled_parameters.algorithm_options.num_iter)

if level == 0:
if (
logger.getEffectiveLevel() <= logging.INFO
) and context.parameters.position_options:
mean_scaling = 0.5 * (
context.parameters.position_options.transform.scale0
+ context.parameters.position_options.transform.scale1
)
logger.info(
f"Global scaling of {mean_scaling:.3e} detected from position correction."
" Probably your estimate of photon energy and/or sample to detector "
"distance is off by that amount."
)
t = context.parameters.position_options.transform.asarray()
logger.info(f"""Affine transform parameters:
{t[0,0]: .3e}, {t[0,1]: .3e}
{t[1,0]: .3e}, {t[1,1]: .3e}
""")
return context.parameters

# Upsample result to next grid
Expand Down

0 comments on commit f8c3db8

Please sign in to comment.