reconstruct.py 1.81 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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
28

29
30

def main():
31
32
33
34
35
    args = parse_params_values(
        ReconstructConfig,
        parser_description="Perform a tomographic reconstruction."
    )

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    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

Pierre Paleo's avatar
Pierre Paleo committed
51
    # (hopefully) temporary patch
52
53
54
    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
55
56
        proc.processing_options["phase"]["energy_kev"] = args["energy"]
    #
57
58
59
60
61
62
63
64
65
66

    W = WorkerProcess(
        proc,
        subregion,
        chunk_size=subregion[-1]-subregion[-2],
        logger=logger,
        extra_options={"clear_gpu_memory_after_buildsino": True}
    )
    W.process_chunk()

67
68


69
70

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