trx.streamlines_ops#

Set operations on streamlines with precision-based matching.

Attributes#

Functions#

intersection(left, right)

Return the intersection of two streamline hash dictionaries.

difference(left, right)

Return the difference of two streamline hash dictionaries.

union(left, right)

Return the union of two streamline hash dictionaries.

get_streamline_key(streamline[, precision])

Produce a hash key from a streamline using a few points.

hash_streamlines(streamlines[, start_index, precision])

Produce a dict from streamlines.

perform_streamlines_operation(operation, streamlines)

Perform an operation on a list of list of streamlines.

Module Contents#

trx.streamlines_ops.MIN_NB_POINTS = 5[source]#
trx.streamlines_ops.KEY_INDEX[source]#
trx.streamlines_ops.intersection(left, right)[source]#

Return the intersection of two streamline hash dictionaries.

Parameters:
leftdict

Hash dictionary returned by hash_streamlines().

rightdict

Hash dictionary returned by hash_streamlines().

Returns:
dict

Dictionary containing only keys present in both inputs.

trx.streamlines_ops.difference(left, right)[source]#

Return the difference of two streamline hash dictionaries.

Parameters:
leftdict

Hash dictionary returned by hash_streamlines().

rightdict

Hash dictionary returned by hash_streamlines().

Returns:
dict

Dictionary containing keys present in left but not in right.

trx.streamlines_ops.union(left, right)[source]#

Return the union of two streamline hash dictionaries.

Parameters:
leftdict

Hash dictionary returned by hash_streamlines().

rightdict

Hash dictionary returned by hash_streamlines().

Returns:
dict

Dictionary containing all keys from both inputs. Values from left overwrite those from right when keys overlap.

trx.streamlines_ops.get_streamline_key(streamline, precision=None)[source]#

Produce a hash key from a streamline using a few points.

Parameters:
streamlinendarray

A single streamline (N, 3).

precisionint, optional

The number of decimals to keep when hashing the points of the streamlines. Allows a soft comparison of streamlines. If None, no rounding is performed.

Returns:
bytes

Hash of the first/last MIN_NB_POINTS points of the streamline.

trx.streamlines_ops.hash_streamlines(streamlines, start_index=0, precision=None)[source]#

Produce a dict from streamlines.

Produce a dict from streamlines by using the points as keys and the indices of the streamlines as values.

Parameters:
streamlineslist of ndarray

The list of streamlines used to produce the dict.

start_indexint, optional

The index of the first streamline. 0 by default.

precisionint, optional

The number of decimals to keep when hashing the points of the streamlines. Allows a soft comparison of streamlines. If None, no rounding is performed.

Returns:
dict

A dict where the keys are streamline points and the values are indices starting at start_index.

trx.streamlines_ops.perform_streamlines_operation(operation, streamlines, precision=0)[source]#

Perform an operation on a list of list of streamlines.

Given a list of list of streamlines, this function applies the operation to the first two lists of streamlines. The result in then used recursively with the third, fourth, etc. lists of streamlines.

A valid operation is any function that takes two streamlines dict as input and produces a new streamlines dict (see hash_streamlines). Union, difference, and intersection are valid examples of operations.

Parameters:
operationcallable

A callable that takes two streamlines dicts as inputs and produces a new streamline dict.

streamlineslist of list of streamlines

The streamlines used in the operation.

precisionint, optional

The number of decimals to keep when hashing the points of the streamlines. Allows a soft comparison of streamlines. If None, no rounding is performed.

Returns:
streamlineslist of nib.streamline.ArraySequence

The streamlines obtained after performing the operation on all the input streamlines.

indicesnp.ndarray

The indices of the streamlines that are used in the output.