Skip to content

Commit

Permalink
Merge 3bba846 into 055d17e
Browse files Browse the repository at this point in the history
  • Loading branch information
megies committed Jun 30, 2016
2 parents 055d17e + 3bba846 commit 6fe45f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -9,6 +9,12 @@
- obspy.db:
* Fixed a bug in obspy-indexer command line script (see #1369,
command line script was not working, probably since 0.10.0)
- obspy.imaging:
* Fixed a bug that leads to pressure/tension color blending when plotting
semi-transparent DC beachball patches (i.e. with "alpha" not equal to 1,
see #1464)
* Fixed a bug when plotting non-DC beachball patches without fill colors
(i.e. with "nofill=True", see #1464)
- obspy.io.ascii:
* Fixed a bug that lead to wrong header information in output files when
writing non-integer sampling rate data to SLIST or TSPAIR formats
Expand Down
88 changes: 49 additions & 39 deletions obspy/imaging/beachball.py
Expand Up @@ -154,22 +154,22 @@ def beach(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k',
size = 100

# Return as collection
plot_dc_used = True
if mt:
(T, N, P) = mt2axes(mt)
if np.fabs(N.val) < EPSILON and np.fabs(T.val + P.val) < EPSILON:
colors, p = plot_dc(np1, size, xy=xy, width=width)
else:
colors, p = plot_mt(T, N, P, size,
plot_zerotrace=True, xy=xy, width=width)
plot_dc_used = False
else:
colors, p = plot_dc(np1, size=size, xy=xy, width=width)

col = collections.PatchCollection(p, match_original=False)
if nofill:
# XXX: not tested with plot_mt
col = collections.PatchCollection([p[1]], match_original=False)
col.set_facecolor('none')
else:
col = collections.PatchCollection(p, match_original=False)
# Replace color dummies 'b' and 'w' by face and bgcolor
fc = [facecolor if c == 'b' else bgcolor for c in colors]
col.set_facecolors(fc)
Expand All @@ -192,6 +192,14 @@ def beach(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k',
col.set_alpha(alpha)
col.set_linewidth(linewidth)
col.set_zorder(zorder)

# warn about color blending bug, see #1464
if alpha != 1 and not nofill and not plot_dc_used:
msg = ("There is a known bug when plotting semi-transparent patches "
"for non-DC sources, which leads to blending of pressure and "
"tension color, see issue #1464.")
warnings.warn(msg)

return col


Expand Down Expand Up @@ -661,42 +669,44 @@ def plot_dc(np1, size=200, xy=(0, 0), width=200):
np.power(np.sin(phi), 2) + np.power(np.cos(phi), 2) *
np.power(90 - d_2, 2) / np.power(90, 2)))

inc = 1
(x_1, y_1) = pol2cart(phi + s_1 * D2R, l1)

if m == 1:
lo = s_1 - 180
hi = s_2
if lo > hi:
inc = -1
th1 = np.arange(s_1 - 180, s_2, inc)
(xs_1, ys_1) = pol2cart(th1 * D2R, 90 * np.ones((1, len(th1))))
(x_2, y_2) = pol2cart(phi + s_2 * D2R, l2)
th2 = np.arange(s_2 + 180, s_1, -inc)
else:
hi = s_1 - 180
lo = s_2 - 180
if lo > hi:
inc = -1
th1 = np.arange(hi, lo, -inc)
(xs_1, ys_1) = pol2cart(th1 * D2R, 90 * np.ones((1, len(th1))))
(x_2, y_2) = pol2cart(phi + s_2 * D2R, l2)
x_2 = x_2[::-1]
y_2 = y_2[::-1]
th2 = np.arange(s_2, s_1, inc)
(xs_2, ys_2) = pol2cart(th2 * D2R, 90 * np.ones((1, len(th2))))
x = np.concatenate((x_1, xs_1[0], x_2, xs_2[0]))
y = np.concatenate((y_1, ys_1[0], y_2, ys_2[0]))

x = x * d / 90
y = y * d / 90

# calculate resolution
res = [value / float(size) for value in width]

# construct the patches
collect = [patches.Ellipse(xy, width=width[0], height=width[1])]
collect.append(xy2patch(y, x, res, xy))
collect = []
# plot paths, once for tension areas and once for pressure areas
for m_ in ((m + 1) % 2, m):
inc = 1
(x_1, y_1) = pol2cart(phi + s_1 * D2R, l1)

if m_ == 1:
lo = s_1 - 180
hi = s_2
if lo > hi:
inc = -1
th1 = np.arange(s_1 - 180, s_2, inc)
(xs_1, ys_1) = pol2cart(th1 * D2R, 90 * np.ones((1, len(th1))))
(x_2, y_2) = pol2cart(phi + s_2 * D2R, l2)
th2 = np.arange(s_2 + 180, s_1, -inc)
else:
hi = s_1 - 180
lo = s_2 - 180
if lo > hi:
inc = -1
th1 = np.arange(hi, lo, -inc)
(xs_1, ys_1) = pol2cart(th1 * D2R, 90 * np.ones((1, len(th1))))
(x_2, y_2) = pol2cart(phi + s_2 * D2R, l2)
x_2 = x_2[::-1]
y_2 = y_2[::-1]
th2 = np.arange(s_2, s_1, inc)
(xs_2, ys_2) = pol2cart(th2 * D2R, 90 * np.ones((1, len(th2))))
x = np.concatenate((x_1, xs_1[0], x_2, xs_2[0]))
y = np.concatenate((y_1, ys_1[0], y_2, ys_2[0]))

x = x * d / 90
y = y * d / 90

# calculate resolution
res = [value / float(size) for value in width]

# construct the patch
collect.append(xy2patch(y, x, res, xy))
return ['b', 'w'], collect


Expand Down

0 comments on commit 6fe45f4

Please sign in to comment.