<commit_before>"""
module __Tools__: Base class to construct pore network tools
==================================================================

.. warning:: The classes of this module should be loaded through the 'Base.__init__.py' file.

"""

import sys, os
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.path[1] != parent_dir:
    sys.path.insert(1, parent_dir)
import OpenPNM
import scipy as sp
from OpenPNM.Utilities import Base

class Tools(Base):
    r'''
    This class contains tools to read and write data in OpenPNM objects

    '''
    def __init__(self, **kwargs):
        r'''
        Initialize
        '''
        super(Tools,self).__init__(**kwargs)
        self._logger.debug("Construct Network container")
        #Initialize network properties dictionaries
        self._pore_data = {}
        self._pore_info = {}
        self._throat_data = {}
        self._throat_info = {}
        #Initialize fluid, physics, and geometry tracking lists
        self._fluids = []
        self._geometry = []
        self._logger.info("Construction of Object container complete")
        
    #--------------------------------------------------------------------------
    '''Setter and Getter Methods'''
    #--------------------------------------------------------------------------
    def _set_data(self,element='',phase='',prop='',data='',locations=''):
        r'''
        Documentation for this method is being updated, we are sorry for the inconvenience.
        '''
        if type(data)!=sp.ndarray: data = sp.array(data,ndmin=1)
        if type(locations)==list: 
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: locations = sp.array(locations,ndmin=1)
        elif type(locations)==sp.ndarray:
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: pass            
        elif locations!='':
            try: locations = locations.name 
            except: pass
            if type(locations)==str: locations = getattr(self,'get_'+element+'_indices')([locations])
              
        try: phase = self.find_object_by_name(phase) 
        except: pass #Accept object

        if phase :

            if sp.shape(data)[0]==1:
                if locations!='':                
                    try: getattr(phase,'_'+element+'_data')[prop]
                    except: getattr(phase,'_'+element+'_data')[prop] = sp.zeros((getattr(phase,'num_'+element+'s')(),))*sp.nan
                    getattr(phase,'_'+element+'_data')[prop][locations] = data
                else:
                    try: 
                        getattr(phase,'_'+element+'_data')[prop]
                        if sp.shape(getattr(phase,'_'+element+'_data')[prop])[0]!=1:
                            print('Warning: '+prop+' '+element+' property was an array which has been overwritten with a scalar value')
                    except: pass
                    getattr(phase,'_'+element+'_data')[prop] = data            
            else:                
                if locations!='':
                    if sp.shape(locations)[0]==sp.shape(data)[0]:
                        try: getattr(phase,'_'+element+'_data')[prop]
                        except: getattr(phase,'_'+element+'_data')[prop] = sp.zeros((getattr(phase,'num_'+element+'s')(),))*sp.nan
                        getattr(phase,'_'+element+'_data')[prop][locations] = data
                    else: 
                        phase._logger.error('locations and data sizes do not match!')
                else:
                    try: 
                        getattr(phase,'num_'+element+'s')()                        
                        if sp.shape(data)[0]==getattr(phase,'num_'+element+'s')():
                            getattr(phase,'_'+element+'_data')[prop] = data
                        else: phase._logger.error('Number of '+element+'s and size of data do not match!')
                    except: phase._logger.error(element+' numbering has not been specified for this phase')
                        
        else:
            
            if sp.shape(data)[0]==1:
                if locations!='':                
                    try: getattr(self,'_'+element+'_data')[prop]
                    except: getattr(self,'_'+element+'_data')[prop] = sp.zeros((getattr(self,'num_'+element+'s')(),))*sp.nan
                    getattr(self,'_'+element+'_data')[prop][locations] = data
                else:
                    try: 
                        getattr(self,'_'+element+'_data')[prop]
                        if sp.shape(getattr(self,'_'+element+'_data')[prop])[0]!=1:
                            print('Warning: '+prop+' '+element+' property was an array which has been overwritten with a scalar value')
                    except: pass
                    getattr(self,'_'+element+'_data')[prop] = data            
            else:                
                if locations!='':
                    if sp.shape(locations)[0]==sp.shape(data)[0]:
                        try: getattr(self,'_'+element+'_data')[prop]
                        except: getattr(self,'_'+element+'_data')[prop] = sp.zeros((getattr(self,'num_'+element+'s')(),))*sp.nan
                        getattr(self,'_'+element+'_data')[prop][locations] = data
                        self._logger.debug(element+' property '+ prop+'has been added')
                    else: self._logger.error('locations and data sizes do not match!')
                else:
                    try: 
                        getattr(self,'num_'+element+'s')()                        
                        if sp.shape(data)[0]==getattr(self,'num_'+element+'s')():
                            getattr(self,'_'+element+'_data')[prop] = data
                            self._logger.debug(element+' property '+ prop+'has been added')
                        else: self._logger.error('Number of '+element+'s and size of data do not match!')
                    except: getattr(self,'_'+element+'_data')[prop] = data


    def _get_data(self,element='',phase='',prop='',locations=''):
        r'''
        Documentation for this method is being updated, we are sorry for the inconvenience.
        '''      
        if type(locations)==list: 
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: locations = sp.array(locations,ndmin=1)<commit_msg>Added more details in logger for data setter.<commit_after>"""
module __Tools__: Base class to construct pore network tools
==================================================================

.. warning:: The classes of this module should be loaded through the 'Base.__init__.py' file.

"""

import sys, os
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.path[1] != parent_dir:
    sys.path.insert(1, parent_dir)
