Project

General

Profile

add new focus measurement method in focuser

Added by Anchi Cheng about 13 years ago

To answer a question from Nicolas Coudray, here is what a focus method function in focuser need to contain:

  1. drift check if necessary. This is currently only implemented for beam-tilt based defocus measurement
  2. send the preset used in the method along with its emtarget to the scope
    presetname = setting['preset name']
    self.presetsclient.toScope(presetname, emtarget)
    

    emtarget includes information that need to be sent to the scope in addition to that of the preset, such as additional image shift required to reach the target.
  3. setup the scope condition for making the measurement if different from the preset.
  4. acquire image under such condition
  5. repeat the last two steps if necessary for different conditions
  6. If scope condition that is not tracked by preset, such as beam tilt or stage position, is changed, return it to the original.
  7. calculate the actual defocus value of the final condition
  8. update resultdata and return status
    • minimal update would on resultdata['defocus'], preferable with the actual defocus of the original scope condition as if resulting from step 1.
    • status is 'ok' if there is no error in the measurement

In leginon code, the 2-7 steps are normally done in calibrationtclient.py not in focuser.py so that the same functions can be used in calibrators if a calibration is required. A simple example is the call to stagetiltcalclient.measureZ function in autoStage even though a calibration is not required for such defocus measurement method. By doing so, it has direct access to acquireImage function defined in CalibrationClient base class. acquireImage function in calibrationClient is convenient because a scope codition defined by an instance of leginondata.ScopeEMData can be passed into it and its output is the standard imagedata (an instance of leginondata.AcquisitionImageData) accepted by other Leginon functions.

Here is an example for setting up a known defocus for making the measurement and then acquire it if it is written in a function in a subclass of CalibrationClient in calibrationclient.py:

state1 = leginondata.ScopeEMData()
state1['defocus'] = known_defocus_in_meters
imagedata1 = self.acquireImage(state1)

If a test code is written without creating a CalibrationClient subclass, the access to Calibrationclient.acquireImage will need to be done through an instance of any CalibrationClient subclass. This means to replace the last line of the code above with, for example,

imagedata1 = self.btcalclient.acquireImage(state1)


Replies (4)

RE: add new focus measurement method in focuser - Added by Nicolas Coudray about 13 years ago

Hi,

Thanks a lot for this helpful tutorial...
Just one question: to add the method in the GUI, is it enough to add it in the "__init__" function of the "Focuser" class, or is there anything else to do? like this for instance:

self.focus_methods = ordereddict.OrderedDict((
('Manual', self.manualCheckLoop),
('Beam Tilt', self.autoFocus),
('Stage Tilt', self.autoStage),
('New Method', self.newMethod),
('None', self.noMeasure),
))

Thanks,
Best,
N.C.

RE: add new focus measurement method in focuser - Added by Anchi Cheng about 13 years ago

Yes, as long as you don't need new settings for the new method.

RE: add new focus measurement method in focuser - Added by Nicolas Coudray about 13 years ago

Hello,

Thanks for the help... Just to give you an update:

We have finally written the code and we are currently testing it. For the steps 2-7, the easier solution has been chosen: they have been written in "focuser.py" (some difficulties in creating a class in "calibrationtclient.py" without any error message...).

However, in our case, the acquisition of the image through the command

imagedata1 = self.btcalclient.acquireImage(state1)

did not work. So, we created a new vaRiable in the init function of the Focuser class:

self.focusscancalclient = calibrationclient.CalibrationClient(self)

and then used it in the code:

imagedata1 = self.focusscancalclient.acquireImage(state1)

It may not be the "cleanest" solution, but it seems to work.

Thanks again for your help,
Best,
N.

RE: add new focus measurement method in focuser - Added by Anchi Cheng about 13 years ago

Don't see why the first solution did not work, Maybe we will try it out here one day.

Anchi

    (1-4/4)