Calibration of a 2 theta arm with a Pilatus 100k detector

The aim of this document is to explain how to use pyFAI.goniometer for calibrating the position of the detector from the goniometer encoders.

Those data have been acquired at ROBL (ESRF-BM20 German CRG) in winter 2017 by Christoph Henning using a Pilatus 100k detector and LaB6 as calibrant. One hundred and twenty one images have been acquired with the detector moving between 5 and 65 degree with a step size of half a degree. The motor position is registered in the filename.

A prior manual calibration (using pyFAI-calib) has been performed on four images locate at 31.5, 33.5, 35 and 35.5 degrees. Those images were the first with two rings. The control points extrated during this initial calibration has been used as a starting point for this calibration. Then more images have been added to make the model more robust.

The raw data files are available at: http://www.silx.org/pub/pyFAI/gonio/Pilatus-100k-LaB6/

Initialization and loading of the libraries

Initialization of the plotting library, matplotlib, to be used with the jupyter notebook

[1]:
%matplotlib inline
# %matplotlib nbagg
import numpy
from matplotlib.pyplot import subplots
import time, pyFAI
start_time = time.perf_counter()
print("Using pyFAI version", pyFAI.version)
Using pyFAI version 0.21.0-dev1
[2]:
#Download all images

import os
from silx.resources import ExternalResources

#Nota: This may be useful if you are behind a firewall
#os.environ["http_proxy"] = "http://proxy.esrf.fr:3128"

downloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages", "PYFAI_DATA")
all_files = downloader.getdir("LaB6_gonio_BM20.tar.bz2")
print([os.path.basename(i) for i in all_files])

['LaB6_gonio_BM20', 'del_45.0_0001p.cbf', 'del_08.5_0001p.cbf', 'del_20.5_0001p.cbf', 'minimum-mask.edf', 'del_09.0_0001p.cbf', 'del_53.0_0001p.cbf', 'del_60.0_0001p.cbf', 'del_63.5_0001p.cbf', 'del_56.5_0001p.cbf', 'del_12.5_0001p.cbf', 'del_53.5_0001p.cbf', 'del_42.5_0001p.cbf', 'del_16.5_0001p.cbf', 'del_05.5_0001p.cbf', 'del_47.0_0001p.cbf', 'del_39.0_0001p.cbf', 'del_47.5_0001p.cbf', 'del_57.0_0001p.cbf', 'del_35.5_0001p.poni', 'del_07.5_0001p.cbf', 'del_41.5_0001p.cbf', 'del_51.0_0001p.cbf', 'del_33.0_0001p.cbf', 'del_22.0_0001p.cbf', 'del_43.5_0001p.cbf', 'del_64.5_0001p.cbf', 'del_35.0_0001p.cbf', 'del_13.5_0001p.cbf', 'del_08.0_0001p.cbf', 'del_29.0_0001p.cbf', 'del_45.5_0001p.cbf', 'del_63.0_0001p.cbf', 'del_61.5_0001p.cbf', 'del_31.5_0001p.npt', 'del_11.0_0001p.cbf', 'del_46.5_0001p.cbf', 'del_11.5_0001p.cbf', 'del_56.0_0001p.cbf', 'del_18.0_0001p.cbf', 'del_06.5_0001p.cbf', 'del_46.0_0001p.cbf', 'del_58.5_0001p.cbf', 'del_35.5_0001p.npt', 'del_30.0_0001p.cbf', 'del_15.5_0001p.cbf', 'del_36.5_0001p.cbf', 'del_13.0_0001p.cbf', 'del_55.0_0001p.cbf', 'del_27.5_0001p.cbf', 'del_31.5_0001p.cbf', 'del_24.0_0001p.cbf', 'del_38.0_0001p.cbf', 'del_48.5_0001p.cbf', 'del_16.0_0001p.cbf', 'del_52.5_0001p.cbf', 'del_38.5_0001p.cbf', 'del_54.5_0001p.cbf', 'del_48.0_0001p.cbf', 'del_31.0_0001p.cbf', 'del_28.5_0001p.cbf', 'del_21.5_0001p.cbf', 'del_06.0_0001p.cbf', 'del_25.5_0001p.cbf', 'del_40.5_0001p.cbf', 'del_44.5_0001p.cbf', 'del_39.5_0001p.cbf', 'del_35.5_0001p.cbf', 'del_62.0_0001p.cbf', 'del_36.0_0001p.cbf', 'del_57.5_0001p.cbf', 'del_28.0_0001p.cbf', 'del_17.5_0001p.cbf', 'del_24.5_0001p.cbf', 'del_35.0_0001p.poni', 'del_50.5_0001p.cbf', 'del_18.5_0001p.cbf', 'del_27.0_0001p.cbf', 'del_19.5_0001p.cbf', 'del_21.0_0001p.cbf', 'del_17.0_0001p.cbf', 'del_50.0_0001p.cbf', 'del_44.0_0001p.cbf', 'del_30.5_0001p.cbf', 'del_51.5_0001p.cbf', 'del_62.5_0001p.cbf', 'del_05.0_0001p.cbf', 'del_26.5_0001p.cbf', 'del_31.5_0001p.poni', 'del_23.5_0001p.cbf', 'del_33.5_0001p.poni', 'del_37.5_0001p.cbf', 'del_19.0_0001p.cbf', 'del_29.5_0001p.cbf', 'del_10.0_0001p.cbf', 'del_40.0_0001p.cbf', 'del_58.0_0001p.cbf', 'del_49.5_0001p.cbf', 'del_09.5_0001p.cbf', 'del_15.0_0001p.cbf', 'del_43.0_0001p.cbf', 'del_60.5_0001p.cbf', 'del_34.0_0001p.cbf', 'del_20.0_0001p.cbf', 'deviation-mask.edf', 'del_41.0_0001p.cbf', 'del_07.0_0001p.cbf', 'del_54.0_0001p.cbf', 'del_33.5_0001p.npt', 'del_33.5_0001p.cbf', 'del_32.0_0001p.cbf', 'del_59.5_0001p.cbf', 'del_14.0_0001p.cbf', 'del_32.5_0001p.cbf', 'del_59.0_0001p.cbf', 'del_65.0_0001p.cbf', 'del_25.0_0001p.cbf', 'del_61.0_0001p.cbf', 'del_34.5_0001p.cbf', 'del_52.0_0001p.cbf', 'del_22.5_0001p.cbf', 'del_10.5_0001p.cbf', 'del_42.0_0001p.cbf', 'del_64.0_0001p.cbf', 'del_14.5_0001p.cbf', 'del_26.0_0001p.cbf', 'del_49.0_0001p.cbf', 'del_35.0_0001p.npt', 'del_55.5_0001p.cbf', 'del_23.0_0001p.cbf', 'del_12.0_0001p.cbf', 'del_37.0_0001p.cbf']
[3]:
#Loading of a few libraries

