pymarthe.utils

utils for pymarthe

Submodules

Classes

MartheGrid

Class to handle Marthe single grid.

Functions

read_grid_file(grid_file[, keep_adj, start, end])

Function to read Marthe grid data in file.

shp2points(shpname[, stack])

Extract xy-coordinates from a point shapefile.

get_kmi(mobj, keys, **kwargs)

Return standard Keys Multi Index from a marthe object data.

Package Contents

pymarthe.utils.read_grid_file(grid_file, keep_adj=False, start=None, end=None)

Function to read Marthe grid data in file. Only structured grids are supported.

Parameters:

grid_file (str) : Marthe Grid file full path

keep_adj (bool)whatever conserving adjacent cells

for nested grids. Default is False.

start/end (int, optional)first/last character index to

consider in whole grid file. If None, `start`=0 and `end`= len(N) (where N is the number of character

in the provided grid file)

Default is None.

Returns:

grid_list (list)contain one or more

MartheGrid instance

Examples:

grids = read_grid_file(‘mymodel.permh’)

pymarthe.utils.shp2points(shpname, stack=True)

Extract xy-coordinates from a point shapefile.

Parameters:
  • (str) (shpname) –

  • (bool) (stack) – If True: [[x0,y0],[x1,y1],.. , [xN,yN]] If False: np.array([x0,x1,.. xN], [y0,y1,.. yN]) Default is True

class pymarthe.utils.MartheGrid(istep, layer, inest, nrow, ncol, xl, yl, dx, dy, xcc, ycc, array, field=None)

Class to handle Marthe single grid.

get_cell_vertices(i, j, closed=False)

DOES NOT WORK PROPERLY!

to_records(fmt='light', base=0)

Convert grid values to flatten recarray.

Parameters:

fmt (str)output format.
Can be:
  • ‘light’ : output columns: ‘layer,inest,i,j,x,y,value’

  • ‘full’ : output columns: ‘node,layer,inest,i,j,x,y,dx,dy,vertices,value’

Default is ‘light’. Note: the ‘full’ format is obviously slower.

base (int)n-based array format
Can be :
  • 0 (Python)

  • 1 (Fortran)

Default is 0.

Returns:

Write data inplace. (record files, listm files, pastp file)

Examples:

mg.to_records(fmt=’light’)

to_string(maxlayer=None, maxnest=None, rlevel=None, keep_uniform_fmt=False)

Convert grid to a single string with Marthe Grid file format. Parameters: ———– maxlayer (int/None, optional) : maximum number of layer.

If None, value will be ‘0’. Default is None.

maxnest (int/None, optional)maximum number of nested grid.

If None, value will be ‘0’. Default is None.

rlevel (int/None, optional)refine level to extract adjacent

cells informations. Default is None.

keep_uniform_fmt (bool, optional)whatever to conserve marthe light format

for uniform grid. If True, light format will be conserved. If False, all grids will be written explictly. Default is False. /!/ CAREFULL /!/ keeping uniform light format on permh field can modify the model geometry.

Return:

lines_str (str)Marthe Grid string format

(ready to write)

Example

mygrid = MartheGrid(0, 0, 125, 126, 325., 750., dx, dy, xcc, ycc, array, field = ‘PERMEAB’) with open(‘mymarthegrid.prop’, ‘r’) as f:

f.write(mygrid.to_string())

to_pyshp()

Convert grid to list of polygons with vertices coordinates.

Parameters:

self (MartheGrid) : MartheGrid instance

Return:

pyshp_parts (list) = polygons parts with

xy-vertices coordinates.

Example

parts = mg.to_pyshp()

to_patches()

Convert grid to list of matplotlib.Path

Parameters:

self (MartheGrid) : MartheGrid instance

Return:

patches (list) = list of Path objects

Example

patches = mg.to_patches()

__str__()

Internal string method.

pymarthe.utils.get_kmi(mobj, keys, **kwargs)

Return standard Keys Multi Index from a marthe object data. keys >= 2.