find_neighbor_pores#
- Delaunay.find_neighbor_pores(pores, mode='or', flatten=True, include_input=False, asmask=False)#
Returns a list of pores that are direct neighbors to the given pore(s)
- Parameters:
pores (array_like) – Indices of the pores whose neighbors are sought
flatten (bool) – If
True
(default) the returned result is a compressed array of all neighbors. IfFalse
, a list of lists with each sub-list containing the neighbors for each input site. Note that an unflattened list might be slow to generate since it is a Pythonlist
rather than a Numpyarray
.include_input (bool) – If
False
(default) then the input pores are not included in the returned list(s). Note that since pores are not neighbors of themselves, the neighbors of pore N will not include N, even if this flag isTrue
.mode (str) –
Specifies logic to filter the resulting list. Options are:
mode
meaning
’or’
All neighbors of the input pores. Also accepts ‘any’ and ‘union’.
’xor’
Only neighbors of one and only one input pore. This is useful for counting the pores that are not shared by any of the input pores. Also accepts ‘exclusive_or’.
’xnor’
Neighbors that are shared by two or more input pores. This is equivalent to counting all neighbors with ‘or’, minus those found with ‘xor’, and is useful for finding neighbors that the inputs have in common.
’and’
Only neighbors shared by all input pores. Also accepts ‘intersection’ and ‘all’
asmask (boolean) – If
False
(default), the returned result is a list of the neighboring pores as indices. IfTrue
, the returned result is a boolean mask. (Useful for labelling)
- Returns:
If
flatten
isTrue
, returns a 1D array of pore indicesfiltered according to the specified mode. If
flatten
isFalse
, returns a list of lists, where each list contains theneighbors of the corresponding input pores.
Notes
The
logic
options are applied to neighboring pores only, thus it is not possible to obtain pores that are part of the global set but not neighbors. This is because (a) the list of global pores might be very large, and (b) it is not possible to return a list of neighbors for each input pores if global pores are considered.Examples
>>> import openpnm as op >>> pn = op.network.Cubic(shape=[5, 5, 5]) >>> Ps = pn.find_neighbor_pores(pores=[0, 2]) >>> print(Ps) [ 1 3 5 7 25 27] >>> Ps = pn.find_neighbor_pores(pores=[0, 1]) >>> print(Ps) [ 2 5 6 25 26] >>> Ps = pn.find_neighbor_pores(pores=[0, 1], mode='or', ... include_input=True) >>> print(Ps) [ 0 1 2 5 6 25 26] >>> Ps = pn.find_neighbor_pores(pores=[0, 2], flatten=False) >>> print(Ps[0]) [ 1 5 25] >>> print(Ps[1]) [ 1 3 7 27] >>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xnor') >>> print(Ps) [1] >>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xor') >>> print(Ps) [ 3 5 7 25 27]