From 4b75d07c73e413126ce47f8cdbd47d588f798fe1 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 12:38:00 +0100 Subject: [PATCH 01/18] fix interpolation center by using voltools for tilt rotation --- src/pytom_tm/weights.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 03952a10..c3f66e52 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -2,6 +2,7 @@ import numpy.typing as npt import logging import scipy.ndimage as ndimage +import voltools as vt from typing import Optional, Union from pytom_tm.io import UnequalSpacingError @@ -513,13 +514,16 @@ def _create_tilt_weighted_wedge( # rotate the image weights to the tilt angle rotated = np.flip( - ndimage.rotate( + vt.transform( tilt, - np.rad2deg(alpha), - axes=(0, 2), - reshape=False, - order=3 - )[:, :, : image_size // 2 + 1] + rotation=(0, alpha, 0), + rotation_units='rad', + rotation_order='rxyz', + center=(image_size // 2, ) * 3, + interpolation='filt_bspline', + device='cpu' + )[:, :, : image_size // 2 + 1], + axis=2 ) # weight with exposure and tilt dampening From 53b779630879005fb7ae775387ed9b76e6f07ae4 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 14:11:36 +0100 Subject: [PATCH 02/18] add exact weighting --- src/pytom_tm/weights.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index c3f66e52..9a14e2a9 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -487,12 +487,19 @@ def _create_tilt_weighted_wedge( image_size = shape[0] # assign to size variable as all dimensions are equal size tilt = np.zeros(shape) q_grid = radial_reduced_grid(shape) + _, q_grid_1d = radial_average(np.fft.ifftshift(q_grid, axes=(0, 1))) tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) for i, alpha in enumerate(tilt_angles): + # calculate weighting correction for overlapping data + sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) + overlap = sampling / (2 / image_size) + exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) + exact_weighting = profile_to_weighting(exact_filter, (image_size, ) * 2) + if ctf_params_per_tilt is not None: ctf = np.fft.fftshift( - create_ctf( + exact_weighting * create_ctf( (image_size, ) * 2, pixel_size_angstrom * 1e-10, ctf_params_per_tilt[i]['defocus'] * 1e-6, @@ -510,7 +517,13 @@ def _create_tilt_weighted_wedge( axis=1 ) else: - tilt[:, :, image_size // 2] = 1 + tilt[:, :, image_size // 2] = np.concatenate( + ( # duplicate and flip the CTF around the 0 frequency; then concatenate to make it non-reduced + np.flip(exact_weighting[:, 1: 1 + image_size - exact_weighting.shape[1]], axis=1), + exact_weighting + ), + axis=1 + ) # rotate the image weights to the tilt angle rotated = np.flip( @@ -540,7 +553,8 @@ def _create_tilt_weighted_wedge( rotated * np.cos(alpha) # apply tilt-dependent weighting ) - tilt_weighted_wedge = np.maximum(tilt_weighted_wedge, weighted_tilt) + + tilt_weighted_wedge += weighted_tilt # np.maximum(tilt_weighted_wedge, weighted_tilt) tilt_weighted_wedge[q_grid > cut_off_radius] = 0 From 3f56d53ff392422b8c72096572c87cdb4f4a796c Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 14:26:30 +0100 Subject: [PATCH 03/18] fix for non-ctf --- src/pytom_tm/weights.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 9a14e2a9..3c4ebde0 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -495,11 +495,11 @@ def _create_tilt_weighted_wedge( sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) overlap = sampling / (2 / image_size) exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) - exact_weighting = profile_to_weighting(exact_filter, (image_size, ) * 2) + exact_weighting = np.fft.fftshift(profile_to_weighting(exact_filter, (image_size, ) * 2), axes=0) if ctf_params_per_tilt is not None: ctf = np.fft.fftshift( - exact_weighting * create_ctf( + create_ctf( (image_size, ) * 2, pixel_size_angstrom * 1e-10, ctf_params_per_tilt[i]['defocus'] * 1e-6, @@ -508,7 +508,7 @@ def _create_tilt_weighted_wedge( ctf_params_per_tilt[i]['cs'] * 1e-3, flip_phase=True # creating a per tilt ctf is hard if the phase is not flipped ), axes=0, - ) + ) * exact_weighting tilt[:, :, image_size // 2] = np.concatenate( ( # duplicate and flip the CTF around the 0 frequency; then concatenate to make it non-reduced np.flip(ctf[:, 1: 1 + image_size - ctf.shape[1]], axis=1), From 0c75e93b9a20398d8c0e47a2216a519c4d201740 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 14:41:59 +0100 Subject: [PATCH 04/18] fix overlap weighting with a exact filter along the y-axis (tilt-axis) --- src/pytom_tm/weights.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 3c4ebde0..9722f26c 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -487,7 +487,10 @@ def _create_tilt_weighted_wedge( image_size = shape[0] # assign to size variable as all dimensions are equal size tilt = np.zeros(shape) q_grid = radial_reduced_grid(shape) - _, q_grid_1d = radial_average(np.fft.ifftshift(q_grid, axes=(0, 1))) + q_grid_1d = np.abs(np.arange( + -image_size // 2 + image_size % 2, + image_size // 2 + image_size % 2, 1. + )) / (image_size // 2) tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) for i, alpha in enumerate(tilt_angles): @@ -495,7 +498,7 @@ def _create_tilt_weighted_wedge( sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) overlap = sampling / (2 / image_size) exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) - exact_weighting = np.fft.fftshift(profile_to_weighting(exact_filter, (image_size, ) * 2), axes=0) + exact_weighting = np.tile(exact_filter, (image_size, 1)).T if ctf_params_per_tilt is not None: ctf = np.fft.fftshift( From b197c74f7b011aceaa7a8849e318d1d7d530d0d7 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 14:46:09 +0100 Subject: [PATCH 05/18] overlap frequency should be further out --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 9722f26c..e366a71a 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -496,7 +496,7 @@ def _create_tilt_weighted_wedge( for i, alpha in enumerate(tilt_angles): # calculate weighting correction for overlapping data sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) - overlap = sampling / (2 / image_size) + overlap = sampling / (2 / (image_size//2)) exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) exact_weighting = np.tile(exact_filter, (image_size, 1)).T From e4bd332da466650df23b91bace52da20b3ea5cc7 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 14:52:39 +0100 Subject: [PATCH 06/18] set weighting to numbers --- src/pytom_tm/weights.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index e366a71a..c2c9b24b 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -490,13 +490,13 @@ def _create_tilt_weighted_wedge( q_grid_1d = np.abs(np.arange( -image_size // 2 + image_size % 2, image_size // 2 + image_size % 2, 1. - )) / (image_size // 2) + )) # / (image_size // 2) tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) for i, alpha in enumerate(tilt_angles): # calculate weighting correction for overlapping data sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) - overlap = sampling / (2 / (image_size//2)) + overlap = sampling / (2 / image_size) exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) exact_weighting = np.tile(exact_filter, (image_size, 1)).T From 6a071d587c3fa6cf3bf3b078b116d77b4068aaf2 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 15:08:43 +0100 Subject: [PATCH 07/18] switch to use slice width --- src/pytom_tm/weights.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index c2c9b24b..5f771917 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -496,7 +496,9 @@ def _create_tilt_weighted_wedge( for i, alpha in enumerate(tilt_angles): # calculate weighting correction for overlapping data sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) - overlap = sampling / (2 / image_size) + smallest_sampling = np.min(sampling[sampling > 0.001]) + slice_width = min(1, smallest_sampling * (image_size // 2)) + overlap = sampling / slice_width exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) exact_weighting = np.tile(exact_filter, (image_size, 1)).T From 3cbd8286c2154f9bcccd0166b868904875d285c3 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 15:13:08 +0100 Subject: [PATCH 08/18] fix use of weighting after putting along y axis --- src/pytom_tm/weights.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 5f771917..5c435e2c 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -513,22 +513,16 @@ def _create_tilt_weighted_wedge( ctf_params_per_tilt[i]['cs'] * 1e-3, flip_phase=True # creating a per tilt ctf is hard if the phase is not flipped ), axes=0, - ) * exact_weighting + ) tilt[:, :, image_size // 2] = np.concatenate( ( # duplicate and flip the CTF around the 0 frequency; then concatenate to make it non-reduced np.flip(ctf[:, 1: 1 + image_size - ctf.shape[1]], axis=1), ctf ), axis=1 - ) + ) * exact_weighting else: - tilt[:, :, image_size // 2] = np.concatenate( - ( # duplicate and flip the CTF around the 0 frequency; then concatenate to make it non-reduced - np.flip(exact_weighting[:, 1: 1 + image_size - exact_weighting.shape[1]], axis=1), - exact_weighting - ), - axis=1 - ) + tilt[:, :, image_size // 2] = exact_weighting # rotate the image weights to the tilt angle rotated = np.flip( From 770c83e220343fd6f51542fe0415284e381b311e Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 16:04:59 +0100 Subject: [PATCH 09/18] try with D as slicewidth --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 5c435e2c..1d07ffb7 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -497,7 +497,7 @@ def _create_tilt_weighted_wedge( # calculate weighting correction for overlapping data sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) smallest_sampling = np.min(sampling[sampling > 0.001]) - slice_width = min(1, smallest_sampling * (image_size // 2)) + slice_width = min(1, smallest_sampling * image_size) overlap = sampling / slice_width exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) exact_weighting = np.tile(exact_filter, (image_size, 1)).T From 336094606950327c7f211757299ec3c9aa3f13bf Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 16:11:47 +0100 Subject: [PATCH 10/18] continue cutoff outside of edge --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 1d07ffb7..82777b5b 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -497,7 +497,7 @@ def _create_tilt_weighted_wedge( # calculate weighting correction for overlapping data sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) smallest_sampling = np.min(sampling[sampling > 0.001]) - slice_width = min(1, smallest_sampling * image_size) + slice_width = smallest_sampling * (image_size / 2) overlap = sampling / slice_width exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) exact_weighting = np.tile(exact_filter, (image_size, 1)).T From d708a591d87f8478e70cd646bb23556ef61608c1 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 16:34:26 +0100 Subject: [PATCH 11/18] switch to ramp weighting up to the overlap frequency --- src/pytom_tm/weights.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 82777b5b..8400a5b3 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -487,21 +487,20 @@ def _create_tilt_weighted_wedge( image_size = shape[0] # assign to size variable as all dimensions are equal size tilt = np.zeros(shape) q_grid = radial_reduced_grid(shape) + tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) + + # create ramp weights for to reweight tilt overlap q_grid_1d = np.abs(np.arange( -image_size // 2 + image_size % 2, image_size // 2 + image_size % 2, 1. - )) # / (image_size // 2) - tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) + )) / (image_size // 2) + tilt_increment = (np.abs(np.array(tilt_angles)[1:] - np.array(tilt_angles)[:-1])).min() + overlap_frequency = tilt_increment * image_size / 2 + ramp_filter = q_grid_1d / overlap_frequency + ramp_filter[ramp_filter > 1] = 1 + ramp_weighting = np.tile(ramp_filter, (image_size, 1)).T for i, alpha in enumerate(tilt_angles): - # calculate weighting correction for overlapping data - sampling = np.sin(np.abs((np.array(tilt_angles) - alpha))) - smallest_sampling = np.min(sampling[sampling > 0.001]) - slice_width = smallest_sampling * (image_size / 2) - overlap = sampling / slice_width - exact_filter = 1 / np.clip(1 - (overlap[:, np.newaxis] * q_grid_1d) ** 2, 0, 2).sum(axis=0) - exact_weighting = np.tile(exact_filter, (image_size, 1)).T - if ctf_params_per_tilt is not None: ctf = np.fft.fftshift( create_ctf( @@ -520,9 +519,9 @@ def _create_tilt_weighted_wedge( ctf ), axis=1 - ) * exact_weighting + ) * ramp_weighting else: - tilt[:, :, image_size // 2] = exact_weighting + tilt[:, :, image_size // 2] = ramp_weighting # rotate the image weights to the tilt angle rotated = np.flip( From 748749785f2ec6126e60700cbceb952c990e1d67 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 16:43:13 +0100 Subject: [PATCH 12/18] add 0 frequency at 1 / len(tilt_angles) --- src/pytom_tm/weights.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 8400a5b3..70877c8a 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -5,6 +5,7 @@ import voltools as vt from typing import Optional, Union from pytom_tm.io import UnequalSpacingError +from itertools import pairwise constants = { @@ -494,9 +495,9 @@ def _create_tilt_weighted_wedge( -image_size // 2 + image_size % 2, image_size // 2 + image_size % 2, 1. )) / (image_size // 2) - tilt_increment = (np.abs(np.array(tilt_angles)[1:] - np.array(tilt_angles)[:-1])).min() + tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) overlap_frequency = tilt_increment * image_size / 2 - ramp_filter = q_grid_1d / overlap_frequency + ramp_filter = q_grid_1d / overlap_frequency + 1 / len(tilt_angles) ramp_filter[ramp_filter > 1] = 1 ramp_weighting = np.tile(ramp_filter, (image_size, 1)).T From be06e4113fb457dd75aaced9ced114d2b62bb835 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 16:52:58 +0100 Subject: [PATCH 13/18] leave 0 frequency as data is anyway normalized by subtracting mean, equal to setting 0 freq in fourier transform to 0 --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 70877c8a..0d3b9557 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -497,7 +497,7 @@ def _create_tilt_weighted_wedge( )) / (image_size // 2) tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) overlap_frequency = tilt_increment * image_size / 2 - ramp_filter = q_grid_1d / overlap_frequency + 1 / len(tilt_angles) + ramp_filter = q_grid_1d / overlap_frequency ramp_filter[ramp_filter > 1] = 1 ramp_weighting = np.tile(ramp_filter, (image_size, 1)).T From b02c41b479fb2a359ffb31de4116a7f8c4064d37 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 17:30:28 +0100 Subject: [PATCH 14/18] correctly decrease weights --- src/pytom_tm/weights.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 0d3b9557..3a606632 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -494,9 +494,9 @@ def _create_tilt_weighted_wedge( q_grid_1d = np.abs(np.arange( -image_size // 2 + image_size % 2, image_size // 2 + image_size % 2, 1. - )) / (image_size // 2) + )) / (image_size // 2) * 0.5 # to nyquist tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) - overlap_frequency = tilt_increment * image_size / 2 + overlap_frequency = 1 / (tilt_increment * image_size) ramp_filter = q_grid_1d / overlap_frequency ramp_filter[ramp_filter > 1] = 1 ramp_weighting = np.tile(ramp_filter, (image_size, 1)).T From 0dc271c72b58d8dc7392d03397b5694ac4b1d529 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Mon, 4 Mar 2024 20:50:31 +0100 Subject: [PATCH 15/18] make options for contructing weights based on reconstruction method --- src/pytom_tm/weights.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 3a606632..2de5c68f 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -490,16 +490,25 @@ def _create_tilt_weighted_wedge( q_grid = radial_reduced_grid(shape) tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) - # create ramp weights for to reweight tilt overlap - q_grid_1d = np.abs(np.arange( - -image_size // 2 + image_size % 2, - image_size // 2 + image_size % 2, 1. - )) / (image_size // 2) * 0.5 # to nyquist - tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) - overlap_frequency = 1 / (tilt_increment * image_size) - ramp_filter = q_grid_1d / overlap_frequency - ramp_filter[ramp_filter > 1] = 1 - ramp_weighting = np.tile(ramp_filter, (image_size, 1)).T + # create ramp weights for reweighting tilt overlap + reconstruction_method = 'ramp-wbp' + if reconstruction_method == 'gridding': + tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) + overlap_frequency = 1 / (tilt_increment * image_size) + ramp_filter = np.abs(np.arange( + -image_size // 2 + image_size % 2, + image_size // 2 + image_size % 2, 1. + )) / (image_size // 2) * .5 / overlap_frequency # to nyquist + ramp_filter[ramp_filter > 1] = 1 + elif reconstruction_method == 'ramp-wbp': + ramp_filter = np.abs(np.arange( + -image_size // 2 + image_size % 2, + image_size // 2 + image_size % 2, 1. + )) / (image_size // 2) + else: + raise ValueError('Unknown reconstruction method!') + + ramp_weighting = np.tile(ramp_filter[:, np.newaxis], (1, image_size)) for i, alpha in enumerate(tilt_angles): if ctf_params_per_tilt is not None: From 01b4c2c4679c7667cb9a1c6b3e61a89d7f8d2f18 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Wed, 6 Mar 2024 11:19:38 +0100 Subject: [PATCH 16/18] update version; remove optional for reconstruction method - weighting up to overlap freq should be most accurate --- pyproject.toml | 2 +- src/pytom_tm/weights.py | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2a01eded..7d2534f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pytom-match-pick" -version = "0.4.3" +version = "0.5.0" description = "PyTOM's GPU template matching module as an independent package" readme = "README.md" license = {file = "LICENSE"} diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 2de5c68f..1cdbfcfa 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -490,24 +490,18 @@ def _create_tilt_weighted_wedge( q_grid = radial_reduced_grid(shape) tilt_weighted_wedge = np.zeros((image_size, image_size, image_size // 2 + 1)) - # create ramp weights for reweighting tilt overlap - reconstruction_method = 'ramp-wbp' - if reconstruction_method == 'gridding': - tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) - overlap_frequency = 1 / (tilt_increment * image_size) - ramp_filter = np.abs(np.arange( - -image_size // 2 + image_size % 2, - image_size // 2 + image_size % 2, 1. - )) / (image_size // 2) * .5 / overlap_frequency # to nyquist - ramp_filter[ramp_filter > 1] = 1 - elif reconstruction_method == 'ramp-wbp': - ramp_filter = np.abs(np.arange( - -image_size // 2 + image_size % 2, - image_size // 2 + image_size % 2, 1. - )) / (image_size // 2) - else: - raise ValueError('Unknown reconstruction method!') - + # create ramp weights to correct tilt summation for overlap + tilt_increment = min([abs(x - y) for x, y in pairwise(tilt_angles)]) + # Crowther freq. determines till what point adjacent tilts overlap in Fourier space + overlap_frequency = 1 / (tilt_increment * image_size) + freq_1d = np.abs(np.arange( + -image_size // 2 + image_size % 2, + image_size // 2 + image_size % 2, 1. + )) / (image_size // 2) * .5 # multiply with .5 for nyquist frequency + ramp_filter = freq_1d / overlap_frequency + ramp_filter[ramp_filter > 1] = 1 # linear increase up to overlap frequency + + # generate 2d weights along the tilt axis ramp_weighting = np.tile(ramp_filter[:, np.newaxis], (1, image_size)) for i, alpha in enumerate(tilt_angles): From 2fbeef0ffa09ad1cc799b36def2d68cadbc09102 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Wed, 6 Mar 2024 12:01:15 +0100 Subject: [PATCH 17/18] add comment --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index 1cdbfcfa..ddee7be1 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -537,7 +537,7 @@ def _create_tilt_weighted_wedge( center=(image_size // 2, ) * 3, interpolation='filt_bspline', device='cpu' - )[:, :, : image_size // 2 + 1], + )[:, :, :image_size // 2 + 1], # crop back z-axis to reduced Fourier form axis=2 ) From 36514aa1c90c744943156350e9abf997ac97101d Mon Sep 17 00:00:00 2001 From: Marten Chaillet <58044494+McHaillet@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:49:47 +0100 Subject: [PATCH 18/18] Update src/pytom_tm/weights.py Co-authored-by: Sander Roet --- src/pytom_tm/weights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/weights.py b/src/pytom_tm/weights.py index ddee7be1..bae83b52 100644 --- a/src/pytom_tm/weights.py +++ b/src/pytom_tm/weights.py @@ -556,7 +556,7 @@ def _create_tilt_weighted_wedge( np.cos(alpha) # apply tilt-dependent weighting ) - tilt_weighted_wedge += weighted_tilt # np.maximum(tilt_weighted_wedge, weighted_tilt) + tilt_weighted_wedge += weighted_tilt tilt_weighted_wedge[q_grid > cut_off_radius] = 0