pytranskit.optrans.utils package
data_utils
- pytranskit.optrans.utils.data_utils.griddata2d(img, f, order=1, fill_value=0.0)[source]
Interpolate 2d scattered data
- Parameters:
img (2d array, shape (height, width)) – Image to interpolate.
f (3d array, shape (2, height, width)) – Coordinates of at which img is defined. First dimension f[0] corresponds to y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the interpolation. Must be in the range 0-2.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
- Returns:
Image interpolated on to regular gird defined by: x = 0:(width-1), y = 0:(height-1).
- Return type:
out, 2d array, shape (height, width)
- pytranskit.optrans.utils.data_utils.interp2d(img, f, order=1, fill_value=0.0)[source]
Interpolation for 2D gridded data.
- Parameters:
img (2d array, shape (height, width)) – Image to interpolate. This function assumes a grid of sample points: x = 0:(width-1), y = 0:(height-1).
f (3d array, shape (2, height, width)) – Coordinates of interpolated points. First dimension f[0] corresponds to y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the spline interpolation. Must be in the range 0-5.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
- Returns:
Image interpolated at points defined by f.
- Return type:
out, 2d array, shape (height, width)
- pytranskit.optrans.utils.data_utils.match_shape2d(a, b)[source]
Crop array B such that it matches the shape of A.
- Parameters:
a (2d array) – Array of desired size.
b (2d array) – Array to crop. Shape must be larger than (or equal to) the shape of array a.
- Returns:
b_crop – Cropped version of b, with the same shape as a.
- Return type:
2d array
- pytranskit.optrans.utils.data_utils.signal_to_pdf(input, sigma=0.0, epsilon=1e-08, total=1.0)[source]
Get the (smoothed) probability density function of a signal.
Performs the following operations: 1. Smooth sigma with a Gaussian filter 2. Normalize signal such that it sums to 1 3. Add epsilon to ensure signal is strictly positive 4. Re-normalize signal such that it sums to total
- Parameters:
input (ndarray) – Input array
sigma (scalar) – Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.
epsilon (scalar) – Offset to ensure that signal is strictly positive.
total (scalar) – Value of the signal summation.
- Returns:
pdf – Returned array of same shape as input
- Return type:
ndarray
validation
- pytranskit.optrans.utils.validation.assert_all_finite(X)[source]
Throw a ValueError if X contains NaN or infinity.
- pytranskit.optrans.utils.validation.assert_equal_shape(a, b, names=None)[source]
Throw a ValueError if a and b are not the same shape.
- pytranskit.optrans.utils.validation.check_array(array, ndim=None, dtype='numeric', force_all_finite=True, force_strictly_positive=False)[source]
Input validation on an array, list, or similar.
- Parameters:
array (object) – Input object to check/convert
ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved. If ‘numeric’, dtype is preserved unless array.dtype is object. If dtype is a list of types, conversion on the first type is only performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
- Returns:
array_converted – The converted and validated array.
- Return type:
object
- pytranskit.optrans.utils.validation.check_decomposition(obj)[source]
Check that an object is a PCA or PLDA (i.e. decomposition) object.
- Parameters:
obj (object) – Object to check
- Returns:
mean (array, shape (n_features,)) – Mean of the data in the decomposition object
components (array, shape (n_components, n_features)) – Components learned by the decomposition object
std (array, shape (n_components,)) – Standard deviation of the training data projected on to each component
visualize
- pytranskit.optrans.utils.visualize.plot_displacements2d(disp, ax=None, scale=1.0, count=50, lw=1, c='k')[source]
Plot 2D pixel displacements as a wireframe grid.
- Parameters:
disp (array, shape (2, height, width)) – Pixel displacements. First index denotes direction: disp[0] is y-displacements, and disp[1] is x-displacements.
ax (matplotlib.axes.Axes object or None (default=None)) – Axes in which to plot the wireframe. If None, a new figure is created.
scale (float (default=1.)) – Exaggeration scale applied to the displacements before visualization.
count (int (default=50)) – Use at most this many rows and columns in the wireframe.
- Returns:
ax – Axes object.
- Return type:
matplotlib.axes.Axes object