Setting autofocus parameters from within a script

classic Classic list List threaded Threaded
7 messages Options
FS
Reply | Threaded
Open this post in threaded view
|

Setting autofocus parameters from within a script

FS
Dear MM users/developers,

I use software-based autofocusing from within my script in the following way:

af = gui.getAutofocus();
af.focus(AFcoarseStepSize, AFcoarseStepNum, AFfineStepSize, AFfineStepNum);

However, the number and size of the fine/coarse steps that I set in the script are not followed. Instead, the AF uses the parameters set from within the main control window (the button with the wrench).

How can I set AF parameters from within my script?

Thanks,

Francois
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

Nico Stuurman
Administrator
Hi Francois,

> I use software-based autofocusing from within my script in the following
> way:
>
> af = gui.getAutofocus();
> af.focus(AFcoarseStepSize, AFcoarseStepNum, AFfineStepSize, AFfineStepNum);
>
> However, the number and size of the fine/coarse steps that I set in the
> script are not followed. Instead, the AF uses the parameters set from within
> the main control window (the button with the wrench).

The Autofocus api lists the function "focus(AFcoarseStepSize, AFcoarseStepNum, AFfineStepSize, AFfineStepNum);" as obsolete and it will most likely be removed in the 1.4 release of Micro-Manager.

> How can I set AF parameters from within my script?

You can query the autofocus device for available properties using:
    String[] getPropertyNames();
You can then set these properties using
    void setProperty(PropertyItem p);
and you likely will need the function:
   PropertyItem getProperty(String key)

Then, activate autofocus using either of:
   double fullFocus();
   double incrementalFocus();
   void enableContinuousFocus(boolean enable)

B.t.w., it looks that (for now), the old method still works when using the Java-based autofocus device (JAF-H&P).

Hope this helps,

Nico
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
FS
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

FS
Hi Nico,

Thanks for the info. At the end of my message, I write here the full commands I'm now using in my script, in case this may be useful to other users.

What is the difference between fullFocus() and incrementalFocus()? I tried both and gave similar results.

Thanks,

Francois

Here are the commands I'm using:

AFcoarseStepSize = "0.2";
AFcoarseStepNum = "3";
AFfineStepSize = "0.5";
AFfineStepNum = "1";
AFthreshold = "1"; //captures all planes rather than stop when reached a "threshold" level. I found this gives better results with bacterial
AFcropRatio = "1"; //looks at the whole field of view

AFcoarseStepSize_PropertyItem = af.getProperty("1st step size");
AFcoarseStepNum_PropertyItem = af.getProperty("1st step number");
AFfineStepSize_PropertyItem = af.getProperty("2nd step size");
AFfineStepSize_PropertyItem = af.getProperty("2nd step number");
AFthreshold_PropertyItem = af.getProperty("Threshold");
AFcropRatio_PropertyItem = af.getProperty("Crop ratio");

AFcoarseStepSize_PropertyItem.setValueFromCoreString( AFcoarseStepSize );
AFcoarseStepNum_PropertyItem.setValueFromCoreString( AFcoarseStepNum );
AFfineStepSize_PropertyItem.setValueFromCoreString( AFfineStepSize );
AFfineStepSize_PropertyItem.setValueFromCoreString( AFfineStepNum );
AFthreshold_PropertyItem.setValueFromCoreString( AFthreshold );
AFcropRatio_PropertyItem.setValueFromCoreString( AFcropRatio );

af.setProperty(AFcoarseStepSize_PropertyItem);
af.setProperty(AFcoarseStepNum_PropertyItem);
af.setProperty(AFfineStepSize_PropertyItem);
af.setProperty(AFfineStepSize_PropertyItem);
af.setProperty(AFthreshold_PropertyItem);
af.setProperty(AFcropRatio_PropertyItem);

// When I need to do the autofocus, I then call:

af.fullFocus();

Nico Stuurman wrote
Hi Francois,

> I use software-based autofocusing from within my script in the following
> way:
>
> af = gui.getAutofocus();
> af.focus(AFcoarseStepSize, AFcoarseStepNum, AFfineStepSize, AFfineStepNum);
>
> However, the number and size of the fine/coarse steps that I set in the
> script are not followed. Instead, the AF uses the parameters set from within
> the main control window (the button with the wrench).

The Autofocus api lists the function "focus(AFcoarseStepSize, AFcoarseStepNum, AFfineStepSize, AFfineStepNum);" as obsolete and it will most likely be removed in the 1.4 release of Micro-Manager.

> How can I set AF parameters from within my script?

You can query the autofocus device for available properties using:
    String[] getPropertyNames();
You can then set these properties using
    void setProperty(PropertyItem p);
and you likely will need the function:
   PropertyItem getProperty(String key)

Then, activate autofocus using either of:
   double fullFocus();
   double incrementalFocus();
   void enableContinuousFocus(boolean enable)

