Project

General

Profile

How to get information from an image data object through sinedon references and attributes

Added by Anchi Cheng over 13 years ago

This is a common question. Here is a specific question so that I can use as an example:

we'd like to transfer other types of
information to the Matlab scripts, and not only the image. I think the
best way would be to transmit not only the image, but also its database ID
(so we can retrieve other information from the database, like pixelsize...
or others... and if we have some specific results related to the image
processing, we could then save them into a new table/database which we
could link accordingly to the correct ID of the Leginon Database).
Anyway, I just can't figure out what lines need to be added to retrieve
the ID of the image sent to Matlab. Could you please help us with that?

Here is a diff of leginon/matlabtargetfinder.py that shows how.

--- matlabtargetfinder.py    (revision 15318)
+++ matlabtargetfinder.py    (working copy)
@@ -13,6 +13,7 @@

 import os.path
 import threading
+import numpy
 import leginondata
 from pyami import mrc
 import targetfinder
@@ -73,12 +74,17 @@

     def findTargets(self, imdata, targetlist):
         image = imdata['image']
+        pixelsize_in_meter = self.calclients['image shift'].getImagePixelSize(imdata)
+        imdata_id = imdata.dbid

         self.setImage(image, 'Image')

         if self.handle is None:
             self.handle = pymat.open()
         pymat.put(self.handle, 'image', image)
+        pymat.put(self.handle, 'image_id',imdata_id)
+        pymat.put(self.handle, 'pixelsize',pixelsize_in_meter)

         self.matlabFindTargets()

When Leginon passes information from an node of Acquisition class to that of TargetFinder class, it passes an instance of AcquisitionImageData class of Sinedon leginondata object that has all its related database information accessible to it either as an attribute or by a reference to an instance of another data object. In the above code, the instance is named imdata.

For example, to get imdata's database `DEF_id`, you can just get the attribute imdata.dbid If you want to know what camera binning that image uses, you can do

binning = imdata['camera']['binning']

Leginon and Appion propogate their MySQL database through Sinedon using definitions found in leginon/leginondata.py and appion/appionlib/appiondata.py, respectively.
If you compare the python definition and propogated MySQL tables, you will see that sinedon has named a reference to a row of another table in the same database in the field named `REF|_table_name_|alias`. The value in the row of data gives the `DEF_id` of the referenced table. While in Leginon or Appion python codes, the alias is used as a dictionary key in the data object so that when you ask for imdata['camera'], it looks under the field `REF|CameraEMData|camera` in the AcquisitionImageData of the leginon MySQL database and returns the sinedon data object of CameraEMData class which has its dbid and other attributes as well as MySQL table field values and references in the dictionary form.

If you do print out binning in the above example, you will find that it is a dictionary with keys 'x' and 'y'. In the MySQL table, they are two fields named `SUBD|binning|x` and `SUBD|binning|y`. There are other types of reference styles that I can't itemize all here.

While you can query through all these references to database to get pixel size of your images, you may want to search for existing functions. We have a lot of functions already in python to get basic information like getImagePixelSize that just requires the input of the imdata, which is why I show the example there. You can go to leginon/calibrationclient.py to study the function.

We don't have a well-documented SDK for Leginon and Appion yet. These experimental programer tips should help you getting started.


Replies (1)

RE: How to get information from an image data object through sinedon references and attributes - Added by Anchi Cheng almost 13 years ago

More about this topic, here is how to get the unique id for the database row of data and the timestamp. These are saved as attribute of the sinedon data object. Therefore, to access them, you write:

session_id = sessiondata.dbid
session_time = sessiondata.timestamp

Note that the time is an datetime python object. You should be able to fine how to use it from python documentation.

    (1-1/1)