core.dpc Module

This module is for Differential Phase Contrast (DPC) imaging based on Fourier shift fitting

skbeam.core.dpc.dpc_fit(rss, ref_reduction, diff_reduction, start_point, solver='Nelder-Mead', tol=1e-06, max_iters=2000)

Nonlinear fitting for 2 points.

Parameters
rsscallable

Objective function to be minimized in DPC fitting.

ref_reductionndarray

Extra argument passed to the objective function. In DPC, it’s the sum of the reference image data along x or y direction.

diff_reductionndarray

Extra argument passed to the objective function. In DPC, it’s the sum of one captured diffraction pattern along x or y direction.

start_pointlist

start_point[0], start-searching value for the amplitude of the sample transmission function at one scanning point. start_point[1], start-searching value for the phase gradient (along x or y direction) of the sample transmission function at one scanning point.

solverstr, optional

Type of solver, one of the following (default ‘Nelder-Mead’): * ‘Nelder-Mead’ * ‘Powell’ * ‘CG’ * ‘BFGS’ * ‘Anneal’ * ‘L-BFGS-B’ * ‘TNC’ * ‘COBYLA’ * ‘SLSQP’

tolfloat, optional

Termination criteria of nonlinear fitting. Default is 1e-6.

max_itersint, optional

Maximum iterations of nonlinear fitting. Default is 2000.

Returns
tuple

Fitting result: intensity attenuation and phase gradient.

class skbeam.core.dpc.dpc_internal_state(ax, ay, gx, gy, ref_fx, ref_fy, index)

Bases: tuple

property ax

Alias for field number 0

property ay

Alias for field number 1

property gx

Alias for field number 2

property gy

Alias for field number 3

property index

Alias for field number 6

property ref_fx

Alias for field number 4

property ref_fy

Alias for field number 5

skbeam.core.dpc.dpc_runner(ref, image_sequence, start_point, pixel_size, focus_to_det, scan_rows, scan_cols, scan_xstep, scan_ystep, energy, padding=0, weighting=0.5, solver='Nelder-Mead', roi=None, bad_pixels=None, negate=True, scale=True)

Wraps lazy_dpc

See docstring for lazy_dpc and reconstruct_phase_from_partial_info for the input parameters for this function and what it returns

skbeam.core.dpc.image_reduction(im, roi=None, bad_pixels=None)

Sum the image data over rows and columns.

Parameters
imndarray

Input image.

roindarray, optional

[r, c, row, col], selects ROI im[r : r + row, c : c + col]. Default is None, which uses the whole image.

bad_pixelslist, optional

List of (row, column) tuples marking bad pixels. [(1, 5), (2, 6)] –> 2 bad pixels –> (1, 5) and (2, 6). Default is None.

Returns
xlinendarray

The row vector of the sums of each column.

ylinendarray

The column vector of the sums of each row.

skbeam.core.dpc.lazy_dpc(ref, image_sequence, start_point, scan_rows, scan_cols, solver='Nelder-Mead', roi=None, bad_pixels=None, dpc_state=None)

Controller function to run the whole Differential Phase Contrast (DPC) imaging calculation.

Parameters
refndarray

The reference image for a DPC calculation.

image_sequenceiterable of 2D arrays

Return diffraction patterns (2D Numpy arrays) when iterated over.

start_pointlist

start_point[0], start-searching value for the amplitude of the sample transmission function at one scanning point. start_point[1], start-searching value for the phase gradient (along x or y direction) of the sample transmission function at one scanning point.

scan_rowsint

Number of scanned rows.

scan_colsint

Number of scanned columns.

solverstr, optional

Type of solver, one of the following (default ‘Nelder-Mead’): * ‘Nelder-Mead’ * ‘Powell’ * ‘CG’ * ‘BFGS’ * ‘Anneal’ * ‘L-BFGS-B’ * ‘TNC’ * ‘COBYLA’ * ‘SLSQP’

roindarray, optional

[r, c, row, col], selects ROI im[r : r + row, c : c + col]. Default is None.

bad_pixelslist, optional

List of (row, column) tuples marking bad pixels. [(1, 5), (2, 6)] –> 2 bad pixels –> (1, 5) and (2, 6). Default is None.

Yields
dpc_statenamedtuple

The internal state that dpc_runner requires for each iteration. Can be passed to reconstruct_phase_from_partial_info which, along with some additional info, will produce the final phase image

References: text [1]
1

Yan, H. et al. Quantitative x-ray phase imaging at the nanoscale by ..

multilayer Laue lenses. Sci. Rep. 3, 1307; DOI:10.1038/srep01307 (2013).
skbeam.core.dpc.recon(gx, gy, scan_xstep, scan_ystep, padding=0, weighting=0.5)

Reconstruct the final phase image.

Parameters
gxndarray

Phase gradient along x direction.

gyndarray

Phase gradient along y direction.

scan_xstepfloat

Scanning step size in x direction (in micro-meter).

scan_ystepfloat

Scanning step size in y direction (in micro-meter).

paddingint, optional

Pad a N-by-M array to be a (N*(2*padding+1))-by-(M*(2*padding+1)) array with the image in the middle with a (N*padding, M*padding) thick edge of zeros. Default is 0.

padding = 0 –> v (the original image, size = (N, M))

0 0 0

padding = 1 –> 0 v 0 (the padded image, size = (3 * N, 3 * M))

0 0 0

weightingfloat, optional

Weighting parameter for the phase gradient along x and y direction when constructing the final phase image. Valid in [0, 1]. Default value = 0.5, which means that gx and gy equally contribute to the final phase image.

Returns
phasendarray

Final phase image.

skbeam.core.dpc.reconstruct_phase_from_partial_info(dpc_state, energy, scan_xstep, scan_ystep, pixel_size=None, focus_to_det=None, negate=True, scale=True, padding=0, weighting=0.5)

Using the partial results from dpc_runner, reconstruct the phase image

Parameters
dpc_statenamedtuple

The thing yielded from dpc_runner

energyfloat

Energy of the scanning x-ray in keV.

focus_to_detfloat

Focus to detector distance in um.

scan_xstepfloat

Scanning step size in x direction (in micro-meter).

scan_ystepfloat

Scanning step size in y direction (in micro-meter).

pixel_sizeNumber, optional

The size of the detector pixels. Pixels must be square. If pixel_size and `focus_to_det are provided, it is assumed that you want to scale the image.

focus_to_detNumber, optional

The distance from the focal point of the beam to the detector. Must be provided as a pair with pixel_size.

negatebool, optional

If True (default), negate the phase gradient along x direction before reconstructing the final phase image. Default is True.

scalebool, optional

If True, scale gx and gy according to the experiment set up. If False, ignore pixel_size, focus_to_det, energy. Default is True.

paddingint, optional

Pad a N-by-M array to be a (N*(2*padding+1))-by-(M*(2*padding+1)) array with the image in the middle with a (N*padding, M*padding) thick edge of zeros. Default is 0.

padding = 0 –> v (the original image, size = (N, M))

0 0 0

padding = 1 –> 0 v 0 (the padded image, size = (3 * N, 3 * M))

0 0 0

weightingfloat, optional

Weighting parameter for the phase gradient along x and y direction when constructing the final phase image. Valid in [0, 1]. Default value = 0.5, which means that gx and gy equally contribute to the final phase image.

Returns
phasendarray

The final reconstructed phase image.

amplitudendarray

Amplitude of the sample transmission function.