index#

Index scanning 3DXRD data: orientation populations per voxel, fitted to the data with the forward model.

The steps, in order (python -m anri.index runs them on an ImageD11 dataset):

  1. ring_table() and ring_profile(): the rings, and how wide they are in the data.

  2. histogram_pixels(): the sparse pixels binned once into H[ring, eta, omega, row], and a row-summed lit map (lit_table()).

  3. choose_grid(), prune() and orientation_mlem(): an orientation grid over the fundamental zone (anri.crystal.orientation_grid()), first filtered by completeness with tolerances from the grid and the data (match_tolerances()), then kept by the likelihood ratio of a global, intensity-aware orientation fit.

  4. fit_occupancy(): sparse occupancy of the kept orientations per voxel by MLEM, every voxel fitted jointly.

  5. populations(): each voxel’s occupancy grouped into orientation populations with fractions and spreads.

Functions

backproject(sino, om_deg, pos, y0, dty0, ystep)

Back-project a sinogram [omega, row] onto voxels at pos [Nv, 3], linearly between rows.

backward(r, cand, pred, ring_j, pos, scan, ...)

Back-project a histogram onto each voxel's candidates: A^T r.

beam_rows(scan)

Rows a voxel's beam profile reaches (odd): the voxel's half diagonal, half the flat top and 3 sigma each side.

block_voxels(q, n_j, budget_bytes[, n_corners])

Voxels per block (a power of 2) so that one block's system entries for q orientations take ~budget_bytes.

candidates(d, pred, ring_j, pos, scan, dims, ...)

Pick each voxel's k best orientations by the first MLEM update from unit occupancy.

candidates_from(d, cand_in, pred, ring_j, ...)

Pick each voxel's k best orientations as candidates() does, but from its own list only.

censored_ratio(d, mu, censor)

Compute the MLEM ratio d / mu, with empty bins taken as censored.

choose_grid(ops, B, rings, geom, lit[, ...])

Choose the coarsest grid step whose chance completeness is at most max_chance.

coarsen_rows(H, n_rows, g)

Sum a histogram's rows in groups of g: row k goes to k // g.

completeness(table, eta, om, ok, ring_j, ...)

Fraction of each orientation's valid predictions with a lit bin within its own tolerance box.

completeness_of(U, delta, B, rings, geom, lit)

Completeness of many orientations, in chunks.

deviance(d, mu, censor)

Poisson deviance of observed bins, plus 2 x (mu - censor) for empty bins the model predicts above censor.

draw_mask(image[, ax])

Draw the sample's outline on an image; returns a function that gives the mask of what was drawn.

dty_offsets(frame_dty, frame_omega, ...[, ...])

Each histogram row's dty, per omega bin, less its nominal dty: where the beam really was.

fit_occupancy(H, pred, ring_j, pos, scan, dims)

Fit sparse occupancies: candidates per voxel, then MLEM.

forward(f, cand, pred, ring_j, pos, scan, ...)

Forward-project occupancies: A f.

histogram(x, val, row, ring_tth, tth_tol, ...)

Bin pixels into H[ring, eta, omega, row] (flattened).

histogram_pixels(chunks, geom, ring_tth, ...)

Stream pixels into one or more histograms in a single pass over the data.

inherit_candidates(pos, pos_c, f_c, cand_c, k2)

Candidates for fine voxels from a coarse fit: what the nearest coarse voxel and its 8 neighbours occupied.

lit_table(lit)

Summed-area table of a lit map, for counting lit bins in any box in constant time.

lorentz_polarisation(U, B, hkls, geom)

Lorentz x polarisation factor of every prediction of some orientations (see predict()).

match_tolerances(eta, ring_j, ring_tth, ...)

Compute the matching tolerances in eta and omega of predictions of grid orientations.

mlem(d, cand, pred, ring_j, pos, scan, dims, ...)

Fit occupancies by MLEM: f <- f A^T(d / A f) / A^T 1, n_iter times, logging the Poisson deviance.

orientation_mlem(d, U, B, rings, geom, bins)

Fit one occupancy per orientation to a row-summed histogram by MLEM, and score each orientation.

otsu(values[, n_bins])

Otsu's threshold of some values: the cut that best separates them into two classes.

pad_voxels(pos, vb)

Pad voxel positions to a multiple of vb with voxels far outside the scan (they reach no rows).

pixel_angles(slow, fast, omega, geom)

Compute (2theta, eta, omega) of pixel centres, seen from the lab origin (no parallax).

polygon_mask(shape, vertices)

Mask [ny, nx] of the pixels inside a polygon given by (x, y) = (column, row) vertices.

populations(f, cand, U_list, ops, radius_deg)

Group each voxel's occupied candidate orientations into up to p populations.

predict(U, B, hkls, geom)

Predict (eta, omega) of every reflection of some orientations, with both omega solutions.

predictions(U, B, rings, geom, etacut[, qc])

Predictions of an orientation list for fit_occupancy(), padded to a multiple of qc.

prune(U, delta, B, rings, geom, lit[, ...])

Keep the grid orientations whose completeness passes a threshold.

ramp_filter(sino)

Filter each projection (row of sino [omega, dty]) along dty with a Hamming-windowed ramp.

reconstruct(H, n_rings, n_e, n_o, scan, b_o, nr)

Reconstruct the whole sample from the indexer's histogram, for a mask (or to check y0).

ring_profile(chunks, geom, ring_tth, chunk)

Measure the rings' offsets and half-widths from a sample of pixels (see ring_widths()).

ring_table(lattice_parameters, space_group, ...)

List the reflections of a crystal's first rings, with their structure factors.

ring_widths(prof, lo, step, ring_tth[, ...])

Measure each ring's offset and half-width (degrees 2theta) from a 2theta profile.

system(eta, om, use, w, ring_j, pos, scan, ...)

Entries of the system matrix: (cell index, weight) for voxels and predictions.

threshold_mask(image[, threshold])

Mask of the sample: the convex hull of the largest connected region above a threshold (default Otsu's).

tth_profile(x, val, lo, step, n)

Sum pixel intensities in 2theta bins.