scallops.codebook.estimate_scale_factors

scallops.codebook.estimate_scale_factors(array, codebook, initial_scale_factors=None, max_iter=10, metric='euclidean', norm_order=2, min_intensity=0, max_distance=inf)

Calculate the scale factors that would result in the mean on bit intensity for each bit to be equal.

Parameters:
  • array (DataArray) – 2-dimensional array with dimensions read and t+c or a 4-dimensional array with dimensions (t, c, y, x).

  • codebook (DataArray) – The codebook used to call features. Dimensions are f (feature), t, c.

  • norm_order (int) – Norm to apply (numpy:reference/generated/numpy.linalg.norm).

  • metric (Literal['braycurtis', 'canberra', 'chebyshev', 'cityblock', 'euclidean', 'haversine', 'infinity', 'kulsinski', 'l1', 'l2', 'manhattan', 'matching', 'minkowski', 'p', 'seuclidean', 'sqeuclidean']) – Distance metric as in sklearn.metrics.pairwise.ArgKmin.valid_metrics().

  • min_intensity (float) – Minimum intensity to include.

  • max_distance (float) – Maximum distance between a feature and its closest code for which the coded target will be assigned.

  • initial_scale_factors (ndarray) – Initial scale factors of 1-dimensional array (t+c) to divide array by. If not provided, set to 90th percentile for each bit.

  • max_iter (int) – Maximum number of iterations to perform.

Returns:

The estimated scaling factors.

Example:

Return type:

ndarray

import xarray as xr
import numpy as np
from scallops.codebook import estimate_scale_factors

# Create synthetic DataArray
image_shape = (3, 4, 100, 100)  # (t, c, y, x)
array = xr.DataArray(np.random.rand(*image_shape), dims=("t", "c", "y", "x"))
codebook_shape = (6, 3, 4)  # (f, t, c)
codebook = xr.DataArray(np.random.rand(*codebook_shape), dims=("f", "t", "c"))

# Calculate the estimated scaling factors
scale_factors = estimate_scale_factors(array, codebook, max_iter=5)