<commit_before># -*- coding: utf-8 -*-
"""
===============================================================================
Network.tools.topology: Assorted topological manipulation methods
===============================================================================

"""
import scipy as _sp
import scipy.sparse as _sprs
import scipy.spatial as _sptl
from OpenPNM.Base import logging as _logging
from OpenPNM.Base import Controller as _controller
logger = _logging.getLogger(__name__)
_ctrl = _controller()

class topology(object):

    def extend(self,network,pore_coords=[],throat_conns=[],labels=[]):
        r'''
        Add individual pores and/or throats to the network from a list of coords
        or conns.  This is an in-place operation, meaning the received Network
        object will be altered directly.
    
        Parameters
        ----------
        network : OpenPNM Network Object
            The Network to which pores or throats should be added
        pore_coords : array_like
            The coordinates of the pores to add
        throat_conns : array_like
            The throat connections to add
        labels : string, or list of strings, optional
            A list of labels to apply to the new pores and throats
    
        Notes
        -----
        This needs to be enhanced so that it increases the size of all pore
        and throat props and labels on ALL associated Phase objects.  At the
        moment it throws an error is there are any associated Phases.
    
        '''
        if (network._phases != []):
            raise Exception('Network has active Phases, cannot proceed')
    
        logger.info('Extending network')
        Np_old = network.num_pores()
        Nt_old = network.num_throats()
        Np = Np_old + int(_sp.size(pore_coords)/3)
        Nt = Nt_old + int(_sp.size(throat_conns)/2)
        # Adjust 'all' labels
        del network['pore.all'], network['throat.all']
        network['pore.all'] = _sp.ones((Np,),dtype=bool)
        network['throat.all'] = _sp.ones((Nt,),dtype=bool)
        # Add coords and conns
        if pore_coords != []:
            coords = _sp.vstack((network['pore.coords'],pore_coords))
            network['pore.coords'] = coords
        if throat_conns != []:
            conns = _sp.vstack((network['throat.conns'],throat_conns))
            network['throat.conns'] = conns
        # Increase size of any prop or label arrays on Network
        for item in network.keys():
            if item.split('.')[1] not in ['coords','conns','all']:
                if item.split('.')[0] == 'pore':
                    N = Np
                else:
                    N = Nt
                if network[item].dtype == bool:
                    temp = network[item]
                    network[item] = _sp.zeros((N,),dtype=bool)
                    network[item][temp] = True
                elif network[item].dtype == object:
                    temp = network[item]
                    network[item] = _sp.ndarray((N,),dtype=object)
                    network[item][_sp.arange(0,_sp.shape(temp)[0])] = temp
                else:
                    temp = network[item]
                    try:
                        network[item] = _sp.ones((N,_sp.shape(temp)[1]),dtype=float)*_sp.nan
                    except:
                        network[item] = _sp.ones((N,),dtype=float)*_sp.nan
                    network[item][_sp.arange(0,_sp.shape(temp)[0])] = temp
        #Apply labels, if supplied
        if labels != []:
            #Convert labels to list if necessary
            if type(labels) is str:
                labels = [labels]
            for label in labels:
                #Remove pore or throat from label, if present
                label = label.split('.')[-1]
                if pore_coords != []:
                    Ps = _sp.r_[Np_old:Np]
                    if 'pore.'+label not in network.labels():
                        network['pore.'+label] = False
                    network['pore.'+label][Ps] = True
                if throat_conns != []:<commit_msg>fixed other logical checks in topology to use sp.size() > 0<commit_after># -*- coding: utf-8 -*-
"""
===============================================================================
Network.tools.topology: Assorted topological manipulation methods
===============================================================================

"""
import scipy as _sp
import scipy.sparse as _sprs
import scipy.spatial as _sptl
from OpenPNM.Base import logging as _logging
from OpenPNM.Base import Controller as _controller
logger = _logging.getLogger(__name__)
_ctrl = _controller()

class topology(object):

    def extend(self,network,pore_coords=[],throat_conns=[],labels=[]):
        r'''
        Add individual pores and/or throats to the network from a list of coords
        or conns.  This is an in-place operation, meaning the received Network
        object will be altered directly.
    
        Parameters
        ----------
        network : OpenPNM Network Object
            The Network to which pores or throats should be added
        pore_coords : array_like
            The coordinates of the pores to add
        throat_conns : array_like
            The throat connections to add
        labels : string, or list of strings, optional
            A list of labels to apply to the new pores and throats
    
        Notes
        -----
        This needs to be enhanced so that it increases the size of all pore
        and throat props and labels on ALL associated Phase objects.  At the
        moment it throws an error is there are any associated Phases.
    
        '''
        if (network._phases != []):
            raise Exception('Network has active Phases, cannot proceed')
    
        logger.info('Extending network')
        Np_old = network.num_pores()
        Nt_old = network.num_throats()
        Np = Np_old + int(_sp.size(pore_coords)/3)
        Nt = Nt_old + int(_sp.size(throat_conns)/2)
        # Adjust 'all' labels
        del network['pore.all'], network['throat.all']
        network['pore.all'] = _sp.ones((Np,),dtype=bool)
        network['throat.all'] = _sp.ones((Nt,),dtype=bool)
        # Add coords and conns
        if _sp.size(pore_coords) > 0:
            coords = _sp.vstack((network['pore.coords'],pore_coords))
            network['pore.coords'] = coords
        if _sp.size(throat_conns) > 0:
            conns = _sp.vstack((network['throat.conns'],throat_conns))
            network['throat.conns'] = conns
        # Increase size of any prop or label arrays on Network
        for item in network.keys():
            if item.split('.')[1] not in ['coords','conns','all']:
                if item.split('.')[0] == 'pore':
                    N = Np
                else:
                    N = Nt
                if network[item].dtype == bool:
                    temp = network[item]
                    network[item] = _sp.zeros((N,),dtype=bool)
                    network[item][temp] = True
                elif network[item].dtype == object:
                    temp = network[item]
                    network[item] = _sp.ndarray((N,),dtype=object)
                    network[item][_sp.arange(0,_sp.shape(temp)[0])] = temp
                else:
                    temp = network[item]
                    try:
                        network[item] = _sp.ones((N,_sp.shape(temp)[1]),dtype=float)*_sp.nan
                    except:
                        network[item] = _sp.ones((N,),dtype=float)*_sp.nan
                    network[item][_sp.arange(0,_sp.shape(temp)[0])] = temp
        #Apply labels, if supplied
        if labels != []:
            #Convert labels to list if necessary
            if type(labels) is str:
                labels = [labels]
            for label in labels:
                #Remove pore or throat from label, if present
                label = label.split('.')[-1]
                if _sp.size(pore_coords) > 0:
                    Ps = _sp.r_[Np_old:Np]
                    if 'pore.'+label not in network.labels():
                        network['pore.'+label] = False
                    network['pore.'+label][Ps] = True
                if _sp.size(throat_conns) > 0:
{'fraction_non_alphanumeric': 0.1436544528027178, 'fraction_numerical': 0.0032759039068187335, 'mean_word_length': 1.8681280445372304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5810266', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2221, 'n_words': 631}