<commit_before># -*- coding: utf-8 -*-
"""
===============================================================================
GenericGeometry -- Base class to manage pore scale geometry
===============================================================================

"""

import scipy as sp
from OpenPNM.Base import Core
from OpenPNM.Base import logging
from OpenPNM.Network import GenericNetwork
logger = logging.getLogger(__name__)
import OpenPNM.Geometry.models

class GenericGeometry(Core):
    r"""
    GenericGeometry - Base class to construct a Geometry object

    Parameters
    ----------
    network : OpenPNM Network Object

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the physics nowhere.  The locations can be
        change after instantiation using ``set_locations()``.

    name : string
        A unique name to apply to the object.  This name will also be used as a
        label to identify where this this geometry applies.

    Examples
    --------
    >>> pn = OpenPNM.Network.TestNet()
    >>> Ps = pn.pores()  # Get all pores
    >>> Ts = pn.throats()  # Get all throats
    >>> geom = OpenPNM.Geometry.GenericGeometry(network=pn,pores=Ps,throats=Ts)
    """

    def __init__(self,network=None,pores=[],throats=[],seed=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericGeometry,self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._geometries.append(self)  # Register self with network.geometries

        #Initialize a label dictionary in the associated network
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        self.set_locations(pores=pores,throats=throats)
        self._seed = seed

    def __getitem__(self,key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'

        if key in self.keys():  # Look for data on self...
            return super(GenericGeometry,self).__getitem__(key)
        if key == 'throat.conns':  # Handle specifically
            [P1,P2] = self._net['throat.conns'][self._net[element+'.'+self.name]].T
            Pmap = sp.zeros((self._net.Np,),dtype=int)-1
            Pmap[self._net.pores(self.name)] = self.Ps
            conns = sp.array([Pmap[P1],Pmap[P2]],dtype=object).T
            conns[sp.where(conns==-1)] = sp.nan
            return conns
        else:  # ...Then check Network
            return self._net[key][self._net[element+'.'+self.name]]

    def set_locations(self,pores=[],throats=[]):
        r'''
        This method can be used to set the pore and throats locations of an
        *empty* object.  Once locations have been set they can not be changed.

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats where the object should be applied.

        Notes
        -----
        This method is intended to assist in the process of loading saved
        objects.  Save data can be loaded onto an empty object, then the object
        can be reassociated with a Network manually by setting the pore and
        throat locations on the object.
        '''
        pores = sp.array(pores,ndmin=1)
        throats = sp.array(throats,ndmin=1)
        if len(pores)>0:
            #Check for existing Geometry in pores
            temp = sp.zeros((self._net.Np,),bool)
            for key in self._net.geometries():
                temp += self._net['pore.'+key]<commit_msg>Final little tweak: It only returns an object array IF there is a need for Nans, otherwise it's a standard int array.<commit_after># -*- coding: utf-8 -*-
"""
===============================================================================
GenericGeometry -- Base class to manage pore scale geometry
===============================================================================

"""

import scipy as sp
from OpenPNM.Base import Core
from OpenPNM.Base import logging
from OpenPNM.Network import GenericNetwork
logger = logging.getLogger(__name__)
import OpenPNM.Geometry.models

class GenericGeometry(Core):
    r"""
    GenericGeometry - Base class to construct a Geometry object

    Parameters
    ----------
    network : OpenPNM Network Object

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the physics nowhere.  The locations can be
        change after instantiation using ``set_locations()``.

    name : string
        A unique name to apply to the object.  This name will also be used as a
        label to identify where this this geometry applies.

    Examples
    --------
    >>> pn = OpenPNM.Network.TestNet()
    >>> Ps = pn.pores()  # Get all pores
    >>> Ts = pn.throats()  # Get all throats
    >>> geom = OpenPNM.Geometry.GenericGeometry(network=pn,pores=Ps,throats=Ts)
    """

    def __init__(self,network=None,pores=[],throats=[],seed=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericGeometry,self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._geometries.append(self)  # Register self with network.geometries

        #Initialize a label dictionary in the associated network
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        self.set_locations(pores=pores,throats=throats)
        self._seed = seed

    def __getitem__(self,key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'

        if key in self.keys():  # Look for data on self...
            return super(GenericGeometry,self).__getitem__(key)
        if key == 'throat.conns':  # Handle specifically
            [P1,P2] = self._net['throat.conns'][self._net[element+'.'+self.name]].T
            Pmap = sp.zeros((self._net.Np,),dtype=int)-1
            Pmap[self._net.pores(self.name)] = self.Ps
            conns = sp.array([Pmap[P1],Pmap[P2]]).T
            # Replace -1's with nans
            if sp.any(conns==-1):
                conns = sp.array(conns,dtype=object)
                conns[sp.where(conns==-1)] = sp.nan
            return conns
        else:  # ...Then check Network
            return self._net[key][self._net[element+'.'+self.name]]

    def set_locations(self,pores=[],throats=[]):
        r'''
        This method can be used to set the pore and throats locations of an
        *empty* object.  Once locations have been set they can not be changed.

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats where the object should be applied.

        Notes
        -----
        This method is intended to assist in the process of loading saved
        objects.  Save data can be loaded onto an empty object, then the object
        can be reassociated with a Network manually by setting the pore and
        throat locations on the object.
        '''
        pores = sp.array(pores,ndmin=1)
        throats = sp.array(throats,ndmin=1)
        if len(pores)>0:
            #Check for existing Geometry in pores
            temp = sp.zeros((self._net.Np,),bool)
            for key in self._net.geometries():
                temp += self._net['pore.'+key]
{'fraction_non_alphanumeric': 0.1489006043461489, 'fraction_numerical': 0.0033431914620033433, 'mean_word_length': 2.3540319103061664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '396872', 'n_tokens_mistral': 2209, 'n_tokens_neox': 2124, 'n_words': 666}