From 04597d97a26a2f0879c09c42d9d98cf49b6eb4be Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Tue, 4 Jun 2024 18:34:18 -0500 Subject: [PATCH 1/4] NEW: Add affine transformation to INFO logging output --- src/tike/ptycho/position.py | 4 ++-- src/tike/ptycho/ptycho.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/tike/ptycho/position.py b/src/tike/ptycho/position.py index 92e00665..0f02f835 100644 --- a/src/tike/ptycho/position.py +++ b/src/tike/ptycho/position.py @@ -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: diff --git a/src/tike/ptycho/ptycho.py b/src/tike/ptycho/ptycho.py index f22b4a95..726f4894 100644 --- a/src/tike/ptycho/ptycho.py +++ b/src/tike/ptycho/ptycho.py @@ -228,6 +228,18 @@ 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 estimate {mean_scaling:.3e} from position correction" + ) + return context.parameters @@ -923,6 +935,16 @@ 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 estimate {mean_scaling:.3e} from position correction" + ) return context.parameters # Upsample result to next grid From e31ae8b7e6fbc58ada4200e54bdf6d65fee0d4b1 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Mon, 10 Jun 2024 14:56:55 -0500 Subject: [PATCH 2/4] DOC: Update global scaling message --- src/tike/ptycho/ptycho.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tike/ptycho/ptycho.py b/src/tike/ptycho/ptycho.py index 726f4894..db3572cb 100644 --- a/src/tike/ptycho/ptycho.py +++ b/src/tike/ptycho/ptycho.py @@ -237,7 +237,9 @@ def reconstruct( + context.parameters.position_options.transform.scale1 ) logger.info( - f"Global scaling estimate {mean_scaling:.3e} from position correction" + 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 ammount." ) return context.parameters @@ -943,7 +945,9 @@ def reconstruct_multigrid( + context.parameters.position_options.transform.scale1 ) logger.info( - f"Global scaling estimate {mean_scaling:.3e} from position correction" + 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 ammount." ) return context.parameters From bb1e01395379653218dd46994f80ccb86615baa6 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Mon, 10 Jun 2024 15:40:17 -0500 Subject: [PATCH 3/4] DOC: Fix spelling --- src/tike/ptycho/ptycho.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tike/ptycho/ptycho.py b/src/tike/ptycho/ptycho.py index db3572cb..09c04d1e 100644 --- a/src/tike/ptycho/ptycho.py +++ b/src/tike/ptycho/ptycho.py @@ -239,7 +239,7 @@ def reconstruct( 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 ammount." + "distance is off by that amount." ) return context.parameters @@ -947,7 +947,7 @@ def reconstruct_multigrid( 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 ammount." + "distance is off by that amount." ) return context.parameters From 3a00a3426adf2011122391397b822f6ff075ae14 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Mon, 17 Jun 2024 13:18:39 -0500 Subject: [PATCH 4/4] DOC: Add full affine transform to output logs --- src/tike/ptycho/ptycho.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tike/ptycho/ptycho.py b/src/tike/ptycho/ptycho.py index 09c04d1e..d280a4e9 100644 --- a/src/tike/ptycho/ptycho.py +++ b/src/tike/ptycho/ptycho.py @@ -241,6 +241,12 @@ def reconstruct( " 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 @@ -949,6 +955,12 @@ def reconstruct_multigrid( " 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