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.

Module Contents

Classes

FitInfo

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

BkgSubInfo

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

Functions

roi_subtraction

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

univariate_normal

Produce a univariate normal distribution.

fit_gaussian_1d

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.

API

class background.FitInfo

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

popt: numpy.ndarray = None
pcov: numpy.ndarray = None
fit_function: Callable = None
class background.BkgSubInfo

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

bkg: float = None
bkg_e: float = None
bkg_sub_function: Callable = None
fit_info: background.FitInfo = None
background.roi_subtraction(image, list_of_regions: List[islatu.region.Region])

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

Args:
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.

background.univariate_normal(data, mean, sigma, offset, factor)

Produce a univariate normal distribution.

Args:

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:

array_like: Ordinate data for univariate normal distribution.

background.fit_gaussian_1d(image: islatu.image.Image, params_0=None, bounds=None, axis=0)

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.

Args:
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:
tuple: 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.