<s> """<STR_LIT>""" <EOL> import scipy as sp <EOL> import scipy . io as spio <EOL> import os <EOL> from OpenPNM . Network import GenericNetwork <EOL> import OpenPNM . Geometry <EOL> import OpenPNM . Utilities . misc as misc <EOL> from OpenPNM . Base import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> class MatFile ( GenericNetwork ) : <EOL> r"""<STR_LIT>""" <EOL> def __init__ ( self , filename = '<STR_LIT>' , path = '<STR_LIT>' , xtra_pore_data = None , <EOL> xtra_throat_data = None , ** kwargs ) : <EOL> super ( ) . __init__ ( ** kwargs ) <EOL> if filename == '<STR_LIT>' : <EOL> return <EOL> if path == '<STR_LIT>' : <EOL> path = os . path . abspath ( '<STR_LIT:.>' ) <EOL> self . _path = path <EOL> filepath = os . path . join ( self . _path , filename ) <EOL> self . _xtra_pore_data = xtra_pore_data <EOL> self . _xtra_throat_data = xtra_throat_data <EOL> self . _dictionary = spio . loadmat ( filepath ) <EOL> self . _Np = sp . size ( self . _dictionary [ '<STR_LIT>' ] ) <EOL> self . _Nt = sp . size ( self . _dictionary [ '<STR_LIT>' ] ) <EOL> self . _add_pores ( ) <EOL> self . _add_throats ( ) <EOL> self . _remove_disconnected_clusters ( ) <EOL> self . _add_xtra_pore_data ( ) <EOL> self . _add_xtra_throat_data ( ) <EOL> self . _add_geometry ( ) <EOL> def _add_pores ( self ) : <EOL> Pind = sp . arange ( <NUM_LIT:0> , self . _Np ) <EOL> self [ '<STR_LIT>' ] = sp . ones_like ( Pind , dtype = bool ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> self [ '<STR_LIT>' ] = sp . array ( self . _dictionary [ '<STR_LIT>' ] , float ) <EOL> def _add_throats ( self ) : <EOL> Tind = sp . arange ( <NUM_LIT:0> , self . _Nt ) <EOL> self [ '<STR_LIT>' ] = sp . ones_like ( Tind , dtype = bool ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> self [ '<STR_LIT>' ] = sp . array ( self . _dictionary [ '<STR_LIT>' ] , int ) <EOL> def _remove_disconnected_clusters ( self ) : <EOL> bad_pores = sp . array ( [ ] , dtype = int ) <EOL> self . _pore_map = self . pores ( ) <EOL> self . _throat_map = self . throats ( ) <EOL> health = self . check_network_health ( ) <EOL> if health [ '<STR_LIT>' ] == [ ] : <EOL> self . _throat_map = self . throats ( ) <EOL> self . _pore_map = self . pores ( ) <EOL> else : <EOL> Np = self . num_pores ( ) <EOL> Nt = self . num_throats ( ) <EOL> cluster_sizes = [ sp . shape ( x ) [ <NUM_LIT:0> ] for x in health [ '<STR_LIT>' ] ] <EOL> acceptable_size = min ( [ min ( [ <NUM_LIT:50> , Np / <NUM_LIT:2> ] ) , max ( cluster_sizes ) ] ) <EOL> for cluster in health [ '<STR_LIT>' ] : <EOL> if sp . shape ( cluster ) [ <NUM_LIT:0> ] < acceptable_size : <EOL> bad_pores = sp . append ( bad_pores , sp . ravel ( cluster ) ) <EOL> bad_throats = sp . unique ( self . find_neighbor_throats ( bad_pores ) ) <EOL> if sp . shape ( bad_pores ) [ <NUM_LIT:0> ] > <NUM_LIT:0> : <EOL> i = <NUM_LIT:0> <EOL> self . _pore_map = sp . zeros ( ( Np - sp . shape ( bad_pores ) [ <NUM_LIT:0> ] , ) , dtype = int ) <EOL> for pore in self . pores ( ) : <EOL> if pore not in bad_pores : <EOL> self . _pore_map [ i ] = pore <EOL> i += <NUM_LIT:1> <EOL> if sp . shape ( bad_throats ) [ <NUM_LIT:0> ] > <NUM_LIT:0> : <EOL> i = <NUM_LIT:0> <EOL> self . _throat_map = sp . zeros ( ( Nt - sp . shape ( bad_throats ) [ <NUM_LIT:0> ] , ) , <EOL> dtype = int ) <EOL> for throat in self . throats ( ) : <EOL> if throat not in bad_throats : <EOL> self . _throat_map [ i ] = throat <EOL> i += <NUM_LIT:1> <EOL> try : <EOL> if sp . shape ( bad_pores ) [ <NUM_LIT:0> ] > <NUM_LIT:0> : <EOL> i = <NUM_LIT:0> <EOL> old_transform = self . _dictionary [ '<STR_LIT>' ] <EOL> self . _dictionary [ '<STR_LIT>' ] = sp . zeros ( ( Np - sp . shape ( bad_pores ) [ <NUM_LIT:0> ] , ) , dtype = int ) <EOL> for pore in self . pores ( ) : <EOL> if pore not in bad_pores : <EOL> self . _dictionary [ '<STR_LIT>' ] [ i ] = old_transform [ pore ] <EOL> i += <NUM_LIT:1> <EOL> except : <EOL> logger . info ( '<STR_LIT>' ) <EOL> pass <EOL> self . trim ( pores = bad_pores ) <EOL> def _add_geometry ( self ) : <EOL> try : <EOL> boundary_pores = sp . where ( self [ '<STR_LIT>' ] != <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> boundary_throats = sp . where ( self [ '<STR_LIT>' ] != <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:1> ) <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:6> ) <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:2> ) <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:5> ) <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:3> ) <EOL> self [ '<STR_LIT>' ] = sp . ravel ( self [ '<STR_LIT>' ] == <NUM_LIT:4> ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT>' ) ) ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT>' ) ) ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT:left>' ) ) ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT:right>' ) ) ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT>' ) ) ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( sp . ravel ( <EOL> self . find_connected_pores ( self . throats ( '<STR_LIT>' ) ) ) ) <EOL> add_boundaries = True <EOL> except : <EOL> boundary_pores = sp . array ( [ ] ) <EOL> boundary_throats = sp . array ( [ ] ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> add_boundaries = False <EOL> Ps = sp . where ( [ pore not in boundary_pores for pore in self . pores ( ) ] ) [ <NUM_LIT:0> ] <EOL> Ts = sp . where ( <EOL> [ throat not in boundary_throats for throat in self . throats ( ) ] ) [ <NUM_LIT:0> ] <EOL> geom = OpenPNM . Geometry . GenericGeometry ( network = self , pores = Ps , throats = Ts ) <EOL> geom [ '<STR_LIT>' ] = sp . ravel ( sp . array ( <EOL> self . _dictionary [ '<STR_LIT>' ] [ self . _pore_map [ Ps ] ] , float ) ) <EOL> geom [ '<STR_LIT>' ] = sp . ravel ( sp . array ( <EOL> self . _dictionary [ '<STR_LIT>' ] [ self . _pore_map [ Ps ] ] , float ) ) <EOL> geom [ '<STR_LIT>' ] = sp . ravel ( sp . array ( <EOL> self . _dictionary [ '<STR_LIT>' ] [ self . _throat_map [ Ts ] ] , float ) ) <EOL> geom . add_model ( propname = '<STR_LIT>' , <EOL> model = OpenPNM . Geometry . models . pore_area . spherical ) <EOL> geom . add_model ( propname = '<STR_LIT>' , <EOL> model = OpenPNM . Geometry . models . throat_area . cylinder ) <EOL> if add_boundaries : <EOL> boun = OpenPNM . Geometry . Boundary ( network = self , <EOL> pores = boundary_pores , <EOL> throats = boundary_throats , <EOL> name = '<STR_LIT>' ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT:left>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT:right>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( pores = self . pores ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT:left>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT:right>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = self . tomask ( throats = self . throats ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mode = '<STR_LIT>' ) ) <EOL> def _add_xtra_pore_data ( self ) : <EOL> xpdata = self . _xtra_pore_data <EOL> if xpdata is not None : <EOL> if isinstance ( xpdata , type ( [ ] ) ) : <EOL> for pdata in xpdata : <EOL> try : <EOL> self [ '<STR_LIT>' + pdata ] = self . _dictionary [ '<STR_LIT:p>' + pdata ] [ self . _pore_map ] <EOL> except : <EOL> logger . warning ( '<STR_LIT>' + pdata + <EOL> '<STR_LIT>' ) <EOL> pass <EOL> else : <EOL> try : <EOL> self [ '<STR_LIT>' + xpdata ] = self . _dictionary [ '<STR_LIT:p>' + xpdata ] [ self . _pore_map ] <EOL> except : <EOL> logger . warning ( '<STR_LIT>' + xpdata + '<STR_LIT>' ) <EOL> pass <EOL> def _add_xtra_throat_data ( self ) : <EOL> xtdata = self . _xtra_throat_data <EOL> if xtdata is not None : <EOL> if isinstance ( xtdata , type ( [ ] ) ) : <EOL> for tdata in xtdata : <EOL> try : <EOL> self [ '<STR_LIT>' + tdata ] = self . _dictionary [ '<STR_LIT:t>' + tdata ] [ self . _throat_map ] <EOL> except : <EOL> logger . warning ( '<STR_LIT>' + tdata + <EOL> '<STR_LIT>' ) <EOL> pass <EOL> else : <EOL> try : <EOL> self [ '<STR_LIT>' + xtdata ] = self . _dictionary [ '<STR_LIT:t>' + xtdata ] [ self . _throat_map ] <EOL> except : <EOL> logger . warning ( '<STR_LIT>' + xtdata + <EOL> '<STR_LIT>' ) <EOL> pass </s>
