reconstruct.py 2.49 KB
Newer Older
1
2
3
4
5
#!/usr/bin/env python

import os
from .utils import parse_params_values
from .cli_configs import ReconstructConfig
6
from ...resources.processconfig import ProcessConfig
Pierre Paleo's avatar
Pierre Paleo committed
7
from ...app.fullfield import FullFieldPipeline
Pierre Paleo's avatar
Pierre Paleo committed
8
9
from ...cuda.utils import __has_pycuda__
if __has_pycuda__:
Pierre Paleo's avatar
Pierre Paleo committed
10
    from ...app.fullfield_cuda import CudaFullFieldPipeline, CudaFullFieldPipelineLimitedMemory
Pierre Paleo's avatar
Pierre Paleo committed
11
from ..logger import Logger
Pierre Paleo's avatar
Pierre Paleo committed
12
from ... import version
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


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)
32

33
34

def main():
35
36
    args = parse_params_values(
        ReconstructConfig,
Pierre Paleo's avatar
Pierre Paleo committed
37
38
        parser_description="Perform a tomographic reconstruction.",
        program_version="nabu " + version
39
    )
40
41
42
43
44
45
46
47
    proc = ProcessConfig(args["input_file"])

    logger = Logger(
        "nabu",
        level=proc.nabu_config["about"]["verbosity"],
        logfile=args["log_file"]
    )

Pierre Paleo's avatar
Pierre Paleo committed
48
49
50
51
52
53
54
    # For now we need the --slice argument
    if args["slice"].strip() == "":
        msg = "Need to provide the --slice argument (ex. --slice 1024 or --slice 0-1024)"
        logger.fatal(msg)
        exit(1)
    #

55
56
57
58
    subregion = get_subregion(
        args["slice"],
        proc.dataset_infos.radio_dims[-1]
    )
Pierre Paleo's avatar
Pierre Paleo committed
59
    logger.info("Going to reconstruct slices %s" % str(subregion))
60
61
    subregion = (None, None) + subregion

Pierre Paleo's avatar
Pierre Paleo committed
62
    # (hopefully) temporary patch
63
64
65
    if args["energy"] > 0:
        logger.warning("Using user-provided energy %.2f keV" % args["energy"])
        proc.dataset_infos.dataset_scanner._energy = args["energy"]
Pierre Paleo's avatar
Pierre Paleo committed
66
        proc.processing_options["phase"]["energy_kev"] = args["energy"]
67
68
69
70
    if proc.dataset_infos.energy  < 1e-3 and proc.nabu_config["phase"]["method"] != None:
        msg = "No information on energy. Cannot retrieve phase. Please use the --energy option"
        logger.fatal(msg)
        raise ValueError(msg)
Pierre Paleo's avatar
Pierre Paleo committed
71
    #
72

Pierre Paleo's avatar
Pierre Paleo committed
73
74
75
76
77
78
    if __has_pycuda__:
        PipelineCls = CudaFullFieldPipeline
    else:
        PipelineCls = FullFieldPipeline

    P = PipelineCls(
79
80
81
82
        proc,
        subregion,
        logger=logger,
    )
Pierre Paleo's avatar
Pierre Paleo committed
83
    P.process_chunk()
84

85
86


87
88

if __name__ == "__main__":
89
    main()