| @@ 33-113 (lines=81) @@ | ||
| 30 | from savu.plugins.utils import register_plugin |
|
| 31 | ||
| 32 | # this decorator is required for the configurator to recognise the plugin |
|
| 33 | @register_plugin |
|
| 34 | class PluginTemplate1WithDetailedNotes(Plugin, CpuPlugin): |
|
| 35 | # Each class must inherit from the Plugin class and a driver |
|
| 36 | def __init__(self): |
|
| 37 | super(PluginTemplate1WithDetailedNotes, self).__init__('PluginTemplate1WithDetailedNotes') |
|
| 38 | ||
| 39 | def nInput_datasets(self): |
|
| 40 | # Called immediately after the plugin is loaded in to the framework |
|
| 41 | return 1 |
|
| 42 | ||
| 43 | def nOutput_datasets(self): |
|
| 44 | # Called immediately after the plugin is loaded in to the framework |
|
| 45 | return 1 |
|
| 46 | ||
| 47 | def setup(self): |
|
| 48 | # This method is called after the number of in/out datasets associated |
|
| 49 | # with the plugin has been established. It tells the framework all |
|
| 50 | # the information it needs to know about the data transport to-and-from |
|
| 51 | # the plugin. |
|
| 52 | ||
| 53 | ||
| 54 | #================== Input and output datasets ========================= |
|
| 55 | # in_datasets and out_datasets are instances of the Data class. |
|
| 56 | # in_datasets were either created in the loader or as output from |
|
| 57 | # previous plugins. out_datasets objects have already been created at |
|
| 58 | # this point, but they are empty and need to be populated. |
|
| 59 | ||
| 60 | # Get the Data instances associated with this plugin |
|
| 61 | in_dataset, out_dataset = self.get_datasets() |
|
| 62 | ||
| 63 | # see https://savu.readthedocs.io/en/latest/api/savu.data.data_structures.data_create/ |
|
| 64 | # for more information on creating datasets. |
|
| 65 | ||
| 66 | # Populate the output dataset(s) |
|
| 67 | out_dataset[0].create_dataset(in_dataset[0]) |
|
| 68 | ||
| 69 | ||
| 70 | #================== Input and output plugin datasets ================== |
|
| 71 | # in_pData and out_pData are instances of the PluginData class. |
|
| 72 | # All in_datasets and out_datasets above have an in/out_pData object |
|
| 73 | # attached to them temporarily for the duration of the plugin, |
|
| 74 | # giving access to additional plugin-specific dataset details. At this |
|
| 75 | # point they have been created but not yet populated. |
|
| 76 | ||
| 77 | # Get the PluginData instances attached to the Data instances above |
|
| 78 | in_pData, out_pData = self.get_plugin_datasets() |
|
| 79 | ||
| 80 | # Each plugin dataset must call this method and define the data access |
|
| 81 | # pattern and number of frames required. |
|
| 82 | in_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
| 83 | ||
| 84 | # 'single', 'multiple' or an int (should only be used if essential) |
|
| 85 | out_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
| 86 | ||
| 87 | # All dataset information can be accessed via the Data and PluginData |
|
| 88 | # instances |
|
| 89 | ||
| 90 | def pre_process(self): |
|
| 91 | # This method is called once before any processing has begun. |
|
| 92 | # Access parameters from the doc string in the parameters dictionary |
|
| 93 | # e.g. self.parameters['example'] |
|
| 94 | pass |
|
| 95 | ||
| 96 | def process_frames(self, data): |
|
| 97 | # This function is called in a loop by the framework until all the |
|
| 98 | # data has been processed. |
|
| 99 | ||
| 100 | # Each iteration of the loop will receive a list of numpy arrays |
|
| 101 | # (data) containing nInput_datasets with the data sliced as requested |
|
| 102 | # in the setup method (SINOGRAM in this case). If 'multiple' or an |
|
| 103 | # integer number of max_frames are requested the array with have an |
|
| 104 | # extra dimension. |
|
| 105 | ||
| 106 | # This plugin has one output dataset, so a single numpy array (a |
|
| 107 | # SINOGRAM in this case) should be returned to the framework. |
|
| 108 | return data[0] |
|
| 109 | ||
| 110 | def post_process(self): |
|
| 111 | # This method is called once after all processing has completed |
|
| 112 | # (after an MPI barrier). |
|
| 113 | pass |
|
| @@ 30-59 (lines=30) @@ | ||
| 27 | from savu.plugins.utils import register_plugin |
|
| 28 | ||
| 29 | ||
| 30 | @register_plugin |
|
| 31 | class PluginTemplate1(Plugin, CpuPlugin): |
|
| 32 | ||
| 33 | def __init__(self): |
|
| 34 | super(PluginTemplate1, self).__init__('PluginTemplate1') |
|
| 35 | ||
| 36 | def nInput_datasets(self): |
|
| 37 | return 1 |
|
| 38 | ||
| 39 | def nOutput_datasets(self): |
|
| 40 | return 1 |
|
| 41 | ||
| 42 | def setup(self): |
|
| 43 | in_dataset, out_dataset = self.get_datasets() |
|
| 44 | out_dataset[0].create_dataset(in_dataset[0]) |
|
| 45 | in_pData, out_pData = self.get_plugin_datasets() |
|
| 46 | in_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
| 47 | out_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
| 48 | ||
| 49 | def pre_process(self): |
|
| 50 | pass |
|
| 51 | ||
| 52 | def process_frames(self, data): |
|
| 53 | # do some processing here |
|
| 54 | # here is how to access a parameter defined in the tools file |
|
| 55 | example = self.parameters['example'] |
|
| 56 | return data[0]*example |
|
| 57 | ||
| 58 | def post_process(self): |
|
| 59 | pass |
|