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 key in sdata2 to best match the data in sdata1 in the overlapping region.

To get the overlap, all x1 values are taken that lie within the range of the x2 values. The sdata2 is then interpolated to these overlapping x1 values. Scipy curve_fit is then used to fit the factor to overlap the two y-datas (now on identical x-points).

If allow_gradient is True and the datas do not overlap, the gradient of sdata1 is extrapolated from the n_vals points closest to the junction to the n_vals x2-values closest to the junction. curve_fit is 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_gradient is False, or if the datas are nested without shared x-values.

  • ValueError – If the x-key is invalid.

Returns:

The factor and its covariance.