import OpenPNM
import scipy as sp
from OpenPNM.Utilities import Base

class Tools(Base):
    r'''
    This class contains tools to read and write data in OpenPNM objects

    '''
    def __init__(self, **kwargs):
        r'''
        Initialize
        '''
        super(Tools,self).__init__(**kwargs)
        self._logger.debug("Construct Network container")
        #Initialize network properties dictionaries
        self._pore_data = {}
        self._pore_info = {}
        self._throat_data = {}
        self._throat_info = {}
        #Initialize fluid, physics, and geometry tracking lists
        self._fluids = []
        self._geometry = []
        self._logger.info("Construction of Object container complete")
        
    #--------------------------------------------------------------------------
    '''Setter and Getter Methods'''
    #--------------------------------------------------------------------------
    def _set_data(self,element='',phase='',prop='',data='',locations=''):
        r'''
        Documentation for this method is being updated, we are sorry for the inconvenience.
        '''
        if type(data)!=sp.ndarray: data = sp.array(data,ndmin=1)
        if type(locations)==list: 
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: locations = sp.array(locations,ndmin=1)
        elif type(locations)==sp.ndarray:
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: pass            
        elif locations!='':
            try: locations = locations.name 
            except: pass
            if type(locations)==str: locations = getattr(self,'get_'+element+'_indices')([locations])
              
        try: phase = self.find_object_by_name(phase) 
        except: pass #Accept object

        if phase :

            if sp.shape(data)[0]==1:
                if locations!='':                
                    try: getattr(phase,'_'+element+'_data')[prop]
                    except: getattr(phase,'_'+element+'_data')[prop] = sp.zeros((getattr(phase,'num_'+element+'s')(),))*sp.nan
                    getattr(phase,'_'+element+'_data')[prop][locations] = data
                else:
                    try: 
                        getattr(phase,'_'+element+'_data')[prop]
                        if sp.shape(getattr(phase,'_'+element+'_data')[prop])[0]!=1:
                            print('Warning: '+prop+' '+element+' property in '+phase.name+' was an array which has been overwritten with a scalar value')
                    except: pass
                    getattr(phase,'_'+element+'_data')[prop] = data  
            else:                
                if locations!='':
                    if sp.shape(locations)[0]==sp.shape(data)[0]:
                        try: getattr(phase,'_'+element+'_data')[prop]
                        except: getattr(phase,'_'+element+'_data')[prop] = sp.zeros((getattr(phase,'num_'+element+'s')(),))*sp.nan
                        getattr(phase,'_'+element+'_data')[prop][locations] = data
                    else: 
                        phase._logger.error('For adding '+element+' property '+prop+' to '+phase.name+', locations and size of data do not match!')
                else:
                    try: 
                        getattr(phase,'num_'+element+'s')()                        
                        if sp.shape(data)[0]==getattr(phase,'num_'+element+'s')():
                            getattr(phase,'_'+element+'_data')[prop] = data
                        else: phase._logger.error('For adding '+element+' property '+prop+' to '+phase.name+', number of '+element+'s and size of data do not match!')
                    except: phase._logger.error(element+' numbering has not been specified for '+phase.name)
            phase._logger.debug(element+' property '+prop+' has been added to '+phase.name)
                        
        else:
            
            if sp.shape(data)[0]==1:
                if locations!='':                
                    try: getattr(self,'_'+element+'_data')[prop]
                    except: getattr(self,'_'+element+'_data')[prop] = sp.zeros((getattr(self,'num_'+element+'s')(),))*sp.nan
                    getattr(self,'_'+element+'_data')[prop][locations] = data
                else:
                    try: 
                        getattr(self,'_'+element+'_data')[prop]
                        if sp.shape(getattr(self,'_'+element+'_data')[prop])[0]!=1:
                            print('Warning: '+prop+' '+element+' property in '+self.name+' was an array which has been overwritten with a scalar value')
                    except: pass
                    getattr(self,'_'+element+'_data')[prop] = data            
            else:                
                if locations!='':
                    if sp.shape(locations)[0]==sp.shape(data)[0]:
                        try: getattr(self,'_'+element+'_data')[prop]
                        except: getattr(self,'_'+element+'_data')[prop] = sp.zeros((getattr(self,'num_'+element+'s')(),))*sp.nan
                        getattr(self,'_'+element+'_data')[prop][locations] = data
                    else: self._logger.error('For adding '+element+' property '+prop+' to '+self.name+', locations and size of data do not match!')
                else:
                    try: 
                        getattr(self,'num_'+element+'s')()                        
                        if sp.shape(data)[0]==getattr(self,'num_'+element+'s')():
                            getattr(self,'_'+element+'_data')[prop] = data
                        else: self._logger.error('For adding '+element+' property '+prop+' to '+self.name+', number of '+element+'s and size of data do not match!')
                    except: getattr(self,'_'+element+'_data')[prop] = data
            self._logger.debug(element+' property '+prop+' has been added to '+self.name)



    def _get_data(self,element='',phase='',prop='',locations=''):
        r'''
        Documentation for this method is being updated, we are sorry for the inconvenience.
        '''      
        if type(locations)==list: 
            try: locations = getattr(self,'get_'+element+'_indices')(locations)
            except: locations = sp.array(locations,ndmin=1)
{'fraction_non_alphanumeric': 0.17118887461265211, 'fraction_numerical': 0.002872042929483788, 'mean_word_length': 1.7856842105263158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7124480', 'n_tokens_mistral': 3583, 'n_tokens_neox': 3414, 'n_words': 729}