Math Operations

Array Math

class PVGeo.filters.math.ArrayMath(**kwargs)[source]

Bases: FilterPreserveTypeBase

This filter allows the user to select two input data arrays on which to perform math operations. The input arrays are used in their order of selection for the operations.

Parameters:
  • multiplier (float) – a static shifter/scale factor across the array after normalization.

  • new_name (str) – The new array’s string name

  • operation (str, int, or callable) – The operation as a string key, int index, or callable method

Available Math Operations:

  • add: This adds the two data arrays together

  • subtract: This subtracts input array 2 from input array 1

  • multiply: Multiplies the two data arrays together

  • divide: Divide input array 1 by input array 2 (arr1/arr2)

  • correlate: Use np.correlate(arr1, arr2, mode=’same’)

RequestData(request, inInfo, outInfo)[source]

Used by pipeline to perform operation and generate output

SetInputArrayToProcess(idx, port, connection, field, name)[source]

Used to set the input array(s)

Parameters:
  • idx (int) – the index of the array to process

  • port (int) – input port (use 0 if unsure)

  • connection (int) – the connection on the port (use 0 if unsure)

  • field (int) – the array field (0 for points, 1 for cells, 2 for field, and 6 for row)

  • name (int) – the name of the array

static _add(arr1, arr2)[source]

Adds two input NumPy arrays

static _correlate(arr1, arr2)[source]

Use np.correlate() on mode='same' on two selected arrays from one input.

static _divide(arr1, arr2)[source]

Divides two input NumPy arrays

_math_up(pdi, pdo)[source]

Make sure to pass array names and integer associated fields. Use helpers to get these properties.

static _multiply(arr1, arr2)[source]

Mutlipies two input NumPy arrays

_set_input_array_1(field, name)[source]

Set 1st input array by name and field

_set_input_array_2(field, name)[source]

Set 2nd input array by name and field

static _subtract(arr1, arr2)[source]

Subtracts two input NumPy arrays

apply(input_data_object, array_name_0, array_name_1)[source]

Run the algorithm on an input data object, specifying array names

get_multiplier()[source]

Return the set multiplier/scalar

get_new_array_name()[source]

Get the name used for the new array

static get_operation(idx)[source]

Gets a math operation based on an index in the keys

Returns:

the math operation method

Return type:

callable

static get_operation_names()[source]

Gets a list of the math operation keys

Returns:

the keys for getting the math operations

Return type:

list(str)

static get_operations()[source]

Returns the math operation methods as callable objects in a dictionary

set_multiplier(val)[source]

This is a static shifter/scale factor across the array after normalization.

set_new_array_name(name)[source]

Give the new array a meaningful name.

set_operation(op)[source]

Set the math operation to perform

Parameters:
  • op (str, int, or callable) – The operation as a string key, int

  • index –

  • method (or callable) –

Note

This can accept a callable method to set a custom operation as long as its signature is: <callable>(arr1, arr2)

Arrays To RGBA

class PVGeo.filters.math.ArraysToRGBA(**kwargs)[source]

Bases: FilterPreserveTypeBase

Use arrays from input data object to set an RGBA array. Sets colors and transparencies.

RequestData(request, inInfo, outInfo)[source]

Execute on pipeline

SetInputArrayToProcess(idx, port, connection, field, name)[source]

Used to set the input array(s)

Parameters:
  • idx (int) – the index of the array to process

  • port (int) – input port (use 0 if unsure)

  • connection (int) – the connection on the port (use 0 if unsure)

  • field (int) – the array field (0 for points, 1 for cells, 2 for field, and 6 for row)

  • name (int) – the name of the array

_get_arrays(wpdi)[source]

Internal helper to fetch RGBA arrays

_mask_arrays(r_arr, g_arr, b_arr, a_arr)[source]

Internal helper to mask RGBA arrays

_set_input_array_blue(field, name)[source]

Set field and name of blue array

_set_input_array_green(field, name)[source]

Set field and name of green array

_set_input_array_red(field, name)[source]

Set field and name of red array

_set_input_array_trans(field, name)[source]

Set field and name of transparency array

apply(input_data_object, r_array, g_array, b_array, a_array=None)[source]

Run the algorithm on an input data object, specifying RGBA array names

set_mask_value(val)[source]

Set the value to mask in the RGBA arrays

