Creating a new Leginon node » History » Revision 11
« Previous |
Revision 11/29
(diff)
| Next »
Anchi Cheng, 09/15/2014 07:25 PM
Creating a new Leginon node¶
The basic steps that will be described in detail below are:
- Code the core functionality in a new subclass
- Define required attribute for all node classes:
- Node Settings and its defaults
- GUI Panel
- Input/Output Events
- Define new data type or event this node produces
- Make the gui
- register it with the list of available nodes
For each task, it is easiest to look at an existing node as an example. Usually we just make a copy of a node the is similar in function and go from there.
Example¶
We have a base class in Leginon that creates a node to fix a particular instrument condition. The module is leginon/condition.py. When a FixConditionEvent is sent to it, it will check the database to find whether the condition fixing has been done recently. If it has past the timeout defined in its settings (Defined by ConditionerSettingsData in leginondata.py), then it will execute the action defined in its fixCondition function, and reset the timer.
The FixConditionEvent is sent normally from the final exposure Acquisition Node (named "Exposure", "Tomography" etc. depending on the node class and application". While the condition is being fixed, the node will wait for it to return before starting to process the targets it received (meaning moving to the acquisition position, focusing, etc).
To make a new subclass that triggers the vacuum pump that pumps the buffer area of the scope, we will make a subclass of Conditioner here, called BufferCycler. There is no settings change, but we want its settings saved separately from the parent.
Code the core functionality¶
- Make a new class in your new module. Let it inherit a class of Leginon nodes. The lowest base class you can use is node.Node
In our example, see leginon/buffercycler.py source:trunk/leginon/buffercycler.py
The new class inherits conditioner.Conditioner. It defines the string for condition type in setCTypes, and how to call buffer cycling.
Define the required attributes for all nodes¶
Settings¶
- The data class that is usually added when a new node is added is the one defines its settings in Leginon gui. Its name should have the class name as prefix.
- To make the class uses the new settings class, it is defined in the module.
In our example:
- Look at the difference in leginon/leginondata.py for r18567, a new subclass of ConditionerSettingsData is defined as BufferCyclerSettingsData without adding anything new.
- We define the settings class used in buffercycler.py
settingsclass = leginondata.BufferCyclerSettingsData
- The defaults of the buffer cycler settings are also inherited from conditioner.Conditioner
defaultsettings = conditioner.Conditioner.defaultsettings
GUI panel class¶
Define panelclass to make the class load the right gui panel that you will write later.
panelclass = leginon.gui.wx.BufferCycler.Panel
Input/Output Events¶
We inherit the eventinputs of the parent class in the example.
eventinputs = conditioner.Conditioner.eventinputs
Define new data type or event this node produces¶
New output data type should be defined in leginondata.py, and new event, if any, defined in event.py
Neither is needed in the example.
Create the user interface¶
See source:trunk/leginon/gui/wx/BufferCycler.py for an inherited example that does not need any new definition. This is the minimal definition of Leginon gui.
- Make a new file under leginon/gui/wx for the gui definition. In the example: gui/wx/BufferCycler.py
- Define Panel Class
- OnSettingsTool method, SettingsDialog class, and ScrolledSettings are redefined in this module so that the local one is used.
Register the node¶
Register the node by adding it to leginon/allnodes.py as shown in the modification made in r18567
back to Leginon Developer Guide
Updated by Anchi Cheng about 10 years ago · 11 revisions