pyextal.jaxGeo.oversub

Reflections whose integration background was over-subtracted.

Weak reflections next to a bright one can have their integration background overestimated – the annulus reaches into the neighbour’s tail – and ApertureSum then clips the result at zero. On SrTiO3 [001] data (-100) and (100), beside the direct beam, were 65-75 % zeros, and the rest sat well below the simulation. oversub models that instead of fitting against it: those channels are compared as max(sim - c - k * I(000), 0), where I(000) is the measured direct-beam intensity at the same pixel, and their data are clipped at zero to match (jaxEngine.postProcess.apply_oversubtraction). Where the data is zero and the model is at or below zero the residual vanishes, so a clipped pixel only says “at most zero”, which is what it measured.

c and k (one pair per reflection) are held at zero until oversub_start, then fitted directly to the current simulation (enable_oversub()) and released to Adam. There is deliberately no per-reflection scale: it would absorb the structure-factor information those rocking curves carry. The stored variance is left as it is, so these channels still weigh what the integration’s error propagation says they do.

Functions

crop(arr, config)

Crops (ny, nx, ...) data to the pixels simulate returns.

oversub_config(config, g_include, wanted[, leak])

Switches the over-subtraction model on for some reflections, held at zero.

fit_oversub(sim, exp, var, indices, leak_index, names)

Fits the over-subtraction of each channel to a simulation, bounded >= 0.

enable_oversub(params, metadata, config, data, sim, names)

Starts the over-subtraction model from a fit to the current simulation.

Module Contents

pyextal.jaxGeo.oversub.crop(arr, config)

Crops (ny, nx, …) data to the pixels simulate returns.

With the Voigt probe on, simulate convolves in ‘valid’ mode and drops kernel_radius pixels on every side.

pyextal.jaxGeo.oversub.oversub_config(config, g_include, wanted, leak=True)

Switches the over-subtraction model on for some reflections, held at zero.

Parameters:
  • config (OptConfig) – The configuration.

  • g_include (array-like) – (n_beams, 3) labels of the experimental beam axis.

  • wanted (sequence) – (h, k, l) triples to model.

  • leak (bool) – Include the term proportional to the measured (000).

Returns:

OptConfig

Raises:

SetupError – If a reflection (or (000), with leak) is not measured.

pyextal.jaxGeo.oversub.fit_oversub(sim, exp, var, indices, leak_index, names)

Fits the over-subtraction of each channel to a simulation, bounded >= 0.

Bounded least squares of max(sim - c - k * I_leak, 0) against the data, with the loss’s variance weights. The slope on sim is held at 1: a free per-channel scale would absorb the structure-factor information these channels carry.

Parameters:
  • sim (np.ndarray) – (ny, nx, n_beams) simulation after scale and background.

  • exp (np.ndarray) – (ny, nx, n_beams) measured intensities, same pixels.

  • var (np.ndarray) – (ny, nx, n_beams) variances.

  • indices (tuple) – Channels to fit.

  • leak_index (int) – Leak source channel, or -1 for a constant offset only.

  • names (list) – Labels for the log.

Returns:

(offsets, leaks) as arrays, one entry per channel.

Return type:

tuple

pyextal.jaxGeo.oversub.enable_oversub(params, metadata, config, data, sim, names)

Starts the over-subtraction model from a fit to the current simulation.

Adam moves a normalised parameter by about lr x range per step, so it cannot travel from zero to an offset of ~1e5 counts in a few hundred steps. Instead fit_oversub() fits the offset and leak of each channel directly, and Adam then refines them with the rest.

Parameters:
  • params (dict) – Current normalised parameters.

  • metadata (dict) – Current metadata; its oversub bounds are replaced.

  • config (OptConfig) – With oversub_indices set.

  • data (dict) – Holds experimental_data and variance.

  • sim (np.ndarray) – The current simulation (simulate_safely).

  • names (list) – Labels of the channels, for the log.

Returns:

(params, config) – parameters holding the fitted values, and the config with oversub_optimize switched on.

Return type:

tuple