Professional Documents
Culture Documents
Ondrej Lexa
1 Package modules 3
1.1 core module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 plotting module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.3 tensors module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.4 db module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2 Tutorial 35
2.1 Basic usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.2 Basic operations with vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.3 Classes Lin and Fol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.4 Vec3 methods for Lin and Fol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.5 Classes Pair and Fault . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.6 Group class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.7 Ortensor class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.8 StereoNet class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.9 StereoGrid class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.10 Fabric plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.11 Cluster class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.12 Some tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3 Installation 61
3.1 Using Conda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.2 Using pip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.3 Master version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4 Usage 63
5 Contributing 65
5.1 Types of Contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.2 Get Started! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.3 Pull Request Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6 Credits 69
6.1 Development Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.2 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
i
Index 73
ii
APSG Documentation, Release 0.7.0 Beta
APSG defines several new python classes to easily manage, analyze and visualize orientational structural geology data.
It is under active developement, so until documenation will be finished, you can go trough tutorial to see what APSG
can do for you.
Contents:
Contents 1
APSG Documentation, Release 0.7.0 Beta
2 Contents
CHAPTER 1
Package modules
3
APSG Documentation, Release 0.7.0 Beta
Example
# The dip direction and dip angle of vector with magnitude of 1 and 3. >>> v = Vec3(120, 60) >>> abs(v) 1.0
H(other)
Return DefGrad rotational matrix H which rotate vector u to vector v. Axis of rotation is perpendicular
to both vectors u and v.
Parameters other (Vec3) – other vector
Returns Defgrad rotational matrix
Example
angle(other)
Calculate the angle between two vectors in degrees.
Parameters other – other Vec3 vector
Returns The angle between self and other in degrees.
Example
cross(other)
Calculate the cross product of two vectors.
Parameters other – other Vec3 vector
Returns The cross product of self and other.
Example
proj(other)
Return projection of vector u onto vector v.
Parameters other (Vec3) – other vector
Returns vector representation of self projected onto ‘other’
Example
>> u.proj(v)
classmethod rand()
Random unit vector from distribution on sphere
rotate(axis, angle)
Return rotated vector about axis.
Parameters
• axis (Vec3) – axis of rotation
• angle (float) – angle of rotation in degrees
Returns vector represenatation of self rotated angle degrees about vector axis. Rotation is clock-
wise along axis direction.
Example
# Rotate e1 vector around z axis. >>> u = Vec3([1, 0, 0]) >>> z = Vec3([0, 0, 1]) >>> u.rotate(z, 90)
V(0.000, 1.000, 0.000)
transform(F, **kwargs)
Return affine transformation of vector u by matrix F.
Parameters F (DefGrad or numpy.array) – transformation matrix
Keyword Arguments norm – normalize transformed vectors. [True or False] Default False
Returns vector representation of affine transformation (dot product) of self by F
Example
# Reflexion of y axis. >>> F = [[1, 0, 0], [0, -1, 0], [0, 0, 1]] >>> u = Vec3([1, 1, 1]) >>> u.transform(F)
V(1.000, -1.000, 1.000)
V
Convert self to Vec3 object.
asfol
Convert self to Fol object.
Example
>>> u = Vec3([1,1,1])
>>> u.asfol
S:225/55
aslin
Convert self to Lin object.
Example
>>> u = Vec3([1,1,1])
>>> u.aslin
L:45/35
asvec3
Convert self to Vec3 object.
Example
>>> l = Lin(120,50)
>>> l.asvec3
V(-0.321, 0.557, 0.766)
dd
Return azimuth, inclination tuple.
Example
flip
Return a new vector with inverted z coordinate.
type
Return the type of self.
upper
Return True if z-coordinate is negative, otherwise False.
uv
Normalize the vector to unit length.
Returns unit vector of self
Example
>>> u = Vec3([1,1,1])
>>> u.uv
V(0.577, 0.577, 0.577)
class apsg.core.Lin
Bases: apsg.core.Vec3
Represents a linear feature.
It provides all Vec3 methods and properties but behave as axial vector.
Parameters
• azi – The plunge direction or trend in degrees.
• inc – The plunge in degrees.
Example
angle(other)
Return an angle (<90) between two linear features in degrees.
Example
cross(other)
Create planar feature defined by two linear features.
Example
>>> l = Lin(120,10)
>>> l.cross(Lin(160,30))
S:196/35
dot(other)
Calculate the axial dot product.
classmethod rand()
Random Lin
dd
Return trend and plunge tuple.
class apsg.core.Fol
Bases: apsg.core.Vec3
Represents a planar feature.
It provides all Vec3 methods and properties but plane normal behave as axial vector.
Parameters
• azi – The dip azimuth in degrees.
• inc – The dip angle in degrees.
Example
angle(other)
Return angle of two planar features in degrees.
Example
cross(other)
Return linear feature defined as intersection of two planar features.
Example
>>> f = Fol(60,30)
>>> f.cross(Fol(120,40))
L:72/29
dot(other)
Axial dot product.
rake(rake)
Return a Vec3 object with given rake.
Example
>>> f = Fol(120,50)
>>> f.rake(30)
V(0.589, 0.711, 0.383)
>>> f.rake(30).aslin
L:50/23
classmethod rand()
Random Fol
transform(F, **kwargs)
Return affine transformation of planar feature by matrix F.
Parameters F (DefGrad or numpy.array) – transformation matrix
Keyword Arguments norm – normalize transformed vectors. True or False. Default False
Returns representation of affine transformation (dot product) of self by F
Example
dd
Return dip-direction, dip tuple.
dv
Return a dip Vec3 object.
Example
>>> f = Fol(120,50)
>>> f.dv
V(-0.321, 0.557, 0.766)
rhr
Return strike and dip tuple (right-hand-rule).
class apsg.core.Pair(fazi, finc, lazi, linc)
Bases: object
The class to store pair of planar and linear feature.
When Pair object is created, both planar and linear feature are adjusted, so linear feature perfectly fit onto
planar one. Warning is issued, when misfit angle is bigger than 20 degrees.
Parameters
• fazi (float) – dip azimuth of planar feature in degrees
• finc (float) – dip of planar feature in degrees
• lazi (float) – plunge direction of linear feature in degrees
• linc (float) – plunge of linear feature in degrees
Example
H(other)
Return DefGrad rotational matrix H which rotate Pair to other Pair.
Parameters other (Pair) – other pair
Returns Defgrad rotational matrix
Example
Example
classmethod rand()
Random Pair
rotate(axis, phi)
Rotates Pair by angle phi about axis.
Parameters
• axis (Vec3) – axis of rotation
• phi (float) – angle of rotation in degrees
Example
transform(F, **kwargs)
Return an affine transformation of Pair by matrix F.
Parameters F (DefGrad or numpy.array) – transformation matrix
Keyword Arguments norm – normalize transformed vectors. True or False. Default False
Returns representation of affine transformation (dot product) of self by F
Example
fol
Return a planar feature of Pair as Fol.
lin
Return a linear feature of Pair as Lin.
rax
Return an oriented vector perpendicular to both Fol and Lin.
type
class apsg.core.Fault(fazi, finc, lazi, linc, sense)
Bases: apsg.core.Pair
Fault class for related Fol and Lin instances with sense of movement.
When Fault object is created, both planar and linear feature are adjusted, so linear feature perfectly fit onto
planar one. Warning is issued, when misfit angle is bigger than 20 degrees.
Parameters
• fazi (float) – dip azimuth of planar feature in degrees
• finc (float) – dip of planar feature in degrees
• lazi (float) – plunge direction of linear feature in degrees
• linc (float) – plunge of linear feature in degrees
• sense (float) – sense of movement +/-1 hanging-wall up/down
Example
Example
d
Return dihedra plane as Fol
m
Return kinematic M-plane as Fol
p
Return P-axis as Lin
pvec
Return P axis as Vec3
sense
Return sense of movement (+/-1)
t
Return T-axis as Lin
tvec
Return T-axis as Vec3.
class apsg.core.Group(data, name=’Default’)
Bases: list
Represents a homogeneous group of Vec3, Fol or Lin objects.
Group provide append and extend methods as well as list indexing to get or set individual items. It also supports
following operators:
• + - merge groups
• ** - mutual cross product
• abs - array of magnitudes (lengths) of all objects
See following methods and properties for additional operations.
Parameters
• data (list) – list of Vec3, Fol or Lin objects
• name (str) – Name of group
Returns Group object
Example
angle(other=None)
Return angles of all data in Group object
Without arguments it returns angles of all pairs in dataset. If argument is group or single data object all
mutual angles are returned.
append(item)
Append object to the end of the list.
bootstrap(N=100, size=None)
Return iterator of bootstraped samples from Group.
Parameters
• N – number of samples to be generated
• size – number of data in sample. Default is same as Group.
Example
>>> np.random.seed(58463123)
>>> g = Group.randn_lin(100, mean=Lin(120,40))
>>> sm = [gb.R for gb in g.bootstrap(100)]
>>> g.fisher_stats
{'k': 16.1719344862197, 'a95': 3.627369676728579, 'csd': 20.142066812987963}
>>> Group(sm).fisher_stats
{'k': 1577.5503256282452, 'a95': 0.3559002104835758, 'csd': 2.
˓→0393577026717056}
(continues on next page)
copy()
Return a shallow copy of the list.
cross(other=None)
Return cross products of all data in Group object
Without arguments it returns cross product of all pairs in dataset. If argument is group or single data object
all mutual cross products are returned.
dot(vec)
Return array of dot products of all data in Group with vector.
classmethod examples(name=None)
Create Group from example datasets. Available names are returned when no name of example dataset is
given as argument.
Keyword Arguments name – name of dataset
Example
>>> g = Group.examples('B2')
extend(items=())
Extend list by appending elements from the iterable.
classmethod fisher_lin(N=100, mean=L:0/90, kappa=20, name=’Default’)
Method to create Group of Lin objects distributed according to Fisher distribution.
Parameters
• N – number of objects to be generated
• kappa – precision parameter of the distribution. Default 20
• name – name of dataset. Default is ‘Default’
Example
Example
Example
classmethod from_file(filename)
Load group from pickle file.
Parameters filename (str) – name of data file to load.
classmethod gss_fol(N=500, name=’Default’)
Method to create Group of uniformly distributed Fol objects. Based on Group.gss_vec3 method,
but only half of sphere is used.
Parameters
• N – number of objects to be generated. Default 500
• name – name of dataset. Default is ‘Default’
Example
>>> g = Group.gss_fol(300)
>>> g.ortensor.eigenvals
(0.33498372991251285, 0.33333659934369725, 0.33167967074378996)
Example
>>> g = Group.gss_lin(300)
>>> g.ortensor.eigenvals
(0.33498372991251285, 0.33333659934369725, 0.33167967074378996)
Example
>>> v = Group.gss_vec3(300)
>>> v.ortensor.eigenvals
(0.3333568856957158, 0.3333231511543691, 0.33331996314991513)
Example
proj(vec)
Return projections of all data in Group onto vector.
classmethod randn_fol(N=100, mean=S:0/0, sig=20, name=’Default’)
Method to create Group of normaly distributed random Fol objects.
Keyword Arguments
• N – number of objects to be generated
• mean – mean orientation given as Fol. Default Fol(0, 0)
• sig – sigma of normal distribution. Default 20
• name – name of dataset. Default is ‘Default’
Example
>>> np.random.seed(58463123)
>>> g = Group.randn_fol(100, Lin(240, 60))
>>> g.R
S:237/60
Example
>>> np.random.seed(58463123)
>>> g = Group.randn_lin(100, Lin(120, 40))
>>> g.R
L:118/42
rotate(axis, phi)
Rotate Group object phi degress about axis.
classmethod sfs_fol(N=500, name=’Default’)
Method to create Group of uniformly distributed Fol objects. Based on Group.sfs_vec3 method,
but only half of sphere is used.
Parameters
• N – number of objects to be generated. Default 500
• name – name of dataset. Default is ‘Default’
Example
>>> g = Group.sfs_fol(300)
>>> g.ortensor.eigenvals
(0.33417707294664595, 0.333339733866985, 0.332483193186369)
Example
>>> g = Group.sfs_lin(300)
>>> g.ortensor.eigenvals
(0.33417707294664595, 0.333339733866985, 0.332483193186369)
Example
>>> v = Group.sfs_vec3(300)
>>> v.ortensor.eigenvals
(0.33346453471636356, 0.33333474915201167, 0.3332007161316248)
Example
>>> g = Group.uniform_fol(300)
>>> g.ortensor.eigenvals
(0.3354383042654646, 0.3322808478672677, 0.3322808478672675)
Example
>>> g = Group.uniform_lin(300)
>>> g.ortensor.eigenvals
(0.33543830426546456, 0.3322808478672677, 0.3322808478672676)
R
Return resultant of data in Group object.
Resultant is of same type as Group. Note that Fol and Lin are axial in nature so resultant can give other
result than expected. For most cases is should not be problem as it is calculated as resultant of centered
data. Anyway for axial data orientation tensor analysis will give you right answer.
As axial summing is not commutative we use vectorial summing of centered data for Fol and Lin
V
Return Group object with all data converted to Vec3.
asfol
Return Group object with all data converted to Fol.
aslin
Return Group object with all data converted to Lin.
asvec3
Return Group object with all data converted to Vec3.
centered
Rotate Group object to position that eigenvectors are parallel to axes of coordinate system: E1(vertical),
E2(east-west), E3(north-south)
cluster
Return hierarchical clustering Cluster of Group.
data
Return list of objects in Group.
dd
Return array of azimuths and inclinations of Group
delta
Cone angle containing ~63% of the data in degrees.
For enough large sample it approach angular standard deviation (csd) of Fisher statistics
fisher_stats
Fisher’s statistics.
fisher_stats property returns dictionary with k estimated precision parameter, csd estimated angular stan-
dard deviation a95 confidence limit
flip
Return Group object with inverted z-coordinate.
halfspace
Change orientation of vectors in Group, so all have angle<=90 with resultant.
ortensor
Return orientation tensor Ortensor of Group.
rdegree
Degree of preffered orientation of data in Group object.
D = 100 * (2 * |R| - n) / n
rhr
Return array of strikes and dips of Group
upper
Return boolean array of z-coordinate negative test
uv
Return Group object with normalized (unit length) elements.
var
Spherical variance based on resultant length (Mardia 1972).
var = 1 - |R| / n
class apsg.core.PairSet(data, name=’Default’)
Bases: list
Represents a homogeneous group of Pair objects.
append(item)
Append object to the end of the list.
extend(items=())
Extend list by appending elements from the iterable.
classmethod from_array(fazis, fincs, lazis, lincs, name=’Default’)
Create PairSet from arrays of azimuths and inclinations
classmethod from_csv(fname, delimiter=’, ’, facol=1, ficol=2, lacol=3, licol=4)
Read PairSet from csv file
rotate(axis, phi)
Rotate PairSet
to_csv(fname, delimiter=’, ’, rounded=False)
data
fol
Return Fol part of PairSet as Group of Fol
fvec
Return vectors of Fol of PairSet as Group of Vec3
lin
Return Lin part of PairSet as Group of Lin
lvec
Return vectors of Lin part of PairSet as Group of Vec3
misfit
Return array of misfits
ortensor
Return Lisle (1989) orientation tensor Ortensor of Group.
rax
Return vectors perpendicular to both Fol and Lin of PairSet as Group of Vec3.
class apsg.core.FaultSet(data, name=’Default’)
Bases: apsg.core.PairSet
Represents a homogeneous group of Fault objects.
angmech(method=’classic’)
Implementation of Angelier-Mechler dihedra method
Parameters
• method – ‘probability’ or ‘classic’. Classic method assigns +/-1
• individual positions, while 'probability' returns maximum
(to) –
• estimate. (likelihood) –
classmethod examples(name=None)
Create FaultSet from example datasets. Available names are returned when no name of example dataset
is given as argument.
Keyword Arguments name – name of dataset
Example
>>> fs = FaultSet.examples('MELE')
Example
>>> s = StereoNet()
>>> g = Group.randn_lin(mean=Lin(40, 20))
>>> s.contourf(g, 8, legend=True, sigma=2)
>>> s.line(g, 'g.', label='My data')
>>> s.show()
animate(**kwargs)
Return artist animation.
arc(l1, l2, *args, **kwargs)
Draw great circle segment between two points.
arrow(pos_lin, dir_lin=None, sense=1, **kwargs)
Draw arrow at given position in given direction.
axtitle(title)
Add title to active axes.
cla()
Clear axes and draw empty projection.
close()
cone(obj, alpha, *args, **kwargs)
Draw small circle.
contour(obj, *args, **kwargs)
Plot contour lines.
contourf(obj, *args, **kwargs)
Plot filled contours.
draw()
fault(obj, *arg, **kwargs)
Draw a fault-and-striae as in Angelier plot
format_coord(x, y)
getfol()
Get Fol instance by mouse click.
getfols()
Get Group of Fol by mouse clicks.
getlin()
Get Lin instance by mouse click.
getlins()
Get Group of Lin by mouse clicks.
hoeppner(obj, *arg, **kwargs)
Draw a fault-and-striae as in tangent lineation plot - Hoeppner plot.
hover(event)
line(obj, *args, **kwargs)
Draw Lin as point.
new()
Re-initialize existing StereoNet.
Examples
cla()
Clear projection.
close()
plot(obj, *args, **kwargs)
savefig(filename=’apsg_roseplot.pdf’, **kwargs)
show()
Example
Example
classmethod from_comp(xx=1, xy=0, xz=0, yx=0, yy=1, yz=0, zx=0, zy=0, zz=1)
Return DefGrad tensor defined by individual components. Default is identity tensor.
Keyword Arguments xy, xz, yx, yy, yz, zx, zy, zz (xx,) – tensor components
Example
classmethod from_pair(p)
classmethod from_ratios(Rxy=1, Ryz=1)
Return isochoric DefGrad tensor with axial stretches defined by strain ratios. Default is identity tensor.
Keyword Arguments Ryz (Rxy,) – strain ratios
Example
rotate(vector, theta=0)
Rotate tensor around axis by angle theta.
Using rotation matrix it returns F = R * F * R . T.
velgrad(time=1)
Return VelGrad for given time
B
Return left Cauchy–Green deformation tensor or Finger deformation tensor
C
Return right Cauchy–Green deformation tensor or Green’s deformation tensor
E1
Max eigenvalue
E2
Middle eigenvalue
E3
Min eigenvalue
I
Returns the inverse tensor.
R
Return rotation part of DefGrad from polar decomposition.
U
Return stretching part of DefGrad from right polar decomposition.
V
Return stretching part of DefGrad from left polar decomposition.
axisangle
Return rotation part of DefGrad axis, angle tuple.
eigenfols
Return `Group` of principal eigenvectors as Fol objects.
eigenlins
Return `Group` of principal eigenvectors as Lin objects.
eigenvals
Return tuple of sorted eigenvalues.
eigenvects
Return `Group` of principal eigenvectors as Vec3 objects.
class apsg.tensors.VelGrad
Bases: numpy.ndarray
VelGrad store velocity gradient tensor derived from numpy.ndarray.
Parameters a (3x3 array_like) – Input data, that can be converted to 3x3 2D array. This
includes lists, tuples and ndarrays.
Returns VelGrad object
Example
defgrad(time=1, steps=1)
Return DefGrad tensor accumulated after given time.
Keyword Arguments
• time (float) – time of deformation. Default 1
• steps (int) – when bigger than 1, will return a list of DefGrad tensors for each
timestep.
classmethod from_comp(xx=0, xy=0, xz=0, yx=0, yy=0, yz=0, zx=0, zy=0, zz=0)
Return VelGrad tensor. Default is zero tensor.
Keyword Arguments xy, xz, yx, yy, yz, zx, zy, zz (xx,) – tensor components
Example
rotate(vector, theta=0)
Rotate tensor around axis by angle theta.
Using rotation matrix it returns F = R * F * R . T.
rate
Return rate of deformation tensor
spin
Return spin tensor
class apsg.tensors.Stress
Bases: numpy.ndarray
Stress store stress tensor derived from numpy.ndarray.
Parameters a (3x3 array_like) – Input data, that can be converted to 3x3 2D array. This
includes lists, tuples and ndarrays.
Returns Stress object
Example
cauchy(n)
Return stress vector associated with plane given by normal vector.
Parameters n – normal given as Vec3 or Fol object
Example
fault(n)
Return Fault object derived from given by normal vector.
Parameters n – normal given as Vec3 or Fol object
Example
Example
normal_stress(n)
Return normal stress component on plane given by normal vector.
rotate(vector, theta=0)
Rotate tensor around axis by angle theta.
Using rotation matrix it returns S = R * S * R . T
shear_stress(n)
Return magnitude of shear stress component on plane given by normal vector.
stress_comp(n)
Return normal and shear stress Vec3 components on plane given by normal vector.
E1
Max eigenvalue
E2
Middle eigenvalue
E3
Min eigenvalue
I1
First invariant
I2
Second invariant
I3
Third invariant
deviatoric
A stress deviator tensor component
diagonalized
Returns Stress tensor in a coordinate system with axes oriented to the principal directions and orthogonal
matrix R, which brings actual coordinate system to principal one.
eigenfols
Returns Group of three eigenvectors represented as Fol
eigenlins
Returns Group of three eigenvectors represented as Lin
eigenvects
Returns Group of three eigenvectors represented as Vec3
hydrostatic
Mean hydrostatic stress tensor component
mean_stress
Mean stress
class apsg.tensors.Ortensor(matrix, **kwargs)
Bases: apsg.tensors.Tensor
Represents an orientation tensor, which characterize data distribution using eigenvalue method. See (Watson
1966, Scheidegger 1965).
See following methods and properties for additional operations.
Parameters matrix (3x3 array_like) – Input data, that can be converted to 3x3 2D matrix.
This includes lists, tuples and ndarrays. Array could be also Group (for backward compatibil-
ity)
Keyword Arguments
• name (str) – name od tensor
• scaled (bool) – When True eigenvectors are scaled by eigenvalues. Otherwise unit
length. Default False
Returns Ortensor object
Example
Example
>>> g = Group.examples('B2')
>>> ot = Ortensor.from_group(g)
>>> ot
Ortensor: B2 Kind: L
(E1:0.9825,E2:0.01039,E3:0.007101)
[[ 0.19780807 -0.13566589 -0.35878837]
[-0.13566589 0.10492993 0.25970594]
[-0.35878837 0.25970594 0.697262 ]]
>>> ot.eigenlins.data
[L:144/57, L:360/28, L:261/16]
Example
B
Cylindricity index (Vollmer, 1990).
E1
Return maximum eigenvalue.
E2
Return middle eigenvalue.
E3
Return minimum eigenvalue.
G
Girdle index (Vollmer, 1990).
Intensity
Intensity index (Lisle, 1985).
MAD
Return approximate deviation according to shape
MADo
Return approximate deviation from the plane normal to E3.
MADp
Return approximate angular deviation from the major axis along E1.
P
Point index (Vollmer, 1990).
R
Random index (Vollmer, 1990).
class apsg.tensors.Ellipsoid(matrix, **kwargs)
Bases: apsg.tensors.Tensor
Ellipsoid class
See following methods and properties for additional operations.
Parameters matrix (3x3 array_like) – Input data, that can be converted to 3x3 2D matrix.
This includes lists, tuples and ndarrays.
Returns Ellipsoid object
Example
1.4 db module
1.4. db module 33
APSG Documentation, Release 0.7.0 Beta
Tutorial
APSG defines several new python classes to easily manage, analyze and visualize orientation structural geology data.
Base class Vec3 is derived from numpy.array class and offers several new method which will be explained in
following examples.
APSG module could be imported either into own name space or into active one for easier interactive work:
Instance of vector object Vec3 could be created from any iterable object as list, tuple or array:
For common vector operation we can use standard mathematical operators or special methods using dot notation:
>>> u + v
V(-1.000, -1.000, 4.000)
>>> u - v
V(3.000, -3.000, 2.000)
>>> 3*u - 2*v
V(7.000, -8.000, 7.000)
Its magnitude or length is most commonly defined as its Euclidean norm and could be calculated using abs:
35
APSG Documentation, Release 0.7.0 Beta
>>> abs(v)
2.4494897427831779
>>> abs(u+v)
4.2426406871192848
>>> u*v
-1
>>> u.dot(v)
-1
>>> u**v
V(-5.000, -7.000, -3.000)
>>> u.cross(v)
V(-5.000, -7.000, -3.000)
>>> u.proj(v)
V(0.333, -0.167, -0.167)
>>> u.angle(v)
96.263952719927218
Method rotate provide possibility to rotate vector around another vector. For example, to rotate vector u around
vector v for 45°:
To work with orientation data in structural geology, APSG provide two classes derived from Vec3 class. There is Fol
class to represent planar features by planes and Lin class to represent linear feature by lines. Both classes provide all
Vec3 methods, but they differ in way how instance is created and how some operations are calculated, as structural
geology data are commonly axial in nature.
To create instance of Lin or Fol class, we have to provide dip direction and dip, both in degrees:
or we can create instance from Vec3 object using aslin and asfol properties:
>>> u.aslin
L:297/53
>>> u.asfol
S:117/37
36 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
To find angle between two linear or planar features we can use method angle:
>>> l1 = Lin(110, 40)
>>> l2 = Lin(160, 30)
>>> l1.angle(l2)
41.597412680035468
>>> p1 = Fol(330, 50)
>>> p2 = Fol(250, 40)
>>> p1.angle(p2)
54.696399321975328
We can use cross product to construct planar feature defined by two linear features:
>>> l1**l2
S:113/40
Cross product of planar and linear features could be used to construct plane defined by linear feature and normal of
planar feature:
>>> l2**p2
S:96/53
To work with paired orientation data like foliations and lineations or fault data in structural geology, APSG provide
two base Pair class and derived Fault class. Both classes are instantiated providing dip direction and dip of planar
and linear measurements, which are automatically orthogonalized. If misfit is too high, warning is raised. The Fault
class expects one more argument providing sense of movement information, either 1 or -1.
To create instance of Pair class, we have to provide dip direction and dip of planar and linear feature, both in degrees:
>>> p = Pair(120, 40, 162, 28)
>>> p
P:118/39-163/30
>>> p.misfit
3.5623168411508175
>>> type(p)
<class 'apsg.core.Pair'>
Planar and linear features are accessible using fol and lin properties:
>>> p.fol
S:118/39
>>> p.lin
L:163/30
>>> type(p.fol)
<class 'apsg.core.Fol'>
>>> type(p.lin)
<class 'apsg.core.Lin'>
Instantiation of Fault class is similar, we just have to provide argument to define sense of movement:
For simple fault analyses Fault class also provide p, t, m and d properties to get PT-axes, kinematic plane and
dihedra separation plane:
>>> f.p
L:315/75
>>> f.t
L:116/14
>>> f.m
S:27/85
>>> f.d
S:290/31
Group class serve as a homogeneous container for Lin, Fol and Vec3 objects. It allows grouping of features either
for visualization or batch analysis:
38 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
>>> len(g)
5
Most of the Lin, Fol and Vec3 methods could be used for Group as well. For example, to measure angles between
all features in group and another feature, we can use method angle:
>>> g.angle(Lin(110,50))
array([ 11.49989817, 3.85569115, 15.61367789, 15.11039885, 16.3947936 ])
To rotate all features in group around another feature, we can use method rotate:
>>> gr = g.rotate(Lin(150, 30), 45)
Property R gives mean or resultant of all features in group. Note that Lin and Fol are axial in nature, so resultant
vector is not reliable. You can use ortensor property.:
>>> g.R
L:110/55
Group class offers several methods to infer spherical statistics as spherical variance, Fisher’s statistics, confidence
cones on data etc.:
>>> g.var
0.02337168447438509
>>> g.fisher_stats
{'k': 34.229454059110871, 'a95': 13.264029905117329, 'csd': 13.844747281750971}
>>> g.delta
12.411724720740544
To calculate orientation tensor of all features in group, we can use ortensor property.:
>>> g.ortensor
Ortensor: L1 Kind: LLS
(E1:0.954,E2:0.04021,E3:0.005749)
[[ 0.07398181 -0.09605477 -0.14324311]
[-0.09605477 0.28446118 0.42092899]
[-0.14324311 0.42092899 0.64155701]]
Ortensor class represents orientation tensor of set of planar or linear features. Eigenvalues and eigenvectors could
be obtained by methods eigenvals and eigenvects. Eigenvectors could be also represented by linear or planar
features using properties eigenlins and eigenfols. Several properties to describe orientation distribution is also
impleneted, e.g. Woodcock’s shape and strength or Vollmer’s P, G, R and C indexes.:
>>> ot = Ortensor.from_group(g)
>>> ot.eigenvals
(0.954038468659639, 0.04021274946196462, 0.005748781878396576)
>>> ot.eigenvects.data
(continues on next page)
When StereoNet class instance is created with arguments, they are immidiatelly plotted and shown. Most of
the objects provided by APSG could be plotted. Here we use the Group object and principal planes and lines of
Ortensor:
When StereoNet class instance is created without arguments, several methods and properties could be used for
additional operations. To finalize plot we can use show method (not needed in jupyter notebooks)
Any Fol, Lin, Group object could be visualized as plane, line or pole in stereographic projection using StereoNet
40 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
class:
>>> s = StereoNet()
>>> s.plane(Fol(150, 40))
>>> s.pole(Fol(150, 40))
>>> s.line(Lin(112, 30))
>>> s.show()
>>> s = StereoNet()
>>> g = Group.randn_lin(mean=Lin(40, 15))
>>> s.line(g, 'k.')
>>> s.cone(g.R, g.fisher_stats['a95'], 'r') # confidence cone on resultant
>>> s.cone(g.R, g.fisher_stats['csd'], 'g') # confidence cone on 63% of data
>>> s.show()
To make density contours plots, a contour and contourf methods are available:
>>> s = StereoNet()
>>> g = Group.randn_lin(mean=Lin(40, 20))
>>> s.contourf(g, 8, legend=True, sigma=2)
>>> s.line(g, 'g.')
>>> s.show()
42 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
Except Group, APSG provides PairSet and FaultSet classes to store Pair or Fault datasets. It can be
inicialized by passing list of Pair or Fault objects as argument or use class methods from_array or from_csv:
StereoNet has two special methods to visualize fault data. Method fault produce classical Angelier plot:
44 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
hoeppner method produce Hoeppner diagram and must be invoked from StereoNet instance:
>>> s = StereoNet()
>>> s.hoeppner(f, label=repr(f))
>>> s.show()
Note that fault method is used, when data are passed directly to StereoNet instance:
46 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
StereoGrid class allows to visualize any scalar field on StereoNet. Internally it is used for plotting contour di-
agrams, but it exposes apply_func method to calculate scalar field by any user-defined function. Function must
accept three element numpy.array as first argument passed from grid points of StereoGrid.
Following example shows how to plot resolved shear stress on plane from given stress tensor. StereoGrid.
apply_func method is used to calculate this value over all directions and finally values are plotted by StereoNet:
The FaultSet provide also amgmech method which provide access to Angelier dihedra method. Results are stored
in StereoGrid. Default behavior is to calculate counts (positive in extension, negative in compression):
>>> f = FaultSet.examples('MELE')
>>> StereoNet(f.angmech())
48 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
>>> f = FaultSet.examples('MELE')
>>> StereoNet(f.angmech(method='probability'))
APSG provides several fabric plots to visualize Tensor-type objects (Ortensor, Ellipsoid). FlinnPlot class
provide classical Flinn’s deformation diagram,
>>> g1 = Group.examples('B2')
>>> g2 = Group.examples('B4')
>>> g3 = Group.uniform_lin(name='Uniform')
>>> FlinnPlot(g1, g2, g3);
50 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
52 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
and HsuPlot class provide Hsu fabric diagram using natural strains.
Cluster class provide access to scipy hierarchical clustering. Distance matrix is calculated as mutual angles of
features within Group keeping axial and/or vectorial nature in mind. Cluster.explain method allows to explore
explained variance versus number of clusters relation. Actual cluster is done by Cluster.cluster method, using
distance or maxclust criterion. Using of Cluster is explained in following example. We generate some data and
plot dendrogram:
>>> g1 = Group.randn_lin(mean=Lin(45,30))
>>> g2 = Group.randn_lin(mean=Lin(320,56))
>>> g3 = Group.randn_lin(mean=Lin(150,40))
>>> g = g1 + g2 + g3
>>> cl = Cluster(g)
>>> cl.dendrogram(no_labels=True)
54 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
Now we can explore evolution of within-groups variance versus number of clusters on Elbow plot (Note change in
slope for three clusters):
>>> cl.elbow()
>>> cl.cluster(maxclust=3)
>>> cl.R.data # Restored centres of clusters
[L:146/39, L:43/26, L:323/59]
>>> StereoNet(*cl.groups)
56 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
>>> p = Fol(250,40)
>>> l = Lin(160,25)
>>> StereoNet(p, l, l**p, p**l, l**p**l, p**l**p)
Pair class could be used to correct measurements of planar linear features which should spatialy overlap:
58 Chapter 2. Tutorial
APSG Documentation, Release 0.7.0 Beta
StereoNet has method arrow to draw arrow. Here is example of Hoeppner plot for variable fault orientation within
given stress field:
60 Chapter 2. Tutorial
CHAPTER 3
Installation
The APSG package is also available through conda-forge. To install APSG using conda, use the following com-
mand:
or simply
conda install apsg
if you added conda-forge to your channels (conda config --add channels conda-forge).
The APSG version on PyPI may always one step behind; you can install the latest development version from the
GitHub repository by executing:
61
APSG Documentation, Release 0.7.0 Beta
62 Chapter 3. Installation
CHAPTER 4
Usage
import apsg
63
APSG Documentation, Release 0.7.0 Beta
64 Chapter 4. Usage
CHAPTER 5
Contributing
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement
it.
65
APSG Documentation, Release 0.7.0 Beta
APSG could always use more documentation, whether as part of the official APSG docs, in docstrings, or even on the
web in blog posts, articles, and such.
3. Install your local copy and activate the virtual environment via pipenv.
$ cd apsg/ $ pipenv shell $ pipenv install –dev
4. Create a branch for local development:
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
66 Chapter 5. Contributing
APSG Documentation, Release 0.7.0 Beta
Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function
with a docstring, and add the feature to the list in README.rst.
3. The pull request should work for Python 2.7, 3.5, and 3.6, and for PyPy. Check https://travis-ci.org/ondrolexa/
apsg/pull_requests and make sure that the tests pass for all supported Python versions.
68 Chapter 5. Contributing
CHAPTER 6
Credits
6.2 Contributors
69
APSG Documentation, Release 0.7.0 Beta
70 Chapter 6. Credits
Python Module Index
a
apsg.core, 3
apsg.plotting, 22
apsg.tensors, 26
71
APSG Documentation, Release 0.7.0 Beta
73
APSG Documentation, Release 0.7.0 Beta
74 Index
APSG Documentation, Release 0.7.0 Beta
Index 75
APSG Documentation, Release 0.7.0 Beta
U
U (apsg.tensors.DefGrad attribute), 27
uniform_fol() (apsg.core.Group class method), 17
uniform_lin() (apsg.core.Group class method), 17
upper (apsg.core.Group attribute), 19
upper (apsg.core.Vec3 attribute), 6
uv (apsg.core.Group attribute), 19
uv (apsg.core.Vec3 attribute), 6
V
V (apsg.core.Group attribute), 18
V (apsg.core.Vec3 attribute), 5
V (apsg.tensors.DefGrad attribute), 27
var (apsg.core.Group attribute), 19
Vec3 (class in apsg.core), 3
vector() (apsg.plotting.StereoNet method), 24
VelGrad (class in apsg.tensors), 28
velgrad() (apsg.tensors.DefGrad method), 27
VollmerPlot (class in apsg.plotting), 24
76 Index