#NEWLINE# def model_attributes_to_shapefile( filename , ml , package_names = None , array_dict = None , **kwargs ) : #NEWLINE# #INDENT# '\n    Wrapper function for writing a shapefile of model data.  If package_names is\n    not None, then search through the requested packages looking for arrays that\n    can be added to the shapefile as attributes\n\n    Parameters\n    ----------\n    filename : string\n        name of the shapefile to write\n    ml : flopy.mbase\n        model instance\n    package_names : list of package names (e.g. ["dis","lpf"])\n        Packages to export data arrays to shapefile. (default is None)\n    array_dict : dict of {name:2D array} pairs\n       Additional 2D arrays to add as attributes to the shapefile. (default is None)\n\n\n    Returns\n    -------\n    None\n\n    Examples\n    --------\n\n    >>> import flopy\n    >>> m = flopy.modflow.Modflow()\n    >>> flopy.utils.model_attributes_to_shapefile(\'model.shp\', m)\n\n    ' #NEWLINE# if ( array_dict is None ) : #NEWLINE# #INDENT# array_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( package_names is not None ) : #NEWLINE# #INDENT# if ( not isinstance ( package_names , list ) ) : #NEWLINE# #INDENT# package_names = [ package_names ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# package_names = [ pak . name [ 0 ] for pak in ml . packagelist ] #NEWLINE# #UNINDENT# for pname in package_names : #NEWLINE# #INDENT# pak = ml . get_package ( pname ) #NEWLINE# if ( pak is not None ) : #NEWLINE# #INDENT# attrs = dir ( pak ) #NEWLINE# for attr in attrs : #NEWLINE# #INDENT# a = pak . __getattribute__ ( attr ) #NEWLINE# if ( isinstance ( a , Util2d ) and ( a . shape == ( ml . nrow , ml . ncol ) ) ) : #NEWLINE# #INDENT# name = a . name . lower ( ) #NEWLINE# array_dict [ name ] = a . array #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( a , Util3d ) : #NEWLINE# #INDENT# for ( i , u2d ) in enumerate ( a ) : #NEWLINE# #INDENT# name = shape_attr_name ( u2d . name ) #NEWLINE# name += '_{:03d}' . format ( ( i + 1 ) ) #NEWLINE# array_dict [ name ] = u2d . array #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( a , Transient2d ) : #NEWLINE# #INDENT# kpers = list ( a . transient_2ds . keys ( ) ) #NEWLINE# kpers . sort ( ) #NEWLINE# for kper in kpers : #NEWLINE# #INDENT# u2d = a . transient_2ds [ kper ] #NEWLINE# name = shape_attr_name ( u2d . name ) #NEWLINE# name = '{}_{:03d}' . format ( name , ( kper + 1 ) ) #NEWLINE# array_dict [ name ] = u2d . array #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( a , MfList ) : #NEWLINE# #INDENT# kpers = a . data . keys ( ) #NEWLINE# for kper in kpers : #NEWLINE# #INDENT# arrays = a . to_array ( kper ) #NEWLINE# for ( name , array ) in arrays . items ( ) : #NEWLINE# #INDENT# for k in range ( array . shape [ 0 ] ) : #NEWLINE# #INDENT# name = shape_attr_name ( name , length = 4 ) #NEWLINE# aname = '{}{:03d}{:03d}' . format ( name , ( k + 1 ) , ( kper + 1 ) ) #NEWLINE# array_dict [ aname ] = array [ k ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( a , list ) : #NEWLINE# #INDENT# for v in a : #NEWLINE# #INDENT# if isinstance ( v , Util3d ) : #NEWLINE# #INDENT# for ( i , u2d ) in enumerate ( v ) : #NEWLINE# #INDENT# name = shape_attr_name ( u2d . name ) #NEWLINE# name += '_{:03d}' . format ( ( i + 1 ) ) #NEWLINE# array_dict [ name ] = u2d . array #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# write_grid_shapefile ( filename , ml . dis . sr , array_dict )