Test Failed
Pull Request — master (#845)
by Daniil
03:37
created

savu.plugins.simulation.tomo_phantom_artifacts   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 13

6 Methods

Rating   Name   Duplication   Size   Complexity  
B TomoPhantomArtifacts.process_frames() 0 40 8
A TomoPhantomArtifacts.nOutput_datasets() 0 2 1
A TomoPhantomArtifacts.get_max_frames() 0 2 1
A TomoPhantomArtifacts.setup() 0 6 1
A TomoPhantomArtifacts.nInput_datasets() 0 2 1
A TomoPhantomArtifacts.__init__() 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:: tomo_phantom_artifacts
17
   :platform: Unix
18
   :synopsis: Adding artifacts to the generated synthetic projection data using TomoPhantom
19
20
.. moduleauthor:: Daniil Kazantsev <[email protected]>
21
"""
22
23
import savu.plugins.utils as pu
24
from savu.plugins.plugin import Plugin
25
from savu.plugins.driver.cpu_plugin import CpuPlugin
26
from savu.plugins.utils import register_plugin
27
28
import tomophantom
29
from tomophantom.supp.artifacts import _Artifacts_
30
import os
31
import numpy as np
32
33
@register_plugin
34
class TomoPhantomArtifacts(Plugin, CpuPlugin):
35
    def __init__(self):
36
        super(TomoPhantomArtifacts, self).__init__('TomoPhantomArtifacts')
37
38
    def setup(self):
39
        in_dataset, out_dataset = self.get_datasets()
40
        out_dataset[0].create_dataset(in_dataset[0])
41
        in_pData, out_pData = self.get_plugin_datasets()
42
        in_pData[0].plugin_data_setup('SINOGRAM', self.get_max_frames())
43
        out_pData[0].plugin_data_setup('SINOGRAM', self.get_max_frames())
44
45
    def process_frames(self, data):
46
        sinogram = data[0]
47
        # apply a variety of artifacts to the generated data:
48
        _noise_={}
49
        if self.parameters['artifacts_noise_type'] is not None:
50
            _noise_ =  {'noise_type' : self.parameters['artifacts_noise_type'],
51
                        'noise_amplitude' : self.parameters['artifacts_noise_amplitude'],
52
                        'noise_seed' : 0,
53
                        'verbose' : False}
54
        # misalignment dictionary
55
        _sinoshifts_={}
56
        if self.parameters['artifacts_misalignment_maxamplitude'] is not None:
57
            _sinoshifts_ = {'sinoshifts_maxamplitude' : self.parameters['artifacts_misalignment_maxamplitude']}
58
        # adding zingers and stripes
59
        _zingers_={}
60
        if self.parameters['artifacts_zingers_percentage'] is not None:
61
            _zingers_ = {'zingers_percentage' : self.parameters['artifacts_zingers_percentage'],
62
                        'zingers_modulus' : self.parameters['artifacts_zingers_modulus']}
63
        _stripes_={}
64
        if self.parameters['artifacts_stripes_percentage'] is not None:
65
            _stripes_ = {'stripes_percentage' : self.parameters['artifacts_stripes_percentage'],
66
                        'stripes_maxthickness' : self.parameters['artifacts_stripes_maxthickness'],
67
                        'stripes_intensity' : self.parameters['artifacts_stripes_intensity'],
68
                        'stripes_type' : self.parameters['artifacts_stripes_type'],
69
                        'stripes_variability' : self.parameters['artifacts_stripes_variability']}
70
        # partial volume effect dictionary
71
        _pve_={}
72
        if self.parameters['artifacts_pve'] is not None:
73
            _pve_ = {'pve_strength' : self.parameters['artifacts_pve']}
74
        # fresnel propagator
75
        _fresnel_propagator_={}
76
        if self.parameters['artifacts_fresnel_distance'] is not None:
77
            _fresnel_propagator_ = {'fresnel_dist_observation' : self.parameters['artifacts_fresnel_distance'],
78
                        'fresnel_scale_factor' : self.parameters['artifacts_fresnel_scale_factor'],
79
                        'fresnel_wavelenght' : self.parameters['artifacts_fresnel_wavelenght']}
80
        if self.parameters['artifacts_misalignment_maxamplitude'] is not None:
81
            [sino_artifacts, shifts] = _Artifacts_(sinogram.copy(), **_noise_, **_zingers_, **_stripes_, **_sinoshifts_, **_pve_, **_fresnel_propagator_)
82
        else:
83
            sino_artifacts = _Artifacts_(sinogram.copy(), **_noise_, **_zingers_, **_stripes_, **_sinoshifts_, **_pve_, **_fresnel_propagator_)
84
        return sino_artifacts
0 ignored issues
show
introduced by
The variable sino_artifacts does not seem to be defined for all execution paths.
Loading history...
85
86
    def get_max_frames(self):
87
        return 'single'
88
89
    def nInput_datasets(self):
90
        return 1
91
92
    def nOutput_datasets(self):
93
        return 1
94