pyFAI.ext package

pyFAI.ext.bilinear module

Module with makes a discrete 2D-array appear like a continuous function thanks to bilinear interpolations.

class pyFAI.ext.bilinear.Bilinear

Bases: object

Bilinear interpolator for finding max.

Instance attribute defined in pxd file

cp_local_maxi
data
f_cy

Function -f((y,x)) where f is a continuous function (y,x) are pixel coordinates pixels outside the image are given an arbitrary high value to help the minimizer

Parameters:x – 2-tuple of float
Returns:Interpolated negative signal from the image (negative for using minimizer to search for peaks)
height
local_maxi

Return the local maximum with sub-pixel refinement.

Sub-pixel refinement: Second order Taylor expansion of the function; first derivative is null

\[delta = x-i = -Inverse[Hessian].gradient\]

If Hessian is singular or \(|delta|>1\): use a center of mass.

Parameters:x – 2-tuple of integers
Returns:2-tuple of float with the nearest local maximum
maxi
mini
width
pyFAI.ext.bilinear.calc_cartesian_positions

Calculate the Cartesian position for array of position (d1, d2) with pixel coordinated stored in array pos. This is bilinear interpolation.

Parameters:
  • d1 – position in dim1
  • d2 – position in dim2
  • pos – array with position of pixels corners
Returns:

3-tuple of position.

pyFAI.ext.bilinear.convert_corner_2D_to_4D

Convert 2 (or 3) arrays of corner position into a 4D array of pixel corner coordinates

Parameters:
  • ndim – 2d or 3D output
  • d1 – 2D position in dim1 (shape +1)
  • d2 – 2D position in dim2 (shape +1)
  • d3 – 2D position in dim3 (z) (shape +1)
Returns:

pos 4D array with position of pixels corners

pyFAI.ext.fastcrc module

Simple Cython module for doing CRC32 for checksums, possibly with SSE4 acceleration

pyFAI.ext.fastcrc.crc32

Calculate the CRC32 checksum of a numpy array

Parameters:data – a numpy array
Returns:unsigned integer

pyFAI.ext.histogram module

A set of histogram functions with or without OpenMP enabled.

Re-implementation of the numpy.histogram, optimized for azimuthal integration.

Deprecated, will be replaced by silx.math.histogramnd.

pyFAI.ext.histogram.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.histogram.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.histogram.histogram

_histogram_omp(pos, weights, int bins=100, bin_range=None, pixelSize_in_Pos=None, int nthread=0, double empty=0.0, double normalization_factor=1.0)

Calculates histogram of pos weighted by weights Multi threaded implementation

Parameters:
  • pos – 2Theta array
  • weights – array with intensities
  • bins – number of output bins
  • pixelSize_in_Pos – size of a pixels in 2theta: DESACTIVATED
  • nthread – OpenMP is disabled. unused
  • empty – value given to empty bins
  • normalization_factor – divide the result by this value
Returns:

2theta, I, weighted histogram, raw histogram

pyFAI.ext.histogram.histogram1d_engine

Implementation of rebinning engine (without splitting) using pure cython histograms

Parameters:
  • radial – radial position 2D array (same shape as raw)
  • npt – number of points to integrate over
  • raw – 2D array with the raw signal
  • dark – array containing the value of the dark noise, to be subtracted
  • flat – Array containing the flatfield image. It is also checked for dummies if relevant.
  • solidangle – the value of the solid_angle. This processing may be performed during the rebinning instead. left for compatibility
  • polarization – Correction for polarization of the incident beam
  • absorption – Correction for absorption in the sensor volume
  • mask – 2d array of int/bool: non-null where data should be ignored
  • dummy – value of invalid data
  • delta_dummy – precision for invalid data
  • normalization_factor – final value is divided by this
  • empty – value to be given for empty bins
  • variance – provide an estimation of the variance
  • dark_variance – provide an estimation of the variance of the dark_current,
  • poissonian – set to “True” for assuming the detector is poissonian and variance = raw + dark

NaN are always considered as invalid values

if neither empty nor dummy is provided, empty pixels are left at 0.

Nota: “azimuthal_range” has to be integrated into the
mask prior to the call of this function
Returns:Integrate1dtpl named tuple containing: position, average intensity, std on intensity, plus the various histograms on signal, variance, normalization and count.
pyFAI.ext.histogram.histogram2d

Calculate 2D histogram of pos0,pos1 weighted by weights

Parameters:
  • pos0 – 2Theta array
  • pos1 – Chi array
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • split – pixel splitting is disabled in histogram
  • nthread – Unused ! see below
  • empty – value given to empty bins
  • normalization_factor – divide the result by this value
Returns:

I, bin_centers0, bin_centers1, weighted histogram(2D), unweighted histogram (2D)

Nota: the histogram itself is not parallelized as it is slower than in serial mode (cache contention)

pyFAI.ext.histogram.histogram2d_engine

Calculate 2D histogram of pos0,pos1 weighted by weights when the weights are preprocessed and contain: signal, variance, normalization for each pixel

Parameters:
  • pos0 – 2Theta array
  • pos1 – Chi array
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • split – pixel splitting is disabled in histogram
  • nthread – OpenMP is disabled. unused here
  • empty – value given to empty bins
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.histogram.histogram2d_preproc

histogram2d_engine(pos0, pos1, bins, weights, pos0_range=None, pos1_range=None, bool split=False, double empty=0.0)

Calculate 2D histogram of pos0,pos1 weighted by weights when the weights are preprocessed and contain: signal, variance, normalization for each pixel

Parameters:
  • pos0 – 2Theta array
  • pos1 – Chi array
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • split – pixel splitting is disabled in histogram
  • nthread – OpenMP is disabled. unused here
  • empty – value given to empty bins
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.histogram.histogram_preproc

Calculates histogram of pos weighted by weights in the case data have been preprocessed, i.e. each datapoint contains (signal, normalization), (signal, variance, normalization), (signal, variance, normalization, count)

Parameters:
  • pos – radial array
  • weights – array with intensities, variance, normalization and count
  • bins – number of output bins
  • bin_range – 2-tuple with lower and upper bound for the valid position range.
Returns:

4 histograms concatenated, radial position (bin center)

pyFAI.ext.histogram.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.inpainting module

Simple Cython module for doing CRC32 for checksums, possibly with SSE4 acceleration

class pyFAI.ext.inpainting.Bilinear

Bases: object

Bilinear interpolator for finding max.

Instance attribute defined in pxd file

cp_local_maxi
data
f_cy

Function -f((y,x)) where f is a continuous function (y,x) are pixel coordinates pixels outside the image are given an arbitrary high value to help the minimizer

Parameters:x – 2-tuple of float
Returns:Interpolated negative signal from the image (negative for using minimizer to search for peaks)
height
local_maxi

Return the local maximum with sub-pixel refinement.

