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¶
|
Crops (ny, nx, ...) data to the pixels simulate returns. |
|
Switches the over-subtraction model on for some reflections, held at zero. |
|
Fits the over-subtraction of each channel to a simulation, bounded >= 0. |
|
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_radiuspixels 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 onsimis 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 rangeper step, so it cannot travel from zero to an offset of ~1e5 counts in a few hundred steps. Insteadfit_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_indicesset.data (dict) – Holds
experimental_dataandvariance.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 withoversub_optimizeswitched on.- Return type:
tuple