def plotHistogram(self, vel_range=None, bins=36, phase='vp', axes=None): '''Plot 1D histogram of seismic velocities in the container :param vel_range: Velocity range, defaults to (5.5, 8.5) :type vel_range: tuple, optional :param bins: bins, defaults to 30 (see :func:`numpy.histogram`) :type bins: int, optional :param phase: Property to plot out of ``['vp', 'vs']``, defaults to 'vp' :type phase: str, optional :param figure: Figure to plot in, defaults to None :type figure: :class:`matplotlib.Figure`, optional ''' import matplotlib.pyplot as plt fig, ax = _getCanvas(axes) if phase not in ['vp', 'vs']: raise AttributeError('phase has to be either vp or vs') data = self._dataMatrix()[phase] ax.hist(data, weights=self.data_matrix['h'], range=vel_range, bins=bins, color='g', alpha=.5) ax.text(.95, .95, '%d Profiles' % self.nprofiles, transform=ax.transAxes, fontsize=10, va='top', ha='right', alpha=.7) ax.set_title('Distribution of %s' % vel_labels[phase]) ax.set_xlabel('%s [km/s]' % vel_labels[phase]) ax.set_ylabel('Cumulative occurrence [N]') xscaled(1. / km, ax) ax.yaxis.grid(alpha=.4) if self.name is not None: ax.set_title('%s for %s' % (ax.get_title(), self.name)) if axes is None: plt.show()
def plotHistogram(self, vel_range=None, bins=36, phase='vp', axes=None): '''Plot 1D histogram of seismic velocities in the container :param vel_range: Velocity range, defaults to (5.5, 8.5) :type vel_range: tuple, optional :param bins: bins, defaults to 30 (see :func:`numpy.histogram`) :type bins: int, optional :param phase: Property to plot out of ``['vp', 'vs']``, defaults to 'vp' :type phase: str, optional :param figure: Figure to plot in, defaults to None :type figure: :class:`matplotlib.Figure`, optional ''' import matplotlib.pyplot as plt fig, ax = _getCanvas(axes) if phase not in ['vp', 'vs']: raise AttributeError('phase has to be either vp or vs') data = self._dataMatrix()[phase] ax.hist(data, weights=self.data_matrix['h'], range=vel_range, bins=bins, color='g', alpha=.5) ax.text(.95, .95, '%d Profiles' % self.nprofiles, transform=ax.transAxes, fontsize=10, va='top', ha='right', alpha=.7) ax.set_title('Distribution of %s' % vel_labels[phase]) ax.set_xlabel('%s [km/s]' % vel_labels[phase]) ax.set_ylabel('Cumulative occurrence [N]') xscaled(1./km, ax) ax.yaxis.grid(alpha=.4) if self.name is not None: ax.set_title('%s for %s' % (ax.get_title(), self.name)) if axes is None: plt.show()
def command_tttview(args): import numpy as num import matplotlib.pyplot as plt from pyrocko.plot.cake_plot import mpl_init, labelspace, xscaled, yscaled mpl_init() def setup(parser): parser.add_option('--source-depth', dest='depth', type=float, help='Source depth in km') parser, options, args = cl_parse( 'tttview', args, setup=setup, details="Comma seperated <phase-ids>, eg. 'fomosto tttview Pdiff,S'.") try: phase_ids = args.pop().split(',') except Exception: parser.error('cannot get <phase-ids> argument') np = 1 store_dir = get_store_dir(args) for phase_id in phase_ids: try: store = gf.Store(store_dir) phase = store.get_stored_phase(phase_id) axes = plt.subplot(2, len(phase_ids), np) labelspace(axes) xscaled(1. / km, axes) yscaled(1. / km, axes) phase.plot_2d(axes) axes.set_title(phase_id) np += 1 except gf.StoreError as e: die(e) axes = plt.subplot(2, 1, 2) num_d = 100 distances = num.linspace(store.config.distance_min, store.config.distance_max, num_d) if options.depth: depth = options.depth depth *= 1000 else: depth = store.config.source_depth_min + ( store.config.source_depth_max - store.config.source_depth_min) / 2. if isinstance(store.config, gf.ConfigTypeA): arrivals = num.empty(num_d) for phase_id in phase_ids: arrivals[:] = num.NAN for i, d in enumerate(distances): arrivals[i] = store.t(phase_id, (depth, d)) axes.plot(distances / 1000, arrivals, label=phase_id) axes.set_title('source depth %s km' % (depth / 1000)) axes.set_xlabel('distance [km]') axes.set_ylabel('TT [s]') axes.legend() plt.tight_layout() plt.show()
def command_modelview(args): import matplotlib.pyplot as plt import numpy as num from pyrocko.plot.cake_plot import mpl_init, labelspace, xscaled, yscaled mpl_init() neat_labels = { 'vp': '$v_p$', 'vs': '$v_s$', 'qp': '$Q_p$', 'qs': '$Q_s$', 'rho': '$\\rho$' } def setup(parser): parser.add_option( '--parameters', dest='parameters', default='vp,vs', metavar='vp,vs,....', help='select one or several of vp, vs, rho, qp, qs, vp/vs, qp/qs') units = {'vp': '[km/s]', 'vs': '[km/s]', 'rho': '[g/cm^3]'} parser, options, args = cl_parse('modelview', args, setup=setup) store_dirs = get_store_dirs(args) parameters = options.parameters.split(',') fig, axes = plt.subplots(1, len(parameters), sharey=True, figsize=(len(parameters) * 3, 5)) if not isinstance(axes, num.ndarray): axes = [axes] axes = dict(zip(parameters, axes)) for store_id in store_dirs: try: store = gf.Store(store_id) mod = store.config.earthmodel_1d z = mod.profile('z') for p in parameters: ax = axes[p] labelspace(ax) if '/' in p: p1, p2 = p.split('/') profile = mod.profile(p1) / mod.profile(p2) else: profile = mod.profile(p) ax.plot(profile, -z, label=store_id.split('/')[-1]) if p in ['vs', 'vp', 'rho']: xscaled(1. / 1000., ax) yscaled(1. / km, ax) except gf.StoreError as e: die(e) for p, ax in axes.items(): ax.grid() if p in neat_labels: lab = neat_labels[p] elif all(x in neat_labels for x in p.split('/')): lab = '/'.join(neat_labels[x] for x in p.split('/')) else: lab = p ax.set_title(lab, y=1.02) if p in units: lab += ' ' + units[p] ax.autoscale() ax.set_xlabel(lab) axes[parameters[0]].set_ylabel('Depth [km]') handles, labels = ax.get_legend_handles_labels() if len(store_dirs) > 1: ax.legend(handles, labels, bbox_to_anchor=(0.5, 0.12), bbox_transform=fig.transFigure, ncol=3, loc='upper center', fancybox=True) plt.subplots_adjust(bottom=0.22, wspace=0.05) plt.show()
def command_tttview(args): import numpy as num import matplotlib.pyplot as plt from pyrocko.plot.cake_plot import mpl_init, labelspace, xscaled, yscaled mpl_init() def setup(parser): parser.add_option( '--source-depth', dest='depth', type=float, help='Source depth in km') parser, options, args = cl_parse( 'tttview', args, setup=setup, details="Comma seperated <phase-ids>, eg. 'fomosto tttview Pdiff,S'.") try: phase_ids = args.pop().split(',') except Exception: parser.error('cannot get <phase-ids> argument') np = 1 store_dir = get_store_dir(args) for phase_id in phase_ids: try: store = gf.Store(store_dir) phase = store.get_stored_phase(phase_id) axes = plt.subplot(2, len(phase_ids), np) labelspace(axes) xscaled(1./km, axes) yscaled(1./km, axes) phase.plot_2d(axes) axes.set_title(phase_id) np += 1 except gf.StoreError as e: die(e) axes = plt.subplot(2, 1, 2) num_d = 100 distances = num.linspace(store.config.distance_min, store.config.distance_max, num_d) if options.depth: depth = options.depth depth *= 1000 else: depth = store.config.source_depth_min + ( store.config.source_depth_max - store.config.source_depth_min)/2. if isinstance(store.config, gf.ConfigTypeA): arrivals = num.empty(num_d) for phase_id in phase_ids: arrivals[:] = num.NAN for i, d in enumerate(distances): arrivals[i] = store.t(phase_id, (depth, d)) axes.plot(distances/1000, arrivals, label=phase_id) axes.set_title('source depth %s km' % (depth/1000)) axes.set_xlabel('distance [km]') axes.set_ylabel('TT [s]') axes.legend() plt.tight_layout() plt.show()
def command_modelview(args): import matplotlib.pyplot as plt import numpy as num from pyrocko.plot.cake_plot import mpl_init, labelspace, xscaled, yscaled mpl_init() neat_labels = { 'vp': '$v_p$', 'vs': '$v_s$', 'qp': '$Q_p$', 'qs': '$Q_s$', 'rho': '$\\rho$'} def setup(parser): parser.add_option( '--parameters', dest='parameters', default='vp,vs', metavar='vp,vs,....', help='select one or several of vp, vs, rho, qp, qs, vp/vs, qp/qs') units = {'vp': '[km/s]', 'vs': '[km/s]', 'rho': '[g/cm^3]'} parser, options, args = cl_parse('modelview', args, setup=setup) store_dirs = get_store_dirs(args) parameters = options.parameters.split(',') fig, axes = plt.subplots(1, len(parameters), sharey=True, figsize=(len(parameters)*3, 5)) if not isinstance(axes, num.ndarray): axes = [axes] axes = dict(zip(parameters, axes)) for store_id in store_dirs: try: store = gf.Store(store_id) mod = store.config.earthmodel_1d z = mod.profile('z') for p in parameters: ax = axes[p] labelspace(ax) if '/' in p: p1, p2 = p.split('/') profile = mod.profile(p1)/mod.profile(p2) else: profile = mod.profile(p) ax.plot(profile, -z, label=store_id.split('/')[-1]) if p in ['vs', 'vp', 'rho']: xscaled(1./1000., ax) yscaled(1./km, ax) except gf.StoreError as e: die(e) for p, ax in axes.items(): ax.grid() if p in neat_labels: lab = neat_labels[p] elif all(x in neat_labels for x in p.split('/')): lab = '/'.join(neat_labels[x] for x in p.split('/')) else: lab = p ax.set_title(lab, y=1.02) if p in units: lab += ' ' + units[p] ax.autoscale() ax.set_xlabel(lab) axes[parameters[0]].set_ylabel('Depth [km]') handles, labels = ax.get_legend_handles_labels() if len(store_dirs) > 1: ax.legend( handles, labels, bbox_to_anchor=(0.5, 0.12), bbox_transform=fig.transFigure, ncol=3, loc='upper center', fancybox=True) plt.subplots_adjust(bottom=0.22, wspace=0.05) plt.show()