Sub-pixel refinement: Second order Taylor expansion of the function; first derivative is null

\[delta = x-i = -Inverse[Hessian].gradient\]

If Hessian is singular or \(|delta|>1\): use a center of mass.

Parameters:x – 2-tuple of integers
Returns:2-tuple of float with the nearest local maximum
maxi
mini
width
pyFAI.ext.inpainting.largest_width

Calculate the width of the largest part in the binary image Nota: this is along the horizontal direction.

pyFAI.ext.inpainting.polar_inpaint

Relaplce the values flagged in topaint with possible values If mask is provided, those values are knows to be invalid and not re-calculated

Parameters:
  • img – image in polar coordinates
  • topaint – pixel which deserves inpatining
  • mask – pixels which are masked and do not need to be inpainted
  • dummy – value for masked
Returns:

image with missing values interpolated from neighbors.

pyFAI.ext.inpainting.polar_interpolate

Perform the bilinear interpolation from polar data into the initial array data

Parameters:
  • data – image with holes, of a given shape
  • mask – array with the holes marked
  • radial – 2D array with the radial position
  • polar – 2D radial/azimuthal averaged image (continuous). shape is pshape
  • radial_pos – position of the radial bins (evenly spaced, size = pshape[-1])
  • azim_pos – position of the azimuthal bins (evenly spaced, size = pshape[0])
Returns:

inpainted image

pyFAI.ext.invert_geometry module

Module providing inversion transformation from pixel coordinate to radial/azimuthal coordinate.

class pyFAI.ext.invert_geometry.InvertGeometry

Bases: object

Class to inverse the geometry: takes the nearest pixel then use linear interpolation

Parameters:
  • radius – 2D array with radial position
  • angle – 2D array with azimuthal position

Call it with (r,chi) to retrieve the pixel where it comes from.

pyFAI.ext.invert_geometry.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.invert_geometry.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.invert_geometry.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.morphology module

This module provides a couple of binary morphology operations on images.

They are also implemented in scipy.ndimage in the general case, but not as fast.

pyFAI.ext.morphology.binary_dilation

Return fast binary morphological dilation of an image.

Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at (i,j). Dilation enlarges bright regions and shrinks dark regions.

:param image : ndarray :param radius: float :return: ndiamge

pyFAI.ext.morphology.binary_erosion

Return fast binary morphological erosion of an image.

Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.

:param image : ndarray :param radius: float :return: ndiamge

pyFAI.ext.preproc module

Contains a preprocessing function in charge of the dark-current subtraction, flat-field normalization… taking care of masked values and normalization.

pyFAI.ext.preproc.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.preproc.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.preproc.preproc

Common preprocessing step for all

Parameters:
  • raw – raw value, as a numpy array, 1D or 2D
  • mask – array non null where data should be ignored
  • dummy – value of invalid data
  • delta_dummy – precision for invalid data
  • dark – array containing the value of the dark noise, to be subtracted
  • flat – Array containing the flatfield image. It is also checked for dummies if relevant.
  • solidangle – the value of the solid_angle. This processing may be performed during the rebinning instead. left for compatibility
  • polarization – Correction for polarization of the incident beam
  • absorption – Correction for absorption in the sensor volume
  • normalization_factor – final value is divided by this
  • empty – value to be given for empty bins
  • variance – variance of the data
  • dark_variance – variance of the dark
  • poissonian – set to True to consider the variance is equal to raw signal (minimum 1)
  • dtype – type for working: float32 or float64

All calculation are performed in the dtype precision

NaN are always considered as invalid

if neither empty nor dummy is provided, empty pixels are 0

pyFAI.ext.preproc.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.reconstruct module

Cython module to reconstruct the masked values of an image.

It’s a simple inpainting module for reconstructing the missing part of an image (masked) to be able to use more common algorithms.

pyFAI.ext.reconstruct.reconstruct

reconstruct missing part of an image (tries to be continuous)

Parameters:
  • data – the input image
  • mask – where data should be reconstructed.
  • dummy – value of the dummy (masked out) data
  • delta_dummy – precision for dummy values
Returns:

reconstructed image.

pyFAI.ext.relabel module

Module providing features to relabel regions.

It is used to flag from largest regions to the smallest.

pyFAI.ext.relabel.countThem

Count

Parameters:
  • label – 2D array containing labeled zones
  • data – 2D array containing the raw data
  • blured – 2D array containing the blured data
Returns:

2D arrays containing:

  • count pixels in labeled zone: label == index).sum()
  • max of data in that zone: data[label == index].max()
  • max of blurred in that zone: blured[label == index].max()
  • data-blurred where data is max.

pyFAI.ext.setup module

pyFAI.ext.setup.configuration(parent_package='', top_path=None)
pyFAI.ext.setup.create_extension_config(name, extra_sources=None, can_use_openmp=False, language='c')

Util function to create numpy extension from the current pyFAI project.

Prefer using numpy add_extension without it.

pyFAI.ext.sparse_builder module

class pyFAI.ext.sparse_builder.SparseBuilder(nbin, mode=u'block', block_size=512, heap_size=0)

Bases: object

This class provade an API to build a sparse matrix from bin data

It provides different internal structure to be able to use it in different context. It can boost a fast insert, or speed up fast convertion to CSR format.

Param:

int nbin: Number of bin to store

Parameters:
  • mode (str) –

    Internal structure used to store the data:

    • ”pack”: Alloc a heap_size and feed it with tuple (bin, indice, value).
      The insert is very fast, conversion to CSR is done using sequencial read and a random write.
    • ”heaplist”: Alloc a heap_size and feed it with a linked list per bins
      containing (indice, value, next). The insert is very fast, conversion to CSR is done using random read and a sequencial write.
    • ”block”: Alloc block_size per bins and feed it with values and indices.
      The conversion to CSR is done sequencially using block copy. The heap_size should be a multiple of the block_size. If the heap_size is zero, block are allocated one by one without management.
    • ”stdlist”: Use standard C++ list. It is head as reference for testing.
  • block_size (Union[None|int]) – Number of element in a block if used. If more space is needed another block are allocated on the fly.
  • heap_size (Union[None|int]) – Number of element in the global memory managment. This system allocation a single time memory for many needs. It reduce the overhead of memory allocation. If set to None or 0, this management is disabled.
__init__

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

get_bin_coefs

Returns the values stored in a specific bin.

Parameters:bin_id (int) – Index of the bin
Return type:numpy.array
get_bin_indexes

Returns the indices stored in a specific bin.

Parameters:bin_id (int) – Index of the bin
Return type:numpy.array
get_bin_size

Returns the size of a specific bin.

Parameters:bin_id (int) – Number of the bin requested
Return type:int
get_bin_sizes

Returns the size of all the bins.

Return type:numpy.ndarray(dtype=int)
insert

Insert an indice and a value in a specific bin.

