pyFAI.gui package
The package pyFAI.gui contains mainly the code of the graphical user interface widgets. This code is not intended to be used by users of pyFAI as a library hence it makes little sense to document it all here. Only documentation on the Jupyter tools are exposed.
pyFAI.gui.cli_calibration module
pyFAI-calib
A tool for determining the geometry of a detector using a reference sample.
- class pyFAI.gui.cli_calibration.AbstractCalibration(img=None, mask=None, detector=None, wavelength=None, calibrant=None)
Bases:
object
Everything that is common to Calibration and Recalibration
- PARAMETERS = ['dist', 'poni1', 'poni2', 'rot1', 'rot2', 'rot3', 'wavelength']
- PTS_PER_DEG = 0.3
- UNITS = {'dist': 'meter', 'poni1': 'meter', 'poni2': 'meter', 'rot1': 'radian', 'rot2': 'radian', 'rot3': 'radian', 'wavelength': 'meter'}
- VALID_URL = ['', 'file', 'hdf5', 'nxs', 'h5']
- __init__(img=None, mask=None, detector=None, wavelength=None, calibrant=None)
Constructor of AbstractCalibration
- Parameters:
img – 2d numpy array with the data
mask – 2d array with invalid pixels marked
detector – Detector name or instance
wavelength – radiation wavelength in meter
calibrant – pyFAI.calibrant.Calibrant instance
- analyse_options(options=None, args=None)
Analyzes options and arguments
- Returns:
option,arguments
- chiplot(rings=None)
plot delta_2theta/2theta = f(chi) and fit the curve.
- Parameters:
rings – list of rings to consider
- configure_parser(version='calibration from pyFAI version 2024.5.0: 21/05/2024', usage='pyFAI-calib [options] input_image.edf', description=None, epilog=None)
Common configuration for parsers
- extract_cpt(method='massif', pts_per_deg=1.0, max_rings=9223372036854775807)
Performs an automatic keypoint extraction: Can be used in recalib or in calib after a first calibration has been performed.
- Parameters:
method – method for keypoint extraction
pts_per_deg – number of control points per azimuthal degree (increase for better precision)
max_rings – extract at most max_rings
- get_pixelSize(ans)
convert a comma separated sting into pixel size
- initgeoRef(defaults=None)
Tries to initialise the GeometryRefinement (dist, poni, rot)
- Param:
default parameters as a dict to be passed to constructor of GeometryRefinement
- Returns:
initialized geometry refinement
- postProcess()
Common part: shows the result of the azimuthal integration in 1D and 2D
- preprocess()
Initialize peakpicker
- prompt()
prompt for commands to guide the calibration process
- Returns:
True when the user is happy with what he has, False to request another refinement
- read_dSpacingFile(verbose=True)
Read the name of the calibrant / file with d-spacing
- read_pixelsSize()
Read the pixel size from prompt if not available
- read_wavelength()
Read the wavelength
- refine(maxiter=1000000, fixed=None)
Contains the common geometry refinement part
- Parameters:
maxiter – number of iteration to run for in the minimizer
fixed – a list of parameters for maintain fixed during the refinement. self.fixed by default.
- Returns:
nothing, object updated in place
- reset_geometry(how='center', refine=False)
Reset the geometry: no tilt in all cases
- Parameters:
how – multiple options * center: set the PONI at the center of the detector * ring: center the poni at the middle of the inner-most ring * best: try both option and keeps the best (this option is not available)
refine – launch the refinement (argument not used)
- set_data(data)
call-back function for the peak-picker
- Parameters:
data – list of point with ring index
- Returns:
associated azimuthal integrator
- validate_calibration()
Validate the calibration and calculate the offset in the diffraction image
- validate_center(slices=36)
Validate the position of the center by cross-correlating two spectra 180 deg appart. Output values are in micron.
Designed for orthogonal setup with centered beam…
- Parameters:
slices – number of slices on which perform
- win_error = 'We are under windows with a 32 bit version of python, matplotlib is not able to display too many images without crashing, this is why the window showing the diffraction image is closed'
- class pyFAI.gui.cli_calibration.Calibration(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, gaussianWidth=None, wavelength=None, calibrant=None)
Bases:
CliCalibration
class doing the calibration of frames
- __init__(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, gaussianWidth=None, wavelength=None, calibrant=None)
Constructor for calibration:
- Parameters:
dataFiles – list of filenames containing data images
darkFiles – list of filenames containing dark current images
flatFiles – list of filenames containing flat images
pixelSize – size of the pixel in meter as 2 tuple
splineFile – file containing the distortion of the taper
detector – Detector name or instance
wavelength – radiation wavelength in meter
calibrant – pyFAI.calibrant.Calibrant instance
- gui_peakPicker()
- parse()
parse options from command line
- preprocess()
do dark, flat correction thresholding, …
- refine(maxiter=1000000, fixed=None)
Contains the geometry refinement part specific to Calibration Sets up the initial guess when starting pyFAI-calib
- Parameters:
maxiter – number of iteration to run for in the minimizer
fixed – a list of parameters for maintain fixed during the refinement. self.fixed by default.
- Returns:
nothing, object updated in place
- class pyFAI.gui.cli_calibration.CheckCalib(poni=None, img=None, unit='2th_deg')
Bases:
object
- __init__(poni=None, img=None, unit='2th_deg')
- get_1dsize()
- integrate()
- parse()
- rebuild()
Rebuild the diffraction image and measures the offset with the reference :return: offset
- show()
Show the image with the the errors
- property size1d
- smooth_mask(hwhm=5)
smooth out around the mask to avoid aligning on the mask
- class pyFAI.gui.cli_calibration.CliCalibration(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, wavelength=None, calibrant=None)
Bases:
AbstractCalibration
- __init__(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, wavelength=None, calibrant=None)
Constructor of CliCalibration
- Parameters:
dataFiles – list of filenames containing data images
darkFiles – list of filenames containing dark current images
flatFiles – list of filenames containing flat images
pixelSize – size of the pixel in meter as 2 tuple
splineFile – file containing the distortion of the taper
detector – Detector name or instance
wavelength – radiation wavelength in meter
calibrant – pyFAI.calibrant.Calibrant instance
- preprocess()
Common part: do dark, flat correction thresholding, … and read missing data from keyboard if needed
- class pyFAI.gui.cli_calibration.MultiCalib(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None)
Bases:
object
- __init__(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None)
- get_pixelSize(ans)
convert a comma separated sting into pixel size
- parse(exe=None, description=None, epilog=None)
parse options from command line :param exe: name of the program (MX-calibrate) :param description: Description of the program
- process()
- read_dSpacingFile()
Read the name of the calibrant or the file with d-spacing
- read_pixelsSize()
Read the pixel size from prompt if not available
- read_wavelength()
Read the wavelength
- regression()
- class pyFAI.gui.cli_calibration.Recalibration(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, wavelength=None, calibrant=None)
Bases:
CliCalibration
class doing the re-calibration of frames
- __init__(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, wavelength=None, calibrant=None)
Constructor for Recalibration:
- Parameters:
dataFiles – list of filenames containing data images
darkFiles – list of filenames containing dark current images
flatFiles – list of filenames containing flat images
pixelSize – size of the pixel in meter as 2 tuple
splineFile – file containing the distortion of the taper
detector – Detector name or instance
wavelength – radiation wavelength in meter
calibrant – pyFAI.calibrant.Calibrant instance
- parse()
parse options from command line
- preprocess()
do dark, flat correction thresholding, …
- read_dSpacingFile()
Read the name of the file with d-spacing
- refine(maxiter=1000000, fixed=None)
Contains the geometry refinement part specific to Recalibration
- Parameters:
maxiter – number of iteration to run for in the minimizer
fixed – a list of parameters for maintain fixed during the refinement. self.fixed by default.
- Returns:
nothing, object updated in place
- pyFAI.gui.cli_calibration.calib(img, calibrant, detector, basename='from_ipython', reconstruct=False, dist=0.1, gaussian=None, interactive=True)
Procedural interfact for calibration
- Parameters:
img – 2d array representing the calibration image
calibrant – Instance of Calibrant, set-up with wavelength
detector – Detector instance containing the mask
basename – output file base
recontruct – perform image reconstruction of masked pixel ?
dist – initial distance
gaussian – width of the gaussian used for difference of gaussian in the “massif” peak-picking algorithm
interactive – set to False for testing
- Returns:
AzimuthalIntegrator instance
- pyFAI.gui.cli_calibration.get_detector(detector, datafiles=None)
Detector factory taking into account the binning knowing the datafiles
- Parameters:
detector – string or detector or other junk
datafiles – can be a list of images to be opened and their shape used
- Returns:
pyFAI.detector.Detector instance
- Raises:
RuntimeError – If no detector found
pyFAI.gui.jupyter module
pyFAI.gui.matplotlib module
This module inits matplotlib and setups the backend to use.
It MUST be imported prior to any other import of matplotlib.
It provides the matplotlib FigureCanvasQTAgg
class corresponding
to the used backend.
pyFAI.gui.peak_picker module
Semi-graphical tool for peak-picking and extracting visually control points from an image with Debye-Scherer rings
- class pyFAI.gui.peak_picker.PeakPicker(data, reconst=False, mask=None, pointfile=None, calibrant=None, wavelength=None, detector=None, method='massif')
Bases:
object
This class is in charge of peak picking, i.e. find bragg spots in the image Two methods can be used : massif or blob
- VALID_METHODS = ['massif', 'blob', 'watershed']
- __init__(data, reconst=False, mask=None, pointfile=None, calibrant=None, wavelength=None, detector=None, method='massif')
- Parameters:
data – input image as numpy array
reconst – shall masked part or negative values be reconstructed (wipe out problems with pilatus gaps)
mask – area in which keypoints will not be considered as valid
pointfile –
- property append_mode
- closeGUI()
- contour(data, cmap='autumn', linewidths=2, linestyles='dashed')
Overlay a contour-plot
- Parameters:
data – 2darray with the 2theta values in radians…
- display_points(minIndex=0, reset=False)
display all points and their ring annotations :param minIndex: ring index to start with :param reset: remove all point before re-displaying them
- finish(filename=None, callback=None)
Ask the ring number for the given points
- Parameters:
filename – file with the point coordinates saved
callback –
- Returns:
list of control points
- gui(log=False, maximize=False, pick=True, widget_klass=None)
Display the GUI
- Parameters:
log – show z in log scale
maximize – set to true to maximize window
pick – activate pixel picking
widget_klass – provide the MplCalibWidget (either Qt or Jupyter) to instanciate the widget
- Returns:
None
- help = ['Please select rings on the diffraction image. In parenthesis, some modified shortcuts for single button mouse (Apple):', ' * Right-click (click+n): try an auto find for a ring', ' * Right-click + Ctrl (click+b): create new group with one point', ' * Right-click + Shift (click+v): add one point to current group', ' * Right-click + m (click+m): find more points for current group', ' * Center-click or (click+d): erase current group', ' * Center-click + 1 or (click+1): erase closest point from current group']
- init(method, sync=True)
Unified initializer
- load(filename)
load a filename and plot data on the screen (if GUI)
- massif_contour(data)
Overlays a mask over a diffraction image
- Parameters:
data – mask to be overlaid
- on_minus_pts_clicked(*args)
callback function
- on_plus_pts_clicked(*args)
callback function
- onclick_append_1_point(yx, ring=None)
Right-click + Shift (click+v): add one point to current group
- Parameters:
xy – 2tuple of coordinates
- onclick_append_more_points(yx, ring)
Right-click + m (click+m): find more points for current group
- onclick_erase_1_point(yx, ring)
Center-click + 1 or (click+1): erase closest point from current group
- onclick_erase_grp(yx, ring)
Center-click or (click+d): erase current group
- onclick_new_grp(yx, ring)
new_grp Right-click (click+n): try an auto find for a ring
- onclick_option(*args)
callback function
- onclick_refine(*args)
callback function
- onclick_single_point(yx, ring)
Right-click + Ctrl (click+b): create new group with one single point
- peaks_from_area(**kwargs)
Return the list of peaks within an area
- Parameters:
mask – 2d array with mask.
Imin – minimum of intensity above the background to keep the point
keep – maximum number of points to keep
method – enforce the use of detection using “massif” or “blob” or “watershed”
ring – ring number to which assign the points
dmin – minimum distance between two peaks (in pixels)
seed – good starting points.
- Returns:
list of peaks [y,x], [y,x], …]
- remove_grp(lbl)
remove a group of points
- Parameters:
lbl – label of the group of points
- reset()
Reset control point and graph (if needed)
- sync_init()
- pyFAI.gui.peak_picker.preprocess_image(data, log=False, clip=0.001)
Preforms the pre-processing of the image
- Parameters:
data – the input image
log – set to apply logarithmic intensity scale
clip – discard pixel fraction which are too weak/intense
- Returns:
scaled image, bounds