B.t.w., it looks that (for now), the old method still works when using the Java-based autofocus device (JAF-H&P).

Hope this helps,

Nico
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
micro-manager-general mailing list
micro-manager-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

Nico Stuurman
Administrator
> What is the difference between fullFocus() and incrementalFocus()? I tried
> both and gave similar results.

The idea is that incrementalFocus will only look at a small range of z-values, whereas fullFocus will do the whole range, however, the implementation depends on the specific Autofocus adapter that you use.  

There are currently 3 Java-based autofocus adapters ( JAF(H&P), JAF(TB), Duo), and at least one C++ based autofocus adapter (SimpleAF, you have to add this one using the Hardware Configuration Wizard), so it is really useful to know which one you are talking about, and you might want to try some of the others to see if they work better.  Also, please feel free to look at the code of these and propose improvements.

Best,

Nico
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
FS
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

FS
Nico Stuurman wrote
There are currently 3 Java-based autofocus adapters ( JAF(H&P), JAF(TB), Duo), and at least one C++ based autofocus adapter (SimpleAF, you have to add this one using the Hardware Configuration Wizard), so it is really useful to know which one you are talking about, and you might want to try some of the others to see if they work better.  Also, please feel free to look at the code of these and propose improvements.
The adapter I'm using is the one we get using the following code:

response = gui.installAutofocusPlugin("Autofocus_");
af = gui.getAutofocus();

Is it H&P?

I've installed SimpleAF using the hardware configuration. When I click on the binoculars icon on the main control window, nothing happens. Also, I don't know how to install it within a script. The following don't seem to work:

response = gui.installAutofocusPlugin("AutofocusSimpleAF_");
response = gui.installAutofocusPlugin("AutofocusSimple_");
response = gui.installAutofocusPlugin("SimpleAF_");

I've tried TB in the past, but didn't see much difference then (possibly slightly slower and less reliable than H&P).

Francois
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

Nico Stuurman
Administrator
Hi Francois,

>> There are currently 3 Java-based autofocus adapters ( JAF(H&P), JAF(TB),
>> Duo), and at least one C++ based autofocus adapter (SimpleAF, you have to
>> add this one using the Hardware Configuration Wizard), so it is really
>> useful to know which one you are talking about, and you might want to try
>> some of the others to see if they work better.  Also, please feel free to
>> look at the code of these and propose improvements.
>
> The adapter I'm using is the one we get using the following code:
>
> response = gui.installAutofocusPlugin("Autofocus_");
> af = gui.getAutofocus();
>
> Is it H&P?

Very good question!  I think it is, but I am quite confused now.  The code for the H&P Java autofocus is here:

https://valelab.ucsf.edu/svn/micromanager2/branches/micromanager1.3/autofocus/Autofocus.java

> I've installed SimpleAF using the hardware configuration. When I click on
> the binoculars icon on the main control window, nothing happens.

I had the same problem, until I selected a channel for the "SimpleAF-Preset" property (which you reach with the "tool" icon).  Then, it did something.

> Also, I
> don't know how to install it within a script. The following don't seem to
> work:
>
> response = gui.installAutofocusPlugin("AutofocusSimpleAF_");
> response = gui.installAutofocusPlugin("AutofocusSimple_");
> response = gui.installAutofocusPlugin("SimpleAF_");

Also a very good question!  I am afraid that we did not fully update the script interface with our last revamp of the autofocus plugin mechanism.  We'll need to fix that and document these issues.  If anyone remembers more, please comment (or even better, write a Wiki page!).

> I've tried TB in the past, but didn't see much difference then (possibly
> slightly slower and less reliable than H&P).

In any case, improvement of the autofocus is possible by writing a new autofocus plugin/adapter, either in C++ or Java.  Modifying one of the existing ones to do the asymmetric acquisition you described should be relatively straight forward.

Best,

Nico


------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
FS
Reply | Threaded
Open this post in threaded view
|

Re: Setting autofocus parameters from within a script

FS
Nico Stuurman wrote
Very good question!  I think it is, but I am quite confused now.  The code for the H&P Java autofocus is here:
https://valelab.ucsf.edu/svn/micromanager2/branches/micromanager1.3/autofocus/Autofocus.java
(1) Indeed Autofocus.java appears to be H&P.

(2) I found out that even using the new code, the Autofocus plug-in used by my script is still the one selected using the "Tools" button on the main control window.

For example, I might have the following in my script:

response = gui.installAutofocusPlugin("AutofocusSimple_");

However, if the "TB" autofocus is selected in the main control window, then the TB autofocus device will be the one used in my script.

(3) One of the property value of the TB autofocus device has a spelling mistake:

JAF(TB)-1st setp number

Notice "setp" instead of "step". In my script, I need to add the spelling mistake when I want to use the TB AF device...

Thanks for the continued help!
Francois