Parameters:
  • bin_id (int) – Index of the bin
  • index (int) – Indice of the data to store
  • coef (int) – Value of the data to store
mode

Returns the storage mode used by the builder.

Return type:str
size

Returns the number of elements contained in the structure.

Return type:int
to_csr

Returns a CSR representation from the stored data.

  • The first array contains all floating values. Sorted by bin number.
  • The second array contains all indices. Sorted by bin number.
  • Lookup table from the bin index to the first index in the 2 first
    arrays. array[10 + 0] contains the index of the first element of the bin 10. array[10 + 1] - 1 is the last elements. This array always starts with 0 and contains one more element than the number of bins.
Return type:Tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)
Returns:A tuple containing values, indices and bin indexes
to_lut

Returns a LUT representation from the stored data.

  • The first array contains all floating values. Sorted by bin number.
  • The second array contains all indices. Sorted by bin number.
  • Lookup table from the bin index to the first index in the 2 first
    arrays. array[10 + 0] contains the index of the first element of the bin 10. array[10 + 1] - 1 is the last elements. This array always starts with 0 and contains one more element than the number of bins.
Return type:numpy.ndarray
Returns:A 2D array tuple containing values, indices and bin indexes
pyFAI.ext.sparse_builder.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.sparse_builder.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.sparse_builder.feed_histogram

Missing docstring for feed_histogram Is this just a demo ?

warning:
  • Unused argument ‘empty’
  • Unused argument ‘normalization_factor’
pyFAI.ext.sparse_builder.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.sparse_utils module

Common Look-Up table/CSR object creation tools and conversion

class pyFAI.ext.sparse_utils.ArrayBuilder

Bases: object

Sparse matrix builder: deprecated, please use sparse_builder

append

Python wrapper for _append in cython

as_CSR
as_LUT
nbytes

Calculate the actual size of the object (in bytes)

size
pyFAI.ext.sparse_utils.CSR_to_LUT

Conversion between sparse matrix representations

Parameters:
  • data – coef of the sparse matrix as 1D array
  • indices – index of the col position in input array as 1D array
  • indptr – index of the start of the row in the indices array
Returns:

the same matrix as LUT representation

Return type:

record array of (int idx, float coef)

