<commit_before># -*- coding: utf-8 -*-
"""
===============================================================================
Delaunay: Generate random networks based on Delaunay Tessellations
===============================================================================

"""
import sys
import scipy as sp
import numpy as np
import scipy.sparse as sprs
import scipy.spatial as sptl
import scipy.ndimage as spim
from OpenPNM.Network import GenericNetwork
from OpenPNM.Base import logging
logger = logging.getLogger(__name__)
from scipy.spatial import Voronoi
from scipy import stats as st
from scipy.special import cbrt
import OpenPNM.Utilities.vertexops as vo

class Delaunay(GenericNetwork):
    r"""
    This class contains the methods for creating a *Delaunay* network topology
    based connecting pores with a Delaunay tessellation.

    To invoke the actual generation it is necessary to run the `generate` method.

    Parameters
    ----------
    name : string
        A unique name for the network

    Examples
    --------
    >>> import OpenPNM
    >>> pn = OpenPNM.Network.Delaunay(num_pores=100, domain_size=[0.0001,0.0001,0.0001])
    >>> pn.num_pores()
    100

    """

    def __init__(self,num_pores=None,domain_size=None,**kwargs):
        '''
        Create Delauny network object
        '''
        super(Delaunay,self).__init__(**kwargs)
        if (num_pores and domain_size) is None:
            num_pores = 1
            domain_size = [1.0,1.0,1.0]
        else:
            self.generate(num_pores,domain_size)

    def generate(self,num_pores,domain_size):
        r'''
        Method to trigger the generation of the network

        Parameters
        ----------
        domain_size : list of floats, [Lx,Ly,Lz]
            Bounding cube for internal pore positions
        num_pores : int
            Number of pores to place randomly within domain

        '''
        logger.info("Start of network topology generation")
        self._generate_setup(num_pores,domain_size)
        self._generate_pores()
        self._generate_throats()
        logger.debug("Network generation complete")

    def _generate_setup(self,num_pores,domain_size):
        r"""
        Perform applicable preliminary checks and calculations required for generation
        """
        logger.debug("generate_setup: Perform preliminary calculations")
        if domain_size is not None and num_pores is not None:
            self._Lx = domain_size[0]
            self._Ly = domain_size[1]
            self._Lz = domain_size[2]
            self._Np = num_pores
            r'''
            TODO: Fix this, btype should be received as an argument
            '''
            self._btype = [0,0,0]
        else:
            logger.error("domain_size and num_pores must be specified")
            raise Exception('domain_size and num_pores must be specified')


    def _generate_pores(self):
        r"""
        Generate the pores with numbering scheme.
        """
        logger.info("Place randomly located pores in the domain")
        #Original Random Point Generator
        #coords = sp.rand(self._Np,3)*[self._Lx,self._Ly,self._Lz]
        #Seeding Code
        coords = np.zeros([self._Np,3])
        #reject points close to boundaries - if False there will be slightly more
        rejection = [False,False,True]
        for j in range(3):
            i = 0<commit_msg>Add prob to delaunay init to determine pore density<commit_after># -*- coding: utf-8 -*-
"""
===============================================================================
Delaunay: Generate random networks based on Delaunay Tessellations
===============================================================================

"""
import sys
import scipy as sp
import numpy as np
import scipy.sparse as sprs
import scipy.spatial as sptl
import scipy.ndimage as spim
from OpenPNM.Network import GenericNetwork
from OpenPNM.Base import logging
logger = logging.getLogger(__name__)
from scipy.spatial import Voronoi
from scipy import stats as st
from scipy.special import cbrt
import OpenPNM.Utilities.vertexops as vo

class Delaunay(GenericNetwork):
    r"""
    This class contains the methods for creating a *Delaunay* network topology
    based connecting pores with a Delaunay tessellation.

    To invoke the actual generation it is necessary to run the `generate` method.

    Parameters
    ----------
    name : string
        A unique name for the network

    Examples
    --------
    >>> import OpenPNM
    >>> pn = OpenPNM.Network.Delaunay(num_pores=100, domain_size=[0.0001,0.0001,0.0001])
    >>> pn.num_pores()
    100

    """

    def __init__(self,num_pores=None,domain_size=None,prob=None,**kwargs):
        '''
        Create Delauny network object
        '''
        super(Delaunay,self).__init__(**kwargs)
        if (num_pores and domain_size) is None:
            num_pores = 1
            domain_size = [1.0,1.0,1.0]
        else:
            self.generate(num_pores,domain_size,prob)

    def generate(self,num_pores,domain_size,prob):
        r'''
        Method to trigger the generation of the network

        Parameters
        ----------
        domain_size : list of floats, [Lx,Ly,Lz]
            Bounding cube for internal pore positions
        num_pores : int
            Number of pores to place randomly within domain
        prob : 3D array with probability of point with relative domain coordinates being kept
            Array does not have to be same size as domain as positions are re-scaled

        '''
        logger.info("Start of network topology generation")
        self._generate_setup(num_pores,domain_size)
        self._generate_pores(prob)
        self._generate_throats()
        logger.debug("Network generation complete")

    def _generate_setup(self,num_pores,domain_size):
        r"""
        Perform applicable preliminary checks and calculations required for generation
        """
        logger.debug("generate_setup: Perform preliminary calculations")
        if domain_size is not None and num_pores is not None:
            self._Lx = domain_size[0]
            self._Ly = domain_size[1]
            self._Lz = domain_size[2]
            self._Np = num_pores
            r'''
            TODO: Fix this, btype should be received as an argument
            '''
            self._btype = [0,0,0]
        else:
            logger.error("domain_size and num_pores must be specified")
            raise Exception('domain_size and num_pores must be specified')

    def _generate_pores(self,prob=None):
        r"""
        Generate the pores with numbering scheme.
        """
        logger.info("Place randomly located pores in the domain")
        if prob is not None:
            coords=[]
            i=0
            while i < self._Np:
                coord = np.random.rand(3)
                [indx,indy,indz]=np.floor(coord*np.shape(prob)).astype(int)
                p = prob[indx][indy][indz]
                if np.random.rand(1)<=p:
                    coords.append(coord)
                    i +=1
            coords = np.asarray(coords)
        else:
            coords = np.random.rand([self._Np,3])
        
        coords*=np.array([self._Lx,self._Ly,self._Lz])
        self['pore.coords'] = coords
        logger.debug("End of method")
        
    def _generate_pores_old(self):
        r"""
        Generate the pores with numbering scheme.
        """
        logger.info("Place randomly located pores in the domain")
        #Original Random Point Generator
        #coords = sp.rand(self._Np,3)*[self._Lx,self._Ly,self._Lz]
        #Seeding Code
        coords = np.zeros([self._Np,3])
        #reject points close to boundaries - if False there will be slightly more
        rejection = [False,False,True]
        for j in range(3):
            i = 0
{'fraction_non_alphanumeric': 0.12800511508951407, 'fraction_numerical': 0.010741687979539642, 'mean_word_length': 2.3857142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5085084', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2151, 'n_words': 645}