How to generate a Savu Plugin

If you do not want to create the plugin files from scratch, you can use templates. The Savu plugin generator can create a template plugin file for you, along with a documentation file for explaining how to use your plugin, and a tools file for defining your plugin parameters.

Use the command: savu_plugin_generator to create a plugin and it’s required files.

usage: savu_plugin_generator [-h] [-q] [-d] plugin_name

There are three tasks which will be completed:

1. If a plugin exists with this name, then the file location will be found. If it does exist, then this file path will be displayed on the command line. If it doesn’t exist, then a file will be created inside the savu/plugins directory.

2. If a plugin tools files exists, then the file location will be found. If it does exist, then this file path will be displayed on the command line. If it doesn’t exist, then a file will be created inside the savu/plugins directory.

3. If a plugin documentation file exists, then the file location will be found. If it does exist, then this file path will be displayed on the command line. If it doesn’t exist, then a file will be created inside the savu/plugins directory.

The template for the plugin class is below.

# Copyright 2014 Diamond Light Source Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
.. module:: plugin_name_example
   :platform: Unix
   :synopsis: (Change this) A template to create a simple plugin that takes 
    one dataset as input and returns a similar dataset as output.

.. moduleauthor:: (Change this) Developer Name <email@address.ac.uk>
"""
from savu.plugins.utils import register_plugin
from savu.plugins.plugin import Plugin
# Import any additional libraries or base plugins here.

# This decorator is required for the configurator to recognise the plugin
@register_plugin
class PluginNameExample(Plugin):
# Each class must inherit from the Plugin class and a driver

    def __init__(self):
        super(PluginNameExample, self).__init__("PluginNameExample")

    def pre_process(self):
        """ This method is called immediately after base_pre_process(). """
        pass  

    def process_frames(self, data):
        """
        This method is called after the plugin has been created by the
        pipeline framework and forms the main processing step

        :param data: A list of numpy arrays for each input dataset.
        :type data: list(np.array)
        """
        pass

    def post_process(self):
        """
        This method is called after the process function in the pipeline
        framework as a post-processing step. All processes will have finished
        performing the main processing at this stage.

        :param exp: An experiment object, holding input and output datasets
        :type exp: experiment class instance
        """
        pass

    def setup(self):
        """
        Initial setup of all datasets required as input and output to the
        plugin.  This method is called before the process method in the plugin
        chain.
        """
        in_dataset, out_dataset = self.get_datasets()
  

You can download this here: plugin file.

An extended version is available here: Plugin Template With Detailed Notes 1

For a list of templates, visit the plugin template page.

Plugin Documentation

Below is a list of the current plugins grouped by type. You may also use the search bar on the left to find a specific one.