class pyFAI.ext.sparse_utils.CsrIntegrator(tuple lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
data
empty
indices
indptr
input_size
integrate

CsrIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

nnz
output_size
sigma_clip

Perform a sigma-clipping iterative filter within each along each row. see the doc of scipy.stats.sigmaclip for more descriptions.

If the error model is “azimuthal”: the variance is the variance within a bin, which is refined at each iteration, can be costly !

Else, the error is propagated according to:

\[signal = (raw - dark) variance = variance + dark_variance normalization = normalization_factor*(flat * solidangle * polarization * absortoption) count = number of pixel contributing\]

Integration is performed using the CSR representation of the look-up table on all arrays: signal, variance, normalization and count

The threshold can automaticlly be calculated from Chauvenet’s: sqrt(2*log(nbpix/sqrt(2.0f*pi)))

Parameters:
  • weights (ndarray) – input image
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • variance (ndarray) – the variance associate to the image
  • dark_variance (ndarray) – the variance associate to the dark
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • safe – set to True to save some tests
  • error_model – set to “poissonian” to use signal as variance (minimum 1), “azimuthal” to use the variance in a ring.
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

pyFAI.ext.sparse_utils.LUT_to_CSR

Conversion between sparse matrix representations

Parameters:lut – Look-up table as 2D array of (int idx, float coef)
Returns:the same matrix as CSR representation
Return type:3-tuple of numpy array (data, indices, indptr)
class pyFAI.ext.sparse_utils.LutIntegrator(lut_t[:, ::1] lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses LUT format with main attributes: * width: width of the LUT * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
empty
input_size
integrate

LutIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

lut

Getter a copy of the LUT as an actual numpy array

lut_size
output_size
class pyFAI.ext.sparse_utils.Vector

Bases: object

Variable size vector: deprecated, please use sparse_builder

allocated
append

Python implementation of _append in cython

get_data
nbytes

Calculate the actual size of the object (in bytes)

size
pyFAI.ext.sparse_utils.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.sparse_utils.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.sparse_utils.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitBBox module

Calculates histograms of pos0 (tth) weighted by Intensity

Splitting is done on the pixel’s bounding box similar to fit2D

pyFAI.ext.splitBBox.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitBBox.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitBBox.histoBBox1d

Calculates histogram of pos0 (tth) weighted by weights

Splitting is done on the pixel’s bounding box like fit2D

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

2theta, I, weighted histogram, unweighted histogram

pyFAI.ext.splitBBox.histoBBox1d_engine

Calculates histogram of pos0 (tth) weighted by weights

Splitting is done on the pixel’s bounding box like fit2D New implementation with variance propagation

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
Returns:

namedtuple with “position intensity error signal variance normalization count”

pyFAI.ext.splitBBox.histoBBox1d_ng

histoBBox1d_engine(weights, pos0, delta_pos0, pos1=None, delta_pos1=None, Py_ssize_t bins=100, pos0_range=None, pos1_range=None, dummy=None, delta_dummy=None, mask=None, variance=None, dark=None, flat=None, solidangle=None, polarization=None, bool allow_pos0_neg=False, data_t empty=0.0, double normalization_factor=1.0)

Calculates histogram of pos0 (tth) weighted by weights

Splitting is done on the pixel’s bounding box like fit2D New implementation with variance propagation

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
Returns:

namedtuple with “position intensity error signal variance normalization count”

pyFAI.ext.splitBBox.histoBBox2d

Calculate 2D histogram of pos0(tth),pos1(chi) weighted by weights

Splitting is done on the pixel’s bounding box like fit2D

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
  • clip_pos1 – clip the azimuthal range to -pi/pi (or 0-2pi), set to False to deactivate behavior
Returns:

I, bin_centers0, bin_centers1, weighted histogram(2D), unweighted histogram (2D)

pyFAI.ext.splitBBox.histoBBox2d_engine

Calculate 2D histogram of pos0(tth),pos1(chi) weighted by weights

Splitting is done on the pixel’s bounding box, similar to fit2D New implementation with variance propagation

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • variance – variance associated with the weights
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
  • clip_pos1 – clip the azimuthal range to [-pi pi] (or [0 2pi]), set to False to deactivate behavior
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.splitBBox.histoBBox2d_ng

histoBBox2d_engine(weights, pos0, delta_pos0, pos1, delta_pos1, bins=(100, 36), pos0_range=None, pos1_range=None, dummy=None, delta_dummy=None, mask=None, variance=None, dark=None, flat=None, solidangle=None, polarization=None, bool allow_pos0_neg=False, bool chiDiscAtPi=1, data_t empty=0.0, double normalization_factor=1.0, bool clip_pos1=True)

Calculate 2D histogram of pos0(tth),pos1(chi) weighted by weights

Splitting is done on the pixel’s bounding box, similar to fit2D New implementation with variance propagation

Parameters:
  • weights – array with intensities
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels & value of “no good” pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • variance – variance associated with the weights
  • dark – array (of float32) with dark noise to be subtracted (or None)
  • flat – array (of float32) with flat-field image
  • solidangle – array (of float32) with solid angle corrections
  • polarization – array (of float32) with polarization corrections
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the result by this value
  • clip_pos1 – clip the azimuthal range to [-pi pi] (or [0 2pi]), set to False to deactivate behavior
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.splitBBox.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitBBoxCSR module

Calculates histograms of pos0 (tth) weighted by Intensity

Splitting is done on the pixel’s bounding box like fit2D, reverse implementation based on a sparse matrix multiplication

class pyFAI.ext.splitBBoxCSR.CsrIntegrator(tuple lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
data
empty
indices
indptr
input_size
integrate

CsrIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

nnz
output_size
sigma_clip

Perform a sigma-clipping iterative filter within each along each row. see the doc of scipy.stats.sigmaclip for more descriptions.

If the error model is “azimuthal”: the variance is the variance within a bin, which is refined at each iteration, can be costly !

Else, the error is propagated according to:

\[signal = (raw - dark) variance = variance + dark_variance normalization = normalization_factor*(flat * solidangle * polarization * absortoption) count = number of pixel contributing\]

Integration is performed using the CSR representation of the look-up table on all arrays: signal, variance, normalization and count

The threshold can automaticlly be calculated from Chauvenet’s: sqrt(2*log(nbpix/sqrt(2.0f*pi)))

Parameters:
  • weights (ndarray) – input image
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • variance (ndarray) – the variance associate to the image
  • dark_variance (ndarray) – the variance associate to the dark
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • safe – set to True to save some tests
  • error_model – set to “poissonian” to use signal as variance (minimum 1), “azimuthal” to use the variance in a ring.
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

class pyFAI.ext.splitBBoxCSR.HistoBBox1d

Bases: pyFAI.ext.splitBBoxCSR.CsrIntegrator, pyFAI.ext.splitBBox_common.SplitBBoxIntegrator

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]

__init__
Parameters:
  • pos0 – 1D array with pos0: tth or q_vect or r …
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins, 100 by default
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins without contributing pixels
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
  • clip_pos1 – clip the azimuthal range to [-π π] (or [0 2π] depending on chiDiscAtPi), set to False to deactivate behavior
check_mask
outPos
class pyFAI.ext.splitBBoxCSR.HistoBBox2d

Bases: pyFAI.ext.splitBBoxCSR.CsrIntegrator, pyFAI.ext.splitBBox_common.SplitBBoxIntegrator

2D histogramming with pixel splitting based on a look-up table stored in CSR format

The initialization of the class can take quite a while (operation are not parallelized) but each integrate is parallelized and efficient.

__init__
Parameters:
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins where no pixels are contributing
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0 (0° when False) or π (180° when True)
  • clip_pos1 – clip the azimuthal range to [-π π] (or [0 2π] depending on chiDiscAtPi), set to False to deactivate behavior
check_mask
outPos0
outPos1
pyFAI.ext.splitBBoxCSR.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitBBoxCSR.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitBBoxCSR.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitBBoxLUT module

Calculates histograms of pos0 (tth) weighted by Intensity

Splitting is done on the pixel’s bounding box like fit2D, reverse implementation based on a sparse matrix multiplication

class pyFAI.ext.splitBBoxLUT.HistoBBox1d

Bases: pyFAI.ext.splitBBoxLUT.LutIntegrator, pyFAI.ext.splitBBox_common.SplitBBoxIntegrator

1D histogramming with pixel splitting based on a Look-up table

The initialization of the class can take quite a while (operation are not parallelized) but each integrate is parallelized and quite efficient.

__init__
Parameters:
  • pos0 – 1D array with pos0: tth or q_vect or r …
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins, 100 by default
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins without contributing pixels
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
  • clip_pos1 – clip the azimuthal range to [-π π] (or [0 2π] depending on chiDiscAtPi), set to False to deactivate behavior
check_mask
outPos
class pyFAI.ext.splitBBoxLUT.HistoBBox2d

Bases: pyFAI.ext.splitBBoxLUT.LutIntegrator, pyFAI.ext.splitBBox_common.SplitBBoxIntegrator

2D histogramming with pixel splitting based on a look-up table

The initialization of the class can take quite a while (operation are not parallelized) but each integrate is parallelized and efficient.

__init__
Parameters:
  • pos0 – 1D array with pos0: tth or q_vect
  • delta_pos0 – 1D array with delta pos0: max center-corner distance
  • pos1 – 1D array with pos1: chi
  • delta_pos1 – 1D array with max pos1: max center-corner distance, unused !
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins where no pixels are contributing
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0 (0° when False) or π (180° when True)
  • clip_pos1 – clip the azimuthal range to [-π π] (or [0 2π] depending on chiDiscAtPi), set to False to deactivate behavior
check_mask
outPos0
outPos1
class pyFAI.ext.splitBBoxLUT.LutIntegrator(lut_t[:, ::1] lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses LUT format with main attributes: * width: width of the LUT * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
empty
input_size
integrate

LutIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

lut

Getter a copy of the LUT as an actual numpy array

lut_size
output_size
pyFAI.ext.splitBBoxLUT.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitBBoxLUT.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitBBoxLUT.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitPixel module

Calculates histograms of pos0 (tth) weighted by Intensity

Splitting is done by full pixel splitting Histogram (direct) implementation

pyFAI.ext.splitPixel.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitPixel.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitPixel.fullSplit1D

Calculates histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box like fit2D. No compromise for speed has been made here.

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64) with flat image
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
Returns:

2theta, I, weighted histogram, unweighted histogram

pyFAI.ext.splitPixel.fullSplit1D_engine

Calculates histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box like fit2D. New implementation with variance propagation

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64) with flat image
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
Returns:

namedtuple with “position intensity error signal variance normalization count”

pyFAI.ext.splitPixel.fullSplit1D_ng

fullSplit1D_engine(pos, weights, Py_ssize_t bins=100, pos0_range=None, pos1_range=None, dummy=None, delta_dummy=None, mask=None, variance=None, dark=None, flat=None, solidangle=None, polarization=None, data_t empty=0.0, double normalization_factor=1.0, bool allow_pos0_neg=False, bool chiDiscAtPi=True)

Calculates histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box like fit2D. New implementation with variance propagation

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64) with flat image
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
Returns:

namedtuple with “position intensity error signal variance normalization count”

pyFAI.ext.splitPixel.fullSplit2D

Calculate 2D histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box like fit2D

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat-field image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64)with solid angle corrections
  • allow_pos0_neg – allow radial dimention to be negative (useful in log-scale!)
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

