diff --git a/src/pytom_tm/template.py b/src/pytom_tm/template.py index db6bed66..dbe4b448 100644 --- a/src/pytom_tm/template.py +++ b/src/pytom_tm/template.py @@ -20,7 +20,7 @@ def generate_template_from_map( input_map: npt.NDArray[float], input_spacing: float, output_spacing: float, - ctf_params: dict, + ctf_params: Optional[dict] = None, center: bool = False, filter_to_resolution: Optional[float] = None, output_box_size: Optional[int] = None, @@ -36,9 +36,13 @@ def generate_template_from_map( mode='edge' ) - if filter_to_resolution is None or filter_to_resolution < (2 * output_spacing): - logging.warning(f'Filter resolution is either not specified (in which case you can ignore this warning) ' - f'or too low, changing to {2 * output_spacing}A (2 * output voxel size)') + if filter_to_resolution is None: + # Set to nyquist resolution + filter_to_resolution = 2 * output_spacing + elif filter_to_resolution < (2 * output_spacing): + warning_text = (f"Filter resolution is too low," + f" setting to {2 * output_spacing}A (2 * output voxel size)") + logging.warning(warning_text) filter_to_resolution = 2 * output_spacing # extend volume to the desired output size before applying convolutions! diff --git a/tests/test_logging.py b/tests/test_logging.py new file mode 100644 index 00000000..e2bbabae --- /dev/null +++ b/tests/test_logging.py @@ -0,0 +1,19 @@ +import unittest +import numpy as np +from pytom_tm.template import generate_template_from_map + +class TestLogging(unittest.TestCase): + def test_lowpass_resolution(self): + template = np.zeros((13, 13, 13), dtype=np.float32) + + # Test too low filter resolution + with self.assertLogs(level='WARNING') as cm: + _ = generate_template_from_map(template, 1., 1., filter_to_resolution=1.5) + self.assertEqual(len(cm.output), 1) + self.assertIn('Filter resolution', cm.output[0]) + self.assertIn('too low', cm.output[0]) + + # Test working filter resolution + with self.assertNoLogs(level='WARNING'): + _ = generate_template_from_map(template, 1., 1., filter_to_resolution=2.5) +