[docs]defcheck_data_health(obj):r""" Checks the health of pore and throat data arrays. Parameters ---------- obj : Base A handle of the object to be checked Returns ------- health : dict Returns a HealthDict object which is a basic dictionary with an added ``health`` attribute that is ``True`` is all entries in the dict are deemed healthy (empty lists), or ``False`` otherwise. """health=HealthDict()foriteminobj.props():health[item]=[]ifobj[item].dtype=='O':health[item]='No checks on object'elifnp.sum(np.isnan(obj[item]))>0:health[item]='Has NaNs'elifnp.shape(obj[item])[0]!=obj._count(item.split('.',1)[0]):health[item]='Wrong Length'returnhealth
[docs]defcheck_network_health(network):r""" This method checks the topological health of the network The following aspects are checked for: (1) Isolated pores (2) Disconnected clusters of pores (3) Duplicate throats (4) Headless throats (5) Bidirectional throats Returns ------- health : dict A dictionary containing the offending pores or throat numbers under each named key. Notes ----- It also returns a list of which pores and throats should be trimmed from the network to restore health. This list is a suggestion only, and is based on keeping the largest cluster and trimming the others. - Does not yet check for duplicate pores - Does not yet suggest which throats to remove - This is just a 'check' and does not 'fix' the problems it finds """importopenpnm.models.networkasmodshealth=HealthDict()# Check for headless throatsheadless=mods.headless_throats(network)health['headless_throats']=np.where(headless)[0].tolist()# Check for throats that loop back onto the same porelooped=mods.looped_throats(network)health['looped_throats']=np.where(looped)[0].tolist()# Check for individual isolated poresisolated=mods.isolated_pores(network)health['isolated_pores']=np.where(isolated)[0].tolist()# Check for separated clusters of poressize=mods.cluster_size(network)mx=np.max(size)health['disconnected_pores']=np.where(size<mx)[0].tolist()# Check for duplicate throatsdupes=mods.duplicate_throats(network)health['duplicate_throats']=np.where(dupes)[0].tolist()# Check for bidirectional throatsbidir=mods.bidirectional_throats(network)health['bidirectional_throats']=np.where(bidir)[0].tolist()returnhealth