[Beamfocus - Server in Python]

ServerFocus Tutorial



The main objective of this tutorial is to show how to set up the “Focus Server” code to be used in automation of X-Ray focusing.


The server is based on the wavefront analysis [1][2][3], and has been used and tested on KB and toroid mirrors at the ESRF. The code is designed to be robust (avoid system crashes) and is only dependent of Python language and its Numeric library.


This code is proposed by Olof Svensson, and refactored and redesigned to be a server by Romeu André Pieritz.





The code can be embedded on any python application, where the main class is instantiated from three main inputs: two wavefront scans (float arrays) and the step motor value (float value). The second scan array is obtained after a motor shift  the original mirror position.


The main example below shows the usage of the ServerFocus code to obtain the step motor value correction.




        from SFSystem     import *

        from SFKernel     import *





        wf1  = "first scan array - direction n"

        wf2  = "second scan array - direction n, in the new position"

        step = "step motor value"

        wfN  = "new scan"




        osfServerFocus = None

        osfServerFocus = SFServerFocus( wf1, wf2, step )




        while( "focusing something" ):

            if ( "new focusing operation" )

           "get the scans and the step motor value"

               osfServerFocus    = SFServerFocus( wf1, wf2, step )

               ofCorrectionValue = osfServerFocus.getCorrection()


               ofCorrectionValue = osfServerFocus.getCorrection( wfN )


            "new operation in the main focusing loop"

            wfN  = "new scan"



Note: More details can be found in the UnitTest file in the main tree code distribution.



Error handling


The application is designed to newer stop if an error occurs. If any code error or mathematical inconsistency happens the default return correction value is “0.0”. A message is displayed in the standard output to indicate the error.


To assist the developer to debug the application an extra Boolean parameter is used in the constructor of the server (default value = false). In that case, the exception and the error debugging messages are displayed on the output.



Test Facility


All code methods and classes are automatically tested by the UnitTest framework available in the source code tree.






Please send an email to :


Romeu André Pieritz - pieritz@esrf.eu

Olof Svensson - svensson@esrf.eu





[1] – O. Hignette, A. K. Freund and E. Chinchio, “Incoherent X-ray mirror metrology”, SPIE Proceedings 3152, 188-199 (1997).


[2] – R. A. Pieritz, O. Svensson, “Beamfocus Refactoring Tutorial”, ESRF/SciSoft Internal Documentation, (under development).


[3] – O. Hignette, G. Rostaing, P. Cloetens, A. Rommeveaux, W. Ludwig and A. Freund, “Submicron focusing of hard X-rays with reflecting surfaces at the ESRF”, SPIE Proceedings, (2001).