create a text file with cor values#

On the following script the python script will collect ‘cor’ values and store it into a dedicated file, then pass the in_data to the next widget.

This script must have a widget which compute center of rotation (cor) upstream. Like:

../../_images/workflow1.png
import os
from silx.io.dictdump import dicttoini, load as load_ini

# in_data can be none if several data as provided to the widget and / or when the link is removed.
if in_data is not None:
    # handle special case of the sa-axis - autofocus use case (needed for tomwer < 1.1)
    # if in_data.axis_params.relative_cor_value is None:
    #    in_data.axis_params.set_relative_value(in_data.saaxis_params._autofcous)
    cor_relative = in_data.axis_params.relative_cor_value
    cor_abs = in_data.axis_params.absolute_cor_value

    # output file which will store the cor.
    # if in_data is a scan contained in /data/visitor/exp/beamline/date/raw/sample/dataset.h5
    # output file will be /data/visitor/exp/beamline/date/output_cor.ini
    output_cor_file = os.path.join(os.path.dirname(in_data.path), "output_cor.ini")

    if os.path.exists(output_cor_file):
        # if a file already exists load the cor
        existing_cors = load_ini(output_cor_file, "ini")
    else:
        # else init the dictionary
        existing_cors = {"cors": {}}

    # update cors values. In this case per dataset we will store the tuple (absolute COR, relative COR)
    existing_cors["cors"][os.path.basename(in_data.path)] = (cor_abs, cor_relative)

    # update the output cor_file
    dicttoini(existing_cors, output_cor_file)

Note

if you have some usage of python script on your side please let us know we can add them to this page (or create dedicated widget if this is of a common interest)