Test Failed
Pull Request — master (#862)
by Daniil
03:30
created

examples.plugin_examples.plugin_templates.general.plugin_template7   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A PluginTemplate7.nInput_datasets() 0 2 1
A PluginTemplate7.pre_process() 0 2 1
A PluginTemplate7.post_process() 0 2 1
A PluginTemplate7.__init__() 0 2 1
A PluginTemplate7.setup() 0 44 1
A PluginTemplate7.nOutput_datasets() 0 2 1
A PluginTemplate7.process_frames() 0 4 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:: plugin_template7
17
   :platform: Unix
18
   :synopsis: A template to create a plugin that reduces the data dimensions.
19
20
.. moduleauthor:: Developer Name <[email protected]>
21
22
"""
23
24
import copy
25
import numpy as np
26
27
from savu.plugins.plugin import Plugin
28
from savu.plugins.utils import register_plugin
29
from savu.plugins.driver.cpu_plugin import CpuPlugin
30
31
32
@register_plugin
33
class PluginTemplate7(Plugin, CpuPlugin):
34
35
    def __init__(self):
36
        super(PluginTemplate7, self).__init__('PluginTemplate7')
37
38
    def nInput_datasets(self):
39
        return 1
40
41
    def nOutput_datasets(self):
42
        return 1
43
44
    def setup(self):
45
        in_dataset, out_dataset = self.get_datasets()
46
47
        #=================== populate output dataset ==========================
48
        # Due to the increase in dimensions, the out_dataset will have
49
        # different axis_labels, patterns and shape to the in_dataset and
50
        # these will need to be defined.
51
        # For more information about the syntax used here see:
52
        # http://savu.readthedocs.io/en/latest/api_plugin/savu.data.data_structures.data_create
53
54
        # AMEND THE PATTERNS: The output dataset will have one dimension more
55
        # than the in_dataset, so add another slice dimensions the patterns
56
        add_dim = str(len(in_dataset[0].get_shape()))
57
        patterns = {in_dataset[0]: ['.'.join(['*', add_dim])]}
58
59
        # AMEND THE AXIS LABELS: Add an extra slice dim to all axis labels
60
        axis_list = ['.'.join(['~' + add_dim, self.parameters['axis_label'],
61
                            self.parameters['axis_unit']])]
62
        axis_labels = {in_dataset[0]: axis_list}
63
64
        # AMEND THE SHAPE: Remove the two unrequired dimensions from the
65
        # original shape and add a new dimension shape.
66
        self.rep = self.parameters['axis_len']
67
        shape = list(in_dataset[0].get_shape())
68
        shape.append(self.rep)
69
70
        # populate the output dataset
71
        out_dataset[0].create_dataset(
72
                patterns=patterns,
73
                axis_labels=axis_labels,
74
                shape=tuple(shape))
75
76
        slice_dim = (out_dataset[0].get_data_dimension_by_axis_label(
77
                'detector_y'),)
78
        core_dims = set(range(0, len(shape))).difference(set(slice_dim))
79
        sinomovie = {'core_dims': tuple(core_dims), 'slice_dims': slice_dim}
80
        out_dataset[0].add_pattern("SINOMOVIE", **sinomovie)
81
        print(out_dataset[0].get_data_patterns()['SINOMOVIE'])
82
83
        #================== populate plugin datasets ==========================
84
        in_pData, out_pData = self.get_plugin_datasets()
85
        in_pData[0].plugin_data_setup('PROJECTION', 'single')
86
        out_pData[0].plugin_data_setup('PROJECTION', self.rep,
87
                 slice_axis=self.parameters['axis_label'])
88
        #======================================================================
89
90
    def pre_process(self):
91
        self.ndims = len(self.get_plugin_in_datasets()[0].get_shape())
92
93
    def process_frames(self, data):
94
        rep_mat = np.repeat(
95
                np.expand_dims(data[0], self.ndims), self.rep, axis=self.ndims)
96
        return rep_mat
97
98
    def post_process(self):
99
        pass