# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
mpl_color as str_to_mpl_color, InvalidColorDef
# modified from http://stackoverflow.com/questions/2417794/ # how-to-make-the-angles-in-a-matplotlib-polar-plot-go-clockwise-with-0-at-the-top
from matplotlib.projections import PolarAxes, register_projection from matplotlib.transforms import Affine2D, Bbox, IdentityTransform
class GlobeCrossSectionAxes(PolarAxes): ''' A variant of PolarAxes where theta starts pointing north and goes clockwise and the radial axis is reversed. ''' name = 'globe_cross_section'
class GlobeCrossSectionTransform(PolarAxes.PolarTransform):
def transform(self, tr): xy = num.zeros(tr.shape, num.float_) t = tr[:, 0:1]*d2r r = cake.earthradius - tr[:, 1:2] x = xy[:, 0:1] y = xy[:, 1:2] x[:] = r * num.sin(t) y[:] = r * num.cos(t) return xy
transform_non_affine = transform
def inverted(self): return GlobeCrossSectionAxes.\ InvertedGlobeCrossSectionTransform()
class InvertedGlobeCrossSectionTransform( PolarAxes.InvertedPolarTransform):
def transform(self, xy): x = xy[:, 0:1] y = xy[:, 1:] r = num.sqrt(x*x + y*y) theta = num.arctan2(y, x)*r2d return num.concatenate((theta, cake.earthradius-r), 1)
def inverted(self): return GlobeCrossSectionAxes.GlobeCrossSectionTransform()
def _set_lim_and_transforms(self): PolarAxes._set_lim_and_transforms(self) try: theta_position = self._theta_label1_position except AttributeError: theta_position = self.get_theta_offset()
self.transProjection = self.GlobeCrossSectionTransform() self.transData = ( self.transScale + self.transProjection + (self.transProjectionAffine + self.transAxes)) self._xaxis_transform = ( self.transProjection + self.PolarAffine(IdentityTransform(), Bbox.unit()) + self.transAxes) self._xaxis_text1_transform = ( theta_position + self._xaxis_transform) self._yaxis_transform = ( Affine2D().scale(num.pi * 2.0, 1.0) + self.transData)
try: rlp = getattr(self, '_r_label1_position') except AttributeError: rlp = getattr(self, '_r_label_position')
self._yaxis_text1_transform = ( rlp + Affine2D().scale(1.0 / 360.0, 1.0) + self._yaxis_transform)
register_projection(GlobeCrossSectionAxes)
'butter1': (252, 233, 79), 'butter2': (237, 212, 0), 'butter3': (196, 160, 0), 'chameleon1': (138, 226, 52), 'chameleon2': (115, 210, 22), 'chameleon3': (78, 154, 6), 'orange1': (252, 175, 62), 'orange2': (245, 121, 0), 'orange3': (206, 92, 0), 'skyblue1': (114, 159, 207), 'skyblue2': (52, 101, 164), 'skyblue3': (32, 74, 135), 'plum1': (173, 127, 168), 'plum2': (117, 80, 123), 'plum3': (92, 53, 102), 'chocolate1': (233, 185, 110), 'chocolate2': (193, 125, 17), 'chocolate3': (143, 89, 2), 'scarletred1': (239, 41, 41), 'scarletred2': (204, 0, 0), 'scarletred3': (164, 0, 0), 'aluminium1': (238, 238, 236), 'aluminium2': (211, 215, 207), 'aluminium3': (186, 189, 182), 'aluminium4': (136, 138, 133), 'aluminium5': (85, 87, 83), 'aluminium6': (46, 52, 54) }
'''Calculate an integer representation deduced from path's given name.'''
'scarletred chameleon skyblue chocolate orange plum'.split()]
light(to01(tango_colors['skyblue1']), i*0.1) for i in range(1, 9)]
paths, zstart, zstop, axes=None, vred=None, distances=None, coloring='by_phase_definition', avoid_same_colors=True, phase_colors={}):
xmin, xmax = distances.min(), distances.max()
paths, coloring, avoid_same_colors, phase_colors=phase_colors)
if path.xmax() < xmin or path.xmin() > xmax: continue
continue
axes.plot(x, t-x/vred, linewidth=2, color=color) axes.plot([x[0]], [t[0]-x[0]/vred], 'o', color=color) axes.plot([x[-1]], [t[-1]-x[-1]/vred], 'o', color=color) axes.text( x[len(x)//2], t[len(x)//2]-x[len(x)//2]/vred, path.used_phase().used_repr(), color=color, va='center', ha='center', clip_on=True, bbox=dict( ec=color, fc=light(color), pad=8, lw=1), fontsize=10) else: x[len(x)//2], t[len(x)//2], path.used_phase().used_repr(), color=color, va='center', ha='center', clip_on=True, bbox=dict( ec=color, fc=light(color), pad=8, lw=1), fontsize=10)
all_t -= all_x/vred
axes.set_xlabel('Distance [deg]') else:
else: if as_degrees: axes.set_ylabel('Time - Distance / %g deg/s [ s ]' % ( vred)) else: axes.set_ylabel('Time - Distance / %g km/s [ s ]' % ( d2r*vred*cake.earthradius/cake.km))
axes = getaxes(axes) from matplotlib import transforms return axes.transData + transforms.ScaledTranslation( dx/72., dy/72., axes.gcf().dpi_scale_trans)
paths, zstart, zstop, axes=None, coloring='by_phase_definition', avoid_same_colors=True, phase_colors={}):
paths, coloring, avoid_same_colors, phase_colors=phase_colors)
# converting ray parameters from s/rad to s/deg x[len(x)//2], p[len(x)//2], path.used_phase().used_repr(), color=color, va='center', ha='center', clip_on=True, bbox=dict( ec=color, fc=light(color), pad=8, lw=1))
axes.set_xlabel('Distance [deg]') else:
paths, coloring='by_phase_definition', avoid_same_colors=True, phase_colors={}):
else: color_id = available_colors.pop()
else: path_to_color[path] = colors[ipath % len(colors)]
axes=None, coloring='by_phase_definition', legend=True, avoid_same_colors=True, aspect=None, phase_colors={}):
axes.set_aspect(aspect/(d2r*cake.earthradius))
paths, coloring, avoid_same_colors, phase_colors=phase_colors)
path.endgaps(zstart, zstop))
else: x = num.linspace(xmin, xmin*10, 6) p = num.atleast_1d(pmin)
p, path.endgaps(zstart, zstop), x_for_headwave=x)
else: fanz, fanx, _ = ray.zxt_path_subdivided() path = ray.path
else: phase_label = path
0.90, dis.z, dis.name, transform=trans, va='center', ha='right', color=dark(color), bbox=dict(ec=dark(color), fc=light(color, 0.3), pad=8, lw=1))
else: else:
lay.ztop, lay.zbot, fc=color, ec=dark(color), label='abc')
axes.text( 0.95, (lay.ztop + lay.zbot)*0.5, lay.name, transform=trans, va='center', ha='right', color=dark(color), bbox=dict(ec=dark(color), fc=light(color, 0.3), pad=8, lw=1))
axes = getaxes(axes) axes.plot( distances, cake.filled(zstop, len(distances)), '^', color='black')
else:
return [x/self._factor for x in AutoLocator.bin_boundaries( self, vmin*self._factor, vmax*self._factor)]
axes.set_xlabel('Distance [deg]') else:
from matplotlib import pyplot as plt data = [] for angle in num.linspace(0., 90., 910.): pp = math.sin(angle*d2r)/mat.vp ps = math.sin(angle*d2r)/mat.vs
escp = cake.psv_surface(mat, pp, energy=True) escs = cake.psv_surface(mat, ps, energy=True) data.append(( angle, escp[cake.psv_surface_ind(cake.P, cake.P)], escp[cake.psv_surface_ind(cake.P, cake.S)], escs[cake.psv_surface_ind(cake.S, cake.S)], escs[cake.psv_surface_ind(cake.S, cake.P)]))
a, pp, ps, ss, sp = num.array(data).T
plt.plot(a, pp, label='PP') plt.plot(a, ps, label='PS') plt.plot(a, ss, label='SS') plt.plot(a, sp, label='SP') plt.xlabel('Incident Angle') plt.ylabel('Energy Normalized Coefficient', position=(-2., 0.5)) plt.legend() mpl_show(plt)
paths, zstart, zstop, distances=None, as_degrees=False, axes=None, show=True, phase_colors={}):
else: plt = None
paths, zstart, zstop, axes=axes, phase_colors=phase_colors)
xmin, xmax = distances.min(), distances.max()
paths, zstart, zstop, distances=None, as_degrees=False, vred=None, axes=None, show=True, phase_colors={}):
else: plt = None
paths, zstart, zstop, vred=vred, distances=distances, axes=axes, phase_colors=phase_colors)
xmin, xmax = distances.min(), distances.max()
mod, paths, rays, zstart, zstop, distances=None, show=True, phase_colors={}):
from matplotlib import pyplot as plt mpl_init()
globe_cross_section() axes = plt.subplot(1, 1, 1, projection='globe_cross_section') plot_rays(paths, rays, zstart, zstop, axes=axes, phase_colors=phase_colors) plot_source(zstart, axes=axes) if distances is not None: plot_receivers(zstop, distances, axes=axes)
axes.set_ylim(0., cake.earthradius) axes.get_yaxis().set_visible(False)
if plt: if show is True: mpl_show(plt)
mod, paths, rays, zstart, zstop, distances=None, as_degrees=False, axes=None, show=True, aspect=None, shade_model=True, phase_colors={}):
else: plt = None
paths = list(set([x.path for x in rays]))
paths, rays, zstart, zstop, axes=axes, aspect=aspect, phase_colors=phase_colors)
plot_receivers(zstop, distances, axes=axes)
mod, paths, rays, zstart, zstop, distances=None, as_degrees=False, show=True, vred=None, phase_colors={}):
paths, zstart, zstop, vred=vred, distances=distances, phase_colors=phase_colors)
plot_receivers(zstop, distances)
else: plt = None
|