Commit c04d7f14 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Integrate new auto-Cor method in pipeline and resources

parent 187e876b
......@@ -29,7 +29,9 @@ class CORFinder:
self._init_flatfield()
self._apply_flatfield()
self.cor = CenterOfRotation()
self._default_search_method = "centered"
if self.halftomo:
self._default_search_method = "global"
def _get_angles(self, angles):
dataset_angles = self.dataset_info.rotation_angles
......@@ -42,10 +44,6 @@ class CORFinder:
def _init_radios(self):
# TODO
if self.halftomo:
raise NotImplementedError("Automatic COR with half tomo is not supported yet")
#
# We take 2 radios. It could be tuned for a 360 degrees scan.
self._n_radios = 2
self._radios_indices = []
......@@ -80,24 +78,37 @@ class CORFinder:
self.flatfield.normalize_radios(self.radios)
def find_cor(self, **cor_kwargs):
def find_cor(self, search_method=None, **cor_kwargs):
"""
Find the center of rotation.
Parameters
----------
This function passes the named parameters to nabu.preproc.alignment.CenterOfRotation.find_shift.
search_method: str, optional
Which CoR search method to use. Default is "auto" (equivalent to "centered").
Returns
-------
cor: float
The estimated center of rotation for the current dataset.
Notes
------
This function passes the named parameters to nabu.preproc.alignment.CenterOfRotation.find_shift.
"""
shift = self.cor.find_shift(
self.radios[0],
np.fliplr(self.radios[1]),
**cor_kwargs
)
search_method = search_method or self._default_search_method
if search_method == "global":
shift = self.cor.find_shift(
self.radios[0],
np.fliplr(self.radios[1]),
low_pass=1, high_pass=20, global_search=True
)
else:
shift = self.cor.find_shift(
self.radios[0],
np.fliplr(self.radios[1]),
**cor_kwargs
)
# find_shift returned a single scalar in 2020.1
# This should be the default after 2020.2 release
if hasattr(shift, "__iter__"):
......
......@@ -78,12 +78,12 @@ class ProcessConfig:
def _get_cor(self):
cor = self.nabu_config["reconstruction"]["rotation_axis_position"]
if cor == "auto":
if isinstance(cor, str): # auto-CoR
self.corfinder = CORFinder(
self.dataset_infos,
halftomo=self.nabu_config["reconstruction"]["enable_halftomo"],
)
cor = self.corfinder.find_cor()
cor = self.corfinder.find_cor(search_method=cor)
self.dataset_infos.axis_position = cor
......@@ -223,7 +223,7 @@ class ProcessConfig:
# New key
rec_options["rotation_axis_position_halftomo"] = (2*cor_i-1)/2.
# New key
rec_options["cor_estimated_auto"] = (nabu_config["reconstruction"]["rotation_axis_position"] == "auto")
rec_options["cor_estimated_auto"] = isinstance(nabu_config["reconstruction"]["rotation_axis_position"], str)
#
# Histogram
......
......@@ -220,8 +220,8 @@ def cor_validator(val):
if isinstance(val, float):
return val
elif len(val.strip()) >= 1:
if val.lower() == "auto":
return "auto"
if val.lower() in ["auto", "global", "centered"]:
return val.lower()
val_float, error = convert_to_float(val)
assert error is None, "Invalid number"
return val_float
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment