Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template.py: make filter warnings conditional and allow for no ctf_params #98

Merged
merged 8 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/pytom_tm/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!
Expand Down
19 changes: 19 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -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)