Esempio n. 1
0
def run_in_project(
        main,
        project_dir_source,
        project_dir,
        event_name,
        config_path):

    playground_dir = get_playground_dir()
    with chdir(playground_dir):

        if os.path.exists(project_dir):
            shutil.rmtree(project_dir)

        put_test_data(project_dir_source + '/', project_dir)

        with chdir(project_dir):

            link_test_data(
                'events/%s/' % event_name, 'data/events/%s/' % event_name)

            env = Environment([config_path, event_name])
            conf = env.get_config()

            store_ids = conf.get_elements('target_groups[:].store_id')
            for store_id in store_ids:
                store_path = 'gf_stores/%s/' % store_id
                if not os.path.exists(store_path):
                    link_test_data(store_path)

            problem_name = env.get_problem().name
            rundir_path = expand_template(
                conf.rundir_template,
                dict(problem_name=problem_name))

            return main(env, rundir_path)
Esempio n. 2
0
def test_scenario():
    playground_dir = common.get_playground_dir()
    common.get_test_data('gf_stores/crust2_ib/')
    common.get_test_data('gf_stores/crust2_ib_static/')
    gf_stores_path = common.test_data_path('gf_stores')

    with chdir(playground_dir):
        scenario_dir = 'scenario'
        if os.path.exists(scenario_dir):
            shutil.rmtree(scenario_dir)

        grond('scenario', '--targets=waveforms,insar,gnss', '--nevents=2',
              '--nstations=3', '--gf-store-superdirs=%s' % gf_stores_path,
              scenario_dir)

        with chdir(scenario_dir):
            config_path = 'config/scenario.gronf'
            quick_config_path = 'config/scenario_quick.gronf'
            event_names = grond('events', config_path).strip().split('\n')

            env = Environment([config_path] + event_names)
            conf = env.get_config()

            mod_conf = conf.clone()
            mod_conf.set_elements(
                'analyser_configs[:].niterations', 100)
            mod_conf.set_elements(
                'optimiser_config.sampler_phases[:].niterations', 100)
            mod_conf.set_elements(
                'optimiser_config.nbootstrap', 5)
            mod_conf.set_basepath(conf.get_basepath())
            config.write_config(mod_conf, quick_config_path)
            grond('diff', config_path, quick_config_path)
            grond('check', quick_config_path, *event_names)

            grond('go', quick_config_path, *event_names)
            rundir_paths = common.get_rundir_paths(config_path, event_names)
            grond('report', *rundir_paths)

            grond(
                'go', quick_config_path,
                '--parallel=2',
                '--force',
                *event_names)
            rundir_paths = common.get_rundir_paths(config_path, event_names)
            grond('report', '--parallel=2', *rundir_paths)
Esempio n. 3
0
def run_example(project_name, config_path, quick_config_path, event_name):
    project_dir = project_name
    if os.path.exists(project_dir):
        shutil.rmtree(project_dir)

    grond('init', project_name, project_dir)
    with chdir(project_dir):
        assert os.path.isdir('config')

        common.link_test_data('events/%s/' % event_name,
                              'data/events/%s/' % event_name)

        env = Environment([config_path, event_name])
        conf = env.get_config()

        store_ids = conf.get_elements('target_groups[:].store_id')
        for store_id in store_ids:
            store_path = 'gf_stores/%s/' % store_id
            if not os.path.exists(store_path):
                common.link_test_data(store_path)

        problem_name = env.get_problem().name
        rundir_path = expand_template(conf.rundir_template,
                                      dict(problem_name=problem_name))

        grond('check', config_path, event_name,
              '--save-stations-used=used_stations.txt')

        sorted(s.station for s in model.load_stations('used_stations.txt'))

        mod_conf = conf.clone()
        mod_conf.set_elements('analyser_configs[:].niterations', 100)
        mod_conf.set_elements('optimiser_config.sampler_phases[:].niterations',
                              100)
        mod_conf.set_elements('optimiser_config.nbootstrap', 10)
        mod_conf.set_basepath(conf.get_basepath())
        config.write_config(mod_conf, quick_config_path)
        grond('go', quick_config_path, event_name)
        grond('harvest', '--force', '--export-fits=best,mean', rundir_path)
        grond('report', rundir_path)
Esempio n. 4
0
def get_rundir_paths(config_path, event_names):
    env = Environment([config_path] + event_names)
    conf = env.get_config()

    rundir_paths = []
    for event_name in event_names:
        env.set_current_event_name(event_name)
        problem_name = env.get_problem().name
        rundir_paths.append(expand_template(
            conf.rundir_template,
            dict(problem_name=problem_name)))

    return rundir_paths
