mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-11-13 01:33:55 +01:00
Enhance line_based_frc function with detailed docstring and input validation checks
This commit is contained in:
1 parent
6de3491928
commit
e0cf3ea2e1
2 files changed
+14
-2
No files matched your search
@@ -1530,7 +1530,8 @@ def calc_spectral_info(dataset, nbins=50):
|
||||
|
||||
def line_based_frc(image1, image2, axis=1, n_bins=None, thresholds={}, pixel_size=1.0, unit="pixels"):
|
||||
"""
|
||||
Compute line-based FRC with multiple threshold methods
|
||||
Compute line-based FRC with multiple threshold methods. This works great for highly anisotropic
|
||||
images, such as those with vertical or horizontal stripes.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -1563,6 +1564,9 @@ def line_based_frc(image1, image2, axis=1, n_bins=None, thresholds={}, pixel_siz
|
||||
if isinstance(image2, t.Tensor):
|
||||
image2 = image2.numpy()
|
||||
|
||||
assert isinstance(image1, np.ndarray), "image1 must be a numpy array or torch tensor"
|
||||
assert isinstance(image2, np.ndarray), "image2 must be a numpy array or torch tensor"
|
||||
|
||||
assert image1.shape == image2.shape, "Images must have same shape"
|
||||
|
||||
if image1.ndim != 2:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
import torch as t
|
||||
from scipy import linalg as la
|
||||
from scipy.sparse import linalg as spla
|
||||
import torch as t
|
||||
|
||||
from cdtools.tools import analysis, initializers
|
||||
from cdtools.tools.analysis import line_based_frc
|
||||
@@ -612,3 +613,10 @@ def test_line_based_frc():
|
||||
assert res_dict["1/2"] > 70.0 and res_dict["1/2"] < 75.0
|
||||
assert res_dict["1/4"] > 52.0 and res_dict["1/4"] < 57.0
|
||||
assert res_dict["1/7"] > 45.0 and res_dict["1/7"] < 48.0
|
||||
|
||||
# Now lets check if we catch some errors correctly
|
||||
# Check if it raises an error for non-2D input
|
||||
with pytest.raises(ValueError):
|
||||
line_based_frc(np.random.rand(30, 17, 3), np.random.rand(30, 17, 3))
|
||||
line_based_frc(np.random.rand(30, 17, 3), np.random.rand(30, 17))
|
||||
line_based_frc("string", np.random.rand(30, 17))
|
||||
Reference in new issue
Block a user