improver.utilities.rescale module

Provides support utility for rescaling data.

apply_double_scaling(data_cube, scaled_cube, data_vals, scaling_vals, combine_function=<ufunc 'minimum'>)[source]

From data_cube, an array of limiting values is created based on a linear rescaling from three data_vals to three scaling_vals. The three values refer to a lower-bound, a mid-point and an upper-bound. This rescaled data_cube is combined with scaled_cube to produce an array containing either the higher or lower value as needed.

Parameters:
  • data_cube (Cube) – Data from which to create a rescaled data array

  • scaled_cube (Cube) – Data already in the rescaled frame of reference which will be combined with the rescaled data_cube using the combine_function.

  • data_vals (Tuple[float, float, float]) – Lower, mid and upper points to rescale data_cube from

  • scaling_vals (Tuple[float, float, float]) – Lower, mid and upper points to rescale data_cube to

  • combine_function (Callable[[ndarray, ndarray], ndarray]) – Function that takes two arrays of the same shape and returns one array of the same shape. Expected to be numpy.minimum (default) or numpy.maximum.

Return type:

ndarray

Returns:

Output data from data_cube after rescaling and combining with scaled_cube. This array will have the same dimensions as scaled_cube.

rescale(data, data_range=None, scale_range=(0.0, 1.0), clip=False)[source]

Rescale data array so that data_min => scale_min and data_max => scale max. All adjustments are linear

Parameters:
  • data (ndarray) – Source values

  • data_range (Union[Tuple[float, float], List[float], None]) – List containing two floats Lowest and highest source value to rescale. Default value of None is converted to [min(data), max(data)]

  • scale_range (Union[Tuple[float, float], List[float]]) – List containing two floats Lowest and highest value after rescaling. Defaults to (0., 1.)

  • clip (bool) – If True, points where data were outside the scaling range will be set to the scale min or max appropriately. Default is False which continues the scaling beyond min and max.

Return type:

ndarray

Returns:

Output array of scaled data. Has same shape as data.