Esempio n. 5
0
def test_joint_locate():
    playground_dir = common.get_playground_dir()
    common.get_test_data('gf_stores/crust2_ib/')
    gf_stores_path = common.test_data_path('gf_stores')

    with chdir(playground_dir):
        scenario_dir = 'scenario_joint_locate'
        if os.path.exists(scenario_dir):
            shutil.rmtree(scenario_dir)

        grond('scenario', '--targets=waveforms', '--nevents=1',
              '--nstations=6', '--gf-store-superdirs=%s' % gf_stores_path,
              '--no-map', scenario_dir)

        with chdir(scenario_dir):
            config_path = 'config/scenario.gronf'
            quick_config_path_templ = 'config/scenario_quick_%i.gronf'
            event_names = grond('events', config_path).strip().split('\n')

            env = Environment([config_path] + event_names)
            conf = env.get_config()

            for irun, pick_weight in enumerate([0.5, 1.0, 2.0]):
                quick_config_path = quick_config_path_templ % irun

                mod_conf = conf.clone()
                target_groups = guts.load_all(string='''
--- !grond.PhasePickTargetGroup
normalisation_family: picks
path: pick.p
weight: 1.0
store_id: crust2_ib
distance_min: 10000.0
distance_max: 1000000.0
pick_synthetic_traveltime: '{stored:any_P}'
pick_phasename: 'any_P'
--- !grond.PhasePickTargetGroup
normalisation_family: picks
path: pick.s
weight: 1.0
store_id: crust2_ib
distance_min: 10000.0
distance_max: 1000000.0
pick_synthetic_traveltime: '{stored:any_S}'
pick_phasename: 'any_S'
''')

                mod_conf.problem_config.name_template \
                    = 'cmt_${event_name}_%i' % irun

                mod_conf.dataset_config.picks_paths = [
                    'data/scenario/picks/picks.markers'
                ]

                mod_conf.target_groups.extend(target_groups)

                mod_conf.set_elements('target_groups[-2:].weight', pick_weight)

                # mod_conf.set_elements(
                #     'analyser_configs[:].niterations', 100)
                # mod_conf.set_elements(
                #     'optimiser_config.sampler_phases[:].niterations', 100)
                # mod_conf.set_elements(
                #     'optimiser_config.nbootstrap', 5)

                mod_conf.optimiser_config.sampler_phases[-1].niterations \
                    = 10000

                mod_conf.set_elements(
                    'optimiser_config.sampler_phases[:].seed', 23)

                mod_conf.set_basepath(conf.get_basepath())
                config.write_config(mod_conf, quick_config_path)

                grond('diff', config_path, quick_config_path)
                grond('check', quick_config_path, *event_names)

                grond('go', quick_config_path, *event_names)
                rundir_paths = common.get_rundir_paths(quick_config_path,
                                                       event_names)
                grond('report', *rundir_paths)
Esempio n. 6
0
def locate(marker_file,
           gf_stores_path,
           scenario_dir,
           config_path,
           stations_path,
           event_name,
           make_report=False):
    playground_dir = common.get_playground_dir()

    with chdir(playground_dir):

        with chdir(scenario_dir):
            quick_config_path = scenario_dir + 'scenario_quick.gronf'
            event_names = grond('events', config_path).strip().split('\n')
            env = Environment([config_path] + event_names)
            conf = env.get_config()
            event_names = [event_name]

            mod_conf = conf.clone()
            #             target_groups = guts.load_all(string='''
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'pick.p'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_P}'
            # pick_phasename: 'any_P'
            # store_id: 'landau_100hz_noweak'
            # depth_max: 1
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'pick.s'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_S}'
            # pick_phasename: 'any_S'
            # store_id: 'landau_100hz_noweak'
            # depth_max: 1
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'moer.p'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_P}'
            # pick_phasename: 'any_P'
            # store_id: 'moer_1hz_no_weak'
            # depth_min: 69
            # depth_max: 71
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'moer.s'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_S}'
            # pick_phasename: 'any_S'
            # store_id: 'moer_1hz_no_weak'
            # depth_min: 69
            # depth_max: 71
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'lde.p'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_P}'
            # pick_phasename: 'any_P'
            # store_id: 'lde_100hz_no_weak'
            # depth_min: 149
            # depth_max: 151
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'lde.s'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_S}'
            # pick_phasename: 'any_S'
            # store_id: 'lde_100hz_no_weak'
            # depth_min: 149
            # depth_max: 151
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'rott.p'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_P}'
            # pick_phasename: 'any_P'
            # store_id: 'rott_100hz_no_weak'
            # depth_min: 304
            # depth_max: 306
            # --- !grond.PhasePickTargetGroup
            # normalisation_family: 'pick'
            # path: 'rott.s'
            # distance_min: 0e3
            # distance_max: 102000.0
            # pick_synthetic_traveltime: '{stored:any_S}'
            # pick_phasename: 'any_S'
            # store_id: 'rott_100hz_no_weak'
            # depth_min: 304
            # depth_max: 306
            # ''')

            mod_conf.dataset_config.picks_paths = [marker_file]
            #mod_conf.target_groups = target_groups
            mod_conf.path_prefix = scenario_dir
            mod_conf.dataset_config.stations_path = stations_path
            mod_conf.event_names = [event_name]
            # mod_conf.set_elements(
            #     'analyser_configs[:].niterations', 100)
            # mod_conf.set_elements(
            #     'optimiser_config.sampler_phases[:].niterations', 100)
            # mod_conf.set_elements(
            #     'optimiser_config.nbootstrap', 5)

            mod_conf.optimiser_config.sampler_phases[-1].niterations = 25000

            mod_conf.set_basepath(conf.get_basepath())
            config.write_config(mod_conf, quick_config_path)

            grond('go', quick_config_path, *event_names)
            rundir_paths = common.get_rundir_paths(quick_config_path,
                                                   event_names)
            best = grond('export', 'best', *rundir_paths, '--output=best.pf')
            best = grond('export', 'mean', *rundir_paths, '--output=mean.pf')
            best = model.load_events(scenario_dir + "/best.pf")[0]
            if make_report is True:
                grond('report', *rundir_paths)

            return best