"This notebook shows how to use the Nabu software for performing a basic reconstruction of a tomography dataset. \n",
"The computations are done on a local machine with a GPU and Cuda available."
...
...
%% Cell type:markdown id: tags:
# Nabu reconstruction demo
# Using the Nabu library from Python
This notebook shows how to use the Nabu software for performing a basic reconstruction of a tomography dataset.
The computations are done on a local machine with a GPU and Cuda available.
%% Cell type:markdown id: tags:
## 1 - Load the dataset informations
We must provide `nabu` with the the configuration file (`nabu.conf`), describing the path to the dataset and the processing steps. This is the equivalent of the `.par` file in PyHST2. In this file, no information is given on the detector size, energy, distance, etc: these informations are extracted from the dataset metadata.
Nabu processes data by chunks of radios (see the [documentation](http://www.silx.org/pub/nabu/doc/definitions.html#radios-and-sinograms) for more explanations).
In a first step, we define how to read chunks of radios.
%% Cell type:code id: tags:
``` python
fromnabu.io.readerimportChunkReader
```
%% Cell type:markdown id: tags:
What is the largest chunk size we can process ?
The answer is given by inspecting the current GPU memory, and the processing steps.
Most of the processing can be done on GPU (or many-core CPU if using OpenCL).
With `pycuda.gpuarray` (or its OpenCL counterpart `pyopencl.array`), we manipulate array objects with memory residing on device. This allows to avoid extraneous host <-> device copies.
%% Cell type:code id: tags:
``` python
importpycuda.gpuarrayasgarray
fromnabu.cuda.utilsimportget_cuda_context
importnumpyasnp
```
%% Cell type:code id: tags:
``` python
# Create a Cuda context on device ID 0
# By default, all following GPU processings will be bound on this context
ctx=get_cuda_context(device_id=0)
```
%% Cell type:code id: tags:
``` python
radios=chunk_reader.files_data.astype(np.float32)
n_angles,n_z,n_x=radios.shape
# transfer the chunk on GPU
d_radios=garray.to_gpu(radios)
```
%% Cell type:markdown id: tags:
## 4 - Pre-processing
Pre-processing utilities are available in the `nabu.preproc` module.
Utilities available with the cuda backend are implemented in a module with a `_cuda` suffix.