I, edges0, edges1, weighted histogram(2D), unweighted histogram (2D)

pyFAI.ext.splitPixel.fullSplit2D_engine

Calculate 2D histogram of pos weighted by weights

Splitting is done on the pixel’s boundary (straight segments) New implementation with variance propagation

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • variance – variance associated with the weights
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat-field image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64)with solid angle corrections
  • allow_pos0_neg – set to true to allow negative radial values.
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.splitPixel.pseudoSplit2D_engine

Calculate 2D histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box, similar to fit2D New implementation with variance propagation

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • variance – variance associated with the weights
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat-field image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64)with solid angle corrections
  • allow_pos0_neg – set to true to allow negative radial values.
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.splitPixel.pseudoSplit2D_ng

pseudoSplit2D_engine(pos, weights, bins, pos0_range=None, pos1_range=None, dummy=None, delta_dummy=None, mask=None, variance=None, dark=None, flat=None, solidangle=None, polarization=None, bool allow_pos0_neg=0, bool chiDiscAtPi=1, float empty=0.0, double normalization_factor=1.0)

Calculate 2D histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box, similar to fit2D New implementation with variance propagation

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • variance – variance associated with the weights
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat-field image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64)with solid angle corrections
  • allow_pos0_neg – set to true to allow negative radial values.
  • chiDiscAtPi – boolean; by default the chi_range is in the range ]-pi,pi[ set to 0 to have the range ]0,2pi[
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
Returns:

Integrate2dtpl namedtuple: “radial azimuthal intensity error signal variance normalization count”

pyFAI.ext.splitPixel.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitPixelFull module

Calculates histograms of pos0 (tth) weighted by Intensity

Splitting is done on the pixel’s bounding box like fit2D, reverse implementation based on a sparse matrix multiplication

pyFAI.ext.splitPixelFull.fullSplit1D(ndarray pos, ndarray weights, size_t bins=100, pos0Range=None, pos1Range=None, dummy=None, delta_dummy=None, mask=None, dark=None, flat=None, solidangle=None, polarization=None, data_t empty=0.0, double normalization_factor=1.0)

Calculates histogram of pos weighted by weights

Splitting is done on the pixel’s bounding box like fit2D. No compromise for speed has been made here.

Parameters:
  • pos – 3D or 4D array with the coordinates of each pixel point
  • weights – array with intensities
  • bins – number of output bins
  • pos0Range – minimum and maximum of the 2th range
  • pos1Range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat image
  • solidangle – array (of float64) with flat image
  • polarization – array (of float64) with polarization correction
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value
Returns:

2theta, I, weighted histogram, unweighted histogram

pyFAI.ext.splitPixelFull.fullSplit2D(ndarray pos, ndarray weights, bins, pos0Range=None, pos1Range=None, dummy=None, delta_dummy=None, mask=None, dark=None, flat=None, solidangle=None, polarization=None, data_t empty=0.0, double normalization_factor=1.0)

Calculate 2D histogram of pos weighted by weights

Parameters:
  • pos – 3D array with pos0; Corner A,B,C,D; tth or chi
  • weights – array with intensities
  • bins – number of output bins int or 2-tuple of int
  • pos0Range – minimum and maximum of the 2th range
  • pos1Range – minimum and maximum of the chi range
  • dummy – value for bins without pixels
  • delta_dummy – precision of dummy value
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • dark – array (of float64) with dark noise to be subtracted (or None)
  • flat – array (of float64) with flat-field image
  • polarization – array (of float64) with polarization correction
  • solidangle – array (of float64)with solid angle corrections
  • empty – value of output bins without any contribution when dummy is None
  • normalization_factor – divide the valid result by this value

TODO: warning: pyFAI/ext/splitPixelFull.pyx:400:16: Unused argument ‘normalization_factor’

Returns:I, edges0, edges1, weighted histogram(2D), unweighted histogram (2D)

pyFAI.ext.splitPixelFullCSR module

Full pixel Splitting implemented using Sparse-matrix Dense-Vector multiplication, Sparse matrix represented using the CompressedSparseRow.

class pyFAI.ext.splitPixelFullCSR.CsrIntegrator(tuple lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
data
empty
indices
indptr
input_size
integrate

CsrIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – set to 2 for variance propagation, leave to 1 for mean calculation
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

nnz
output_size
sigma_clip

Perform a sigma-clipping iterative filter within each along each row. see the doc of scipy.stats.sigmaclip for more descriptions.

If the error model is “azimuthal”: the variance is the variance within a bin, which is refined at each iteration, can be costly !

Else, the error is propagated according to:

\[signal = (raw - dark) variance = variance + dark_variance normalization = normalization_factor*(flat * solidangle * polarization * absortoption) count = number of pixel contributing\]

Integration is performed using the CSR representation of the look-up table on all arrays: signal, variance, normalization and count

The threshold can automaticlly be calculated from Chauvenet’s: sqrt(2*log(nbpix/sqrt(2.0f*pi)))

Parameters:
  • weights (ndarray) – input image
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • variance (ndarray) – the variance associate to the image
  • dark_variance (ndarray) – the variance associate to the dark
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • safe – set to True to save some tests
  • error_model – set to “poissonian” to use signal as variance (minimum 1), “azimuthal” to use the variance in a ring.
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

class pyFAI.ext.splitPixelFullCSR.FullSplitCSR_1d

Bases: pyFAI.ext.splitPixelFullCSR.CsrIntegrator, pyFAI.ext.splitpixel_common.FullSplitIntegrator

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]

__init__
Parameters:
  • pos – 3D or 4D array with the coordinates of each pixel point
  • bins – number of output bins, 100 by default
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value of output bins without any contribution when dummy is None
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
check_mask
outPos
class pyFAI.ext.splitPixelFullCSR.FullSplitCSR_2d

Bases: pyFAI.ext.splitPixelFullCSR.CsrIntegrator, pyFAI.ext.splitpixel_common.FullSplitIntegrator

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]

__init__
Parameters:
  • pos – 3D or 4D array with the coordinates of each pixel point
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins where no pixels are contributing
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
check_mask
outPos0
outPos1
pyFAI.ext.splitPixelFullCSR.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitPixelFullCSR.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitPixelFullCSR.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.splitPixelFullLUT module

Full pixel Splitting implemented using Sparse-matrix Dense-Vector multiplication, Sparse matrix represented using the LUT representation.

class pyFAI.ext.splitPixelFullLUT.HistoLUT1dFullSplit

Bases: pyFAI.ext.splitPixelFullLUT.LutIntegrator, pyFAI.ext.splitpixel_common.FullSplitIntegrator

Now uses LUT representation for the integration

