prsctrl.data.merge.get_spectrum_scale_factor#
- get_spectrum_scale_factor(sdata1: ndarray[tuple[Any, ...], dtype[_ScalarT]], cols1: list[str], sdata2: ndarray[tuple[Any, ...], dtype[_ScalarT]], cols2: list[str], key: str = 'dI-X_I', xkey: str = 'E', allow_gradient: bool = False, n_vals: int = 3) tuple[float, float][source]#
Calculates the factor so that
y1 = y2 * factor.Determine a factor with which to scale the data to
keyinsdata2to best match the data insdata1in the overlapping region.To get the overlap, all x1 values are taken that lie within the range of the x2 values. The
sdata2is then interpolated to these overlapping x1 values. Scipycurve_fitis then used to fit the factor to overlap the two y-datas (now on identical x-points).If
allow_gradientis True and the datas do not overlap, the gradient ofsdata1is extrapolated from then_valspoints closest to the junction to then_valsx2-values closest to the junction.curve_fitis then used to fit the factor so that these extrapolated y1-values match the actual y2-values.If the fit procedure fails, a scale of 1.0 with error of 1.0 is returned.
- Parameters:
sdata1 – Spectrum data 1.
cols1 – Columns to spectrum data 2. Must contain key and xkey.
sdata2 – Spectrum data 2.
cols2 – Columns to spectrum data 2. Must contain key and xkey.
key – (y)-key of the data column to calculate the scaling factor for.
xkey – X-data key.
allow_gradient – If True, fall back to gradient extrapolation when there is no overlap. Defaults to False.
n_vals – Number of points used for the gradient extrapolation. Defaults to 3.
- Raises:
RuntimeError – If the data has no x-overlap and
allow_gradientis False, or if the datas are nested without shared x-values.ValueError – If the x-key is invalid.
- Returns:
The factor and its covariance.