A new way to trim throats from a network? #2013
Locked
jgostick
started this conversation in
Development
Replies: 1 comment
-
I answered my own question: The answer, as always, is no don't do a class if you don't need it. I distilled it down to a stupid simple function: def drop_sites(conns, site_mask):
r"""
Find new conns array after dropping sites
Parameters
----------
conns : ndarray
The [head, tail] indices for each bond
site_mask : ndarray
A boolean array with ``False`` values indicating which sites to
remove
Returns
-------
conns : ndarray
An update conns array with headless throats removed and site indices
updated
bond_mask : ndarray
A boolean array with ``False`` values indicating which throats
were headless and should be dropped for other throat arrays.
"""
site_id = np.cumsum(site_mask) - 1
bond_mask = np.all(site_mask[conns], axis=1)
conns = site_id[conns[bond_mask]]
return conns, bond_mask This returns the new conns, as well as a mask that is used for dropping elements from all other throat arrays, like: for arr in obj.keys():
if arr.startswith('throat'):
obj[arr] = obj[arr][bond_mask] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been trying to think of a way to drop pores from the network more easily/robustly. The problem is that when you drop a pore 2 things need to happen. (1) all throats pointing to that pore must be deleted and (2) the throat conns array must be renumbered since pores have new indices on account of some being removed.
The code snippet below handles this using a class with several interdependent methosd on it. I normally don't like defining a class that I have no intension of reusing in future but this case seems to make sense since the class holds all the data and methods together.
So the idea is this: You call
op.topotools.trim(network, pores=Ps)
and inside that function the following class is instantiated. It is then used to drop the pores by updating thesite_mask
attribute to putFalse
values in pores to be removed. You then overwrite thethroat.conns
array of the network with theconns
attribute of this new class. There is also abond_mask
attribute that can be used to trim all the other throat properties.Beta Was this translation helpful? Give feedback.
All reactions