__init__
Parameters:
  • pos – 3D or 4D array with the coordinates of each pixel point
  • bins – number of output bins, 100 by default
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value of output bins without any contribution when dummy is None
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
check_mask
outPos
class pyFAI.ext.splitPixelFullLUT.HistoLUT2dFullSplit

Bases: pyFAI.ext.splitPixelFullLUT.LutIntegrator, pyFAI.ext.splitpixel_common.FullSplitIntegrator

Now uses CSR (Compressed Sparse raw) with main attributes: * nnz: number of non zero elements * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]

__init__
Parameters:
  • pos – 3D or 4D array with the coordinates of each pixel point
  • bins – number of output bins (tth=100, chi=36 by default)
  • pos0_range – minimum and maximum of the 2th range
  • pos1_range – minimum and maximum of the chi range
  • mask – array (of int8) with masked pixels with 1 (0=not masked)
  • allow_pos0_neg – enforce the q<0 is usually not possible
  • unit – can be 2th_deg or r_nm^-1 …
  • empty – value for bins where no pixels are contributing
  • chiDiscAtPi – tell if azimuthal discontinuity is at 0° or 180°
check_mask
class pyFAI.ext.splitPixelFullLUT.LutIntegrator(lut_t[:, ::1] lut, int image_size, data_t empty=0.0)

Bases: object

Abstract class which implements only the integrator…