import os
import random
import fabio
import pyFAI
from pyFAI.goniometer import GeometryTransformation, GoniometerRefinement, Goniometer
from pyFAI.gui import jupyter

Display of an image and its headers

[4]:
#loading of the list of files, and display of the last one with its headers

image_files = [i for i in all_files if i.endswith(".cbf")]
image_files.sort()
print("List of images: " + ", ".join([os.path.basename(i) for i in image_files]) + "." + os.linesep)
fimg = fabio.open(image_files[-1])

print("Image headers:")
for key, value in  fimg.header.items():
    print("%s: %s"%(key,value))

jupyter.display(fimg.data, label=os.path.basename(fimg.filename))
pass
List of images: del_05.0_0001p.cbf, del_05.5_0001p.cbf, del_06.0_0001p.cbf, del_06.5_0001p.cbf, del_07.0_0001p.cbf, del_07.5_0001p.cbf, del_08.0_0001p.cbf, del_08.5_0001p.cbf, del_09.0_0001p.cbf, del_09.5_0001p.cbf, del_10.0_0001p.cbf, del_10.5_0001p.cbf, del_11.0_0001p.cbf, del_11.5_0001p.cbf, del_12.0_0001p.cbf, del_12.5_0001p.cbf, del_13.0_0001p.cbf, del_13.5_0001p.cbf, del_14.0_0001p.cbf, del_14.5_0001p.cbf, del_15.0_0001p.cbf, del_15.5_0001p.cbf, del_16.0_0001p.cbf, del_16.5_0001p.cbf, del_17.0_0001p.cbf, del_17.5_0001p.cbf, del_18.0_0001p.cbf, del_18.5_0001p.cbf, del_19.0_0001p.cbf, del_19.5_0001p.cbf, del_20.0_0001p.cbf, del_20.5_0001p.cbf, del_21.0_0001p.cbf, del_21.5_0001p.cbf, del_22.0_0001p.cbf, del_22.5_0001p.cbf, del_23.0_0001p.cbf, del_23.5_0001p.cbf, del_24.0_0001p.cbf, del_24.5_0001p.cbf, del_25.0_0001p.cbf, del_25.5_0001p.cbf, del_26.0_0001p.cbf, del_26.5_0001p.cbf, del_27.0_0001p.cbf, del_27.5_0001p.cbf, del_28.0_0001p.cbf, del_28.5_0001p.cbf, del_29.0_0001p.cbf, del_29.5_0001p.cbf, del_30.0_0001p.cbf, del_30.5_0001p.cbf, del_31.0_0001p.cbf, del_31.5_0001p.cbf, del_32.0_0001p.cbf, del_32.5_0001p.cbf, del_33.0_0001p.cbf, del_33.5_0001p.cbf, del_34.0_0001p.cbf, del_34.5_0001p.cbf, del_35.0_0001p.cbf, del_35.5_0001p.cbf, del_36.0_0001p.cbf, del_36.5_0001p.cbf, del_37.0_0001p.cbf, del_37.5_0001p.cbf, del_38.0_0001p.cbf, del_38.5_0001p.cbf, del_39.0_0001p.cbf, del_39.5_0001p.cbf, del_40.0_0001p.cbf, del_40.5_0001p.cbf, del_41.0_0001p.cbf, del_41.5_0001p.cbf, del_42.0_0001p.cbf, del_42.5_0001p.cbf, del_43.0_0001p.cbf, del_43.5_0001p.cbf, del_44.0_0001p.cbf, del_44.5_0001p.cbf, del_45.0_0001p.cbf, del_45.5_0001p.cbf, del_46.0_0001p.cbf, del_46.5_0001p.cbf, del_47.0_0001p.cbf, del_47.5_0001p.cbf, del_48.0_0001p.cbf, del_48.5_0001p.cbf, del_49.0_0001p.cbf, del_49.5_0001p.cbf, del_50.0_0001p.cbf, del_50.5_0001p.cbf, del_51.0_0001p.cbf, del_51.5_0001p.cbf, del_52.0_0001p.cbf, del_52.5_0001p.cbf, del_53.0_0001p.cbf, del_53.5_0001p.cbf, del_54.0_0001p.cbf, del_54.5_0001p.cbf, del_55.0_0001p.cbf, del_55.5_0001p.cbf, del_56.0_0001p.cbf, del_56.5_0001p.cbf, del_57.0_0001p.cbf, del_57.5_0001p.cbf, del_58.0_0001p.cbf, del_58.5_0001p.cbf, del_59.0_0001p.cbf, del_59.5_0001p.cbf, del_60.0_0001p.cbf, del_60.5_0001p.cbf, del_61.0_0001p.cbf, del_61.5_0001p.cbf, del_62.0_0001p.cbf, del_62.5_0001p.cbf, del_63.0_0001p.cbf, del_63.5_0001p.cbf, del_64.0_0001p.cbf, del_64.5_0001p.cbf, del_65.0_0001p.cbf.

