.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/visualization/using_get_result.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_visualization_using_get_result.py: The `get_result` Function ========================= The `get_result` function is the main entry point to access results while an acquisition is running, and after it has finished. The function can be slightly confusing at first but this tutorial hopefully helps to simplify and clarify its usage and show how powerful the function is and how you can leverage it to build fast/responsive visualization tools. The simplest usage of `get_result` is to get the most recently acquired frame. .. GENERATED FROM PYTHON SOURCE LINES 13-26 .. code-block:: Python from deapi import Client from deapi import ContrastStretchType import time import sys client = Client() if not sys.platform.startswith("win"): client.usingMmf = ( False # True if on same machine as DE Server and a Windows machine ) client.connect(port=13240) # connect to the running DE Server .. rst-class:: sphx-glr-script-out .. code-block:: none Command Version: 15 .. GENERATED FROM PYTHON SOURCE LINES 27-30 Get A Single Diffraction Pattern -------------------------------- We will acquire a single image. By default, this is the Raw image that is acquired from the camera. .. GENERATED FROM PYTHON SOURCE LINES 30-43 .. code-block:: Python print("Acquiring a single diffraction pattern...") client.scan(enable="Off") # Disable scanning client.start_acquisition(1) # wait for the acquisition to finish while client.acquiring: time.sleep(1) print("Acquisition finished.") img = client.get_result("singleframe_integrated") img.plot() .. image-sg:: /examples/visualization/images/sphx_glr_using_get_result_001.png :alt: using get result :srcset: /examples/visualization/images/sphx_glr_using_get_result_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Acquiring a single diffraction pattern... Acquisition finished. .. GENERATED FROM PYTHON SOURCE LINES 44-52 Advanced Usage of `get_result` ------------------------------ Many times, for display you might want to resize the image, apply a contrast stretch, etc. These are costly operations and doing them on the client side can be slow. If you are operating over a network connection, sending large images reduces the responsiveness of your application. The `get_result` function has a number of parameters that allow you to do these operations on the server side, and only send the final result to the client. This can greatly improve the responsiveness of your application. .. GENERATED FROM PYTHON SOURCE LINES 52-59 .. code-block:: Python img = client.get_result( "singleframe_integrated", window_width=128, window_height=128 # resize to 128x128 ) img.plot() .. image-sg:: /examples/visualization/images/sphx_glr_using_get_result_002.png :alt: using get result :srcset: /examples/visualization/images/sphx_glr_using_get_result_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 60-62 We can also apply a contrast stretch on the server side. This is much faster than sending the raw image to the client and doing the contrast stretch there. .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. code-block:: Python img = client.get_result( "singleframe_integrated", window_width=128, # resize to 128x128 window_height=128, stretch_type=ContrastStretchType.DIFFRACTION, ) img.plot() .. image-sg:: /examples/visualization/images/sphx_glr_using_get_result_003.png :alt: using get result :srcset: /examples/visualization/images/sphx_glr_using_get_result_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 70-73 You'll notice that the image is now contrast stretched. The histogram continues to show the full range of the data, with the color map imposed on histogram bins. you can also change the color map. .. GENERATED FROM PYTHON SOURCE LINES 73-83 .. code-block:: Python img = client.get_result( "singleframe_integrated", window_width=128, # resize to 128x128 window_height=128, stretch_type=ContrastStretchType.HIGHCONTRAST, ) img.plot( cmap="magma", ) .. image-sg:: /examples/visualization/images/sphx_glr_using_get_result_004.png :alt: using get result :srcset: /examples/visualization/images/sphx_glr_using_get_result_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.050 seconds) .. _sphx_glr_download_examples_visualization_using_get_result.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: using_get_result.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: using_get_result.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: using_get_result.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_