Now uses LUT format with main attributes: * width: width of the LUT * data: coefficient of the matrix in a 1D vector of float32 * indices: Column index position for the data (same size as * indptr: row pointer indicates the start of a given row. len nrow+1

Nota: nnz = indptr[-1]+1 = len(indices) = len(data)

__init__

Constructor for a CSR generic integrator

Parameters:
  • lut – Sparse matrix in CSR format, tuple of 3 arrays with (data, indices, indptr)
  • size – input image size
  • empty – value for empty pixels
empty
input_size
integrate

LutIntegrator.integrate_legacy(self, weights, dummy=None, delta_dummy=None, dark=None, flat=None, solidAngle=None, polarization=None, double normalization_factor=1.0, int coef_power=1)

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_legacy

Actually perform the integration which in this case looks more like a matrix-vector product

Parameters:
  • weights (ndarray) – input image
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • normalization_factor – divide the valid result by this value
  • coef_power – put coef to a given power, 2 for variance, 1 for mean
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

4-tuple of ndarrays

integrate_ng
Actually perform the integration which in this case consists of:
  • Calculate the signal, variance and the normalization parts
  • Perform the integration which is here a matrix-vector product
Parameters:
  • weights (ndarray) – input image
  • variance (ndarray) – the variance associate to the image
  • poissonian – set to use signal as variance (minimum 1), set to False to use azimuthal model.
  • dummy (float) – value for dead pixels (optional)
  • delta_dummy (float) – precision for dead-pixel value in dynamic masking
  • dark (ndarray) – array with the dark-current value to be subtracted (if any)
  • flat (ndarray) – array with the dark-current value to be divided by (if any)
  • solidAngle (ndarray) – array with the solid angle of each pixel to be divided by (if any)
  • polarization (ndarray) – array with the polarization correction values to be divided by (if any)
  • absorption (ndarray) – Apparent efficiency of a pixel due to parallax effect
  • normalization_factor – divide the valid result by this value
Returns:

positions, pattern, weighted_histogram and unweighted_histogram

Return type:

Integrate1dtpl 4-named-tuple of ndarrays

lut

Getter a copy of the LUT as an actual numpy array

lut_size
output_size
pyFAI.ext.splitPixelFullLUT.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext.splitPixelFullLUT.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext.splitPixelFullLUT.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext.watershed module

Peak peaking via inverse watershed for connecting region of high intensity

class pyFAI.ext.watershed.Bilinear

Bases: object

Bilinear interpolator for finding max.

Instance attribute defined in pxd file

cp_local_maxi
data
f_cy

Function -f((y,x)) where f is a continuous function (y,x) are pixel coordinates pixels outside the image are given an arbitrary high value to help the minimizer

Parameters:x – 2-tuple of float
Returns:Interpolated negative signal from the image (negative for using minimizer to search for peaks)
height
local_maxi

Return the local maximum with sub-pixel refinement.

Sub-pixel refinement: Second order Taylor expansion of the function; first derivative is null

\[delta = x-i = -Inverse[Hessian].gradient\]

If Hessian is singular or \(|delta|>1\): use a center of mass.

Parameters:x – 2-tuple of integers
Returns:2-tuple of float with the nearest local maximum
maxi
mini
width
class pyFAI.ext.watershed.InverseWatershed

Bases: object

Idea:

  • label all peaks
  • define region around those peaks which raise always to this peak
  • define the border of such region
  • search for the pass between two peaks
  • merge region with high pass between them
NAME = 'Inverse watershed'
VERSION = '1.0'
__init__
Parameters:data – 2d image as numpy array
init
init_borders
init_labels
init_pass
init_regions
classmethod load(cls, fname)

Load data from a HDF5 file

merge_intense

Merge groups then (pass-mini)/(maxi-mini) >=thres

merge_singleton

merge single pixel region

merge_twins

Twins are two peak region which are best linked together: A -> B and B -> A

peaks_from_area
Parameters:
  • mask – mask of data points valid
  • Imin – Minimum intensity for a peak
  • keep – Number of points to keep
  • refine – refine sub-pixel position
  • dmin – minimum distance from
save

Save all regions into a HDF5 file

class pyFAI.ext.watershed.Region

Bases: object

border
get_borders
get_highest_pass
get_index
get_maxi
get_mini
get_neighbors
get_pass_to
get_size
highest_pass
index
init_values

Initialize the values : maxi, mini and pass both height and so on :param flat: flat view on the data (intensity) :return: True if there is a problem and the region should be removed

maxi
merge

merge 2 regions

mini
neighbors
pass_to
peaks
size

Module contents

Package containing all Cython binary extensions

pyFAI.ext private package

ext._bispev Module

Module containing a re-implementation of bi-cubic spline evaluation from scipy.

pyFAI.ext._bispev.bisplev

Evaluate a bivariate B-spline and its derivatives.

Return a rank-2 array of spline function values (or spline derivative values) at points given by the cross-product of the rank-1 arrays x and y. In special cases, return an array or just a float if either x or y or both are floats. Based on BISPEV from FITPACK.

See bisplrep() to generate the tck representation.

See also splprep(), splrep(), splint(), sproot(), splev(), UnivariateSpline(), BivariateSpline()

References: [1], [2], [3].

[1]Dierckx P. : An algorithm for surface fitting with spline functions Ima J. Numer. Anal. 1 (1981) 267-283.
[2]Dierckx P. : An algorithm for surface fitting with spline functions report tw50, Dept. Computer Science,K.U.Leuven, 1980.
[3]Dierckx P. : Curve and surface fitting with splines, Monographs on Numerical Analysis, Oxford University Press, 1993.
Parameters:
  • x (ndarray) – Rank-1 arrays specifying the domain over which to evaluate the spline or its derivative.
  • y (ndarray) – Rank-1 arrays specifying the domain over which to evaluate the spline or its derivative.
  • tck (tuple) – A sequence of length 5 returned by bisplrep containing the knot locations, the coefficients, and the degree of the spline: [tx, ty, c, kx, ky].
  • dx (int) – The orders of the partial derivatives in x. This version does not implement derivatives.
  • dy (int) – The orders of the partial derivatives in y. This version does not implement derivatives.
Return type:

ndarray

Returns:

The B-spline or its derivative evaluated over the set formed by the cross-product of x and y.

ext._blob Module

Some Cythonized function for blob detection function.

It is used to find peaks in images by performing subsequent blurs.

pyFAI.ext._blob.local_max

Calculate if a point is a maximum in a 3D space: (scale, y, x)

Parameters:
  • dogs – 3D array of difference of gaussian
  • mask – mask with invalid pixels
  • N_5 – take a neighborhood of 5x5 pixel in plane
Returns:

3d_array with 1 where is_max

ext._convolution Module

Implementation of a separable 2D convolution.

It is used in real space are used to blurs images, used in blob-detection algorithm.

pyFAI.ext._convolution.gaussian

Return a Gaussian window of length “width” with standard-deviation “sigma”.

Parameters:
  • sigma – standard deviation sigma
  • width – length of the windows (int) By default 8*sigma+1,

Width should be odd.

The FWHM is 2*sqrt(2 * pi)*sigma

pyFAI.ext._convolution.gaussian_filter

Performs a gaussian bluring using a gaussian kernel.

Parameters:
  • img – input image
  • sigma – width parameter of the gaussian
pyFAI.ext._convolution.horizontal_convolution

Implements a 1D horizontal convolution with a filter. The only implemented mode is “reflect” (default in scipy.ndimage.filter)

Use Mixed precision accumulator

Parameters:
  • img – input image
  • filter – 1D array with the coefficients of the array
Returns:

array of the same shape as image with

pyFAI.ext._convolution.vertical_convolution

Implements a 1D vertical convolution with a filter. The only implemented mode is “reflect” (default in scipy.ndimage.filter)

Use Mixed precision accumulator

Parameters:
  • img – input image
  • filter – 1D array with the coefficients of the array
Returns:

array of the same shape as image with

ext._distortion Module

Distortion correction are correction are applied by look-up table (or CSR)

class pyFAI.ext._distortion.Distortion

Bases: object

This class applies a distortion correction on an image.

It is also able to apply an inversion of the correction.

__init__
Parameters:detector – detector instance or detector name
calc_LUT
calc_LUT_size

Considering the “half-CCD” spline from ID11 which describes a (1025,2048) detector, the physical location of pixels should go from: [-17.48634 : 1027.0543, -22.768829 : 2028.3689] We chose to discard pixels falling outside the [0:1025,0:2048] range with a lose of intensity

We keep self.pos: pos_corners will not be compatible with systems showing non adjacent pixels (like some xpads)

calc_pos
correct

Correct an image based on the look-up table calculated …

Parameters:image – 2D-array with the image
Returns:corrected 2D image
uncorrect

Take an image which has been corrected and transform it into it’s raw (with loss of information)

Parameters:image – 2D-array with the image
Returns:uncorrected 2D image and a mask (pixels in raw image
pyFAI.ext._distortion.calc_CSR

Calculate the Look-up table as CSR format

Parameters:
  • pos – 4D position array
  • shape – output shape
  • bin_size – number of input element per output element (as numpy array)
  • max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
  • mask – array with invalid pixels marked
  • offset – global offset for pixel coordinates
Returns:

look-up table in CSR format: 3-tuple of array

pyFAI.ext._distortion.calc_LUT
Parameters:
  • pos – 4D position array
  • shape – output shape
  • bin_size – number of input element per output element (numpy array)
  • max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
  • mask – arry with bad pixels marked as True
  • offset – global offset for pixel position
Returns:

look-up table

pyFAI.ext._distortion.calc_area

Calculate the area between I1 and I2 of a line with a given slope & intercept

pyFAI.ext._distortion.calc_pos

Calculate the pixel boundary position on the regular grid

Parameters:
  • pixel_corners – pixel corner coordinate as detector.get_pixel_corner()
  • shape – requested output shape. If None, it is calculated
  • pixel2 (pixel1,) – pixel size along row and column coordinates
Returns:

pos, delta1, delta2, shape_out, offset

pyFAI.ext._distortion.calc_size

Calculate the number of items per output pixel

Parameters:
  • pos – 4D array with position in space
  • shape – shape of the output array
  • mask – input data mask
  • offset – 2-tuple of float with the minimal index of
Returns:

number of input element per output elements

pyFAI.ext._distortion.calc_sparse

Calculate the look-up table (or CSR) using OpenMP

Parameters:
  • pos – 4D position array
  • shape – output shape
  • max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
  • mask – array with invalid pixels marked (True)
  • format – can be “CSR” or “LUT”
  • bins_per_pixel – average splitting factor (number of pixels per bin)
  • offset – global pixel offset
Returns:

look-up table in CSR/LUT format

pyFAI.ext._distortion.calc_sparse_v2

Calculate the look-up table (or CSR) using OpenMP :param pos: 4D position array :param shape: output shape :param max_pixel_size: (2-tuple of int) size of a buffer covering the largest pixel :param format: can be “CSR” or “LUT” :param bins_per_pixel: average splitting factor (number of pixels per bin) #deprecated :return: look-up table in CSR/LUT format

pyFAI.ext._distortion.clip

Limits the value to bounds

Parameters:
  • value – the value to clip
  • min_value – the lower bound
  • max_value – the upper bound
Returns:

clipped value in the requested range

pyFAI.ext._distortion.correct

Correct an image based on the look-up table calculated … dispatch according to LUT type

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 2D-array of struct
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
  • method – integration method: can be “kahan” using single precision compensated for error or “double” in double precision (64 bits)
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_CSR

Correct an image based on the look-up table calculated …

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 3-tuple array of ndarray
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
  • variance – unused for now … TODO: propagate variance.
  • method – integration method: can be “kahan” using single precision compensated for error or “double” in double precision (64 bits)
Returns:

corrected 2D image

Nota: patch image on proper buffer size if needed.

pyFAI.ext._distortion.correct_CSR_double

Correct an image based on the look-up table calculated … using double precision accumulator

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 3-tuple array of ndarray
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_CSR_kahan

Correct an image based on the look-up table calculated … using kahan’s error compensated algorithm

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 3-tuple array of ndarray
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_CSR_preproc_double

Correct an image based on the look-up table calculated … implementation using double precision accumulator

Parameters:
  • image – 2D-array with the image (signal, variance, normalization)
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 3-tuple array of ndarray
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
  • empty – numerical value for empty pixels (if dummy is not provided)
  • method – integration method: can be “kahan” using single precision compensated for error or “double” in double precision (64 bits)
Returns:

corrected 2D image + array with (signal, variance, norm)

pyFAI.ext._distortion.correct_LUT

Correct an image based on the look-up table calculated … dispatch between kahan and double

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 2D-array of struct
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
  • method – integration method: can be “kahan” using single precision compensated for error or “double” in double precision (64 bits)
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_LUT_double

Correct an image based on the look-up table calculated … double precision accumulated

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 2D-array of struct
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_LUT_kahan

Correct an image based on the look-up table calculated …

Parameters:
  • image – 2D-array with the image
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 2D-array of struct
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
Returns:

corrected 2D image

pyFAI.ext._distortion.correct_LUT_preproc_double

Correct an image based on the look-up table calculated … implementation using double precision accumulator

Parameters:
  • image – 2D-array with the image (signal, variance, normalization)
  • shape_in – shape of input image
  • shape_out – shape of output image
  • LUT – Look up table, here a 2D-array of struct
  • dummy – value for invalid pixels
  • delta_dummy – precision for invalid pixels
  • empty – numerical value for empty pixels (if dummy is not provided)
  • method – integration method: can be “kahan” using single precision compensated for error or “double” in double precision (64 bits)
Returns:

corrected 2D image + array with (signal, variance, norm)

pyFAI.ext._distortion.recenter

This function checks the pixel to be on the azimuthal discontinuity via the sign of its algebric area and recenters the corner coordinates in a consistent manner to have all azimuthal coordinate in

Nota: the returned area is negative since the positive area indicate the pixel is on the discontinuity.

Parameters:
  • pixel – 4x2 array with radius, azimuth for the 4 corners. MODIFIED IN PLACE !!!
  • chiDiscAtPi – set to 0 to indicate the range goes from 0-2π instead of the default -π:π
Returns:

signed area (approximate & negative)

pyFAI.ext._distortion.resize_image_2D

Reshape the image in such a way it has the required shape

Parameters:
  • image – 2D-array with the image
  • shape – expected shape of input image
Returns:

2D image with the proper shape

pyFAI.ext._distortion.resize_image_3D

Reshape the image in such a way it has the required shape This version is optimized for n-channel images used after preprocesing like: nlines * ncolumn * (value, variance, normalization)

Parameters:
  • image – 3D-array with the preprocessed image
  • shape – expected shape of input image (2D only)
Returns:

3D image with the proper shape

pyFAI.ext._distortion.uncorrect_CSR

Take an image which has been corrected and transform it into it’s raw (with loss of information)

Parameters:
  • image – 2D-array with the image
  • shape – shape of output image
  • LUT – Look up table, here a 3-tuple of ndarray
Returns:

uncorrected 2D image and a mask (pixels in raw image not existing)

pyFAI.ext._distortion.uncorrect_LUT

Take an image which has been corrected and transform it into it’s raw (with loss of information)

Parameters:
  • image – 2D-array with the image
  • shape – shape of output image
  • LUT – Look up table, here a 2D-array of struct
Returns:

uncorrected 2D image and a mask (pixels in raw image not existing)

ext._geometry Module

This extension is a fast-implementation for calculating the geometry, i.e. where every pixel of an array stays in space (x,y,z) or its (r, \(\chi\)) coordinates.

pyFAI.ext._geometry.calc_chi

Calculate the chi array (azimuthal angles) using OpenMP

X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3)) - L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3) - L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) + sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2) tan(Chi) = X2 / X1