Image headers:
_array_data.header_convention: PILATUS_1.2
_array_data.header_contents: # Detector: PILATUS 2M, 24-0111
# 2016-05-17T18:12:57.232113
# Pixel_size 172e-6 m x 172e-6 m
# Silicon sensor, thickness 0.000450 m
# Exposure_time 9.9977 s
# Exposure_period 9.9977 s
# Tau = 1.991e-07 s
# Count_cutoff 1071182 counts
# Threshold_setting: 4024.0 eV
# Gain_setting: low gain (vrf = -0.300)
# N_excluded_pixels = 1
# Excluded_pixels: badpix_mask.tif
# Flat_field: FF_p2m0111_E26000_T13000_vrf_m0p30.tif
# Trim_file: p2m0111_E26000_T13000_vrf_m0p30.bin
# Image_path: /ramdisk/
# Wavelength 0.7749 A
# Start_angle 0.00 deg.
# Angle_increment 0.00 deg.
# Omega 0.00 deg.
# Omega_increment 0.00 deg.
# Phi 0.00 deg.
# Phi_increment 0.00 deg.
# Kappa 0.0 deg.
# Oscillation_axis PHI
# Detector_distance 0.157 m
# Detector_Voffset 0.0 m
# Beam_xy (542.41, 732.4) pixels
# Flux 0 counts
# Temperature 0.00 K
# Blower 0.0 C
# Lakeshore 0.00 K
Content-Type: application/octet-stream;
conversions: x-CBF_BYTE_OFFSET
Content-Transfer-Encoding: BINARY
X-Binary-Size: 95035
X-Binary-ID: 1
X-Binary-Element-Type: signed 32-bit integer
X-Binary-Element-Byte-Order: LITTLE_ENDIAN
Content-MD5: darooj/7FEQRNdNzNDo0XQ==
X-Binary-Number-of-Elements: 94965
X-Binary-Size-Fastest-Dimension: 487
X-Binary-Size-Second-Dimension: 195
X-Binary-Size-Padding: 4095
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_5_1.png

Definition of the geometry transformation

This is the most difficult part to understand.

The next cell defines 2 functions, one for transforming the geometry and the other one to read the goniometer angle from the metadata

[5]:
#Definition of the goniometer translation function:
# The detector rotates vertically, around the horizontal axis, i.e. rot2

goniotrans = GeometryTransformation(param_names = ["dist", "poni1", "poni2", "rot1",
                                                   "rot2_offset", "rot2_scale"],
                                    dist_expr="dist",
                                    poni1_expr="poni1",
                                    poni2_expr="poni2",
                                    rot1_expr="rot1",
                                    rot2_expr="rot2_scale * pos + rot2_offset",
                                    rot3_expr="0.0")


#Definition of the function reading the goniometer angle from the filename of the image.

def get_angle(basename):
    """Takes the basename (like del_65.0_0001p ) and returns the angle of the detector"""
    return float(os.path.basename((basename.split("_")[1])))

basename = os.path.basename(fimg.filename)
print('filename', basename, "angle:",get_angle(basename))
filename del_65.0_0001p.cbf angle: 65.0
[6]:
#Definition of the detector, its mask, the calibrant
mask_files = [i for i in all_files if i.endswith("-mask.edf")]
mask = numpy.logical_or(fabio.open(mask_files[0]).data, fabio.open(mask_files[1]).data)
pilatus = pyFAI.detector_factory("Pilatus100k")
pilatus.mask = mask

LaB6 = pyFAI.calibrant.CALIBRANT_FACTORY("LaB6")
wavelength = 7.7490120575e-11
LaB6.wavelength = wavelength
[7]:
#Definition of the geometry refinement: the parameter order is the same as the param_names
epsilon = numpy.finfo(numpy.float32).eps
param = {"dist":0.8,
         "poni1":0.02,
         "poni2":0.04,
         "rot1":0,
         "rot2_offset":0,
         "rot2_scale": numpy.pi/180. # rot2 is in radians, while the motor position is in degrees
        }
#Defines the bounds for some variables
bounds = {"dist": (0.8, 0.8),
          "rot1": (-0.00, 0.00),
          "rot2_offset": (-0.00, 0.00),
          "rot2_scale": (numpy.pi/180., numpy.pi/180.) #strict bounds on the scale: we expect the gonio to be precise
         }
gonioref = GoniometerRefinement(param, #initial guess
                                bounds=bounds,
                                pos_function=get_angle,
                                trans_function=goniotrans,
                                detector=pilatus, wavelength=wavelength)
print("Empty refinement object:")
print(gonioref)
Empty refinement object:
GoniometerRefinement with 0 geometries labeled: .
[8]:
#Let's populate the goniometer refinement object with all control point files:

ponis = [i for i in all_files if i.endswith(".poni")]
ponis.sort()
for fn in ponis:
    base = os.path.splitext(fn)[0]
    basename = os.path.basename(base)
    fimg = fabio.open(base + ".cbf")
    sg =gonioref.new_geometry(basename, image=fimg.data, metadata=basename, control_points=base+".npt",
                              geometry=fn, calibrant=LaB6)
    print(sg.label, "Angle:", sg.get_position())
    print(sg.geometry_refinement)
    print()


