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

dataset_analyzer: add get_0_180_radios and get_angles functions

parent 6ceeca6d
......@@ -2,6 +2,7 @@ import os
import posixpath
from tempfile import mkdtemp
import numpy as np
from silx.io import get_data
from silx.io.url import DataUrl
from tomoscan.esrf.edfscan import EDFTomoScan
from tomoscan.esrf.hdf5scan import HDF5TomoScan
......@@ -385,3 +386,71 @@ def analyze_dataset(dataset_path, processes_file=None, extra_options=None, logge
)
return dataset_structure
def get_0_180_radios(dataset_info, angles=None):
"""
Get the radios at 0 degres and 180 degrees.
Parameters
----------
dataset_info: `dataset_infos`
Data structure with the dataset information
angles: array, optional
Array with the rotation angles. If provided, it overwrites the information from 'dataset_info', if any.
"""
if angles is None:
angles = dataset_info.rotation_angles
radios_indices = []
radios_indices = sorted(dataset_info.projections.keys())
# Take angles 0 and 180 degrees. It might not work of there is an offset
i_0 = np.argmin(np.abs(angles))
i_180 = np.argmin(np.abs(angles - np.pi))
_min_indices = [i_0, i_180]
radios_indices = [
radios_indices[i_0],
radios_indices[i_180]
]
n_radios = 2
radios = np.zeros((n_radios, ) + dataset_info.radio_dims[::-1], "f")
for i in range(n_radios):
radio_idx = radios_indices[i]
radios[i] = get_data(dataset_info.projections[radio_idx]).astype("f")
return radios
def get_angles(dataset_info, logger=None):
"""
Get rotation angles (in radians) from a dataset_info data structure.
If no such information is available, generates an array with standard angles.
Parameters
----------
dataset_info: `dataset_infos`
Data structure with the dataset information
logger: Logger
Logger object
"""
logger = LoggerOrPrint(logger)
dataset_angles = dataset_info.rotation_angles
if dataset_angles is not None:
return dataset_angles
theta_min, theta_max = 0, np.pi
msg = "no information on angles was found for this dataset. Using default range "
endpoint = False
if dataset_info.is_halftomo:
theta_max *= 2
endpoint = True
msg += "[0, 360]"
else:
msg += "[0, 180["
logger.warning(msg)
angles = np.linspace(
theta_min, theta_max, len(dataset_info.projections),
endpoint=endpoint
)
return angles
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