pyFAI.gui package

Subpackages

pyFAI.gui.ApplicationContext module

Context shared through all the application

class pyFAI.gui.ApplicationContext.ApplicationContext(settings=None)

Bases: object

__init__(settings=None)

Initialize self. See help(type(self)) for accurate signature.

createFileDialog(parent, previousFile=None)

Create a file dialog configured with a default path.

Return type

qt.QFileDialog

createImageFileDialog(parent, previousFile=None)

Create an image file dialog configured with a default path.

Return type

silx.gui.dialog.ImageFileDialog.ImageFileDialog

static instance()
Return type

CalibrationContext

parent()
restoreWindowLocationSettings(groupName, window)

Restore the window settings using this settings object

Parameters

settings (qt.QSettings) – Initialized settings

saveSettings()

Save the settings of all the application

saveWindowLocationSettings(groupName, window)

Save the window settings to this settings object

Parameters

settings (qt.QSettings) – Initialized settings

setParent(parent)

pyFAI.gui.CalibrationContext module

Context shared through all the application

class pyFAI.gui.CalibrationContext.CalibrationContext(settings=None)

Bases: pyFAI.gui.ApplicationContext.ApplicationContext

__init__(settings=None)

Initialize self. See help(type(self)) for accurate signature.

createMarkerColors()
disabledMarkerColor()
getAngleUnit()
getBackgroundColor()

Returns the Qt color used to display part of the diagram outside of the data.

Return type

qt.QColor

getCalibrationModel()
getColormapDialog()

Returns a shared color dialog.

Return type

ColorDialog

getCurrentStyle()
getHtmlMarkerColor(index)
getLabelColor()

Returns the Qt color used to display text label

Return type

qt.QColor

getLengthUnit()
getMarkerColor(index, mode='qt')
getMaskedColor()

Returns the Qt color used to display masked pixels

Return type

qt.QColor

getRawColormap()

Returns the user preference colormap used to display raw data images

Return type

Colormap

getScatteringVectorUnit()
getWavelengthUnit()
static instance()
Return type

CalibrationContext

markerColorList()
restoreSettings()

Restore the settings of all the application

saveSettings()

Save the settings of all the application

pyFAI.gui.CalibrationWindow module

class pyFAI.gui.CalibrationWindow.CalibrationWindow(context)

Bases: PyQt5.QtWidgets.QMainWindow

__init__(context)

Initialize self. See help(type(self)) for accurate signature.

closeEvent(self, QCloseEvent)
createTasks()
model()
nextTask()
resizeEvent(self, QResizeEvent)
setModel(model)
class pyFAI.gui.CalibrationWindow.MenuItem(parent)

Bases: PyQt5.QtWidgets.QListWidgetItem

IconMode = 1
TextMode = 0
__init__(parent)

Initialize self. See help(type(self)) for accurate signature.

setDisplayMode(mode)
setIcon(self, QIcon)
setText(self, str)
setWarnings(warnings)

pyFAI.gui.IntegrationDialog module

pyFAI-integrate

A graphical tool for performing azimuthal integration on series of files.

class pyFAI.gui.IntegrationDialog.IntegrationDialog(input_data=None, output_path=None, json_file='.azimint.json', context=None)

Bases: PyQt5.QtWidgets.QWidget

Dialog to configure an azimuthal integration.

__init__(input_data=None, output_path=None, json_file='.azimint.json', context=None)

Initialize self. See help(type(self)) for accurate signature.

batchProcessRequested
closeEvent(self, QCloseEvent)
die()
dump(filename=None)

Dump the status of the current widget to a file in JSON

Parameters

filename (string) – path where to save the config

Returns

dict with configuration

get_config()

Read the configuration of the plugin and returns it as a dictionary

Returns

dict with all information.

help()
restore(filename='.azimint.json')

Restore from JSON file the status of the current widget

Parameters

filename (str) – path where the config was saved

save_config()
set_config(dico)

Setup the widget from its description

Parameters

dico (dict) – dictionary with description of the widget

set_input_data(stack)
class pyFAI.gui.IntegrationDialog.IntegrationProcess(parent=None)

Bases: PyQt5.QtWidgets.QDialog, pyFAI.app.integrate.IntegrationObserver

__init__(parent=None)

Initialize self. See help(type(self)) for accurate signature.

createObserver(qtSafe=True)

Returns a processing observer connected to this widget.

Parameters

qtSafe (bool) – If True the returned observer can be called from any thread. Else it have to be called from the main Qt thread.

Return type

integrate.IntegrationObserver

data_result(data_info, result)

Called after each data processing, with the result

Parameters
  • data_info (DataInfo) – Contains data and metadata from the data to integrate

  • result (object) – Result of the integration.

processing_data(data_info, approximate_count=None)

Start processing the data data_info

Parameters
  • data_info (DataInfo) – Contains data and metadata from the data to integrate

  • approximate_count (int) – If set, the amount of total data to process have changed

processing_finished()

Called when the full processing is finisehd.

processing_interrupted()

Called before processing_finished if the processing was interrupted.

Parameters

error ([str,Exception,None]) – A reason of the interruption.

processing_started(data_count)

Called before starting the full processing.

Parameters

data_count (int) – Number of data to integrate

processing_succeeded()

Called before processing_finished if the processing succedded.

worker_initialized(worker)

Called when the worker is initialized

Parameters