print("Filled refinement object:")
print(gonioref)

del_31.5_0001p Angle: 31.5
Detector Pilatus 100k    PixelSize= 1.720e-04, 1.720e-04 m
Wavelength= 7.749012e-11m
SampleDetDist= 8.058209e-01m    PONI= 5.700310e-03, 4.599931e-02m       rot1=-0.000000  rot2= 0.560707  rot3= -0.000065 rad
DirectBeamDist= 951.518mm       Center: x=267.438, y=2975.017 pix       Tilt=32.126 deg  tiltPlanRotation= 90.000 deg

del_33.5_0001p Angle: 33.5
Detector Pilatus 100k    PixelSize= 1.720e-04, 1.720e-04 m
Wavelength= 7.749012e-11m
SampleDetDist= 8.061475e-01m    PONI= 1.998418e-02, 4.623309e-02m       rot1=0.000061  rot2= 0.577898  rot3= -0.000000 rad
DirectBeamDist= 962.435mm       Center: x=268.511, y=3172.837 pix       Tilt=33.111 deg  tiltPlanRotation= 90.005 deg

del_35.0_0001p Angle: 35.0
Detector Pilatus 100k    PixelSize= 1.720e-04, 1.720e-04 m
Wavelength= 7.749012e-11m
SampleDetDist= 8.053432e-01m    PONI= 5.551240e-03, 4.624546e-02m       rot1=-0.000016  rot2= 0.622009  rot3= 0.000012 rad
DirectBeamDist= 990.936mm       Center: x=268.944, y=3389.181 pix       Tilt=35.638 deg  tiltPlanRotation= 89.999 deg

del_35.5_0001p Angle: 35.5
Detector Pilatus 100k    PixelSize= 1.720e-04, 1.720e-04 m
Wavelength= 7.749012e-11m
SampleDetDist= 8.061272e-01m    PONI= 5.998339e-03, 3.450065e-02m       rot1=-0.014779  rot2= 0.630136  rot3= 0.000007 rad
DirectBeamDist= 997.856mm       Center: x=269.857, y=3453.432 pix       Tilt=36.113 deg  tiltPlanRotation= 88.839 deg

Filled refinement object:
GoniometerRefinement with 4 geometries labeled: del_31.5_0001p, del_33.5_0001p, del_35.0_0001p, del_35.5_0001p.
[9]:
#Display all images with associated calibration:
nimg = len(gonioref.single_geometries)
fig,ax = subplots(nimg, 1, figsize=(20,nimg*5))
for i, sg in enumerate(gonioref.single_geometries.values()):
    jupyter.display(sg=sg, ax=ax[i])
pass
WARNING:matplotlib.legend:No handles with labels found to put in legend.
WARNING:matplotlib.legend:No handles with labels found to put in legend.
WARNING:matplotlib.legend:No handles with labels found to put in legend.
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_11_1.png
[10]:
# Initial refinement of the goniometer model with 5 dof
gonioref.refine3()
Free parameters: ['poni1', 'poni2']
Fixed: {'dist': 0.8, 'rot1': 0, 'rot2_offset': 0, 'rot2_scale': 0.017453292519943295}
     fun: 1.702784127034382e-08
     jac: array([-5.56158988e-07, -3.01741512e-08])
 message: 'Optimization terminated successfully'
    nfev: 25
     nit: 8
    njev: 8
  status: 0
 success: True
       x: array([0.01451716, 0.04616762])
Constrained Least square 4.676280279481871e-05 --> 1.702784127034382e-08
maxdelta on poni2: 0.04 --> 0.04616761672564747
[10]:
1.702784127034382e-08
[11]:
# This function adds new images to the pool of data used for the refinement.
# A set of new control points are extractred and a refinement step is performed at each iteration
# The last image of the serie is displayed

def optimize_with_new_images(list_images, pts_per_deg=1):
    sg = None
    for fname in list_images:
        print()
        basename = os.path.basename(fname)
        base = os.path.splitext(basename)[0]
        fimg = fabio.open(fname)
        if base in gonioref.single_geometries:
            continue
        print(base)
        sg = gonioref.new_geometry(base, image=fimg.data, metadata=base,
                                   calibrant=LaB6)
        print(sg.extract_cp(pts_per_deg=pts_per_deg))
    print("*"*50)
    gonioref.refine3()
    if sg:
        sg.geometry_refinement.set_param(gonioref.get_ai(sg.get_position()).param)
        jupyter.display(sg=sg)

[12]:
# Append all other images bewteen 30 and 40 degrees

images_30_40 = [i for i in all_files if ("del_3" in i and i.endswith("0001p.cbf"))]
random.shuffle(images_30_40)
optimize_with_new_images(images_30_40, pts_per_deg=3)


del_38.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# c ring 10: 30 points

del_36.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# d ring 9: 36 points

del_34.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# e ring 8: 36 points

del_37.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
# f ring 9: 36 points
# g ring 10: 30 points

del_32.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# h ring 7: 36 points

del_38.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
# i ring 10: 30 points
# j ring 11: 30 points

del_31.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# k ring 6: 36 points


del_30.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# l ring 6: 36 points

del_37.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# m ring 10: 30 points

del_36.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# n ring 9: 36 points

del_33.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# o ring 7: 36 points

del_34.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# p ring 8: 36 points

del_32.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# q ring 7: 36 points


del_39.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
# r ring 10: 21 points
# s ring 11: 30 points


