From 86a2d02c37fa6ac970d98685727219928a045410 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Wed, 24 Jan 2024 15:13:49 +0100 Subject: [PATCH 1/3] calculate the whitening filter only in the user specified region of interest --- src/pytom_tm/tmjob.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pytom_tm/tmjob.py b/src/pytom_tm/tmjob.py index 595067da..8a186267 100644 --- a/src/pytom_tm/tmjob.py +++ b/src/pytom_tm/tmjob.py @@ -179,7 +179,15 @@ def __init__( self.whitening_filter = self.output_dir.joinpath(f'{self.tomo_id}_whitening_filter.npy') if self.whiten_spectrum and not self.whitening_filter.exists(): logging.info('Estimating whitening filter...') - weights = 1 / np.sqrt(power_spectrum_profile(read_mrc(self.tomogram))) + weights = 1 / np.sqrt( + power_spectrum_profile( + read_mrc(self.tomogram)[ + self.search_origin[0]: self.search_origin[0] + self.search_size[0], + self.search_origin[1]: self.search_origin[1] + self.search_size[1], + self.search_origin[2]: self.search_origin[2] + self.search_size[2] + ] + ) + ) weights /= weights.max() # scale to 1 np.save(self.whitening_filter, weights) From 62e8ec1d4d1f8b2b462ae3e5c0c328df938a4c6b Mon Sep 17 00:00:00 2001 From: McHaillet Date: Fri, 26 Jan 2024 12:25:09 +0100 Subject: [PATCH 2/3] always calculate a new whitening filter, since version 0.3.3 its fast to calculate and it wont bug if the search size of the tomogram is changed --- src/pytom_tm/tmjob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytom_tm/tmjob.py b/src/pytom_tm/tmjob.py index 8a186267..8805885a 100644 --- a/src/pytom_tm/tmjob.py +++ b/src/pytom_tm/tmjob.py @@ -177,7 +177,7 @@ def __init__( self.ctf_data = ctf_data self.whiten_spectrum = whiten_spectrum self.whitening_filter = self.output_dir.joinpath(f'{self.tomo_id}_whitening_filter.npy') - if self.whiten_spectrum and not self.whitening_filter.exists(): + if self.whiten_spectrum: logging.info('Estimating whitening filter...') weights = 1 / np.sqrt( power_spectrum_profile( From c3f77dbe4b49f865156f071772c560892599fd14 Mon Sep 17 00:00:00 2001 From: McHaillet Date: Fri, 26 Jan 2024 12:38:22 +0100 Subject: [PATCH 3/3] test the size of whitening filter upon reducing search box --- tests/test_tmjob.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_tmjob.py b/tests/test_tmjob.py index 0291c17f..8500630d 100644 --- a/tests/test_tmjob.py +++ b/tests/test_tmjob.py @@ -182,6 +182,18 @@ def test_tm_job_weighting_options(self): score, angle = job.start_job(0, return_volumes=True) self.assertEqual(score.shape, job.tomo_shape, msg='TMJob with only whitening filter failed') + # load the whitening filter from previous job to compare against + whitening_filter = np.load(TEST_WHITENING_FILTER) + job = TMJob('0', 10, TEST_TOMOGRAM, TEST_TEMPLATE, TEST_MASK, TEST_DATA_DIR, + angle_increment='90.00', voxel_size=1., whiten_spectrum=True, search_y=[10, 90]) + new_whitening_filter = np.load(TEST_WHITENING_FILTER) + self.assertNotEqual(whitening_filter.shape, new_whitening_filter.shape, + msg='After reducing the search region along the largest dimension the whitening filter ' + 'should have less sampling points') + self.assertEqual(new_whitening_filter.shape, (max(job.search_size) // 2 + 1, ), + msg='The whitening filter does not have the expected size, it should be equal (x // 2) + 1, ' + 'where x is the largest dimension of the search box.') + # TMJob with none of these weighting options is tested in all other runs in this file. def test_custom_angular_search(self):