set_use_transparency(flag)[source]

Set a boolean flag on whether or not to use a transparency component

Normalize Array

class PVGeo.filters.math.NormalizeArray(**kwargs)[source]

Bases: FilterPreserveTypeBase

This filter allows the user to select an array from the input data set to be normalized. The filter will append another array to that data set for the output. The user can specify how they want to rename the array, can choose a multiplier, and can choose from several types of common normalizations (more functionality added as requested).

Parameters:
  • multiplier (float) – a static shifter/scale factor across the array after normalization.

  • new_name (str) – The new array’s string name

  • absolute (bool) –

  • normalization (str, int, or callable) – The operation as a string key, integer index, or callable method

Normalization Types:

  • feature_scale: Feature Scale

  • standard_score: tandard Score

  • log10: Natural Log

  • natural_log: Log Base 10

  • just_multiply: Only Multiply by Multiplier

RequestData(request, inInfo, outInfo)[source]

Used by pipeline to generate output

SetInputArrayToProcess(idx, port, connection, field, name)[source]

Used to set the input array(s)

Parameters:
  • idx (int) – the index of the array to process

  • port (int) – input port (use 0 if unsure)

  • connection (int) – the connection on the port (use 0 if unsure)

  • field (int) – the array field (0 for points, 1 for cells, 2 for field, and 6 for row)

  • name (int) – the name of the array

static _feature_scale(arr, rng=None)[source]

Returns feature scale normalization of input array

static _log10(arr)[source]

Returns log base 10 of input array

static _log_nat(arr)[source]

Returns natural logarithm of input array

_normalize(pdi, pdo)[source]

Perform normalize on a data array for any given VTK data object.

static _pass_array(arr)[source]

Cast an input array as a NumPy array

static _standard_score(arr)[source]

Returns standard score normalization of input array

apply(input_data_object, array_name)[source]

Run the algorithm on an input data object, specifying the array

static get_array_range(pdi, field, name)[source]

Returns a tuple of the range for a vtkDataArray on a vtkDataObject.

get_multiplier()[source]

Return the set multiplier/scalar

get_new_array_name()[source]

Get the name of the new array

static get_normalization(idx)[source]

Gets a normalization based on an index in the keys

Returns:

the normalization method

Return type:

callable

static get_normalization_names()[source]

Gets a list of the normalization keys

Returns:

the keys for getting the normalizations

Return type:

list(str)

static get_normalizations()[source]

All Available normalizations

Returns:

dictionary of callable methods for normalizing an array

Return type:

dict

set_multiplier(val)[source]

This is a static shifter/scale factor across the array after normalization.

set_new_array_name(name)[source]

Give the new array a meaningful name.

set_normalization(norm)[source]

Set the normalization operation to perform

Parameters:

norm (str, int, or callable) – The operation as a string key, int index, or callable method

Note

This can accept a callable method to set a custom operation as long as its signature is: <callable>(arr)

set_shift(sft)[source]

Set a static shifter to the input data array

set_take_absolute_value(flag)[source]

This will take the absolute value of the array before normalization.

Percent Threshold

class PVGeo.filters.math.PercentThreshold(percent=50, invert=False, **kwargs)[source]

Bases: FilterBase

Allows user to select a percent of the data range to threshold. This will find the data range of the selected input array and remove the bottom percent. This can be reversed using the invert property.

RequestData(request, inInfo, outInfo)[source]

Used by pipeline for execution

SetInputArrayToProcess(idx, port, connection, field, name)[source]

Used to set the input array(s)

Parameters:
  • idx (int) – the index of the array to process

  • port (int) – input port (use 0 if unsure)

  • connection (int) – the connection on the port (use 0 if unsure)

  • field (int) – the array field (0 for points, 1 for cells, 2 for field, and 6 for row)

  • name (int) – the name of the array

apply(input_data_object, array_name)[source]

Run the algorithm on an input data object, specifying the array

set_invert(flag)[source]

Use to invert the threshold filter

set_percent(percent)[source]

Set the percent for the threshold in range (0, 100). Any values falling beneath the set percent of the total data range will be removed.

set_use_continuous_cell_range(flag)[source]

If this is on (default is off), we will use the continuous interval [minimum cell scalar, maxmimum cell scalar] to intersect the threshold bound , rather than the set of discrete scalar values from the vertices