-
Notifications
You must be signed in to change notification settings - Fork 1
/
stereonet_axes.py
843 lines (700 loc) · 34.8 KB
/
stereonet_axes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
import numpy as np
import matplotlib as mpl
from matplotlib.transforms import Affine2D
from matplotlib.projections import register_projection, LambertAxes
from matplotlib.axes import Axes, subplot_class_factory
from matplotlib.ticker import NullLocator, FixedLocator
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.collections as mcollections
from . import stereonet_math
from . import contouring
from . import stereonet_transforms
class StereonetAxes(LambertAxes):
"""An axes representing a lower-hemisphere "schmitt" (a.k.a. equal area)
projection."""
name = 'stereonet'
RESOLUTION = 60
_base_transform = stereonet_transforms.LambertTransform
_default_center_lat = 0
_default_center_lon = 0
_scale = np.sqrt(2)
def __init__(self, *args, **kwargs):
"""Initialization is identical to a normal Axes object except for the
following kwarg:
Parameters
-----------
rotation : number
The rotation of the stereonet in degrees clockwise from North.
center_latitude : number
The center latitude of the stereonet in degrees.
center_longitude : number
The center longitude of the stereonet in degrees.
All additional args and kwargs are identical to Axes.__init__
"""
self.horizon = np.radians(90)
self._rotation = -np.radians(kwargs.pop('rotation', 0))
y0 = kwargs.get('center_latitude', self._default_center_lat)
x0 = kwargs.get('center_longitude', self._default_center_lon)
kwargs['center_latitude'] = y0
kwargs['center_longitude'] = x0
self._overlay_axes = None
LambertAxes.__init__(self, *args, **kwargs)
def _get_core_transform(self, resolution):
"""The projection for the stereonet as a matplotlib transform. This is
primarily called by LambertAxes._set_lim_and_transforms."""
return self._base_transform(self._center_longitude,
self._center_latitude,
resolution)
def _get_affine_transform(self):
"""The affine portion of the base transform. This is called by
LambertAxes._set_lim_and_transforms."""
# How big is the projected globe?
# In the case of a stereonet, it's actually constant.
xscale = yscale = self._scale
# Create an affine transform to stretch the projection from 0-1
return Affine2D() \
.rotate(np.radians(self.rotation)) \
.scale(0.5 / xscale, 0.5 / yscale) \
.translate(0.5, 0.5)
def _set_lim_and_transforms(self):
"""Setup the key transforms for the axes."""
# Most of the transforms are set up correctly by LambertAxes
LambertAxes._set_lim_and_transforms(self)
# Transform for latitude ticks. These are typically unused, but just
# in case we need them...
yaxis_stretch = Affine2D().scale(4 * self.horizon, 1.0)
yaxis_stretch = yaxis_stretch.translate(-self.horizon, 0.0)
# These are identical to LambertAxes._set_lim_and_transforms, but we
# need to update things to reflect the new "yaxis_stretch"
yaxis_space = Affine2D().scale(1.0, 1.1)
self._yaxis_transform = \
yaxis_stretch + \
self.transData
yaxis_text_base = \
yaxis_stretch + \
self.transProjection + \
(yaxis_space + \
self.transAffine + \
self.transAxes)
self._yaxis_text1_transform = \
yaxis_text_base + \
Affine2D().translate(-8.0, 0.0)
self._yaxis_text2_transform = \
yaxis_text_base + \
Affine2D().translate(8.0, 0.0)
def set_longitude_grid(self, degrees):
"""
Set the number of degrees between each longitude grid.
"""
number = int((360.0 / degrees) + 1)
locs = np.linspace(-np.pi, np.pi, number, True)[1:]
locs[-1] -= 0.01 # Workaround for "back" gridlines showing.
self.xaxis.set_major_locator(FixedLocator(locs))
self._logitude_degrees = degrees
self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
def set_position(self, pos, which='both'):
"""Identical to Axes.set_position (This docstring is overwritten)."""
self._polar.set_position(pos, which)
if self._overlay_axes is not None:
self._overlay_axes.set_position(pos, which)
LambertAxes.set_position(self, pos, which)
# Use default docstring, as usage is identical.
set_position.__doc__ = Axes.set_position.__doc__
def set_rotation(self, rotation):
"""Set the rotation of the stereonet in degrees clockwise from North."""
self._rotation = np.radians(rotation)
self._polar.set_theta_offset(self._rotation + np.pi / 2.0)
self.transData.invalidate()
self.transAxes.invalidate()
self._set_lim_and_transforms()
def get_rotation(self):
"""The rotation of the stereonet in degrees clockwise from North."""
return np.degrees(self._rotation)
# Using explicit property (instead of decorator) to allow explicit
# matplotlib-style getters and setters.
rotation = property(get_rotation, set_rotation)
def cla(self):
"""Identical to Axes.cla (This docstring is overwritten)."""
Axes.cla(self)
# Set grid defaults...
self.set_longitude_grid(10)
self.set_latitude_grid(10)
self.set_longitude_grid_ends(90)
# Hide all ticks and tick labels for the "native" lon and lat axes
self.xaxis.set_minor_locator(NullLocator())
self.yaxis.set_minor_locator(NullLocator())
self.xaxis.set_ticks_position('none')
self.yaxis.set_ticks_position('none')
self.xaxis.set_tick_params(label1On=False)
self.yaxis.set_tick_params(label1On=False)
# Set the grid on or off based on the rc params.
self.grid(mpl.rcParams['axes.grid'])
# Set the default limits (so that the "native" ticklabels will be
# correct if they're turned back on)...
Axes.set_xlim(self, -2 * self.horizon, 2 * self.horizon)
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
# Set up the azimuth ticks.
self._polar.set_theta_offset(np.radians(self.rotation + 90))
self._polar.set_theta_direction(-1)
self._polar.grid(False)
self._polar.set_rticks([])
# Use default docstring, as usage is identical.
cla.__doc__ = Axes.cla.__doc__
def format_coord(self, x, y):
"""Format displayed coordinates during mouseover of axes."""
p, b = stereonet_math.geographic2plunge_bearing(x, y)
s, d = stereonet_math.geographic2pole(x, y)
# pb = u'P/B={:0.0f}\u00b0/{:03.0f}\u00b0'.format(p[0], b[0])
pb = u'Dip direction={:03.0f}\u00b0'.format(b[0])
# sd = u'S/D={:03.0f}\u00b0/{:0.0f}\u00b0'.format(s[0], d[0])
sd = u'Dip={:0.0f}\u00b0'.format(d[0])
return u'{}, {}'.format(pb, sd)
def grid(self, b=None, which='major', axis='both', kind='arbitrary',
center=None, **kwargs):
"""
Usage is identical to a normal axes grid except for the ``kind`` and
``center`` kwargs. ``kind="polar"`` will add a polar overlay.
The ``center`` and ``kind`` arguments allow you to add a grid from a
differently-centered stereonet. This is useful for making "polar
stereonets" that still use the same coordinate system as a standard
stereonet. (i.e. a plane/line/whatever will have the same
representation on both, but the grid is displayed differently.)
To display a polar grid on a stereonet, use ``kind="polar"``.
It is also often useful to display a grid relative to an arbitrary
measurement (e.g. a lineation axis). In that case, use the
``lon_center`` and ``lat_center`` arguments. Note that these are in
radians in "stereonet coordinates". Therefore, you'll often want to
use one of the functions in ``stereonet_math`` to convert a
line/plane/rake into the longitude and latitude you'd input here. For
example: ``add_overlay(center=stereonet_math.line(plunge, bearing))``.
If no parameters are specified, this is equivalent to turning on the
standard grid.
"""
grid_on = self._gridOn
Axes.grid(self, False)
if kind == 'polar':
center = 0, 0
if self._overlay_axes is not None:
self._overlay_axes.remove()
self._overlay_axes = None
if not b and b is not None:
return
if b is None:
if grid_on:
return
if center is None or np.allclose(center, (np.pi/2, 0)):
return Axes.grid(self, b, which, axis, **kwargs)
self._add_overlay(center)
self._overlay_axes.grid(True, which, axis, **kwargs)
self._gridOn = True
grid.__doc__ += Axes.grid.__doc__
def _add_overlay(self, center):
"""
Add a grid from a differently-centered stereonet. This is useful for
making "polar stereonets" that still use the same coordinate system as
a standard stereonet. (i.e. a plane/line/whatever will have the same
representation on both, but the grid is displayed differently.)
To display a polar grid on a stereonet, use ``kind="polar"``.
It is also often useful to display a grid relative to an arbitrary
measurement (e.g. a lineation axis). In that case, use the
``lon_center`` and ``lat_center`` arguments. Note that these are in
radians in "stereonet coordinates". Therefore, you'll often want to
use one of the functions in ``stereonet_math`` to convert a
line/plane/rake into the longitude and latitude you'd input here. For
example: ``add_overlay(center=stereonet_math.line(plunge, bearing))``.
If no parameters are specified, this is equivalent to turning on the
standard grid.
Parameters
----------
center: 2-item tuple of numbers
A tuple of (longitude, latitude) in radians that the overlay is
centered on.
"""
plunge, bearing = stereonet_math.geographic2plunge_bearing(*center)
lon0, lat0 = center
fig = self.get_figure()
self._overlay_axes = fig.add_axes(self.get_position(True),
frameon=False, projection=self.name,
center_longitude=0,
center_latitude=np.radians(plunge),
label='overlay',
rotation=bearing)
self._overlay_axes._polar.remove()
self._overlay_axes.format_coord = self._overlay_format_coord
self._overlay_axes.grid(True)
def set_longitude_grid_ends(self, value):
LambertAxes.set_longitude_grid_ends(self, value)
if self._overlay_axes is not None:
self._overlay_axes.set_longitude_grid_ends(value)
# Use the existing docstring...
set_longitude_grid_ends.__doc__ =\
LambertAxes.set_longitude_grid_ends.__doc__
@property
def _polar(self):
"""The "hidden" polar axis used for azimuth labels."""
# This will be called inside LambertAxes.__init__ as well as every
# time the axis is cleared, so we need the try/except to avoid having
# multiple hidden axes when `cla` is _manually_ called.
try:
return self._hidden_polar_axes
except AttributeError:
fig = self.get_figure()
self._hidden_polar_axes = fig.add_axes(self.get_position(True),
frameon=False, projection='polar')
self._hidden_polar_axes.format_coord = self._polar_format_coord
return self._hidden_polar_axes
def _format_helper(self, ax, x, y):
xdisp, ydisp = ax.transData.transform_point([x, y])
x, y = self.transData.inverted().transform_point([xdisp, ydisp])
return self.format_coord(x, y)
def _overlay_format_coord(self, x, y):
return self._format_helper(self._overlay_axes, x, y)
def _polar_format_coord(self, x, y):
return self._format_helper(self._hidden_polar_axes, x, y)
def set_azimuth_ticks(self, angles, labels=None, frac=None, **kwargs):
"""
Sets the azimuthal tick locations (Note: tick lines are not currently
drawn or supported.).
Parameters
----------
angles : sequence of numbers
The tick locations in degrees.
labels : sequence of strings
The tick label at each location. Defaults to a formatted version
of the specified angles.
frac : number
The radial location of the tick labels. 1.0 is the along the edge,
1.1 would be outside, and 0.9 would be inside.
**kwargs
Additional parameters are text properties for the labels.
"""
return self._polar.set_thetagrids(angles, labels, frac, **kwargs)
def get_azimuth_ticks(self, minor=False):
return self._polar.get_xticks(minor)
def set_azimuth_ticklabels(self, labels, fontdict=None, **kwargs):
"""
Sets the labels for the azimuthal ticks.
Parameters
----------
labels : A sequence of strings
Azimuth tick labels
**kwargs
Additional parameters are text properties for the labels.
"""
return self._polar.set_xticklabels(labels, fontdict, **kwargs)
def get_azimuth_ticklabels(self, minor=False):
"""Get the azimuth tick labels as a list of Text artists."""
return self._polar.get_xticklabels(minor)
def cone(self, plunge, bearing, angle, segments=100, bidirectional=True,
**kwargs):
"""
Plot a polygon of a small circle (a.k.a. a cone) with an angular radius
of *angle* centered at a p/b of *plunge*, *bearing*. Additional keyword
arguments are passed on to the ``PathCollection``. (e.g. to have an
unfilled small small circle, pass "facecolor='none'".)
Parameters
----------
plunge : number or sequence of numbers
The plunge of the center of the cone in degrees.
bearing : number or sequence of numbers
The bearing of the center of the cone in degrees.
angle : number or sequence of numbers
The angular radius of the cone in degrees.
segments : int, optional
The number of vertices to use for the cone. Defaults to 100.
bidirectional : boolean, optional
Whether or not to draw two patches (the one given and its antipode)
for each measurement. Defaults to True.
**kwargs
Additional parameters are ``matplotlib.collections.PatchCollection``
properties.
Returns
-------
collection : ``matplotlib.collections.PathCollection``
Notes
-----
If *bidirectional* is ``True``, two circles will be plotted, even if
only one of each pair is visible. This is the default behavior.
"""
plunge, bearing, angle = np.atleast_1d(plunge, bearing, angle)
patches = []
lons, lats = stereonet_math.cone(plunge, bearing, angle, segments)
codes = mpath.Path.LINETO * np.ones(segments, dtype=np.uint8)
codes[0] = mpath.Path.MOVETO
if bidirectional:
p, b = -plunge, bearing + 180
alons, alats = stereonet_math.cone(p, b, angle, segments)
codes = np.hstack([codes, codes])
lons = np.hstack([lons, alons])
lats = np.hstack([lats, alats])
for lon, lat in zip(lons, lats):
xy = np.vstack([lon, lat]).T
path = mpath.Path(xy, codes)
patches.append(mpatches.PathPatch(path))
col = mcollections.PatchCollection(patches, **kwargs)
self.add_collection(col)
return col
def plane(self, strike, dip, *args, **kwargs):
"""
Plot lines representing planes on the axes. Additional arguments and
keyword arguments are passed on to `ax.plot`.
Parameters
----------
strike, dip : number or sequences of numbers
The strike and dip of the plane(s) in degrees. The dip direction is
defined by the strike following the "right-hand rule".
segments : int, optional
The number of vertices to use for the line. Defaults to 100.
**kwargs
Additional parameters are passed on to `plot`.
Returns
-------
A sequence of Line2D artists representing the lines specified by
`strike` and `dip`.
"""
segments = kwargs.pop('segments', 100)
center = self._center_latitude, self._center_longitude
lon, lat = stereonet_math.plane(strike, dip, segments, center)
return self.plot(lon, lat, *args, **kwargs)
def pole(self, strike, dip, *args, **kwargs):
"""
Plot points representing poles to planes on the axes. Additional
arguments and keyword arguments are passed on to `ax.plot`.
Parameters
----------
strike, dip : numbers or sequences of numbers
The strike and dip of the plane(s) in degrees. The dip direction is
defined by the strike following the "right-hand rule".
**kwargs
Additional parameters are passed on to `plot`.
Returns
-------
A sequence of Line2D artists representing the point(s) specified by
`strike` and `dip`.
"""
lon, lat = stereonet_math.pole(strike, dip)
args, kwargs = self._point_plot_defaults(args, kwargs)
return self.plot(lon, lat, *args, **kwargs)
def rake(self, strike, dip, rake_angle, *args, **kwargs):
"""
Plot points representing lineations along planes on the axes.
Additional arguments and keyword arguments are passed on to `plot`.
Parameters
----------
strike, dip : number or sequences of numbers
The strike and dip of the plane(s) in degrees. The dip direction is
defined by the strike following the "right-hand rule".
rake_angle : number or sequences of numbers
The angle of the lineation(s) on the plane(s) measured in degrees
downward from horizontal. Zero degrees corresponds to the "right
hand" direction indicated by the strike, while negative angles are
measured downward from the opposite strike direction.
**kwargs
Additional arguments are passed on to `plot`.
Returns
-------
A sequence of Line2D artists representing the point(s) specified by
`strike` and `dip`.
"""
lon, lat = stereonet_math.rake(strike, dip, rake_angle)
args, kwargs = self._point_plot_defaults(args, kwargs)
return self.plot(lon, lat, *args, **kwargs)
def line(self, plunge, bearing, *args, **kwargs):
"""
Plot points representing linear features on the axes. Additional
arguments and keyword arguments are passed on to `plot`.
Parameters
----------
plunge, bearing : number or sequence of numbers
The plunge and bearing of the line(s) in degrees. The plunge is
measured in degrees downward from the end of the feature specified
by the bearing.
**kwargs
Additional parameters are passed on to `plot`.
Returns
-------
A sequence of Line2D artists representing the point(s) specified by
`strike` and `dip`.
"""
lon, lat = stereonet_math.line(plunge, bearing)
args, kwargs = self._point_plot_defaults(args, kwargs)
return self.plot([lon], [lat], *args, **kwargs)
def _point_plot_defaults(self, args, kwargs):
"""To avoid confusion for new users, this ensures that "scattered"
points are plotted by by `plot` instead of points joined by a line.
Parameters
----------
args : tuple
Arguments representing additional parameters to be passed to
`self.plot`.
kwargs : dict
Keyword arguments representing additional parameters to be passed
to `self.plot`.
Returns
-------
Modified versions of `args` and `kwargs`.
"""
if args:
return args, kwargs
if 'ls' not in kwargs and 'linestyle' not in kwargs:
kwargs['linestyle'] = 'none'
if 'marker' not in kwargs:
kwargs['marker'] = 'o'
return args, kwargs
def _contour_helper(self, args, kwargs):
"""Unify defaults and common functionality of ``density_contour`` and
``density_contourf``."""
contour_kwargs = {}
contour_kwargs['measurement'] = kwargs.pop('measurement', 'poles')
contour_kwargs['method'] = kwargs.pop('method', 'exponential_kamb')
contour_kwargs['sigma'] = kwargs.pop('sigma', 3)
contour_kwargs['gridsize'] = kwargs.pop('gridsize', 100)
contour_kwargs['weights'] = kwargs.pop('weights', None)
lon, lat, totals = contouring.density_grid(*args, **contour_kwargs)
return lon, lat, totals, kwargs
def density_contour(self, *args, **kwargs):
"""
Estimates point density of the given linear orientation measurements
(Interpreted as poles, lines, rakes, or "raw" longitudes and latitudes
based on the `measurement` keyword argument.) and plots contour lines of
the resulting density distribution.
Parameters
----------
*args : A variable number of sequences of measurements.
By default, this will be expected to be ``strike`` & ``dip``, both
array-like sequences representing poles to planes. (Rake
measurements require three parameters, thus the variable number of
arguments.) The ``measurement`` kwarg controls how these arguments
are interpreted.
measurement : string, optional
Controls how the input arguments are interpreted. Defaults to
``"poles"``. May be one of the following:
``"poles"`` : strikes, dips
Arguments are assumed to be sequences of strikes and dips
of planes. Poles to these planes are used for contouring.
``"lines"`` : plunges, bearings
Arguments are assumed to be sequences of plunges and
bearings of linear features.
``"rakes"`` : strikes, dips, rakes
Arguments are assumed to be sequences of strikes, dips, and
rakes along the plane.
``"radians"`` : lon, lat
Arguments are assumed to be "raw" longitudes and latitudes
in the stereonet's underlying coordinate system.
method : string, optional
The method of density estimation to use. Defaults to
``"exponential_kamb"``. May be one of the following:
``"exponential_kamb"`` : Kamb with exponential smoothing
A modified Kamb method using exponential smoothing [1]_. Units
are in numbers of standard deviations by which the density
estimate differs from uniform.
``"linear_kamb"`` : Kamb with linear smoothing
A modified Kamb method using linear smoothing [1]_. Units are
in numbers of standard deviations by which the density estimate
differs from uniform.
``"kamb"`` : Kamb with no smoothing
Kamb's method [2]_ with no smoothing. Units are in numbers of
standard deviations by which the density estimate differs from
uniform.
``"schmidt"`` : 1% counts
The traditional "Schmidt" (a.k.a. 1%) method. Counts points
within a counting circle comprising 1% of the total area of the
hemisphere. Does not take into account sample size. Units are
in points per 1% area.
sigma : int or float, optional
The number of standard deviations defining the expected number of
standard deviations by which a random sample from a uniform
distribution of points would be expected to vary from being evenly
distributed across the hemisphere. This controls the size of the
counting circle, and therefore the degree of smoothing. Higher
sigmas will lead to more smoothing of the resulting density
distribution. This parameter only applies to Kamb-based methods.
Defaults to 3.
gridsize : int or 2-item tuple of ints, optional
The size of the grid that the density is estimated on. If a single
int is given, it is interpreted as an NxN grid. If a tuple of ints
is given it is interpreted as (nrows, ncols). Defaults to 100.
weights : array-like, optional
The relative weight to be applied to each input measurement. The
array will be normalized to sum to 1, so absolute value of the
weights do not affect the result. Defaults to None.
**kwargs
Additional keyword arguments are passed on to matplotlib's
`contour` function.
Returns
-------
A matplotlib ContourSet.
See Also
--------
mplstereonet.density_grid
mplstereonet.StereonetAxes.density_contourf
matplotlib.pyplot.contour
matplotlib.pyplot.clabel
Examples
--------
Plot density contours of poles to the specified planes using a
modified Kamb method with exponential smoothing [1]_.
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contour(strikes, dips)
Plot density contours of a set of linear orientation measurements.
>>> plunges, bearings = [-10, 20, -30], [120, 315, 86]
>>> ax.density_contour(plunges, bearings, measurement='lines')
Plot density contours of a set of rake measurements.
>>> strikes, dips, rakes = [120, 315, 86], [22, 85, 31], [-5, 20, 9]
>>> ax.density_contour(strikes, dips, rakes, measurement='rakes')
Plot density contours of a set of "raw" longitudes and latitudes.
>>> lon, lat = np.radians([-40, 30, -85]), np.radians([21, -59, 45])
>>> ax.density_contour(lon, lat, measurement='radians')
Plot density contours of poles to planes using a Kamb method [2]_
with the density estimated on a 10x10 grid (in long-lat space)
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contour(strikes, dips, method='kamb', gridsize=10)
Plot density contours of poles to planes with contours at [1,2,3]
standard deviations.
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contour(strikes, dips, levels=[1,2,3])
References
----------
.. [1] Vollmer, 1995. C Program for Automatic Contouring of Spherical
Orientation Data Using a Modified Kamb Method. Computers &
Geosciences, Vol. 21, No. 1, pp. 31--49.
.. [2] Kamb, 1959. Ice Petrofabric Observations from Blue Glacier,
Washington, in Relation to Theory and Experiment. Journal of
Geophysical Research, Vol. 64, No. 11, pp. 1891--1909.
"""
lon, lat, totals, kwargs = self._contour_helper(args, kwargs)
return self.contour(lon, lat, totals, **kwargs)
def density_contourf(self, *args, **kwargs):
"""
Estimates point density of the given linear orientation measurements
(Interpreted as poles, lines, rakes, or "raw" longitudes and latitudes
based on the `measurement` keyword argument.) and plots filled contours
of the resulting density distribution.
Parameters
----------
*args : A variable number of sequences of measurements.
By default, this will be expected to be ``strike`` & ``dip``, both
array-like sequences representing poles to planes. (Rake
measurements require three parameters, thus the variable number of
arguments.) The ``measurement`` kwarg controls how these arguments
are interpreted.
measurement : string, optional
Controls how the input arguments are interpreted. Defaults to
``"poles"``. May be one of the following:
``"poles"`` : strikes, dips
Arguments are assumed to be sequences of strikes and dips
of planes. Poles to these planes are used for contouring.
``"lines"`` : plunges, bearings
Arguments are assumed to be sequences of plunges and
bearings of linear features.
``"rakes"`` : strikes, dips, rakes
Arguments are assumed to be sequences of strikes, dips, and
rakes along the plane.
``"radians"`` : lon, lat
Arguments are assumed to be "raw" longitudes and latitudes
in the stereonet's underlying coordinate system.
method : string, optional
The method of density estimation to use. Defaults to
``"exponential_kamb"``. May be one of the following:
``"exponential_kamb"`` : Kamb with exponential smoothing
A modified Kamb method using exponential smoothing [1]_. Units
are in numbers of standard deviations by which the density
estimate differs from uniform.
``"linear_kamb"`` : Kamb with linear smoothing
A modified Kamb method using linear smoothing [1]_. Units are
in numbers of standard deviations by which the density estimate
differs from uniform.
``"kamb"`` : Kamb with no smoothing
Kamb's method [2]_ with no smoothing. Units are in numbers of
standard deviations by which the density estimate differs from
uniform.
``"schmidt"`` : 1% counts
The traditional "Schmidt" (a.k.a. 1%) method. Counts points
within a counting circle comprising 1% of the total area of the
hemisphere. Does not take into account sample size. Units are
in points per 1% area.
sigma : int or float, optional
The number of standard deviations defining the expected number of
standard deviations by which a random sample from a uniform
distribution of points would be expected to vary from being evenly
distributed across the hemisphere. This controls the size of the
counting circle, and therefore the degree of smoothing. Higher
sigmas will lead to more smoothing of the resulting density
distribution. This parameter only applies to Kamb-based methods.
Defaults to 3.
gridsize : int or 2-item tuple of ints, optional
The size of the grid that the density is estimated on. If a single
int is given, it is interpreted as an NxN grid. If a tuple of ints
is given it is interpreted as (nrows, ncols). Defaults to 100.
weights : array-like, optional
The relative weight to be applied to each input measurement. The
array will be normalized to sum to 1, so absolute value of the
weights do not affect the result. Defaults to None.
**kwargs
Additional keyword arguments are passed on to matplotlib's
`contourf` function.
Returns
-------
A matplotlib `QuadContourSet`.
See Also
--------
mplstereonet.density_grid
mplstereonet.StereonetAxes.density_contour
matplotlib.pyplot.contourf
matplotlib.pyplot.clabel
Examples
--------
Plot filled density contours of poles to the specified planes using
a modified Kamb method with exponential smoothing [1]_.
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contourf(strikes, dips)
Plot filled density contours of a set of linear orientation
measurements.
>>> plunges, bearings = [-10, 20, -30], [120, 315, 86]
>>> ax.density_contourf(plunges, bearings, measurement='lines')
Plot filled density contours of a set of rake measurements.
>>> strikes, dips, rakes = [120, 315, 86], [22, 85, 31], [-5, 20, 9]
>>> ax.density_contourf(strikes, dips, rakes, measurement='rakes')
Plot filled density contours of a set of "raw" longitudes and
latitudes.
>>> lon, lat = np.radians([-40, 30, -85]), np.radians([21, -59, 45])
>>> ax.density_contourf(lon, lat, measurement='radians')
Plot filled density contours of poles to planes using a Kamb method
[2]_ with the density estimated on a 10x10 grid (in long-lat space)
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contourf(strikes, dips, method='kamb', gridsize=10)
Plot filled density contours of poles to planes with contours at
[1,2,3] standard deviations.
>>> strikes, dips = [120, 315, 86], [22, 85, 31]
>>> ax.density_contourf(strikes, dips, levels=[1,2,3])
References
----------
.. [1] Vollmer, 1995. C Program for Automatic Contouring of Spherical
Orientation Data Using a Modified Kamb Method. Computers &
Geosciences, Vol. 21, No. 1, pp. 31--49.
.. [2] Kamb, 1959. Ice Petrofabric Observations from Blue Glacier,
Washington, in Relation to Theory and Experiment. Journal of
Geophysical Research, Vol. 64, No. 11, pp. 1891--1909.
"""
lon, lat, totals, kwargs = self._contour_helper(args, kwargs)
return self.contourf(lon, lat, totals, **kwargs)
class EqualAngleAxes(StereonetAxes):
"""An axes representing a lower-hemisphere "Wulff" (a.k.a. equal angle)
projection."""
_base_transform = stereonet_transforms.StereographicTransform
_scale = 2.0
name = 'equal_angle_stereonet'
class EqualAreaAxes(StereonetAxes):
"""An axes representing a lower-hemisphere "Schmitt" (a.k.a. equal area)
projection."""
name = 'equal_area_stereonet'
# We need to define explict subplot classes so that we don't mess up the
# method resolution order when using matplotlib subplots.
EqualAngleAxesSubplot = subplot_class_factory(EqualAngleAxes)
EqualAngleAxesSubplot.__module__ = EqualAngleAxes.__module__
EqualAreaAxesSubplot = subplot_class_factory(EqualAngleAxes)
EqualAreaAxesSubplot.__module__ = EqualAngleAxes.__module__
register_projection(StereonetAxes)
register_projection(EqualAreaAxes)
register_projection(EqualAngleAxes)