del_39.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# t ring 11: 30 points

del_30.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# u ring 6: 36 points
**************************************************
Free parameters: ['poni1', 'poni2']
Fixed: {'dist': 0.8, 'rot1': 0, 'rot2_offset': 0, 'rot2_scale': 0.017453292519943295}
     fun: 1.2854285230525488e-08
     jac: array([-9.52660700e-07, -2.92712942e-08])
 message: 'Optimization terminated successfully'
    nfev: 3
     nit: 1
    njev: 1
  status: 0
 success: True
       x: array([0.01451716, 0.04616762])
Constrained Least square 1.2854285230525488e-08 --> 1.2854285230525488e-08
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_14_1.png
[13]:
# Append all other images

all_images = [i for i in all_files if i.endswith(".cbf")]
random.shuffle(all_images)
optimize_with_new_images(all_images)

del_49.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
# v ring 17: 9 points
# w ring 18: 3 points

del_46.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
# x ring 14: 9 points
# y ring 15: 10 points

del_44.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
# z ring 13: 9 points

del_14.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#aa ring 1: 24 points

del_06.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_09.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_20.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_45.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ab ring 14: 10 points
#ac ring 15: 3 points


del_24.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ad ring 4: 16 points



del_27.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ae ring 5: 14 points

del_06.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_53.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#af ring 20: 8 points

del_15.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ag ring 1: 24 points

del_43.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ah ring 13: 10 points

del_42.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_50.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ai ring 17: 9 points
#aj ring 18: 8 points

del_44.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ak ring 13: 10 points
#al ring 14: 10 points

del_63.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#am ring 26: 8 points

del_45.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#an ring 13: 10 points
#ao ring 14: 10 points

del_13.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_17.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_54.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ap ring 20: 8 points
#aq ring 21: 5 points

del_23.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ar ring 4: 11 points

del_17.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#as ring 2: 12 points

del_22.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#at ring 3: 17 points


del_46.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#au ring 14: 10 points
#av ring 15: 10 points

del_59.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#aw ring 23: 8 points

del_60.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ax ring 24: 8 points

del_05.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_41.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ay ring 12: 10 points


del_48.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#az ring 16: 9 points
#ba ring 17: 9 points


del_21.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bb ring 3: 17 points

del_50.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#bc ring 17: 9 points
#bd ring 18: 8 points

del_61.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#be ring 24: 8 points
#bf ring 25: 8 points

del_41.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bg ring 12: 10 points


del_62.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bh ring 25: 8 points

del_26.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bi ring 5: 14 points

del_58.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bj ring 23: 8 points

del_12.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bk ring 0: 12 points


del_29.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bl ring 6: 7 points

del_12.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_27.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bm ring 5: 14 points


del_58.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#bn ring 22: 8 points
#bo ring 23: 8 points



del_28.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_57.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#bp ring 22: 8 points
#bq ring 23: 8 points

del_24.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#br ring 4: 16 points

del_47.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#bs ring 15: 10 points
#bt ring 16: 9 points

del_10.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bu ring 0: 34 points

del_05.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_61.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#bv ring 24: 8 points
#bw ring 25: 8 points

del_10.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#bx ring 0: 33 points

del_29.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_49.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#by ring 16: 9 points
#bz ring 17: 9 points

del_64.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ca ring 26: 8 points
#cb ring 27: 8 points

del_59.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cc ring 24: 6 points

del_25.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cd ring 4: 16 points

del_55.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ce ring 20: 8 points
#cf ring 21: 8 points



del_47.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#cg ring 15: 10 points
#ch ring 16: 9 points

del_28.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_60.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#ci ring 24: 8 points
#cj ring 25: 8 points

del_18.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ck ring 2: 19 points


del_11.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cl ring 0: 34 points

del_51.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#cm ring 18: 7 points
#cn ring 19: 8 points

del_63.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#co ring 26: 8 points

del_13.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_51.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#cp ring 18: 8 points
#cq ring 19: 8 points

del_15.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cr ring 1: 24 points

del_57.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#cs ring 22: 8 points
#ct ring 23: 8 points

del_56.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#cu ring 21: 8 points
#cv ring 22: 8 points

del_16.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cw ring 1: 24 points

del_07.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_54.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cx ring 20: 8 points

del_43.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cy ring 13: 10 points

del_18.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#cz ring 2: 19 points

del_52.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#da ring 19: 8 points

del_40.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#db ring 11: 10 points
#dc ring 12: 10 points

del_56.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#dd ring 21: 8 points
#de ring 22: 8 points

del_08.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_65.0_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#df ring 27: 8 points
#dg ring 28: 8 points

del_14.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dh ring 1: 11 points

del_48.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#di ring 16: 9 points

del_64.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#dj ring 26: 8 points
#dk ring 27: 8 points

del_11.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dl ring 0: 31 points

del_40.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#dm ring 11: 10 points
#dn ring 12: 10 points

del_53.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#do ring 19: 8 points

del_52.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dp ring 19: 8 points

del_55.5_0001p
ControlPoints instance containing 2 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 2 groups of points:
#dq ring 20: 8 points
#dr ring 21: 7 points

del_21.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ds ring 3: 17 points


del_08.5_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:

del_09.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dt ring 0: 15 points

del_16.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#du ring 1: 5 points

del_19.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dv ring 2: 19 points

del_23.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dw ring 4: 16 points

del_62.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dx ring 25: 8 points


del_07.0_0001p
ControlPoints instance containing 0 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 0 groups of points:


del_26.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dy ring 5: 14 points


del_20.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#dz ring 3: 17 points

del_42.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ea ring 12: 10 points


