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_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_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()