woo.post2d

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 particles/contacts and plotting the results. There are 2 basic components: flatteners and extractors.

The algorithms operate on particles (default) or contacts, depending on the con parameter of post2d.data.

Flatteners

Instance of classes that convert 3d (model) coordinates to 2d (plot) coordinates. Their interface is defined by the woo.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 woo import post2d
import pylab # the matlab-like interface of matplotlib

O.load('/tmp/uniax-tension.xml.bz2')

# 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 woo.post2d.AxisFlatten(axis=2, useRef=False, swapAxes=False, dispScale=1.0)[source]
Parameters
  • useRef (bool) – use reference positions rather than actual positions (only meaningful when operating on Particles)

  • axis ({0,1,2}) – axis normal to the plane; the return value will be simply position with this component dropped.

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 woo.post2d.CylinderFlatten(axis=2, useRef=False, origin=Vector3(0, 0, 0), dispScale=1.0)[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.

Parameters
  • useRef – (bool) use reference positions rather than actual positions

  • axis – axis of the cylinder, ∈{0,1,2}

normal(b, vec)[source]

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

planar(b, vec)[source]

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

class woo.post2d.Flatten(dispScale=1.0)[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.

scaledPos(p)[source]
class woo.post2d.HelixFlatten(useRef, thetaRange, dH_dTheta, axis=2, periodStart=0, dispScale=1.0)[source]

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

Parameters
  • useRef (bool) – use reference positions rather than actual positions

  • thetaRange ((θmin,θmax)) – particles 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]

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

planar(b, vec)[source]

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

class woo.post2d.LocalAxisFlatten(pos, ori, axis=2, useRef=False, swapAxes=False, dispScale=1.0)[source]

Like AxisFlatten, but transform the point to local coordinates first, using given position (Vector3) and orientation (Quaternion).

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.

woo.post2d.data(scene, extractor, flattener, con=False, onlyDynamic=True, stDev=None, relThreshold=3.0, perArea=0, div=(50, 50), margin=(0, 0), radius=1)[source]

Filter all particles/contacts, 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 con parameter determines whether we operate on particles or contacts; the extractor provided should expect to receive body/interaction.

Parameters
  • extractor (callable) – receives woo.dem.Particle (or woo.dem.Contact, if con is True) instance, should return scalar, a 2-tuple (vector fields) or None (to skip that body/interaction)

  • flattener (callable) – woo.post2d.Flatten instance, receiving body/interaction, returns its 2d coordinates or None (to skip that body/interaction)

  • con (bool) – operate on contacts rather than particles

  • onlyDynamic (bool) – skip all non-dynamic particles

  • 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 particles or contacts; if a callable, receives body/interaction and returns radius

Returns

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’.

Raw data further contains ‘radii’.

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

woo.post2d.plot(data, axes=None, clabel=True, cbar=False, rawVecColorRadius=True, bbox=None, 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.axes instance where the figure will be plotted; if None, will be created from scratch.

  • data – value returned by woo.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)

  • rawVecColorRadius – if True, use radius associated with each point to color arrows in raw quiver plot.

  • bbox – if given, use this as axes limits instead of bbox computed from data points

  • clip_path – clip plotted image maps, contour lines or patches with this clip path (should be an instance of matplotlib.patches.Patch).

Returns

tuple of (axes,mappable); mappable can be used in further calls to pylab.colorbar.

Tip

Report issues or inclarities to github.