diff --git a/src/cdtools/models/bragg_2d_ptycho.py b/src/cdtools/models/bragg_2d_ptycho.py index 84cdd13..38a3eca 100644 --- a/src/cdtools/models/bragg_2d_ptycho.py +++ b/src/cdtools/models/bragg_2d_ptycho.py @@ -236,7 +236,6 @@ class Bragg2DPtycho(CDIModel): propagation_distance=None, scattering_mode=None, oversampling=1, - auto_center=False, probe_fourier_crop=None, propagate_probe=True, correct_tilt=True, @@ -255,12 +254,6 @@ class Bragg2DPtycho(CDIModel): (indices, translations), patterns = dataset[:] dataset.get_as(*get_as_args[0],**get_as_args[1]) - # Set to none to avoid issues with things outside the detector - if auto_center: - center = tools.image_processing.centroid(t.sum(patterns,dim=0)) - else: - center = None - # Then, generate the exit wave geometry from the dataset ewg = tools.initializers.exit_wave_geometry ew_basis = ewg(det_basis, diff --git a/src/cdtools/models/rpi.py b/src/cdtools/models/rpi.py index b2246aa..3ebe77b 100644 --- a/src/cdtools/models/rpi.py +++ b/src/cdtools/models/rpi.py @@ -60,7 +60,7 @@ class RPI(CDIModel): def __init__(self, wavelength, detector_geometry, probe_basis, - probe, obj_guess, detector_slice=None, + probe, obj_guess, background=None, mask=None, saturation=None, obj_support=None, oversampling=1, weight_matrix=False, simulate_finite_pixels=False): @@ -83,7 +83,6 @@ class RPI(CDIModel): scale_factor = t.tensor([probe.shape[-1]/obj_guess.shape[-1], probe.shape[-2]/obj_guess.shape[-2]]) self.obj_basis = self.probe_basis * scale_factor - self.detector_slice = detector_slice # Maybe something to include in a bit # self.surface_normal = t.tensor(surface_normal) @@ -117,13 +116,8 @@ class RPI(CDIModel): # self.obj = t.nn.Parameter(obj_guess.to(t.float32)) if background is None: - if detector_slice is not None: - background = 1e-6 * t.ones( - self.probe[0][self.detector_slice].shape, - dtype=t.float32) - else: - background = 1e-6 * t.ones(self.probe[0].shape, - dtype=t.float32) + background = 1e-6 * t.ones(self.probe[0].shape, + dtype=t.float32) self.background = t.tensor(background, dtype=t.float32) @@ -139,7 +133,7 @@ class RPI(CDIModel): @classmethod - def from_dataset(cls, dataset, probe, obj_size=None, background=None, mask=None, padding=0, n_modes=1, saturation=None, scattering_mode=None, oversampling=1, auto_center=False, initialization='random', weight_matrix=False, probe_threshold=0, simulate_finite_pixels=False): + def from_dataset(cls, dataset, probe, obj_size=None, background=None, mask=None, n_modes=1, saturation=None, scattering_mode=None, oversampling=1, initialization='random', weight_matrix=False, probe_threshold=0, simulate_finite_pixels=False): wavelength = dataset.wavelength det_basis = dataset.detector_geometry['basis'] @@ -153,21 +147,14 @@ class RPI(CDIModel): _, patterns = dataset[:] dataset.get_as(*get_as_args[0],**get_as_args[1]) - # Set to none to avoid issues with things outside the detector - if auto_center: - center = tools.image_processing.centroid(t.sum(patterns,dim=0)) - else: - center = None # Then, generate the probe geometry from the dataset ewg = tools.initializers.exit_wave_geometry - probe_basis, probe_shape, det_slice = ewg(det_basis, - det_shape, - wavelength, - distance, - center=center, - padding=padding, - oversampling=oversampling) + ew_basis = ewg(det_basis, + det_shape, + wavelength, + distance, + oversampling=oversampling) if not isinstance(probe,t.Tensor): probe = t.as_tensor(probe) @@ -248,8 +235,8 @@ class RPI(CDIModel): obj_support = probe_lr > t.max(probe_lr) * probe_threshold obj_support = t.as_tensor(binary_dilation(obj_support)) - return cls(wavelength, det_geo, probe_basis, - probe, obj_guess, detector_slice=det_slice, + return cls(wavelength, det_geo, ew_basis, + probe, obj_guess, background=background, mask=mask, saturation=saturation, obj_support=obj_support, oversampling=oversampling, weight_matrix=weight_matrix, @@ -359,7 +346,6 @@ class RPI(CDIModel): # a 4D wavefield array as well as a 5D array. m = tools.measurements.quadratic_background(wavefields, self.background, - detector_slice=self.detector_slice, measurement=tools.measurements.incoherent_sum, saturation=self.saturation, oversampling=self.oversampling, diff --git a/src/cdtools/tools/analysis/analysis.py b/src/cdtools/tools/analysis/analysis.py index 187a6c8..741c040 100644 --- a/src/cdtools/tools/analysis/analysis.py +++ b/src/cdtools/tools/analysis/analysis.py @@ -612,7 +612,7 @@ def calc_frc(im1, im2, basis, im_slice=None, nbins=None, snr=1., limit='side'): #n_pix = n_pix / 4 # This is for an apodized image, apodized with a hann window - frc = np.abs(numerator) / np.sqrt(denominator_F1*denominator_F2) + frc = numerator / np.sqrt(denominator_F1*denominator_F2) # This moves from combined-image SNR to single-image SNR snr /= 2 @@ -1210,8 +1210,10 @@ def standardize_reconstruction_set( ip.hann_window(obj_2[window]), full['obj_basis'], nbins=nbins, limit=frc_limit) + + # The correct formulation when the final output is the full reconstruction - ssnr = 2 * frc / (1 - frc) + ssnr = 2 * np.abs(frc) / (1 - np.abs(frc)) results = { 'obj_half_1': obj_1, diff --git a/src/cdtools/tools/propagators/propagators.py b/src/cdtools/tools/propagators/propagators.py index c7edecd..3760c9b 100644 --- a/src/cdtools/tools/propagators/propagators.py +++ b/src/cdtools/tools/propagators/propagators.py @@ -147,12 +147,12 @@ def generate_high_NA_k_intensity_map(sample_basis, det_basis,det_shape,distance, det_shape = np.array(tuple(det_shape)) try: - distance = distance.detach().cpu().numpy()[0] + distance = distance.detach().cpu().numpy().ravel()[0] except: pass try: - wavelength = wavelength.detach().cpu().numpy()[0] + wavelength = wavelength.detach().cpu().numpy().ravel()[0] except: pass