islatu.background

Background substraction is a necessary component of reflectometry reduction, where the background scattering is removed from the reflected intensity.

Herein are some functions to enable that for a two-dimensional detector image, as well as simple dataclasses in which we can store some information relating to the background subtraction, and any fitting that we might have carried out.

class islatu.background.BkgSubInfo(bkg: float, bkg_e: float, bkg_sub_function: Callable, fit_info: Optional[FitInfo] = None)[source]

Bases: object

A simple data class in which we can store information relating to a background subtraction.

bkg: float
bkg_e: float
bkg_sub_function: Callable
fit_info: FitInfo = None
class islatu.background.FitInfo(popt: ndarray, pcov: ndarray, fit_function: Callable)[source]

Bases: object

A simple dataclass in which we can store data relating to the quality of a fit.

fit_function: Callable
pcov: ndarray
popt: ndarray
islatu.background.fit_gaussian_1d(image: Image, params_0=None, bounds=None, axis=0)[source]

Fit a one-dimensional Gaussian function with some ordinate offset to an image with uncertainty. This is achieved by averaging in a given axis before performing the fit. Return the results, and index of the offset.

Parameters
  • image – The islatu image object to fit.

  • params_0 (list, optional) – An initial guess at the parameters. Defaults to values based on the image.

  • bounds (list of tuple, optional) – Bounds for the fitting. Defaults to values based on the image.

  • axis (int) – The dimension along which the averaging will be performed.

Returns

Containing:
  • array_like: The results (with uncertainties) for each

    of the 6 parameters fit.

  • int: The index of the offset.

  • None: As it is not possible to describe the reflected

    peak width.

Return type

tuple

islatu.background.roi_subtraction(image, list_of_regions: List[Region])[source]

Carry out background subtraction by taking a series of rectangular regions of interested (ROIs) as being fair Poissonian measurements of the background.

Parameters
  • image – The islatu.image.Image object from which we should subtract background from.

  • list_of_regions – A list of instances of the Regions class corresponding to background regions.

islatu.background.univariate_normal(data, mean, sigma, offset, factor)[source]

Produce a univariate normal distribution.

Parameters
  • data (array_like) – Abscissa data.

  • mean (float) – Mean (horizontal).

  • sigma (float) – Variance (horizontal).

  • offset (float) – Offset from the 0 for the ordinate, this is the background level.

  • factor (float) – Multiplicative factor for area of normal distribution.

Returns

Ordinate data for univariate normal distribution.

Return type

array_like