Parameters:
  • L – distance sample - PONI
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
  • chi_discontinuity_at_pi – set to False to obtain chi in the range [0, 2pi[ instead of [-pi, pi[
Returns:

ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_cosa

Calculate the cosine of the incidence angle using OpenMP. Used for sensors thickness effect corrections

Parameters:
  • L – distance sample - PONI
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
Returns:

ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_delta_chi

Calculate the delta chi array (azimuthal angles) using OpenMP

Parameters:
  • centers – numpy array with chi angles of the center of the pixels
  • corners – numpy array with chi angles of the corners of the pixels
Returns:

ndarray of double with same shape and size as centers woth the delta chi per pixel

pyFAI.ext._geometry.calc_pos_zyx

Calculate the 3D coordinates in the sample’s referential

Parameters:
  • L – distance sample - PONI
  • poni1 – PONI coordinate along y axis
  • poni2 – PONI coordinate along x axis
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
Returns:

3-tuple of ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_q

Calculate the q (scattering vector) array using OpenMP

X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3)) - L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3) - L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) + sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2) tan(Chi) = X2 / X1

Parameters:
  • L – distance sample - PONI
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
  • wavelength – in meter to get q in nm-1
Returns:

ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_r

Calculate the radius array (radial direction) in parallel

Parameters:
  • L – distance sample - PONI
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
Returns:

ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_rad_azim

Calculate the radial & azimutal position for each pixel from pos1, pos2, pos3.

Parameters:
  • L – distance sample - PONI
  • poni1 – PONI coordinate along y axis
  • poni2 – PONI coordinate along x axis
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
  • space – can be “2th”, “q” or “r” for radial units. Azimuthal units are radians
  • chi_discontinuity_at_pi – set to False to obtain chi in the range [0, 2pi[ instead of [-pi, pi[
Returns:

ndarray of double with same shape and size as pos1 + (2,),

Raise:

KeyError when space is bad ! ValueError when wavelength is missing

pyFAI.ext._geometry.calc_sina

Calculate the sine of the incidence angle using OpenMP. Used for sensors thickness effect corrections

Parameters:
  • L – distance sample - PONI
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
Returns:

ndarray of double with same shape and size as pos1

pyFAI.ext._geometry.calc_tth

Calculate the 2theta array (radial angle) in parallel

Parameters:
  • L – distance sample - PONI
  • rot1 – angle1
  • rot2 – angle2
  • rot3 – angle3
  • pos1 – numpy array with distances in meter along dim1 from PONI (Y)
  • pos2 – numpy array with distances in meter along dim2 from PONI (X)
  • pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behind the detector
Returns:

ndarray of double with same shape and size as pos1

ext._tree Module

Module used in file hierarchy tree for the diff_map graphical user interface.

class pyFAI.ext._tree.TreeItem(unicode label=None, TreeItem parent=None)

Bases: object

Node of a tree …

Each node contains:

  • children: list
  • parent: TreeItem parent
  • label: str
  • order: int
  • type: str can be “dir”, “file”, “group” or “dataset”
  • extra: any object
__init__

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

add_child
children

children: list

extra

extra: object

first
get
has_child
label

label: unicode

last
name
next
order

order: ‘int’

parent

parent: pyFAI.ext._tree.TreeItem

previous
size
sort
type

type: unicode

update

Add new children in tree