pyxc.core.processor.arrays

Module Contents

Functions

reshape_if_1dim(→ numpy.ndarray)

Reshape the provided array if it's one-dimensional.

image_notator(→ tuple[numpy.ndarray, numpy.ndarray, ...)

Label X- and Y-indices of the provided image.

image_serializer(→ tuple[numpy.ndarray, Ellipsis])

Flatten image to tuple(s).

get_structured_array_field_names_from_indices(...)

Return field names from the provided dtype_object based on the integer indices.

xy2matrix(→ numpy.ndarray)

Return (n, 3) shaped array after receiving two (n,) shaped arrays.

matrix2xy(→ tuple[numpy.ndarray, numpy.ndarray])

Extract the first (x) and second (y) columns from the provided (n, 3) shaped array.

structured_array_query(→ numpy.ndarray)

Return a structured array based on the given integer indices.

column_parser(→ numpy.ndarray)

Re-order the provided array_like object with respect to the format string.

xyd_splitter(→ tuple[numpy.ndarray, numpy.ndarray, ...)

Split a structured array into three separate arrays.

pyxc.core.processor.arrays.reshape_if_1dim(array: numpy.ndarray, is_structured=False) numpy.ndarray[source]

Reshape the provided array if it’s one-dimensional.

If the shape of the provided array is (n, ), then it will be reshaped to (n, 1). If the array is two-dimensional or is a structured array, it will be returned as is. Otherwise, a ValueError will be raised.

Parameters:
arraynp.ndarray

The input array to be reshaped.

is_structuredbool, default=False

A boolean flag indicating whether the input array is structured.

Returns:
np.ndarray

The reshaped array.

Raises:
ValueError

If the dimensions of the input array are either too low or too high.

pyxc.core.processor.arrays.image_notator(image: numpy.typing.ArrayLike, channel: int | None = None) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Label X- and Y-indices of the provided image.

Parameters:
imagearray_like or np.ndarray

A 2D or 3D array-like object representing the image. For 3D arrays, the last dimension should be the channel.

channelint, optional

Specifies the channel to be considered if the input image is a 3D array. If None (default), all channels are considered.

Returns:
tuple of np.ndarray

A tuple containing: - X-indices of the image as a ndarray - Y-indices of the image as a ndarray - The supplied image or its specific channel as a ndarray

Raises:
ValueError

If the dimension of the input image is not 2D or 3D.

pyxc.core.processor.arrays.image_serializer(image: numpy.typing.ArrayLike) tuple[numpy.ndarray, Ellipsis][source]

Flatten image to tuple(s).

Return flattened image from the supplied image.

Parameters:
imagearray_like

2-dimensional or 3-dimensional array-like image.

Returns:
tuple[np.ndarray, …]

Flattened image. Each row contains image information.

pyxc.core.processor.arrays.get_structured_array_field_names_from_indices(dtype_object: numpy.dtype, indices: Sequence[int]) tuple[str, Ellipsis][source]

Return field names from the provided dtype_object based on the integer indices.

Parameters:
dtype_objectnp.dtype

A np.dtype object of the structured array.

indicesSequence

A sequence of the desired index or indices.

Returns:
tuple[str, …]
pyxc.core.processor.arrays.xy2matrix(x: numpy.typing.ArrayLike, y: numpy.typing.ArrayLike) numpy.ndarray[source]

Return (n, 3) shaped array after receiving two (n,) shaped arrays.

Parameters:
xarray_like

NumPy array contains x-coordinate values.

yarray_like

NumPy array contains y-coordinate values.

Returns:
np.ndarray
pyxc.core.processor.arrays.matrix2xy(matrix_like_array: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]

Extract the first (x) and second (y) columns from the provided (n, 3) shaped array.

Parameters:
matrix_like_arraynp.ndarray

(n, 3) shaped array. First and second columns are x and y coordinates.

Returns:
np.ndarray

x-coordinates

np.ndarray

y-coordinates

pyxc.core.processor.arrays.structured_array_query(structured_array: numpy.ndarray, indices: Sequence[int]) numpy.ndarray[source]

Return a structured array based on the given integer indices.

Get a subset of the structured array based on given indices. Usually, column slicing of the structured array is performed using key values. This function provides structured array column slicing by integer column indices.

Parameters:
structured_arraynp.ndarray

Structured array.

indicesSequence[int, …]

A sequence of integer column indices.

Returns:
np.ndarray

Structured array.

pyxc.core.processor.arrays.column_parser(array: numpy.typing.ArrayLike, format_string: str, return_unspecified=True) numpy.ndarray[source]

Re-order the provided array_like object with respect to the format string.

Parameters:
arrayarray_like

2-dimensional array or structured array.

format_stringstr

A Format string. See Notes section.

return_unspecifiedbool, default=True

If False, the unspecified portion of columns will NOT be returned together. See Notes.

Returns:
np.ndarray

Re-ordered np.ndarray respective with the provided format string.

Raises:
ValueError

When the provided format string or the provided array-like object is not right.

Notes

A format string key-letter is x, y, and _. Each letter corresponds to x-coordinates, y-coordinates, and columns to be ignored. All other characters than x, y, and _ will be treated as valid columns.

If return_unspecified is False, then unspecified columns won’t be returned together. For example, when the format string is given by yxd__dd and the provided array is a structured array with column names of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), then this function returns columns (2, 1, 3, 6, 7, 8, 9, 10) by default. However, when return_unspecified is False, then this function returns (2, 1, 3, 6, 7) only.

pyxc.core.processor.arrays.xyd_splitter(array: numpy.typing.ArrayLike) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Split a structured array into three separate arrays.

Parameters:
arrayarray_like

Array-like object to be split. If it is a structured array, then the number of columns should be greater than or equal to 3.

Returns:
np.ndarray

X-coordinates. Unstructured array. Shape is (n, )

np.ndarray

Y-coordinates. Unstructured array. Shape is (n, )

np.ndarray

Data array. If the initially given array and number of the columns is greater than or equal to 4 in the structured array, then return a structured array. Else, return a 2-dimensional unstructured array.

Raises:
ValueError

If the input array has less than three columns.