data_count (int) – Number of data to integrate

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(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=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__(dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, detector=None, wavelength=None, calibrant=None)

Constructor of AbstractCalibration

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

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 0.18.0: 03/02/2019', usage='pyFAI-calib [options] input_image.edf', description=None, epilog=None)

Common configuration for parsers

extract_cpt(method='massif', pts_per_deg=1.0)

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)

get_pixelSize(ans)

convert a comma separated sting into pixel size

postProcess()

Common part: shows the result of the azimuthal integration in 1D and 2D

preprocess()

Common part: do dark, flat correction thresholding, … and read missing data from keyboard if needed

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()

Contains the common geometry refinement part

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

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: pyFAI.gui.cli_calibration.AbstractCalibration

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()
initgeoRef()

Tries to initialise the GeometryRefinement (dist, poni, rot) Returns a dictionary of key value pairs

parse()

parse options from command line

preprocess()

do dark, flat correction thresholding, …

refine()

Contains the geometry refinement part specific to Calibration Sets up the initial guess when starting pyFAI-calib

class pyFAI.gui.cli_calibration.CheckCalib(poni=None, img=None, unit='2th_deg')

Bases: object

__init__(poni=None, img=None, unit='2th_deg')

Initialize self. See help(type(self)) for accurate signature.

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

size1d
smooth_mask(hwhm=5)

smooth out around the mask to avoid aligning on the mask

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: pyFAI.gui.cli_calibration.AbstractCalibration

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()

Contains the geometry refinement part specific to Recalibration

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.diffmap_widget module

class pyFAI.gui.diffmap_widget.DiffMapWidget

Bases: PyQt5.QtWidgets.QWidget

__init__()

Initialize self. See help(type(self)) for accurate signature.

clear_selection(*args, **kwargs)

called to remove selected files from the list

configure_diffraction(*arg, **kwarg)
configure_output(*args, **kwargs)

called when clicking on “outputFileSelector”

create_connections()

Signal-slot connection

display_processing(config)

Setup the display for visualizing the processing

Parameters

config – configuration of the processing ongoing

do_abort()
dump(fname=None)

Save the configuration in a JSON file

Parameters

fname – file where the config is saved as JSON

get_config()

Return a dict with the plugin configuration which is JSON-serializable

input_filer(*args, **kwargs)

Called when addFiles clicked: opens a file-browser and populates the listFiles object

json_file = '.diffmap.json'
process(config=None)

Called in a separate thread

progressbarChanged
restore(fname=None)

Restore the widget from saved config

Parameters

fname – file where the config is saved as JSON

save_config()
set_config(dico)

Set up the widget from dictionary

Parameters

dico – dictionary

set_validator()
sort_input()
start_processing(*arg, **kwarg)
uif = 'diffmap.ui'
update_number_of_frames()
update_number_of_points()
update_processing(idx_file, idx_img)

Update the process bar and the images

Parameters
  • idx_file – file number

  • idx_img – frame number

update_slice(*args)

Update the slice

class pyFAI.gui.diffmap_widget.IntegrateDialog(parent=None)

Bases: PyQt5.QtWidgets.QDialog

__init__(parent=None)

Initialize self. See help(type(self)) for accurate signature.

class pyFAI.gui.diffmap_widget.TreeModel(win, root_item)

Bases: PyQt5.QtCore.QAbstractItemModel

__init__(win, root_item)

Initialize self. See help(type(self)) for accurate signature.

columnCount(self, parent: QModelIndex = QModelIndex()) → int
data(midx, role)

What to display depending on model_index and role

flags(self, QModelIndex) → Qt.ItemFlags
headerData(self, int, Qt.Orientation, role: int = Qt.DisplayRole) → Any
index(self, int, int, parent: QModelIndex = QModelIndex()) → QModelIndex
parent(self, QModelIndex) → QModelIndex

parent(self) -> QObject

rowCount(self, parent: QModelIndex = QModelIndex()) → int
update(new_root)

pyFAI.gui.jupyter module

pyFAI.gui.jupyter.display(img=None, cp=None, ai=None, label=None, sg=None, ax=None)

Display an image with the control points and the calibrated rings in Jupyter notebooks

Parameters
  • img – 2D numpy array with an image

  • cp – ControlPoint instance

  • ai – azimuthal integrator for iso-2th curves

  • label – name of the curve

  • sg – single geometry object regrouping img, cp and ai

  • ax – subplot object to display in, if None, a new one is created.

Returns

Matplotlib subplot

pyFAI.gui.jupyter.plot1d(result, calibrant=None, label=None, ax=None)

Display the powder diffraction pattern in the jupyter notebook

Parameters
  • result – instance of Integrate1dResult

  • calibrant – Calibrant instance to overlay diffraction lines

  • label – (str) name of the curve

  • ax – subplot object to display in, if None, a new one is created.

Returns

Matplotlib subplot

pyFAI.gui.jupyter.plot2d(result, calibrant=None, label=None, ax=None)

Display the caked image in the jupyter notebook

Parameters
  • result – instance of Integrate2dResult

  • calibrant – Calibrant instance to overlay diffraction lines

  • label – (str) name of the curve

  • ax – subplot object to display in, if None, a new one is created.

Returns

Matplotlib subplot

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

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

gui(log=False, maximize=False, pick=True)
Parameters

log – show z in log scale

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_option_clicked(*args)

callback function

on_plus_pts_clicked(*args)

callback function

on_refine_clicked(*args)

callback function

onclick(event)

Called when a mouse is clicked

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.setup module

pyFAI.gui.setup.configuration(parent_package='', top_path=None)

Module contents

Module containing dependency with Qt or matplotlib GUI