コード例 #1
0
    def setup(self):
        self.set_name('Cake Phase')

        # self._phase_names = ('PmP ~S ~P ~P(moho)s ~P(sill-top)s'
        #                       ' ~P(sill-bottom)s Pdiff').split()
        self._phase_names = ('~P Pg Sg pP p P Pdiff PKP PcP PcS PKIKP pPKIKP'
                             ' SSP PPS SPP PSP SP PS ~PS ~SP Pn s S Sn PP PPP'
                             ' ScS Sdiff SS SSS PcP SKS SKIKS').split()

        for iphase, name in enumerate(self._phase_names):
            self.add_parameter(Switch(name, 'wantphase_%i' % iphase,
                                      iphase == 0))

        self._models = cake.builtin_models()
        self.model_choice = Choice('Model', 'chosen_model',
                                   'ak135-f-continental.m', self._models)

        self.add_parameter(self.model_choice)

        self.add_parameter(Param('Global shift', 'tshift', 0., -20., 20.))
        self.add_parameter(Switch('Use station depth',
                                  'use_station_depth', False))
        self.add_trigger('Add Phase', self.add_phase_definition)
        self.add_trigger('Add Model', self.add_model_to_choice)
        self.add_trigger('Plot Model', self.plot_model)
        self.add_trigger('Plot Rays', self.plot_rays)

        self._phases = {}
        self._model = None
コード例 #2
0
    def setup(self):
        self.set_name('Cake Phase')

        # self._phase_names = ('PmP ~S ~P ~P(moho)s ~P(sill-top)s'
        #                       ' ~P(sill-bottom)s Pdiff').split()
        self._phase_names = ('~P Pg Sg pP p P Pdiff PKP PcP PcS PKIKP pPKIKP'
                             ' SSP PPS SPP PSP SP PS ~PS ~SP Pn s S Sn PP PPP'
                             ' ScS Sdiff SS SSS PcP SKS SKIKS').split()

        for iphase, name in enumerate(self._phase_names):
            self.add_parameter(
                Switch(name, 'wantphase_%i' % iphase, iphase == 0))

        self._models = cake.builtin_models()
        self.model_choice = Choice('Model', 'chosen_model',
                                   'ak135-f-continental.m', self._models)

        self.add_parameter(self.model_choice)

        self.add_parameter(Param('Global shift', 'tshift', 0., -20., 20.))
        self.add_parameter(
            Switch('Use station depth', 'use_station_depth', False))
        self.add_trigger('Add Phase', self.add_phase_definition)
        self.add_trigger('Add Model', self.add_model_to_choice)
        self.add_trigger('Plot Model', self.plot_model)
        self.add_trigger('Plot Rays', self.plot_rays)

        self._phases = {}
        self._model = None
コード例 #3
0
    def setup(self):
        self.set_name('Cake Phase')

        #self._phase_names = 'PmP ~S ~P ~P(moho)s ~P(sill-top)s ~P(sill-bottom)s Pdiff'.split()
        self._phase_names = '~P Pg Sg pP p P Pdiff PKP PcP PcS PKIKP pPKIKP SSP PPS SPP PSP SP PS ~PS ~SP Pn s S Sn PP PPP ScS Sdiff SS SSS PcP SKS SKIKS'.split()

        for iphase, name in enumerate(self._phase_names):
            self.add_parameter(Switch(name, 'wantphase_%i' % iphase, iphase==0))
        

        self._models = cake.builtin_models()
        self._engine = gf.LocalEngine(use_config=True)
        store_ids = self._engine.get_store_ids()
        self._models.extend(store_ids)

        self.model_choice = Choice('Model', 'chosen_model', 
                'ak135-f-continental.m', self._models)

        self.add_parameter(self.model_choice)
        self.add_parameter(Param('Global shift', 'tshift', 0., -20., 20.))
        self.add_trigger('Add Phase', self.add_phase_definition)
        self.add_trigger('Add Model', self.add_model_to_choice)
        self.add_trigger('Plot Model', self.plot_model)
        self.add_trigger('Plot Rays', self.plot_rays)

        self._phases = {}
        self._model = None
コード例 #4
0
 def update_model(self):
     if not self._model or self._model[0] != self.chosen_model:
         if self.chosen_model in cake.builtin_models():
             load_model = cake.load_model(self.chosen_model)
         else:
             load_model = self._engine.get_store(self.chosen_model).config.earthmodel_1d 
         self._model = (self.chosen_model, load_model)
コード例 #5
0
 def update_model(self):
     if not self._model or self._model[0] != self.chosen_model:
         if self.chosen_model in cake.builtin_models()\
          or os.path.exists(self.chosen_model):
             load_model = cake.load_model(self.chosen_model)
         else:
             load_model = self._engine.get_store(self.chosen_model)\
                 .config.earthmodel_1d
         self._model = (self.chosen_model, load_model)
コード例 #6
0
    def setup(self):
        '''Customization of the snuffling.'''
        
        self.set_name('Cake')
        self._phases = ('p P pP pP\ pPv3pP\ pPv3pPv3pP\ P(moho)p S s'.split())
        for iphase, phase in enumerate(self._phases):
            self.add_parameter(Switch(phase, 'wantphase_%s' % iphase, iphase==0)) 

        self.choice = Choice('Model','earth_model',cake.builtin_models()[0],(cake.builtin_models()))
        self.add_parameter(self.choice)
        self.add_trigger('Plot Model', self.plot_model)
        self.add_trigger('Plot Rays', self.plot_rays)
        self.add_trigger('Add Model', self.add_model_to_choice)
        self.add_trigger('Add Phase', self.add_phase_definition)
        self.add_trigger('Print Arrivals', self.print_arrivals)
        self.set_live_update(False) 

        self.model = cake.load_model(self.earth_model)
        self.called = False
        self.stations = None
コード例 #7
0
    def setup(self, config):
        Shifter.setup(self, config)
        self._earthmodels = config.earthmodels
        self._earthmodels.extend([
            CakeEarthmodel(id=fn,
                           earthmodel_1d=cake.load_model(
                               cake.builtin_model_filename(fn)))
            for fn in cake.builtin_models()
        ])
        self._tabulated_phases = config.tabulated_phases

        if not self._tabulated_phases:
            raise LassieError('missing tabulated phases in config')

        self._cache_path = config.expand_path(config.cache_path)
コード例 #8
0
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)
コード例 #9
0
ファイル: cake.py プロジェクト: emolch/pyrocko
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)