Module for 2d postprocessing, containing classes to project points from 3d to 2d in various ways, providing basic but flexible framework for extracting arbitrary scalar values from bodies/interactions and plotting the results. There are 2 basic components: flatteners and extractors.

The algorithms operate on bodies (default) or interactions, depending on the intr parameter of post2d.data.

## Flatteners¶

Instance of classes that convert 3d (model) coordinates to 2d (plot) coordinates. Their interface is defined by the post2d.Flatten class (__call__, planar, normal).

## Extractors¶

Callable objects returning scalar or vector value, given a body/interaction object. If a 3d vector is returned, Flattener.planar is called, which should return only in-plane components of the vector.

## Example¶

This example can be found in examples/concrete/uniax-post.py

from yade import post2d
import pylab # the matlab-like interface of matplotlib

# flattener that project to the xz plane
flattener=post2d.AxisFlatten(useRef=False,axis=1)
# return scalar given a Body instance
extractDmg=lambda b: b.state.normDmg
# will call flattener.planar implicitly
# the same as: extractVelocity=lambda b: flattener.planar(b,b.state.vel)
extractVelocity=lambda b: b.state.vel

# create new figure
pylab.figure()
# plot raw damage
post2d.plot(post2d.data(extractDmg,flattener))

# plot smooth damage into new figure
pylab.figure(); ax,map=post2d.plot(post2d.data(extractDmg,flattener,stDev=2e-3))
# show color scale
pylab.colorbar(map,orientation='horizontal')

# raw velocity (vector field) plot
pylab.figure(); post2d.plot(post2d.data(extractVelocity,flattener))

# smooth velocity plot; data are sampled at regular grid
pylab.figure(); ax,map=post2d.plot(post2d.data(extractVelocity,flattener,stDev=1e-3))
# save last (current) figure to file
pylab.gcf().savefig('/tmp/foo.png')

# show the figures
pylab.show()

class yade.post2d.AxisFlatten(inherits Flatten → object)[source]
__init__(useRef=False, axis=2)[source]
Parameters: useRef (bool) – use reference positions rather than actual positions (only meaningful when operating on Bodies) axis ({0,1,2}) – axis normal to the plane; the return value will be simply position with this component dropped.
normal(pos, vec)[source]
planar(pos, vec)[source]
class yade.post2d.CylinderFlatten(inherits Flatten → object)[source]

Class for converting 3d point to 2d based on projection onto plane from circle. The y-axis in the projection corresponds to the rotation axis; the x-axis is distance form the axis.

__init__(useRef, axis=2)[source]
Parameters: useRef – (bool) use reference positions rather than actual positions axis – axis of the cylinder, ∈{0,1,2}
normal(b, vec)[source]
planar(b, vec)[source]
class yade.post2d.Flatten(inherits object)[source]

Abstract class for converting 3d point into 2d. Used by post2d.data2d.

normal(pos, vec)[source]

Given position and vector value, return lenght of the vector normal to the flat plane.

planar(pos, vec)[source]

Given position and vector value, project the vector value to the flat plane and return its 2 in-plane components.

class yade.post2d.HelixFlatten(inherits Flatten → object)[source]

Class converting 3d point to 2d based on projection from helix. The y-axis in the projection corresponds to the rotation axis

__init__(useRef, thetaRange, dH_dTheta, axis=2, periodStart=0)[source]
Parameters: useRef (bool) – use reference positions rather than actual positions thetaRange ((θmin,θmax)) – bodies outside this range will be discarded dH_dTheta (float) – inclination of the spiral (per radian) axis ({0,1,2}) – axis of rotation of the spiral periodStart (float) – height of the spiral for zero angle
normal(pos, vec)[source]
planar(b, vec)[source]
yade.post2d.data(extractor, flattener, intr=False, onlyDynamic=True, stDev=None, relThreshold=3.0, perArea=0, div=(50, 50), margin=(0, 0), radius=1)[source]

Filter all bodies/interactions, project them to 2d and extract required scalar value; return either discrete array of positions and values, or smoothed data, depending on whether the stDev value is specified.

The intr parameter determines whether we operate on bodies or interactions; the extractor provided should expect to receive body/interaction.

Parameters: extractor (callable) – receives Body (or Interaction, if intr is True) instance, should return scalar, a 2-tuple (vector fields) or None (to skip that body/interaction) flattener (callable) – post2d.Flatten instance, receiving body/interaction, returns its 2d coordinates or None (to skip that body/interaction) intr (bool) – operate on interactions rather than bodies onlyDynamic (bool) – skip all non-dynamic bodies stDev (float/None) – standard deviation for averaging, enables smoothing; None (default) means raw mode, where discrete points are returned relThreshold (float) – threshold for the gaussian weight function relative to stDev (smooth mode only) perArea (int) – if 1, compute weightedSum/weightedArea rather than weighted average (weightedSum/sumWeights); the first is useful to compute average stress; if 2, compute averages on subdivision elements, not using weight function div ((int,int)) – number of cells for the gaussian grid (smooth mode only) margin ((float,float)) – x,y margins around bounding box for data (smooth mode only) radius (float/callable) – Fallback value for radius (for raw plotting) for non-spherical bodies or interactions; if a callable, receives body/interaction and returns radius dictionary

Returned dictionary always containing keys ‘type’ (one of ‘rawScalar’,’rawVector’,’smoothScalar’,’smoothVector’, depending on value of smooth and on return value from extractor), ‘x’, ‘y’, ‘bbox’.

Scalar fields contain ‘val’ (value from extractor), vector fields have ‘valX’ and ‘valY’ (2 components returned by the extractor).

yade.post2d.plot(data, axes=None, alpha=0.5, clabel=True, cbar=False, aspect='equal', **kw)[source]

Given output from post2d.data, plot the scalar as discrete or smooth plot.

For raw discrete data, plot filled circles with radii of particles, colored by the scalar value.

For smooth discrete data, plot image with optional contours and contour labels.

For vector data (raw or smooth), plot quiver (vector field), with arrows colored by the magnitude.

Parameters: axes – matplotlib.axesinstance where the figure will be plotted; if None, will be created from scratch. data – value returned by post2d.data clabel (bool) – show contour labels (smooth mode only), or annotate cells with numbers inside (with perArea==2) cbar (bool) – show colorbar (equivalent to calling pylab.colorbar(mappable) on the returned mappable) tuple of (axes,mappable); mappable can be used in further calls to pylab.colorbar.