Leginon Developer Guide » History » Version 20
Anchi Cheng, 01/04/2023 05:09 PM
1 | 1 | Jim Pulokas | h1. Leginon Developer Guide |
---|---|---|---|
2 | |||
3 | 4 | Jim Pulokas | h2. Overview of the code repository |
4 | |||
5 | Over the years, Leginon has grown and divided. With the addition of the Appion processing pipeline, several components that were once subsystems of Leginon were broken out to be used as a common tool set for both Leginon and Appion. The top level master package that now contains the entire software suite developed at AMI is called _myami_. Inside of myami you will find leginon, appion and all of these common packages. Here is a brief description of the contents of the AMI software repository: |
||
6 | |||
7 | * *myami* - the complete suite of software |
||
8 | ** *appion* - the processing pipeline |
||
9 | ** *comarray* - Python extension to retrieve COM SafeArrays into NumPy arrays (deprecated, see [[Installing comtypes]] instead) |
||
10 | ** *dbschema* - If you are running your myami system out of a sandbox and frequently pulling changes from the repository, then your database schema is generally kept up to date automaticall. But most production installations update only between major revisions. The dbschema directory summarizes all of the database schema updates between revisions, which can be applied in sequence when doing a major jump in revisions. |
||
11 | 5 | Jim Pulokas | ** *imageviewer* - this is a newer image viewer widget for wx meant to replace the old ImageViewer widget in the Leginon GUI. So far only the tomography node uses it. |
12 | 6 | Jim Pulokas | ** *install* - adds automation to the installation process |
13 | 1 | Jim Pulokas | ** *leginon* - microscope control and automation |
14 | 6 | Jim Pulokas | ** *modules* - python extensions that must be compiled |
15 | *** *libcv* - key point detection and matching |
||
16 | 15 | Jim Pulokas | *** *numextension* - misc image functions. More info here: [[numextension]] |
17 | 6 | Jim Pulokas | *** *radermacher* - functions for tilt picker, see http://emg.nysbc.org/projects/tiltpicker/wiki/TiltPicker_Installation |
18 | 7 | Jim Pulokas | ** *myamiweb* - all of the php web server stuff for the the web viewer, appion pipeline, etc. |
19 | ** *programs* - |
||
20 | ** *pyami* - miscellaneous pure python modules that are usefull for both leginon and appion |
||
21 | ** *pyscope* - Python interface to several TEMs and cameras |
||
22 | ** *redux* - a Python replacement for php_mrc, but also generally useful on its own for image conversions, FFTs, resizing, etc. |
||
23 | ** *sinedon* - object relational mapping module, so you can use python objects to populate your MySQL database |
||
24 | 1 | Jim Pulokas | |
25 | 16 | Anchi Cheng | h2. Sinedon usage |
26 | |||
27 | Sinedon is the ORM used in leginon. The data objects are dictionary-like so that the mapped field name with its values of the table are key-value pairs in this data objects. |
||
28 | leginondata.py in leginon packages is where the data classes are defined. |
||
29 | |||
30 | For example, the following python commands creates an instance of SessionData data object and prints the referenced names of the fields for this database table. |
||
31 | <pre> |
||
32 | from leginon import leginondata |
||
33 | print(leginondata.SessionData().keys()) |
||
34 | </pre> |
||
35 | |||
36 | You can query database with this. results=2 makes it returns the a queryset contains the most recent 2 row of this table, sorted in descending order by their primary keys (accessed through dbid attribute, if you want to know). |
||
37 | <pre> |
||
38 | sessions = leginondata.SessionData().query(results=2) |
||
39 | newest_session = sessions[0] |
||
40 | print('primary key for the newest session=', newest_session.dbid) |
||
41 | </pre> |
||
42 | |||
43 | You can also find out any field value by the key. For example, session name: |
||
44 | <pre> |
||
45 | print('name=', newest_session['name']) |
||
46 | </pre> |
||
47 | |||
48 | Somtimes the a data object reference another data object. In SessionData, user field is a referenced UserData. If you want to know the lastname of the user who created this session. You can do |
||
49 | <pre> |
||
50 | print(newest_session['user']['lastname']) |
||
51 | </pre> |
||
52 | Sinedon is lazy-loaded, meaning that it does not perform the query that retrieves this referenced object until you access it. This ensures performance. |
||
53 | |||
54 | Please read leginon/leginondata.py to see all the data classes defined for leginon package. |
||
55 | |||
56 | 7 | Jim Pulokas | h2. Brief description of the design of Leginon |
57 | 1 | Jim Pulokas | |
58 | 8 | Jim Pulokas | Leginon is a flexible framework for automating your TEM data collection. The flexibility comes from the fact that key tasks are coded into _nodes_, which can then be dynamically assembled into an event driven _application_. Each node performs a task, and generates events to trigger other nodes to perform their tasks. In addition to passing events between each other, nodes may also share the data they produce. For example, an Acquisition node may acquire an image from the instrument, then generate an event to notify another node to process that image. Another area of flexibility is in how applications may distribute the nodes among several hosts on the network. Processing could be optimized depending on which nodes are on the instrument host versus which ones are on a more powerful host elsewhere. |
59 | 1 | Jim Pulokas | |
60 | 17 | Anchi Cheng | h2. Access pyscope instrument get/set method from Node class instance |
61 | |||
62 | Pyscope TEM and CCDCamera and their subclasses defines the instrument control and are available in most Leginon Node classes through self.instrument. Only one TEM and CCDCamera class is active at a time and accessed through self.instrument.tem and self.instrument.ccdcamera. The get/set methods in the instrument class can be used a property as well as calling the method. |
||
63 | |||
64 | 19 | Anchi Cheng | For example, to get stage position of the active TEM class in a node of Leginon, we can do either of these inside a function of the class |
65 | 17 | Anchi Cheng | <pre> |
66 | pos = self.instrument.tem.StagePosition |
||
67 | </pre> |
||
68 | |||
69 | <pre> |
||
70 | pos = self.instrument.tem.getStagePosition() |
||
71 | </pre> |
||
72 | |||
73 | to set stage position which needs a dictionary input with valid keys (x,y,z,a), we could do either |
||
74 | <pre> |
||
75 | self.instrument.tem.StagePosition = {'x':0.0} |
||
76 | </pre> |
||
77 | |||
78 | <pre> |
||
79 | self.instrument.tem.setStagePosition({'x':0.0}) |
||
80 | 1 | Jim Pulokas | </pre> |
81 | 19 | Anchi Cheng | |
82 | 20 | Anchi Cheng | See navigator.py Navigator class for some examples. |
83 | 17 | Anchi Cheng | |
84 | 7 | Jim Pulokas | h2. Adding new features and functionality to Leginon |
85 | 4 | Jim Pulokas | |
86 | 7 | Jim Pulokas | The two most common ways you will be adding a new idea to Leginon: |
87 | 4 | Jim Pulokas | |
88 | 10 | Jim Pulokas | * A small addition to an existing node. For example, a new parameter to auto focusing would require a new entry box in the GUI and a modification to some underlying function call. |
89 | * A completely new feature that is different enough to belong in its own node. For example, a new target finding technique. See [[Creating a new Leginon node]] |
||
90 | 7 | Jim Pulokas | |
91 | h2. Simulation: when you do not have access to a real TEM and/or camera. |
||
92 | |||
93 | * You still need the overall infrastructure in place: myami installed, database created, etc., but at least this can still be an option for a stand-alone laptop that is not even connected to the network. |
||
94 | 13 | Anchi Cheng | * configure your instruments.cfg file with SimTEM and SimCCDCamera instruments. These are the defaults in instruments.cfg.template. |
95 | 7 | Jim Pulokas | * Start Leginon and do not connect to any external clients during the session setup wizard |
96 | 12 | Anchi Cheng | * Go through calibrations as if they are real microscope and camera. You can however, [[Fake calibrations for Leginon simulator|fake the values]]. |
97 | 7 | Jim Pulokas | * Most functionality can be tested, however your images will be simulated and the more advanced target finders may not work so well. |
98 | 14 | Anchi Cheng | * [[Premade Realistic-looking calibration and images for simulation ]] |
99 | 3 | Anchi Cheng | |
100 | h2. Useful diagonosis scripts |
||
101 | |||
102 | 9 | Jim Pulokas | * [[testing pyscope instrument]] functions without Leginon. |
103 | 11 | Anchi Cheng | * [[setup simulator with VMware]] |