Utilities

Utility functions for array processing and analysis.

objscale.coarsen_array(array: ndarray[tuple[int, ...], dtype[_ScalarType_co]], factor: int) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Coarsen an array by averaging superpixel regions.

Takes an input array and reduces it by a given factor along both the x and y dimensions. The coarsening is achieved by summing ‘superpixel’ regions of the original array and dividing by the number of pixels in each region.

Parameters:
  • array (np.ndarray) – The input array to be coarsened.

  • factor (int) – The coarsening factor for reducing the array resolution. Must be a positive integer.

Returns:

The coarsened array with reduced resolution.

Return type:

np.ndarray

Examples

>>> original_array = np.array([[1, 2], [3, 4]])
>>> coarsened = coarsen_array(original_array, factor=2)
>>> coarsened
array([[2.5]])
objscale.linear_regression(x: ndarray[tuple[int, ...], dtype[floating]], y: ndarray[tuple[int, ...], dtype[floating]]) tuple[tuple[float, float], tuple[float, float]][source]

Perform linear regression and return coefficients with 95% confidence errors.

Parameters:
  • x (np.ndarray) – Independent variable values.

  • y (np.ndarray) – Dependent variable values.

Returns:

  • coefficients (tuple of float) – (slope, y-intercept) from linear regression.

  • errors (tuple of float) – (error_slope, error_y_intercept) for 95% confidence.

Raises:

TypeError – If x or y are not numpy arrays.

objscale.encase_in_value(array: ~numpy.ndarray[tuple[int, ...], ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], value: float = nan, dtype: ~numpy.dtype = <class 'numpy.float32'>, n_deep: int = 1) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Add a border of specified value around a 2-D array.

Parameters:
  • array (np.ndarray) – 2-D input array.

  • value (scalar, default=np.nan) – Value to append on the edge.

  • dtype (np.dtype, default=np.float32) – Data type of the resulting array.

  • n_deep (int, default=1) – Number of layers deep to add around the edge.

Returns:

Same as input but with a layer ‘n_deep’ of ‘value’ all around the edge.

Return type:

np.ndarray

objscale.set_num_threads(n: int) None[source]

Set the number of threads used for parallel computations.

Controls the number of threads Numba uses for parallel operations such as correlation integral calculation and structure property analysis.

Parameters:

n (int) – Number of threads to use. Must be between 1 and the number of logical CPU cores available.

Raises:

ValueError – If n is less than 1 or greater than the available CPU count.