GSEGUtils.base_arrays

See BaseArrays for background motivation.

Provides a class with builtin functionality of:

  • Interaction like a Numpy array

  • Pydantic level automatic validation on class and attributes

  • Simplistic class and attribute definition like dataclasses

class GSEGUtils.base_arrays.BaseArray

Bases: ABC, BaseModel

Subclassable array supporting all shapes and numeric/boolean dtypes.

Parameters:

arr (ArrayT) – Input array data

arr: ArrayT

Contains the raw numpy ndarray data

property T: Self

Returns a transposed view of the array

Return type:

Self

property shape: tuple[int, ...]

Returns the shape of the array

Return type:

tuple[int, …]

property dtype: dtype

Returns the dtype of the array

Return type:

dtype

property ndim: int

Dimensions in the array

Return type:

int

property base: bool'>)] | None

Returns the base array if the array is a view, otherwise None

Return type:

ArrayT | None

property size: int

Returns the number of elements in the array

Return type:

int

view(dtype=None, _type=None)

Return a view of the underlying array

Parameters:
Return type:

ArrayT

min(**kwargs)

Returns self.arr.min(**kwargs) See numpy.min for more info.

Parameters:

kwargs (dict[str, Any])

Return type:

Any

max(**kwargs)

Returns self.arr.max(**kwargs) See numpy.max for more info.

Parameters:

kwargs (dict[str, Any])

Return type:

Any

copy(array=None, *, deep=True, update=None, **kwargs)

Creates a copy of this object.

Also supports deep / shallow copies and overriding update of attributes via the update dictionary paramter.

Parameters:
  • array (ArrayT | Self | None, optional) – If set, directly passed as the arr attribute in the new instance

  • deep (bool, optional) – Deep/shallow copy flag

  • update (dict[str, Any] or None, optional) – Dictionary of attributes to override in the new instance

  • kwargs (dict[str, Any])

  • self (Self)

Return type:

Self

class GSEGUtils.base_arrays.NumericMixins

Bases: BaseArray

Subclassable array type with Python built-in numerical and logical operators

Parameters:

arr (ArrayT) – Input array data

class GSEGUtils.base_arrays.FixedLengthArray

Bases: NumericMixins

Class supporting sample, reduce, extract and mask funcs for row-based data

E.g., vectors or coordinate sets

Parameters:

arr (ArrayT) – Input array data

create_mask(selection)

Converts a basic or advanced numpy index to a boolean vector mask that corresponds to the row indices

Parameters:

selection (IndexLike)

Return type:

Vector_Bool_T

sample(index)

Return a sample copy of the array

Parameters:

index (IndexLike)

Return type:

Vector_Bool_T

reduce(index)

Reduces the array to the points indexed

Parameters:

index (IndexLike)

Return type:

None

extract(index)

Splits the array with the indexed points being returned and the object containing the remaining values.

Parameters:

index (IndexLike)

Return type:

Self

class GSEGUtils.base_arrays.BaseVector

Bases: FixedLengthArray

Shape validated 1D array

Parameters:

arr (ArrayT) – Input array data

arr: VectorT

Contains the raw numpy ndarray data

class GSEGUtils.base_arrays.HomogeneousArray

Bases: FixedLengthArray

Helper class for homogeneous coordinate creation

Parameters:

arr (ArrayT) – Input array data

property H: bool'>)]

Returns the homogeneous coordinates of the array by adding a column of ones to the right

Return type:

ArrayT

class GSEGUtils.base_arrays.ArrayNx2

Bases: HomogeneousArray

Shape validated Nx2 array

Parameters:

arr (ArrayT) – Input array data

Helper class for homogeneous coordinate creation

Parameters:

arr (ArrayT) – Input array data

arr: Array_Nx2_T

Contains the raw numpy ndarray data

class GSEGUtils.base_arrays.ArrayNx3

Bases: HomogeneousArray

Shape validated Nx3 array

Parameters:

arr (ArrayT) – Input array data

Helper class for homogeneous coordinate creation

Parameters:

arr (ArrayT) – Input array data

arr: Array_Nx3_Float_T

Contains the raw numpy ndarray data