Centre of Mass
ibex_bluesky_core.callbacks.CentreOfMass provides functionality for calculating a specific definition of a “centre of mass”: it computes the centre of mass of a 2-dimensional region bounded by:
min(x)max(x)min(y)Straight-line segments joining
(x, y)data points with their nearest neighbours along the x axis
CentreOfMass stores its result in the result property.
Note
This will return different results from the com property available from bluesky.callbacks.fitting.PeakStats in the following cases:
Points irregularly sampled along the x-axis
Points with negative y-values
x data which does not monotonically increase
For a detailed comparison of the two implementations, see unit tests written to expose tricky cases.
Given non-continuous arrays of collected data x and y, CentreOfMass returns the x value of the centre of mass.
Many of our use cases require that our algorithm follows the following rules:
Any background on data should not change the centre of mass.
The order in which data is received should not change the centre of mass
Should support non-constant point spacing without skewing the centre of mass
Note
Note that this is designed for only positive peaks.
ibex_bluesky_core.callbacks.CentreOfMass is included in our callbacks collection.
Implementation details
Sort
xandyarrays in respect ofxascending. This is so that data can be received in any order.From each
yelement, subtractmin(y). This means that any constant background over data is ignored.Decompose the curve into a series of trapezoidal regions, and then further decompose those trapezoidal regions into rectangular and triangular regions.
Compute centre of mass of the overall shape by composition of each region: