Reconstructing a complete scan using nabu and config file, from python¶
In previous notebooks nabu_basic_reconstruction.ipynb and nabu_from_python_with_gpu.ipynb, we saw how to manipulate the individual processing classes for step-by-step processing (eg. FlatField, PaganinPhaseRetrieval ; and their cuda counterparts).
In this notebook, we see how to use a facility class FullFieldReconstructor which assembles all these steps, does the "boring work" for you (memory allocation, data transfers, configuration ingestion, ...). It reconstructs the input volume by parts, handling the necessary overlap between sub-volumes if needed.
1. Get the scan (.nx file) and processing configuration (.conf file)¶
In [ ]:
Copied!
import os
from nabu.testutils import utilstest, get_file
from nabu.pipeline.fullfield.processconfig import ProcessConfig
import os
from nabu.testutils import utilstest, get_file
from nabu.pipeline.fullfield.processconfig import ProcessConfig
In [ ]:
Copied!
print("Getting dataset (downloading if necessary) ...")
data_path = get_file("bamboo_reduced.nx")
print("... OK")
# Get the configuration file of this dataset
conf_fname = get_file("bamboo_reduced.conf")
# Change directory to the path where the data is located (only useful for this tutorial)
os.chdir(utilstest.data_home)
# Parse this configuration file
conf = ProcessConfig(conf_fname)
print("Getting dataset (downloading if necessary) ...")
data_path = get_file("bamboo_reduced.nx")
print("... OK")
# Get the configuration file of this dataset
conf_fname = get_file("bamboo_reduced.conf")
# Change directory to the path where the data is located (only useful for this tutorial)
os.chdir(utilstest.data_home)
# Parse this configuration file
conf = ProcessConfig(conf_fname)
In [ ]:
Copied!
2. Running volume reconstruction¶
You can specify which reconstruction backend to use ("numpy" or "cuda")
In [ ]:
Copied!
from nabu.pipeline.fullfield.reconstruction import FullFieldReconstructor
from nabu.pipeline.fullfield.reconstruction import FullFieldReconstructor
In [ ]:
Copied!
reconstructor = FullFieldReconstructor(conf, backend="cuda")
reconstructor = FullFieldReconstructor(conf, backend="cuda")
In [ ]:
Copied!
reconstructor.reconstruct()
reconstructor.reconstruct()
In [ ]:
Copied!
output_file = reconstructor.merge_hdf5_reconstructions()
output_file = reconstructor.merge_hdf5_reconstructions()
3. Visualization¶
In [ ]:
Copied!
from tomoscan.io import HDF5File
from tomoscan.io import HDF5File
In [ ]:
Copied!
with HDF5File(output_file, "r") as f:
data_ptr = f["entry0000/reconstruction/results/data"]
middle_slice_horiz = data_ptr[reconstructor.delta_z//2]
middle_slice_vertic = data_ptr[:, :, reconstructor.n_x//2]
with HDF5File(output_file, "r") as f:
data_ptr = f["entry0000/reconstruction/results/data"]
middle_slice_horiz = data_ptr[reconstructor.delta_z//2]
middle_slice_vertic = data_ptr[:, :, reconstructor.n_x//2]
In [ ]:
Copied!
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(121)
plt.imshow(middle_slice_horiz, cmap="gray")
plt.xlabel("Horizontal slice, middle")
plt.subplot(122)
plt.imshow(middle_slice_vertic, cmap="gray")
plt.xlabel("Vertical slice, middle")
plt.show()
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(121)
plt.imshow(middle_slice_horiz, cmap="gray")
plt.xlabel("Horizontal slice, middle")
plt.subplot(122)
plt.imshow(middle_slice_vertic, cmap="gray")
plt.xlabel("Vertical slice, middle")
plt.show()
In [ ]:
Copied!