Commit 1dff9238 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Add cli tool nabu to reconstruct data

parent 9d476afa
Pipeline #22900 passed with stage
in 52 seconds
......@@ -25,6 +25,8 @@ class PhaseRetrievalComponent(Component):
def _init_phase_retrieval(self, radio_dims):
if (self.dataset_infos.energy == 0):
raise ValueError("Energy is zero. Cannot retrieve phase.")
phaseretr_cls = PaganinPhaseRetrieval
phaseretr_args = [radio_dims]
phaseretr_kwargs = {
......
......@@ -4,7 +4,6 @@ import pycuda.driver as cuda
import pycuda.gpuarray as garray
dev_attrs = cuda.device_attribute
# TODO add logger ? inherit from Processing class with logger ?
# NB: we must detach from a context before creating another context
class CudaProcessing(object):
def __init__(self, device_id=None, ctx=None, cleanup_at_exit=True):
......
......@@ -9,7 +9,7 @@ try:
except ImportError:
__have_scipy__ = False
from silx.image.utils import gaussian_kernel # TODO !
from silx.image.utils import gaussian_kernel
class UnsharpMask(object):
"""
......
......@@ -222,6 +222,3 @@ class CudaLog(CCDProcessing):
)
return radios
# TODO create a class to convert to float32. Merge with CudaLog ?
......@@ -51,6 +51,14 @@ ReconstructConfig = {
"help": "Nabu input file",
"mandatory": True,
},
"log_file": {
"help": "Log file. Default is nabu.log",
"default": "nabu.log",
},
"slice": {
"help": "Slice(s) indice(s) to reconstruct, in the format z1-z2. Default is the whole volume.",
"default": "",
},
"compute": {
"help": "Computation distribution method. Can be 'local' or 'slurm'",
"default": "local",
......@@ -60,4 +68,9 @@ ReconstructConfig = {
"default": 1,
"type": int,
},
"energy": {
"help": "Beam energy in keV. DEPRECATED, was used to patch missing fields in BCU HDF5 file.",
"default": -1,
"type": float,
}
}
#!/usr/bin/env python
"""
reconstruct.py: Entry point for performing tomographic reconstructions.
The user needs to provide:
- A parameter file ("nabu.conf")
- Optionally, the description on how the computations are to be distributed.
"""
import os
from .utils import parse_params_values
from .cli_configs import ReconstructConfig
from .validate import validate_conffile_noexcept
from ...resources.processconfig import ProcessConfig
from ...app.process import WorkerProcess
from ...app.logger import Logger
def get_subregion(slices_indices, radio_nz):
if len(slices_indices) == 0:
return (0, radio_nz)
try:
if "-" in slices_indices:
z_start, z_stop = slices_indices.split("-")
z_start = int(z_start)
z_stop = int(z_stop)
else:
z_idx = int(slices_indices)
z_start = z_idx
z_stop = z_idx + 1
except Exception as exc:
print("Could not interpret slice indices: %s")
print(exc)
exit(1)
return (z_start, z_stop)
def main():
......@@ -21,9 +33,34 @@ def main():
parser_description="Perform a tomographic reconstruction."
)
validator = validate_conffile_noexcept(args["input_file"], print_ok=False)
nabu_config = validator.nabu_config
dataset_structure = validator.dataset_config
proc = ProcessConfig(args["input_file"])
logger = Logger(
"nabu",
level=proc.nabu_config["about"]["verbosity"],
logfile=args["log_file"]
)
subregion = get_subregion(
args["slice"],
proc.dataset_infos.radio_dims[-1]
)
print("Going to reconstruct slices %s" % str(subregion))
subregion = (None, None) + subregion
if args["energy"] > 0:
logger.warning("Using user-provided energy %.2f keV" % args["energy"])
proc.dataset_infos.dataset_scanner._energy = args["energy"]
W = WorkerProcess(
proc,
subregion,
chunk_size=subregion[-1]-subregion[-2],
logger=logger,
extra_options={"clear_gpu_memory_after_buildsino": True}
)
W.process_chunk()
......
......@@ -53,7 +53,7 @@ class NabuValidator(object):
"""
n_angles = self.dataset_infos.n_angles
nx, nz = self.dataset_infos.radio_dims
ny = nx # TODO support non-square reconstruction
ny = nx
what = (
("reconstruction", "start_x", nx),
("reconstruction", "end_x", nx),
......
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