pymarthe.utils.vtk_utils

Some usefull tools to handle geometry and vtk export. This script was higly inspired by the flopy package. https://github.com/modflowpy/flopy

Classes

Point

Quick point definition class

Vtk

Class to build and manage unstructured vtk grid.

Functions

gridlist_to_verts(gridlist)

Convert list of MartheGrid instance into vertices.

area_of_polygon(x, y)

Calculates the signed area of an arbitrary polygon given its vertices

centroid_of_polygon(points)

Compute the centroid coordinates of a given polygon

is_between(a, b, c[, epsilon])

Boolean response for point between other 2 points

shared_face(ivlist1, ivlist2)

Boolean response whatever 2 lists of vertices share face.

segment_face(ivert, ivlist1, ivlist2, vertices)

Check the vertex lists for cell 1 and cell 2.

to_cvfd(vertdict[, nodestart, nodestop, ...])

Convert a vertex dictionary into verts and iverts

Module Contents

pymarthe.utils.vtk_utils.gridlist_to_verts(gridlist)

Convert list of MartheGrid instance into vertices.

Parameters:

gridlidt (list) : List of structured grid (MartheGrid instance).

Returns:

verts, iverts (nd.array,list)vertices and list of cells which

vertices comprise the cells

Examples:

verts, iverts = mm.imask.to_grids(layer=0)

pymarthe.utils.vtk_utils.area_of_polygon(x, y)

Calculates the signed area of an arbitrary polygon given its vertices http://stackoverflow.com/a/4682656/190597 (Joe Kington)

Parameters:

x,y (it) : vertices coordinates

Returns:

area (float) : area of given polygon

Examples:

x = [0,0,2,2] y = [0,2,2,0] area = area_of_polygon(x,y)

pymarthe.utils.vtk_utils.centroid_of_polygon(points)

Compute the centroid coordinates of a given polygon

Parameters:

points (it) : sequence of xy points coordinates

Returns:

result_x, result_y : xy-coordinates of centroid

Examples:

points = [(30,50), (200,10), (250,50),

(350,100), (200,180),(100,140)]

centroid = centroid_of_polygon(points)

class pymarthe.utils.vtk_utils.Point(x, y)

Quick point definition class

pymarthe.utils.vtk_utils.is_between(a, b, c, epsilon=0.001)

Boolean response for point between other 2 points

pymarthe.utils.vtk_utils.shared_face(ivlist1, ivlist2)

Boolean response whatever 2 lists of vertices share face.

pymarthe.utils.vtk_utils.segment_face(ivert, ivlist1, ivlist2, vertices)

Check the vertex lists for cell 1 and cell 2. Add a new vertex to cell 1 if necessary.

Parameters:

iverts (int) : vertex id to check ivlist1 (list) : vertices for cell 1 ivlist2 (list) : vertices for cell 2 vertices (ndarray) : xy-vertices

Returns:

segmented (bool)True if a face in cell 1 was split

up by adding a new vertex

pymarthe.utils.vtk_utils.to_cvfd(vertdict, nodestart=None, nodestop=None, skip_hanging_node_check=False, verbose=False)

Convert a vertex dictionary into verts and iverts

Parameters:

vertdict (dict)vertices dictionary.

Format : {icell: [(x1, y1), (x2, y2), (x3, y3), …]}

nodestart (int)starting node number.

Default is 0.

nodestop (int)ending node number up to but not including.

Default is len(vertdict).

skip_hanging_node_check (bool)skip the hanging node check.

Only be necessary for quad-based grid refinement (nested model). Default is False.

verbose (bool)print messages to the screen.

Default is False

Returns:

verts (ndarray) : xy-vertices iverts (list) : vertice ids for each cell

class pymarthe.utils.vtk_utils.Vtk(mm, vertical_exageration=10, hws=None, smooth=False, binary=True, xml=False, shared_points=False)

Class to build and manage unstructured vtk grid.

_create_smoothed_elevation_graph(adjk)

Method to create a dictionary of shared point mean smoothed elevations

Parameters:

adjk (int) : confining bed adjusted layer

Returns:

elevation (dict) : {vertex number: elevation}

_build_grid_geometry()

Method that creates lists of vertex points and cell faces

_set_vtk_grid_geometry()

Method to set vtk’s geometry and add it to the vtk grid object

_mask_values(array, masked_values=None)

Method to mask values in array with nan

Parameters:

array (ndarray) : values in array masked_values (float/it) : values to convert to nan

Default are [9999, 8888, 0, -9999].

Returns:

array (ndarray) : array with nan

add_array(array, name, trans='none', masked_values=None, dtype=None)

Method to set an array to the vtk grid. It will apply a value for each cell

Parameters:

array (ndarray)values in array.

Note: must be same same as nnodes.

name (str) : array name for vtk trans (str) : transformation to apply to the values.

See pymarthe.utils.pest_utils.transform. Default is ‘none’.

masked_values (float/it)values to mask by converting to nan

Default are [9999, 8888, 0, -9999].

dtype (vtk datatype) : method to supply and force a vtk datatype

Returns:

Set array data in self.vtk_grid inplace

Example:

mv = [9999,8888,0,-9999] array = mm.prop[‘permh’].data[‘value’] myvtk.add_array(array, ‘permh’, trans=’log10’, masked_values=mv)

_get_writer()

Get adequate writer and file extension according to .xlm and .binary attribut.

write(filename)

Method to write a unstructured grid from the VTK object

Parameters:

filename (str)vtk file name to write without extension.

Extension will be inferred