def get_store_velocity_profile(self): engine = self.server.engine fig = plt.figure() axes = fig.gca() store_ids = list(engine.get_store_ids()) store_ids.sort(key=lambda x: x.lower()) for match in re.finditer( r'/gfws/api/(' + store_id_pattern + ')/profile', self.path): store_id = match.groups()[0] try: store = engine.get_store(store_id) except Exception: self.send_error(404) self.end_headers() return cake_plot.my_model_plot(store.config.earthmodel_1d, axes=axes) f = BytesIO() fig.savefig(f, format='png') length = f.tell() self.send_response(200, 'OK') self.send_header("Content-Type", "image/png;") self.send_header("Content-Length", str(length)) self.send_header("Access-Control-Allow-Origin", '*') self.end_headers() f.seek(0) return f.read()
def plot(self, axes=None): ''' Plot the velocity profile, see :class:`pyrocko.cake`. :param axes: Axes to plot into. :type axes: :class:`matplotlib.Axes`''' import matplotlib.pyplot as plt fig, ax = _getCanvas(axes) my_model_plot(self.getLayeredModel(), axes=axes) ax.set_title('Global Crustal Database\n' 'Velocity Structure at {p.lat:.4f}N, ' ' {p.lat:.4f}E (uid {p.uid})'.format(p=self)) if axes is None: plt.show()
def main(args=None): if args is None: args = sys.argv[1:] subcommand_descriptions = { 'print': 'get information on model/phase/material properties', 'arrivals': 'print list of phase arrivals', 'paths': 'print ray path details', 'plot-xt': 'plot traveltime vs distance curves', 'plot-xp': 'plot ray parameter vs distance curves', 'plot-rays': 'plot ray propagation paths', 'plot': 'plot combination of ray and traveltime curves', 'plot-model': 'plot velocity model', 'list-models': 'list builtin velocity models', 'list-phase-map': 'show translation table for classic phase names', 'simplify-model': 'create a simplified version of a layered model', 'scatter': 'show details about scattering at model interfaces' } usage = '''cake <subcommand> [options] Subcommands: print %(print)s arrivals %(arrivals)s paths %(paths)s plot-xt %(plot_xt)s plot-xp %(plot_xp)s plot-rays %(plot_rays)s plot %(plot)s plot-model %(plot_model)s list-models %(list_models)s list-phase-map %(list_phase_map)s simplify-model %(simplify_model)s scatter %(scatter)s To get further help and a list of available options for any subcommand run: cake <subcommand> --help '''.strip() % d2u(subcommand_descriptions) usage_sub = 'cake %s [options]' if len(args) < 1: sys.exit('Usage: %s' % usage) command = args[0] descr = subcommand_descriptions.get(command, None) subusage = usage_sub % command if command == 'print': c = optparse((), ('model', 'phases', 'material', 'output_format'), usage=subusage, descr=descr) if 'model' in c: if c.output_format == 'textual': print(c.model) print() elif c.output_format == 'nd': cake.write_nd_model_fh(c.model, sys.stdout) if 'phases' in c: for phase in c.phases: print(phase) print() if 'material' in c: print(c.material.describe()) print() elif command == 'arrivals': c = optparse(('model', 'phases', 'distances'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr) print_arrivals( c.model, **c.getn('zstart', 'zstop', 'phases', 'distances', 'as_degrees')) elif command == 'paths': c = optparse(('model', 'phases'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr) mod = c.model for path in mod.gather_paths(**c.getn('phases', 'zstart', 'zstop')): print(path.describe(path.endgaps(c.zstart, c.zstop), c.as_degrees)) elif command in ('plot-xt', 'plot-xp', 'plot-rays', 'plot'): if command in ('plot-xt', 'plot'): c = optparse(('model', 'phases'), ('zstart', 'zstop', 'distances', 'as_degrees', 'vred', 'phase_colors'), usage=subusage, descr=descr) else: c = optparse(('model', 'phases'), ('zstart', 'zstop', 'distances', 'as_degrees', 'aspect', 'shade_model', 'phase_colors'), usage=subusage, descr=descr) mod = c.model paths = mod.gather_paths(**c.getn('phases', 'zstart', 'zstop')) if c.distances is not None: arrivals = mod.arrivals( **c.getn('phases', 'zstart', 'zstop', 'distances')) else: arrivals = None if command == 'plot-xp': plot.my_xp_plot(paths, c.zstart, c.zstop, c.distances, c.as_degrees, phase_colors=c.phase_colors) elif command == 'plot-xt': plot.my_xt_plot(paths, c.zstart, c.zstop, c.distances, c.as_degrees, vred=c.vred, phase_colors=c.phase_colors) elif command == 'plot-rays': if c.as_degrees: plot.my_rays_plot_gcs(mod, paths, arrivals, c.zstart, c.zstop, c.distances, phase_colors=c.phase_colors) else: plot.my_rays_plot(mod, paths, arrivals, c.zstart, c.zstop, c.distances, aspect=c.aspect, shade_model=c.shade_model, phase_colors=c.phase_colors) elif command == 'plot': plot.my_combi_plot(mod, paths, arrivals, c.zstart, c.zstop, c.distances, c.as_degrees, vred=c.vred, phase_colors=c.phase_colors) elif command in ('plot-model', ): c = optparse(('model', ), (), usage=subusage, descr=descr) mod = c.model plot.my_model_plot(mod) elif command in ('simplify-model', ): c = optparse(('model', ), ('accuracy', ), usage=subusage, descr=descr) my_simplify_model(c.model, c.accuracy) elif command in ('list-models', ): c = optparse((), (), usage=subusage, descr=descr) for x in cake.builtin_models(): print(x) elif command in ('list-phase-map', ): c = optparse((), (), usage=subusage, descr=descr) defs = cake.PhaseDef.classic_definitions() for k in sorted(defs.keys()): print('%-15s: %s' % (k, ', '.join(defs[k]))) elif command in ('scatter', ): c = optparse(('model', ), ('slowness', 'interface', 'as_degrees'), usage=subusage, descr=descr) print_scatter(c.model, p=c.slowness, interface=c.interface) elif command in ('help-options', ): optparse((), ('model', 'accuracy', 'slowness', 'interface', 'phases', 'distances', 'zstart', 'zstop', 'distances', 'as_degrees', 'material', 'vred'), usage='cake help-options', descr='list all available options') elif command in ('--help', '-h', 'help'): sys.exit('Usage: %s' % usage) else: sys.exit('cake: no such subcommand: %s' % command)
def main(args=None): if args is None: args = sys.argv[1:] subcommand_descriptions = { 'print': 'get information on model/phase/material properties', 'arrivals': 'print list of phase arrivals', 'paths': 'print ray path details', 'plot-xt': 'plot traveltime vs distance curves', 'plot-xp': 'plot ray parameter vs distance curves', 'plot-rays': 'plot ray propagation paths', 'plot': 'plot combination of ray and traveltime curves', 'plot-model': 'plot velocity model', 'list-models': 'list builtin velocity models', 'list-phase-map': 'show translation table for classic phase names', 'simplify-model': 'create a simplified version of a layered model', 'scatter': 'show details about scattering at model interfaces'} usage = '''cake <subcommand> [options] Subcommands: print %(print)s arrivals %(arrivals)s paths %(paths)s plot-xt %(plot_xt)s plot-xp %(plot_xp)s plot-rays %(plot_rays)s plot %(plot)s plot-model %(plot_model)s list-models %(list_models)s list-phase-map %(list_phase_map)s simplify-model %(simplify_model)s scatter %(scatter)s To get further help and a list of available options for any subcommand run: cake <subcommand> --help '''.strip() % d2u(subcommand_descriptions) usage_sub = 'cake %s [options]' if len(args) < 1: sys.exit('Usage: %s' % usage) command = args[0] descr = subcommand_descriptions.get(command, None) subusage = usage_sub % command if command == 'print': c = optparse( (), ('model', 'phases', 'material', 'output_format'), usage=subusage, descr=descr) if 'model' in c: if c.output_format == 'textual': print(c.model) print() elif c.output_format == 'nd': cake.write_nd_model_fh(c.model, sys.stdout) if 'phases' in c: for phase in c.phases: print(phase) print() if 'material' in c: print(c.material.describe()) print() elif command == 'arrivals': c = optparse( ('model', 'phases', 'distances'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr) print_arrivals( c.model, **c.getn('zstart', 'zstop', 'phases', 'distances', 'as_degrees')) elif command == 'paths': c = optparse( ('model', 'phases'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr) mod = c.model for path in mod.gather_paths(**c.getn('phases', 'zstart', 'zstop')): print(path.describe(path.endgaps(c.zstart, c.zstop), c.as_degrees)) elif command in ('plot-xt', 'plot-xp', 'plot-rays', 'plot'): if command in ('plot-xt', 'plot'): c = optparse( ('model', 'phases'), ('zstart', 'zstop', 'distances', 'as_degrees', 'vred', 'phase_colors'), usage=subusage, descr=descr) else: c = optparse( ('model', 'phases'), ('zstart', 'zstop', 'distances', 'as_degrees', 'aspect', 'shade_model', 'phase_colors'), usage=subusage, descr=descr) mod = c.model paths = mod.gather_paths(**c.getn('phases', 'zstart', 'zstop')) if c.distances is not None: arrivals = mod.arrivals( **c.getn('phases', 'zstart', 'zstop', 'distances')) else: arrivals = None if command == 'plot-xp': plot.my_xp_plot( paths, c.zstart, c.zstop, c.distances, c.as_degrees, phase_colors=c.phase_colors) elif command == 'plot-xt': plot.my_xt_plot( paths, c.zstart, c.zstop, c.distances, c.as_degrees, vred=c.vred, phase_colors=c.phase_colors) elif command == 'plot-rays': if c.as_degrees: plot.my_rays_plot_gcs( mod, paths, arrivals, c.zstart, c.zstop, c.distances, phase_colors=c.phase_colors) else: plot.my_rays_plot( mod, paths, arrivals, c.zstart, c.zstop, c.distances, aspect=c.aspect, shade_model=c.shade_model, phase_colors=c.phase_colors) elif command == 'plot': plot.my_combi_plot( mod, paths, arrivals, c.zstart, c.zstop, c.distances, c.as_degrees, vred=c.vred, phase_colors=c.phase_colors) elif command in ('plot-model',): c = optparse(('model',), (), usage=subusage, descr=descr) mod = c.model plot.my_model_plot(mod) elif command in ('simplify-model',): c = optparse(('model',), ('accuracy',), usage=subusage, descr=descr) my_simplify_model(c.model, c.accuracy) elif command in ('list-models',): c = optparse((), (), usage=subusage, descr=descr) for x in cake.builtin_models(): print(x) elif command in ('list-phase-map',): c = optparse((), (), usage=subusage, descr=descr) defs = cake.PhaseDef.classic_definitions() for k in sorted(defs.keys()): print('%-15s: %s' % (k, ', '.join(defs[k]))) elif command in ('scatter',): c = optparse( ('model',), ('slowness', 'interface', 'as_degrees'), usage=subusage, descr=descr) print_scatter(c.model, p=c.slowness, interface=c.interface) elif command in ('help-options',): optparse( (), ('model', 'accuracy', 'slowness', 'interface', 'phases', 'distances', 'zstart', 'zstop', 'distances', 'as_degrees', 'material', 'vred'), usage='cake help-options', descr='list all available options') elif command in ('--help', '-h', 'help'): sys.exit('Usage: %s' % usage) else: sys.exit('cake: no such subcommand: %s' % command)
def save_varied_models(mods, folder, plot=False, name="model"): for i, mod in enumerate(mods): if plot is True: plot.my_model_plot(mod) cake.write_nd_model(mod, folder+"/%s_%s" % (name, i))