Test Failed
Pull Request — master (#700)
by Daniil
03:23
created

savu.plugins.reconstructions.projectors.forward_projector_tomobar   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ForwardProjectorTomobar.__init__() 0 2 1
A ForwardProjectorTomobar.get_max_frames() 0 2 1
A ForwardProjectorTomobar.process_frames() 0 17 1
A ForwardProjectorTomobar.setup() 0 11 1
A ForwardProjectorTomobar.nInput_datasets() 0 2 1
A ForwardProjectorTomobar.nOutput_datasets() 0 2 1
1
# Copyright 2014 Diamond Light Source Ltd.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
"""
16
.. module:: forward_projector_tomobar
17
   :platform: Unix
18
   :synopsis: A forward data projector using ToMoBAR software
19
20
.. moduleauthor:: Daniil Kazantsev <[email protected]>
21
"""
22
23
from savu.plugins.reconstructions.base_recon import BaseRecon
24
from savu.plugins.driver.cpu_plugin import CpuPlugin
25
from savu.plugins.utils import register_plugin
26
27
from tomobar.methodsDIR import RecToolsDIR
28
import numpy as np
29
30
@register_plugin
31
class ForwardProjectorTomobar(BaseRecon, CpuPlugin):
32
    """
33
    This plugin uses ToMoBAR software and CPU Astra projector to generate projection data,
34
    one needs to provide 2 inputs [original projection data, object to project].
35
    The plugin will project the given object using geometry of the provided projection data
36
37
    :param out_datasets: Default out dataset names. Default: ['forw_proj']
38
    """
39
40
    def __init__(self):
41
        super(ForwardProjectorTomobar, self).__init__('ForwardProjectorTomobar')
42
43
    def setup(self):
44
        in_dataset, out_dataset = self.get_datasets()
45
        in_pData, out_pData = self.get_plugin_datasets()
46
        in_pData[0].plugin_data_setup('SINOGRAM', self.get_max_frames())
47
        in_pData[1].plugin_data_setup('VOLUME_XZ', 'single')
48
49
        out_shape_sino = in_dataset[0].get_shape()
50
        out_dataset[0].create_dataset(patterns=in_dataset[0],
51
                                           axis_labels=in_dataset[0],
52
                                           shape=out_shape_sino)
53
        out_pData[0].plugin_data_setup('SINOGRAM',self.get_max_frames())
54
55
    def process_frames(self, data):
56
        cor, angles, vol_shape, init  = self.get_frame_params()
57
        sinogram = data[0].astype(np.float32)
58
        image = data[1].astype(np.float32)
59
        objsize_image = np.shape(image)[0]
60
        proj_number, self.DetectorsDimH = np.shape(sinogram)
61
        self.anglesRAD = np.deg2rad(angles.astype(np.float32))
62
        half_det_width = 0.5*self.DetectorsDimH
63
        cor_astra = half_det_width - cor
64
        RectoolsDIR = RecToolsDIR(DetectorsDimH = self.DetectorsDimH+1,  # DetectorsDimH # detector dimension (horizontal)
65
                            DetectorsDimV = None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
66
                            CenterRotOffset = cor_astra.item() - 0.5, # Center of Rotation (CoR) scalar (for 3D case only)
67
                            AnglesVec = self.anglesRAD, # array of angles in radians
68
                            ObjSize = objsize_image, # a scalar to define reconstructed object dimensions
69
                            device_projector='cpu')
70
        sinogram_new = RectoolsDIR.FORWPROJ(image)
71
        return sinogram_new
72
73
    def get_max_frames(self):
74
        return 'single'
75
76
    def nInput_datasets(self):
77
        return 2
78
79
    def nOutput_datasets(self):
80
        return 1
81