Cubic.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)

  • 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. If False, 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 Python list rather than a Numpy array.

  • 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 is True.

  • mode (str) –

    Specifies logic to filter the resulting list. Options are:




    All neighbors of the input pores. Also accepts ‘any’ and ‘union’.


    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’.


    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.


    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. If True, the returned result is a boolean mask. (Useful for labelling)


  • If flatten is True, returns a 1D array of pore indices

  • filtered according to the specified mode. If flatten is

  • False, returns a list of lists, where each list contains the

  • neighbors of the corresponding input pores.


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.


>>> import openpnm as op
>>> pn =[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)
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xor')
>>> print(Ps)
[ 3  5  7 25 27]