|
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
|
|
|
.. module:: testing_iterative_plugin4 |
|
16
|
|
|
:platform: Unix |
|
17
|
|
|
:synopsis: Iterative plugin example |
|
18
|
|
|
.. moduleauthor:: Nicola Wadeson <[email protected]> |
|
19
|
|
|
""" |
|
20
|
|
|
|
|
21
|
|
|
from savu.plugins.utils import register_plugin |
|
22
|
|
|
from savu.plugins.filters.base_filter import BaseFilter |
|
23
|
|
|
from savu.plugins.driver.iterative_plugin import IterativePlugin |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
@register_plugin |
|
27
|
|
|
class TestingIterativePlugin4(BaseFilter, IterativePlugin): |
|
28
|
|
|
""" |
|
29
|
|
|
A plugin to test the iterative plugin driver - switching between sinograms |
|
30
|
|
|
and projections on each iteration. |
|
31
|
|
|
""" |
|
32
|
|
|
|
|
33
|
|
|
def __init__(self): |
|
34
|
|
|
super(TestingIterativePlugin4, self).\ |
|
35
|
|
|
__init__("TestingIterativePlugin4") |
|
36
|
|
|
|
|
37
|
|
|
def pre_process(self): |
|
38
|
|
|
self.set_iterations(3) |
|
39
|
|
|
|
|
40
|
|
|
def process_frames(self, data): |
|
41
|
|
|
return data[0] |
|
42
|
|
|
|
|
43
|
|
|
def post_process(self): |
|
44
|
|
|
# option here to break out of the iterations |
|
45
|
|
|
# self.set_processing_complete() |
|
46
|
|
|
pass |
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
def setup(self): |
|
|
|
|
|
|
49
|
|
|
# set up the output dataset that is created by the plugin |
|
50
|
|
|
in_dataset, out_dataset = self.get_datasets() |
|
51
|
|
|
|
|
52
|
|
|
in_pData, out_pData = self.get_plugin_datasets() |
|
53
|
|
|
in_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
54
|
|
|
|
|
55
|
|
|
out_dataset[0].create_dataset(in_dataset[0]) |
|
56
|
|
|
# Clone and set as alternating dataset - should I actually do this here? |
|
57
|
|
|
self.clone_dataset(out_dataset[1], out_dataset[0]) |
|
58
|
|
|
|
|
59
|
|
|
# HOw to set more than one pattern associated with a plugin |
|
60
|
|
|
out_pData[0].plugin_data_setup('SINOGRAM', 'single') # set first pattern |
|
61
|
|
|
out_pData[1].plugin_data_setup('PROJECTION', 'single') # set first pattern |
|
62
|
|
|
|
|
63
|
|
|
# Do I need two plugin data objects? When should I set this? |
|
64
|
|
|
|
|
65
|
|
|
# try replacing input dataset with the output dataset *****option to change the pattern on each iteration? |
|
66
|
|
|
# option to set any number of patterns one after another |
|
67
|
|
|
self.set_iteration_datasets(0, [in_dataset[0]], [out_dataset[0]], pattern='SINOGRAM') # Add option for pattern to be a dictionary with different pattern for each dataset |
|
68
|
|
|
self.set_iteration_datasets(1, [out_dataset[0]], [out_dataset[1]], pattern='PROJECTION') # PROJECTION |
|
69
|
|
|
# out_dataset[0] and out_dataset[1] will continue to alternate for the |
|
70
|
|
|
# remaining iterations |
|
71
|
|
|
self.set_alternating_patterns(['SINOGRAM', 'PROJECTION']) # or explicitly add it as above or a combination of both |
|
72
|
|
|
# it could be that the first two iterations have the same pattern and the remainder alternate |
|
73
|
|
|
|
|
74
|
|
|
# alternatively to above you could just have |
|
75
|
|
|
# self.set_iteration_datasets(0, [in_dataset[0]], [out_dataset[0]]) |
|
76
|
|
|
# self.set_iteration_datasets(1, [out_dataset[0]], [out_dataset[1]]) |
|
77
|
|
|
# self.set_alternating_patterns(['SINOGRAM', 'PROJECTION']) # what if there is more than on pattern - this should also be a dictionary |
|
78
|
|
|
|
|
79
|
|
|
# So, to set different patterns there are two ways |
|
80
|
|
|
# first way is to add 'pattern' key word to set_iteration_datasets function call |
|
81
|
|
|
# second way is to pass a list of patterns to set_alternating_patterns function call |
|
82
|
|
|
# in either case, each entry can be a list of a dictionary |
|
83
|
|
|
# if a list apply to all datasets |
|
84
|
|
|
# if a dictionary, they should be {dataset: pattern} key value pairs |
|
85
|
|
|
|
|
86
|
|
|
# Now I just have to make this work - can I just create an extra pluginData object for each dataset and alternate between those? |
|
87
|
|
|
# Or will I have to calculate mfp/mft every time? |
|
88
|
|
|
# Don't forget to call "finalise_datasets" or whatever the function is (usually called after the setup method) |
|
89
|
|
|
|
|
90
|
|
|
def nOutput_datasets(self): |
|
91
|
|
|
return 2 |
|
92
|
|
|
|
|
93
|
|
|
def nClone_datasets(self): |
|
94
|
|
|
return 1 |
|
95
|
|
|
|