del_19.0_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#eb ring 2: 19 points


del_25.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ec ring 5: 14 points

del_22.5_0001p
ControlPoints instance containing 1 group of point:
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
Containing 1 groups of points:
#ed ring 3: 17 points
**************************************************
Free parameters: ['poni1', 'poni2']
Fixed: {'dist': 0.8, 'rot1': 0, 'rot2_offset': 0, 'rot2_scale': 0.017453292519943295}
     fun: 1.873088477239349e-08
     jac: array([ 9.30369342e-07, -2.82031860e-08])
 message: 'Optimization terminated successfully'
    nfev: 19
     nit: 6
    njev: 6
  status: 0
 success: True
       x: array([0.01452782, 0.04552288])
Constrained Least square 2.0911479723925726e-08 --> 1.873088477239349e-08
maxdelta on poni2: 0.04616761672564747 --> 0.045522879668271475
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_15_1.png
[14]:
# Check the calibration of the first and the last image with rings

print("First & last rings")

print("Total number of images:", len(gonioref.single_geometries) )

fig,ax  = subplots(2, 1, figsize=(20,8))
for idx,lbl in enumerate(["del_10.0_0001p", "del_65.0_0001p"]):
    sg = gonioref.single_geometries[lbl]
    if sg.control_points.get_labels():
        sg.geometry_refinement.set_param(gonioref.get_ai(sg.get_position()).param)
    jupyter.display(sg=sg, ax=ax[idx])
WARNING:matplotlib.legend:No handles with labels found to put in legend.
First & last rings
Total number of images: 121
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_16_2.png
[15]:
# Final pass of refinement with all constrains removed, very fine refinement

