Spot Analyse

A collection of useful functions for spot analysis.

fredtools.fitSpotProfile(pos: ArrayLike, vec: ArrayLike, cutLevel: Annotated[float, Ge(ge=0)] = 0, fixAmplitude: bool = False, fixCentreToZero: bool = False, method: Literal['singleGauss'] = 'singleGauss') ModelResult

Fit a gaussian-like function to profile.

The function fits a gaussian-like function defined by method to a profile defined as pos and vec parameters, where they are vectors of positions and values, respectively.

Parameters:
  • pos (array_like 1xN) – An iterable with the positions of the values.

  • vec (array_like 1xN) – An iterable with the values corresponding to pos.

  • cutLevel (scalar, optional) – Fraction of the maximum value of vec for which the fit will be performed. Only the points with values greater than or equal to max(vec)*`cutLevel` are kept for the fit. (def. 0)

  • fixAmplitude (bool, optional) – Fix the amplitude to the maximum value of vec and do not use it in the fitting. (def. False)

  • fixCentreToZero (bool, optional) – Fix the centre to zero and do not use it in the fitting. (def. False)

  • method ({"singleGauss"}, optional) – Method of the fitting. Only single gaussian fitting is implemented now. (def. “singleGauss”)

Returns:

An instance of lmfit.model.ModelResult class.

Return type:

lmfit.model.ModelResult

Raises:
  • TypeError – If pos or vec is not iterable, is not a one-dimensional vector, or if pos and vec are not of the same length.

  • ValueError – If the method is not recognised.

fredtools.fitSpotImg(img: Image, cutLevel: Annotated[float, Ge(ge=0)] = 0, fixAmplitude: bool = False, fixCentreToZero: bool = False, method: Literal['singleGauss'] = 'singleGauss') ModelResult

Fit a 2D gaussian-like function to spot image.

The function fits a 2D gaussian-like function defined by method to a spot image defined as img parameter, which is a 2D SimpleITK image.

Parameters:
  • img (SITKImage) – 2D SimpleITK image of the spot.

  • cutLevel (scalar, optional) – Fraction of the maximum value of img for which the fit will be performed. Only the voxels with values greater than or equal to max(img)*`cutLevel` are kept for the fit (the others are set to zero). (def. 0)

  • fixAmplitude (bool, optional) – Fix the amplitude to the maximum value of img and do not use it in the fitting. (def. False)

  • fixCentreToZero (bool, optional) – Fix the centre to zero and do not use it in the fitting. (def. False)

  • method ({"singleGauss"}, optional) – Method of the fitting. Only single gaussian fitting is implemented now. (def. “singleGauss”)

Returns:

An instance of lmfit.model.ModelResult class.

Return type:

lmfit.model.ModelResult

Raises:
  • TypeError – If img is not a 2D SimpleITK image.

  • ValueError – If the method is not recognised.

fredtools.findSpots(img: Image, DCO: Annotated[int | float | number, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=0), Le(le=1)])] = 0.1, margin: Annotated[float, Gt(gt=0)] | Iterable[Annotated[float, Gt(gt=0)]] = 3, displayInfo: bool = False) Image

Find spots in 2D SITK image.

The function identifies spots in a 2D SimpleITK image by applying a dose cut-off (DCO) to define the spot region, followed by morphological operations to refine the regions. The identified spots are then labelled and returned as a labelled image. In detail, the image is first smoothed with a median filter of a fixed 5x5 voxel kernel and binarised at DCO times the image maximum. The binary regions are dilated by margin (converted from mm to voxels), labelled as fully connected components with holes filled, and components smaller than 20 voxels are dropped. The remaining labels are sorted by size (the largest component gets label 1), and finally each label region is replaced by its axis-aligned bounding box, so each spot is described by a rectangular label region.

Parameters:
  • img (SITKImage) – 2D SITK image.

  • DCO (Numeric, optional) – Dose cut-off to define spot region. (def. 0.1)

  • margin (Numeric | Iterable[Numeric], optional) – Margin around spot region in mm. (def. 3)

  • displayInfo (bool, optional) – Display information about found spots. (def. False)

Returns:

Labelled image of found spots.

Return type:

SITKImage

Raises:
  • TypeError – If img is not a 2D SimpleITK image. If margin is not a scalar or an iterable.

  • ValueError – If DCO is not a positive scalar between 0 and 1.

fredtools.fitSigmaSquaredModel(pos: Iterable[int | float | number], beamSize: Iterable[int | float | number]) ModelResult

Fit sigma squared model to beam size data.

The function fits the sigma squared model to the beam size data provided. The model is defined as: σ²(z) = a + b*z + c*z², where σ is the beam size at position z, and a, b, c are the parameters to be fitted. Note that the fit is performed on the squared beam size, i.e. beamSize**2.

Parameters:
  • pos (Iterable[Numeric]) – Positions where the beam sizes were measured.

  • beamSize (Iterable[Numeric]) – Measured beam sizes at the corresponding positions.

Returns:

An instance of lmfit.model.ModelResult class.

Return type:

lmfit.model.ModelResult