iqm.cpc.core.dataset.multifit_along_coordinates

iqm.cpc.core.dataset.multifit_along_coordinates#

iqm.cpc.core.dataset.multifit_along_coordinates(data_array: DataArray, main_coord: str, supp_coord: str, func: Callable[[ndarray, ndarray, ndarray, Sequence[str] | None], tuple[dict, ndarray]], cloned_arguments: Sequence[str] = (), returns: None = None, add_to: Dataset | None = None, result_parameter: Parameter | None = None, prefix: str = '') DataArray#
iqm.cpc.core.dataset.multifit_along_coordinates(data_array: DataArray, main_coord: str, supp_coord: str, func: Callable[[ndarray, ndarray, ndarray, Sequence[str] | None], tuple[dict, ndarray]], cloned_arguments: Sequence[str], returns: Sequence[str], add_to: Dataset | None = None, result_parameter: Parameter | None = None, prefix: str = '') tuple[DataArray, ...]

Extension of apply_along_coordinate() to two dimensions.

The main difference is the addition of cloned_arguments, which enable the user to fit some parameters once per each value on the second, supplementary coordinate. The function generates a 2d fit, some 1d arrays for the cloned arguments, and 0d arrays for the non-cloned ones, so it needs to know which are cloned and which are not. These dimensions are automatically extended by additional dimensions on the data, and so this function supports arbitrary additional dimensions.

For example, let’s say we want to fit a family of exponential curves \(a_i\exp(-x/b)\) where \(a_i\) and \(b\) are the fitting parameters and \(x\) is the primary dimension. The value of \(b\) is the same for the whole family, whereas \(a_i\) is different for each coordinate i of the supplementary dimension. In this case, we clone “a” so that we get a single fit value for \(b\), and separate fit values for \(a_i\).

Parameters:
  • data_array (DataArray) – DataArray that contains the Nd data to operate on.

  • main_coord (str) – Name of the main coordinate over which the 2d operation is performed. Can be any coordinate or dimension of data_array.

  • supp_coord (str) – Name of the supplementary coordinate over which the 2d operation is performed. This coordinate also define the cloning axis for the cloned arguments.

  • func (Callable[[ndarray, ndarray, ndarray, Sequence[str] | None], tuple[dict, ndarray]]) – A function that takes 2-dimensional data in format (x, y, z) and returns a dictionary containing the extra results (e.g. fit parameters), and the fitted 2d array.

  • cloned_arguments (Sequence[str]) – The names of func arguments that the fitter should clone along the supplementary coordinate. They also define the shape of the returns corresponding to those arguments.

  • returns (Sequence[str] | None) – Names of extra results to return. Each string should match one of the keys returned by func. The arrays are added to the result tuple in the same order as given in returns. Note that the computed array is always returned first and does not need to be specified.

  • add_to (Dataset | None) – If given, the returned arrays are added to this dataset. The dataset is modified as a side effect.

  • result_parameter (Parameter | None) – This parameter represents the computed data. By default will be generated by generate_fit_parameter().

  • prefix (str) – If given, the names of all arrays in returns are prefixed with <prefix>_. Used to avoid name clashes with existing data variables.

Returns:

List of data arrays depending on returns. The first array is always the result produced by applying func along the axis coord. It has the same \(N\) dimensions as data_array. The other arrays have either \(N-1\) (if cloned) or \(N-2\) (if not cloned) dimensions and represent the extras requested in returns.

Return type:

tuple[DataArray, …] | DataArray