#gonioref.bounds=None
gonioref.refine3(method="simplex")
WARNING:pyFAI.goniometer:No bounds for optimization method Nelder-Mead
/usr/lib/python3/dist-packages/scipy/optimize/_minimize.py:535: RuntimeWarning: Method Nelder-Mead cannot handle constraints nor bounds.
  warn('Method %s cannot handle constraints nor bounds.' % method,
Free parameters: ['dist', 'poni1', 'poni2', 'rot1', 'rot2_offset', 'rot2_scale']
Fixed: {}
 final_simplex: (array([[ 0.80411172, -0.03308864,  0.09017548,  0.05739362,  0.05889406,
         0.01745677],
       [ 0.80409934, -0.03320649,  0.0902785 ,  0.05752833,  0.05904001,
         0.01745677],
       [ 0.80409686, -0.0332818 ,  0.09042   ,  0.05771327,  0.05913343,
         0.01745676],
       [ 0.80410902, -0.03305052,  0.0904551 ,  0.0577405 ,  0.05884603,
         0.01745676],
       [ 0.80407896, -0.03346824,  0.09025512,  0.05750826,  0.05936483,
         0.01745678],
       [ 0.80410014, -0.03325207,  0.09037756,  0.05765138,  0.05909737,
         0.01745673],
       [ 0.80410654, -0.03316395,  0.09040935,  0.05768789,  0.05898659,
         0.01745678]]), array([7.93026982e-09, 7.93036251e-09, 7.93038526e-09, 7.93042044e-09,
       7.93050495e-09, 7.93054610e-09, 7.93058903e-09]))
           fun: 7.930269823769664e-09
       message: 'Maximum number of function evaluations has been exceeded.'
          nfev: 1200
           nit: 766
        status: 1
       success: False
             x: array([ 0.80411172, -0.03308864,  0.09017548,  0.05739362,  0.05889406,
        0.01745677])
Constrained Least square 1.873088477239349e-08 --> 7.930269823769664e-09
maxdelta on rot2_offset: 0.0 --> 0.058894057184652626
[15]:
7.930269823769664e-09
[16]:
#Create a MultiGeometry integrator from the refined geometry:

angles = []
images = []
for sg in gonioref.single_geometries.values():
    angles.append(sg.get_position())
    images.append(sg.image)

multigeo = gonioref.get_mg(angles)
multigeo.radial_range=(4, 66)
print(multigeo)
MultiGeometry integrator with 121 geometries on (4, 66) radial range (2th_deg) and (-180, 180) azimuthal range (deg)
[27]:
# Calculate the optimal number of point for integration
over = 3
npt = int(over * numpy.deg2rad(max(multigeo.radial_range) - min(multigeo.radial_range)) /
          numpy.arctan2(pilatus.pixel1, gonioref.nt_param(*gonioref.param).dist))
print("Number of bins: %s"%npt)
Number of bins: 15176
[28]:
# Integrate the whole set of images in a single run:

res = multigeo.integrate1d(images, npt)
jupyter.plot1d(res)
pass
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_20_0.png
[19]:
# Save the goniometer configuration with 1 angle

gonioref.save("ROBL_v1.json")
[20]:
#Can the refinement be improved by freeing another degree of freedom ? what about rot1 ?

goniotrans2 = GeometryTransformation(param_names = ["dist", "poni1", "poni2",
                                                    "rot1", "rot1_scale",
                                                    "rot2_offset", "rot2_scale"],
                                     dist_expr="dist",
                                     poni1_expr="poni1",
                                     poni2_expr="poni2",
                                     rot1_expr="rot1_scale * pos + rot1",
                                     rot2_expr="rot2_scale * pos + rot2_offset",
                                     rot3_expr="0.0")

param2 = (gonioref.nt_param(*gonioref.param))._asdict()
param2["rot1_scale"] = 0

gonioref2 = GoniometerRefinement(param2,
                                 pos_function = get_angle,
                                 trans_function=goniotrans2,
                                 detector=pilatus,
                                 wavelength=wavelength)
gonioref2.single_geometries = gonioref.single_geometries.copy()

print(gonioref2.chi2(), gonioref.chi2())
gonioref2.refine3()
gonioref2.refine3(method="simplex")
gonioref2.save("ROBL_v2.json")
7.930269823769664e-09 7.930269823769664e-09
Free parameters: ['dist', 'poni1', 'poni2', 'rot1', 'rot1_scale', 'rot2_offset', 'rot2_scale']
Fixed: {}
WARNING:pyFAI.goniometer:No bounds for optimization method Nelder-Mead
     fun: 5.089806313748771e-09
     jac: array([-5.40692030e-09,  3.87851656e-09,  5.98062905e-09,  3.72671793e-09,
        6.84786633e-09, -6.25082808e-09, -2.31932218e-07])
 message: 'Optimization terminated successfully'
    nfev: 197
     nit: 24
    njev: 24
  status: 0
 success: True
       x: array([ 8.01337045e-01, -3.28665250e-02,  8.96257807e-02,  5.76895772e-02,
       -4.12456335e-05,  5.88251793e-02,  1.74569389e-02])
Constrained Least square 7.930269823769664e-09 --> 5.089806313748771e-09
maxdelta on dist: 0.8041117229634442 --> 0.8013370450921333
Free parameters: ['dist', 'poni1', 'poni2', 'rot1', 'rot1_scale', 'rot2_offset', 'rot2_scale']
Fixed: {}
/usr/lib/python3/dist-packages/scipy/optimize/_minimize.py:535: RuntimeWarning: Method Nelder-Mead cannot handle constraints nor bounds.
  warn('Method %s cannot handle constraints nor bounds.' % method,
 final_simplex: (array([[ 7.95392974e-01, -7.10682802e-02,  7.84590473e-02,
         4.38756302e-02, -5.10107741e-06,  1.06928871e-01,
         1.74571088e-02],
       [ 7.95319078e-01, -7.13973113e-02,  7.83340802e-02,
         4.37256245e-02, -5.14463323e-06,  1.07347161e-01,
         1.74571242e-02],
       [ 7.95345823e-01, -7.12555794e-02,  7.84933456e-02,
         4.39239116e-02, -4.92452984e-06,  1.07167201e-01,
         1.74571127e-02],
       [ 7.95402743e-01, -7.09996311e-02,  7.85683646e-02,
         4.40130742e-02, -4.87421364e-06,  1.06841567e-01,
         1.74571080e-02],
       [ 7.95379078e-01, -7.11331339e-02,  7.84738851e-02,
         4.38981277e-02, -5.18512480e-06,  1.07010622e-01,
         1.74571217e-02],
       [ 7.95433189e-01, -7.08764954e-02,  7.85115107e-02,
         4.39457276e-02, -5.32713186e-06,  1.06684708e-01,
         1.74571212e-02],
       [ 7.95400962e-01, -7.10114298e-02,  7.84853056e-02,
         4.39144437e-02, -5.22348770e-06,  1.06856202e-01,
         1.74571273e-02],
       [ 7.95387117e-01, -7.10637171e-02,  7.84503850e-02,
         4.38660942e-02, -5.13974545e-06,  1.06923830e-01,
         1.74571167e-02]]), array([4.89233725e-09, 4.89236979e-09, 4.89237816e-09, 4.89238073e-09,
       4.89238236e-09, 4.89238544e-09, 4.89241561e-09, 4.89242802e-09]))
           fun: 4.892337252622797e-09
       message: 'Maximum number of function evaluations has been exceeded.'
          nfev: 1401
           nit: 918
        status: 1
       success: False
             x: array([ 7.95392974e-01, -7.10682802e-02,  7.84590473e-02,  4.38756302e-02,
       -5.10107741e-06,  1.06928871e-01,  1.74571088e-02])
Constrained Least square 5.089806313748771e-09 --> 4.892337252622797e-09
maxdelta on rot2_offset: 0.058825179338546384 --> 0.10692887072304197
[21]:
# Check the calibration of the first and the last image with rings

print("First & last rings")

fig,ax = subplots(2, 1, figsize=(10,8))
for idx,lbl in enumerate(["del_10.0_0001p", "del_65.0_0001p"]):
    sg = gonioref.single_geometries[lbl]
    if sg.control_points.get_labels():
        sg.geometry_refinement.set_param(gonioref2.get_ai(sg.get_position()).param)
    jupyter.display(sg=sg, ax=ax[idx])
WARNING:matplotlib.legend:No handles with labels found to put in legend.
First & last rings
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_23_2.png
[22]:
#Create a MultiGeometry integrator from the refined geometry and display the integrated image:

multigeo2 = gonioref2.get_mg(angles)
multigeo2.radial_range=(4, 66)
print(multigeo2)

res2 = multigeo2.integrate1d(images, npt)

#Display the 2 curves with a zoom
fig,ax = subplots(2, 1, figsize=(15,10))
ax[0].plot(*res2, label="rot1 & rot2 rotation")
ax[0].plot(*res, label="rot2 only rotation")
ax[0].set_xlabel(res.unit.label)
ax[0].set_ylabel("Intensity")
ax[0].set_title("Azimuthal integration of 121 images merged")
ax[0].legend()

ax[1].plot(*res2, label="rot1 & rot2 rotation")
ax[1].plot(*res, label="rot2 only rotation")
ax[1].set_xlabel(res.unit.label)
ax[1].set_ylabel("Intensity")
ax[1].set_xlim(10.5,11)
ax[1].set_title("Zoom on first peak")
ax[1].legend()
pass
MultiGeometry integrator with 121 geometries on (4, 66) radial range (2th_deg) and (-180, 180) azimuthal range (deg)
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_24_1.png

With the first model, the refinement was not perfect on the very low angles and indicates a miss-fit. Relaxing the constrains on rot1 allowed to spot a non (perfect) orthogonality between the goniometer axis and the incident beam. Releasing the distances is also possible, for example to cope with the sample not perfectly mounted on the center of the goniometer.

Evaluation of the peak-profile

For every peak, as listed in the calibrant’s definition, the peak height can be extracted and the nearest minimum evaluated. The the full width at half maximum can be measured an ploted as function of the scattering angle. The FWHM can be fitted against Caglioti’s formula:

FWHM² = U tan² \(\theta\) + V tan \(\theta\) + W

[23]:
# Line profile function...
#Peak profile

from scipy.interpolate import interp1d
from scipy.optimize import bisect

def calc_fwhm(integrate_result, calibrant):
    "calculate the tth position and FWHM for each peak"
    delta = integrate_result.intensity[1:] - integrate_result.intensity[:-1]
    maxima = numpy.where(numpy.logical_and(delta[:-1]>0, delta[1:]<0))[0]
    minima = numpy.where(numpy.logical_and(delta[:-1]<0, delta[1:]>0))[0]
    maxima += 1
    minima += 1
    tth = []
    FWHM = []
    for tth_rad in calibrant.get_2th():
        tth_deg = tth_rad*integrate_result.unit.scale
        if (tth_deg<=integrate_result.radial[0]) or (tth_deg>=integrate_result.radial[-1]):
            continue
        idx_theo = abs(integrate_result.radial-tth_deg).argmin()
        id0_max = abs(maxima-idx_theo).argmin()
        id0_min = abs(minima-idx_theo).argmin()
        I_max = integrate_result.intensity[maxima[id0_max]]
        I_min = integrate_result.intensity[minima[id0_min]]
        tth_maxi = integrate_result.radial[maxima[id0_max]]
        I_thres = (I_max + I_min)/2.0
        if minima[id0_min]>maxima[id0_max]:
            if id0_min == 0:
                min_lo = integrate_result.radial[0]
            else:
                min_lo = integrate_result.radial[minima[id0_min-1]]
            min_hi = integrate_result.radial[minima[id0_min]]
        else:
            if id0_min == len(minima) -1:
                min_hi = integrate_result.radial[-1]
            else:
                min_hi = integrate_result.radial[minima[id0_min+1]]
            min_lo = integrate_result.radial[minima[id0_min]]

        f = interp1d(integrate_result.radial, integrate_result.intensity-I_thres)
        tth_lo = bisect(f, min_lo, tth_maxi)
        tth_hi = bisect(f, tth_maxi, min_hi)
        FWHM.append(tth_hi-tth_lo)
        tth.append(tth_deg)
    return tth, FWHM

[24]:
#Fit against Caglioti's formula:
# FWHM^2 = Utan2 + Vtan + W
tth_deg, FWHM_deg = calc_fwhm(res2, LaB6)

def model_Caglioti(tth_deg, U, V, W):
    tantheta = numpy.tan(numpy.deg2rad(tth_deg)/2.0)
    FWHM2 = U*tantheta*tantheta + V*tantheta + W
    return numpy.rad2deg(numpy.sqrt(FWHM2))

from scipy.optimize import curve_fit
fit,cov = curve_fit(model_Caglioti, tth_deg, FWHM_deg, p0=[1e-6,1e-7,1e-8])
print(fit)
print(cov)
[-6.03503895e-08  1.55171681e-07  1.39112294e-07]
[[ 3.09501020e-14 -2.32739292e-14  3.60204342e-15]
 [-2.32739292e-14  1.82372571e-14 -2.99268203e-15]
 [ 3.60204342e-15 -2.99268203e-15  5.47164417e-16]]
[25]:
fig, ax = subplots(figsize=(12,8))
ax.plot(*calc_fwhm(res, LaB6), "o", label="rot2")
ax.plot(*calc_fwhm(res2, LaB6), "o", label="rot1 + 2")
# for lbl, sg in gonioref2d.single_geometries.items():
#     ai = gonioref2d.get_ai(sg.get_position())
#     img = sg.image * ai.dist * ai.dist / ai.pixel1 / ai.pixel2
#     res = ai.integrate1d(img, 5000, unit="2th_deg", method="splitpixel")
#     t,w = calc_fwhm(res, calibrant=calibrant)
#     ax.plot(t, w,"-o", label=lbl)
ax.set_title("Peak profile as function of the angle")
ax.set_ylabel("FWHM of peaks (in degrees)")
ax.set_xlabel(res.unit.label)
ax.plot(tth_deg, model_Caglioti(tth_deg, *fit), label="U:%.1e, V:%.1e, W:%.1e"%(fit[0], fit[1], fit[2]))
ax.legend()
pass
../../../../_images/usage_tutorial_Goniometer_Rotation-Pilatus100k_Multi120_Pilatus100k_28_0.png

Conclusion

This notebook exposes the how to calibrate the goniometer for a small detector moving on a 2theta arm. Once calibrated, the geometry can be saved and restored and stays valid as long as the detector or the goniometer is not unmounted from the beam-line. This configuration can subsequently be used to integrate the data acquired with any sample, in minutes instead of hours. The resolution limit is now the pixel size. Fortunately, pixel detector with small pixel like the MaxiPix or the Lambda detector exists and offer higher resolution.

[26]:
print(f"Total execution time: {time.perf_counter() - start_time:.3f} s")
Total execution time: 145.456 s