Commit b52e4388 authored by payno's avatar payno
Browse files

one more step on addinf 3D-XRD. Add rocking and base tilt datasets

parent 4db180a4
Pipeline #45896 failed with stages
in 59 seconds
......@@ -40,6 +40,7 @@ from nxtomomill.io.confighandler import XRD3DHDF5ConfigHandler
from nxtomomill.io.confighandler import SETTABLE_PARAMETERS_UNITS
from collections.abc import Iterable
from nxtomomill.utils import Format
from nxtomomill.io.config import XRD3DHDF5Config
import argparse
......@@ -92,13 +93,13 @@ def main(argv):
"--file_extension",
default=None,
help="extension of the output file. Valid values are "
"" + "/".join(utils.FileExtension.values()),
"" + "/".join(utils.FileExtension.values()),
)
parser.add_argument(
"--single-file",
help="merge all scan sequence to the same output file. "
"By default create one file per sequence and "
"group all sequence in the output file",
"By default create one file per sequence and "
"group all sequence in the output file",
dest="single_file",
action="store_true",
default=None,
......@@ -118,7 +119,7 @@ def main(argv):
parser.add_argument(
"--entries",
help="Specify (root) entries to be converted. By default it will try "
"to convert all existing entries.",
"to convert all existing entries.",
default=None,
)
parser.add_argument(
......@@ -129,14 +130,14 @@ def main(argv):
parser.add_argument(
"--raises-error",
help="Raise errors if some data are not met instead of providing some"
" default values",
" default values",
action="store_true",
default=None,
)
parser.add_argument(
"--field-of-view",
help="Force the output to be `Half` or `Full` acquisition. Otherwise "
"parse raw data to find this information.",
"parse raw data to find this information.",
default=None,
)
parser.add_argument(
......@@ -185,8 +186,8 @@ def main(argv):
"--valid-camera-names",
default=None,
help="Valid NXDetector dataset name to be considered. Otherwise will"
"try to deduce them from NX_class attibute (value should be"
"NXdetector) or from instrument group child structure.",
"try to deduce them from NX_class attibute (value should be"
"NXdetector) or from instrument group child structure.",
)
parser.add_argument(
"--rot_angle_keys",
......@@ -255,10 +256,10 @@ def main(argv):
default=None,
nargs="*",
help="Allow manual definition of some parameters. "
"Valid parameters (and expected input unit) "
"are: {}. Should be added at the end of the command line because "
"will try to cover all text set after this "
"option.".format(_getPossibleInputParams()),
"Valid parameters (and expected input unit) "
"are: {}. Should be added at the end of the command line because "
"will try to cover all text set after this "
"option.".format(_getPossibleInputParams()),
)
parser.add_argument(
......@@ -268,7 +269,7 @@ def main(argv):
"--configuration-file",
default=None,
help="file containing the full configuration to convert from h5 "
"bliss to nexus",
"bliss to nexus",
)
options = parser.parse_args(argv[1:])
if options.request_input:
......@@ -282,6 +283,7 @@ def main(argv):
return
else:
configuration = configuration_handler.configuration
assert isinstance(configuration, XRD3DHDF5Config)
for title in configuration.init_titles:
assert title != ""
configuration.format = Format.XRD_3D
......
......@@ -107,6 +107,7 @@ class StandardAcquisition(BaseAcquisition):
self._acq_expo_time = None
self._copied_dataset = {}
"register dataset copied. Key if the original location as" "DataUrl.path. Value is the DataUrl it has been moved to"
self._current_scan_n_frame = None
@property
def image_key(self):
......@@ -284,7 +285,7 @@ class StandardAcquisition(BaseAcquisition):
self._virtual_sources_len.append(n_frame)
return n_frame
def __treate_valid_camera(
def _treate_valid_camera(
self,
detector_node,
entry,
......@@ -388,6 +389,7 @@ class StandardAcquisition(BaseAcquisition):
n_frame=n_frame,
)
)
self._current_scan_n_frame = n_frame
def camera_is_valid(self, det_name):
assert isinstance(det_name, str)
......@@ -449,7 +451,7 @@ class StandardAcquisition(BaseAcquisition):
continue
else:
detector_node = instrument_grp[key]
self.__treate_valid_camera(
self._treate_valid_camera(
detector_node,
entry=entry,
frame_type=type_,
......
......@@ -38,6 +38,9 @@ __date__ = "19/04/2021"
from nxtomomill.converter.hdf5.acquisition.standardacquisition import (
StandardAcquisition,
)
import logging
_logger = logging.getLogger(__name__)
class XRD3DAcquisition(StandardAcquisition):
......@@ -63,12 +66,52 @@ class XRD3DAcquisition(StandardAcquisition):
self._rocking = rocking
def _get_rocking_dataset(self, entry, n_frames):
raise NotImplementedError()
for grp in self._get_positioners_node(entry), entry:
try:
rocking, unit = self._get_node_values_for_frame_array(
node=grp,
n_frame=n_frames,
keys=self.configuration.rocking_keys,
info_retrieve="rocking",
expected_unit=None,
)
except (ValueError, KeyError):
pass
else:
return rocking, None
mess = "Unable to find rocking for {}" "".format(self.root_url.path())
if self.raise_error_if_issue:
raise ValueError(mess)
else:
mess += "default value will be set. (0)"
_logger.warning(mess)
return 0, None
def _get_base_tilt_dataset(self, entry, n_frames):
raise NotImplementedError()
for grp in self._get_positioners_node(entry), entry:
try:
base_tilt, unit = self._get_node_values_for_frame_array(
node=grp,
n_frame=n_frames,
keys=self.configuration.base_tilt_keys,
info_retrieve="base tilt",
expected_unit=None,
)
except (ValueError, KeyError):
pass
else:
return base_tilt, None
mess = "Unable to find base tilt for {}" "".format(self.root_url.path())
if self.raise_error_if_issue:
raise ValueError(mess)
else:
mess += "default value will be set. (0)"
_logger.warning(mess)
return 0, None
def __treate_valid_camera(
def _treate_valid_camera(
self,
detector_node,
entry,
......@@ -78,7 +121,7 @@ class XRD3DAcquisition(StandardAcquisition):
entry_path,
entry_url,
):
super().__treate_valid_camera(
super()._treate_valid_camera(
detector_node=detector_node,
entry=entry,
frame_type=frame_type,
......@@ -89,17 +132,30 @@ class XRD3DAcquisition(StandardAcquisition):
)
# store base tilt information
if not self._ignore_sample_output("base_tilt"):
rots = self._get_base_tilt_dataset(entry=entry, n_frames=self._n_frames)[0]
self._base_tilt.extend(rots)
base_tilt, _ = self._get_base_tilt_dataset(
entry=entry, n_frames=self._current_scan_n_frame
)
self._base_tilt.extend(base_tilt)
else:
self._base_tilt = None
# store rocking information
if not self._ignore_sample_output("rocking"):
rocking, _ = self._get_rocking_dataset(
entry=entry, n_frames=self._current_scan_n_frame
)
self._rocking.extend(rocking)
else:
self._rocking = None
def _preprocess_registered_entries(self, output_file):
super()._preprocess_registered_entries(output_file=output_file)
self._base_tilt = []
self._rocking = []
super()._preprocess_registered_entries(output_file=output_file)
def _write_instrument(self, root_node):
super()._write_instrument(root_node)
#instrument_node = root_node.create_group("instrument")
#raise NotImplementedError()
def _write_sample(self, root_node):
super()._write_sample(root_node)
sample_node = root_node.require_group("sample")
if self._rocking is not None:
sample_node["rocking"] = self._rocking
if self._base_tilt is not None:
sample_node["base_tilt"] = self._base_tilt
......@@ -1106,6 +1106,49 @@ class TomoHDF5Config:
class XRD3DHDF5Config(TomoHDF5Config):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._rocking_keys = settings.XRD3D.H5.ROCKING_KEYS
self._base_tilt_keys = settings.XRD3D.H5.BASE_TILT_KEYS
@property
def rocking_keys(self) -> Iterable:
return self._rocking_keys
@rocking_keys.setter
def rocking_keys(self, keys) -> None:
if not isinstance(keys, Iterable):
raise TypeError("'keys' should be an Iterable")
else:
self._rocking_keys = keys
@staticmethod
def from_cfg_file(file_path: str, encoding=None):
assert file_path is not None, "file_path should not be None"
config_parser = configparser.ConfigParser(allow_no_value=True)
config_parser.read(file_path, encoding=encoding)
return XRD3DHDF5Config.from_dict(config_parser)
@staticmethod
def from_dict(dict_: dict):
"""
Create a HDF5Config object and set it from values contained in the
dictionary
:param dict dict_: settings dictionary
:return: HDF5Config
"""
config = XRD3DHDF5Config()
config.load_from_dict(dict_)
return config
@property
def base_tilt_keys(self) -> Iterable:
return self._base_tilt_keys
@base_tilt_keys.setter
def base_tilt_keys(self, keys) -> None:
if not isinstance(keys, Iterable):
raise TypeError("'keys' should be an Iterable")
else:
self._base_tilt_keys = keys
def generate_default_h5_config() -> dict:
......
......@@ -191,6 +191,7 @@ class _BaseHDF5ConfigHandler:
class TomoHDF5ConfigHandler(_BaseHDF5ConfigHandler):
def _create_HDF5_config(self):
print("A")
if self.argparse_options.config:
return TomoHDF5Config.from_cfg_file(self.argparse_options.config)
else:
......@@ -296,8 +297,10 @@ class TomoHDF5ConfigHandler(_BaseHDF5ConfigHandler):
_logger.error(err)
return False
class XRD3DHDF5ConfigHandler(_BaseHDF5ConfigHandler):
def _create_HDF5_config(self):
print("B")
if self.argparse_options.config:
return XRD3DHDF5Config.from_cfg_file(self.argparse_options.config)
else:
......@@ -324,16 +327,13 @@ class XRD3DHDF5ConfigHandler(_BaseHDF5ConfigHandler):
"x_trans_keys": ("x_trans_keys", self.get_tuple_of_keys_from_cmd),
"y_trans_keys": ("y_trans_keys", self.get_tuple_of_keys_from_cmd),
"z_trans_keys": ("z_trans_keys", self.get_tuple_of_keys_from_cmd),
"rot_angle_keys": (
"rotation_angle_keys", self.get_tuple_of_keys_from_cmd),
"rot_angle_keys": ("rotation_angle_keys", self.get_tuple_of_keys_from_cmd),
"acq_expo_time_keys": (
"exposition_time_keys",
self.get_tuple_of_keys_from_cmd,
),
"x_pixel_size_key": (
"x_pixel_size_paths", self.get_tuple_of_keys_from_cmd),
"y_pixel_size_key": (
"y_pixel_size_paths", self.get_tuple_of_keys_from_cmd),
"x_pixel_size_key": ("x_pixel_size_paths", self.get_tuple_of_keys_from_cmd),
"y_pixel_size_key": ("y_pixel_size_paths", self.get_tuple_of_keys_from_cmd),
"init_titles": ("init_titles", self.get_tuple_of_keys_from_cmd),
"init_zserie_titles": (
"zserie_init_titles",
......@@ -341,10 +341,8 @@ class XRD3DHDF5ConfigHandler(_BaseHDF5ConfigHandler):
),
"dark_titles": ("dark_titles", self.get_tuple_of_keys_from_cmd),
"ref_titles": ("flat_titles", self.get_tuple_of_keys_from_cmd),
"proj_titles": (
"projections_titles", self.get_tuple_of_keys_from_cmd),
"align_titles": (
"alignment_titles", self.get_tuple_of_keys_from_cmd),
"proj_titles": ("projections_titles", self.get_tuple_of_keys_from_cmd),
"align_titles": ("alignment_titles", self.get_tuple_of_keys_from_cmd),
"set_params": ("param_already_defined", _extract_param_value),
}
for argparse_name, (config_name, format_fct) in mapping.items():
......@@ -368,31 +366,31 @@ class XRD3DHDF5ConfigHandler(_BaseHDF5ConfigHandler):
# check no other option are provided
duplicated_inputs = []
for opt in (
"set_params",
"align_titles",
"proj_titles",
"ref_titles",
"dark_titles",
"init_zserie_titles",
"init_titles",
"init_zserie_titles",
"x_pixel_size_key",
"y_pixel_size_key",
"acq_expo_time_keys",
"rot_angle_keys",
"valid_camera_names",
"z_trans_keys",
"y_trans_keys",
"x_trans_keys",
"request_input",
"raises_error",
"ignore_sub_entries",
"entries",
"debug",
"overwrite",
"single_file",
"file_extension",
"field_of_view",
"set_params",
"align_titles",
"proj_titles",
"ref_titles",
"dark_titles",
"init_zserie_titles",
"init_titles",
"init_zserie_titles",
"x_pixel_size_key",
"y_pixel_size_key",
"acq_expo_time_keys",
"rot_angle_keys",
"valid_camera_names",
"z_trans_keys",
"y_trans_keys",
"x_trans_keys",
"request_input",
"raises_error",
"ignore_sub_entries",
"entries",
"debug",
"overwrite",
"single_file",
"file_extension",
"field_of_view",
):
if getattr(options, opt):
duplicated_inputs.append(opt)
......
......@@ -140,6 +140,6 @@ class Tomo:
class XRD3D(Tomo):
class H5(Tomo.H5):
ROCKING_KEYS = ("mcha4_raw",)
ROCKING_KEYS = ("nfdtx",)
BASE_TILT_KEYS = ("mcha5_raw",)
BASE_TILT_KEYS = ("ffdtilt",)
Markdown is supported
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