Skip to content

Commit

Permalink
Merge pull request #40 from pyrocko/v1.2.0-dev
Browse files Browse the repository at this point in the history
Merge development branches
  • Loading branch information
miili authored Jun 4, 2019
2 parents 6d0b81e + e8acedd commit 43ced96
Show file tree
Hide file tree
Showing 31 changed files with 1,093 additions and 430 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to Grond will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Added
- Added Covariance weighting from `SatelliteTarget` and `GNSSTarget`.
- Added new Volume source (VLVD).
- Added SVG as `grond plot` export format.

### Changed
- Consistent utilisation of `ModelHistory` for plots and results.
- `MTLocationPlot` supports Gamma scaling (misfit^gamma).
- `SatelliteTarget` speeds up bootstrapping by multi-threading.
- `Envronment` can be initialised from `ProblemConfig`.
- Improved: `grondown` downloading seismic wave forms.


## [1.2.0] 2019-02-19

### Added
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from setuptools.command.install import install
from setuptools.command.build_py import build_py

version = '1.2.0'
version = '1.3.0'


class CustomInstallCommand(install):
Expand Down Expand Up @@ -111,6 +111,7 @@ def run(self):
'grond.problems.double_dc',
'grond.problems.rectangular',
'grond.problems.volume_point',
'grond.problems.vlvd',
'grond.optimisers',
'grond.optimisers.highscore',
'grond.analysers',
Expand Down
9 changes: 7 additions & 2 deletions src/apps/grond.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,11 @@ def setup(parser):
parser.add_option(
'--parallel', dest='nparallel', type=int, default=1,
help='set number of events to process in parallel, '
'If set to more than one, --status=quiet is implied.')
'if set to more than one, --status=quiet is implied.')
parser.add_option(
'--threads', dest='nthreads', type=int, default=0,
help='set number of threads per process. This defaults to 0,'
'which is using all available cores.')

parser, options, args = cl_parse('go', args, setup)

Expand All @@ -749,7 +753,8 @@ def setup(parser):
force=options.force,
preserve=options.preserve,
status=status,
nparallel=options.nparallel)
nparallel=options.nparallel,
nthreads=options.nthreads)
if len(env.get_selected_event_names()) == 1:
logger.info(CLIHints(
'go', rundir=env.get_rundir_path()))
Expand Down
40 changes: 24 additions & 16 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def forward(rundir_or_config_path, event_names):
def harvest(rundir, problem=None, nbest=10, force=False, weed=0):

env = Environment([rundir])
optimiser = env.get_optimiser()
nchains = env.get_optimiser().nchains

if problem is None:
Expand All @@ -152,7 +153,6 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):

logger.info('Harvesting problem "%s"...' % problem.name)

optimiser = load_optimiser_info(rundir)
dumpdir = op.join(rundir, 'harvest')
if op.exists(dumpdir):
if force:
Expand All @@ -164,7 +164,7 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):

ibests_list = []
ibests = []
gms = problem.combine_misfits(misfits)
gms = bootstrap_misfits[:, 0]
isort = num.argsort(gms)

ibests_list.append(isort[:nbest])
Expand Down Expand Up @@ -442,10 +442,10 @@ def check(

def go(environment,
force=False, preserve=False,
nparallel=1, status='state'):
nparallel=1, status='state', nthreads=0):

g_data = (environment, force, preserve,
status, nparallel)
status, nparallel, nthreads)
g_state[id(g_data)] = g_data

nevents = environment.nevents_selected
Expand All @@ -460,7 +460,7 @@ def go(environment,

def process_event(ievent, g_data_id):

environment, force, preserve, status, nparallel = \
environment, force, preserve, status, nparallel, nthreads = \
g_state[g_data_id]

config = environment.get_config()
Expand Down Expand Up @@ -513,6 +513,8 @@ def process_event(ievent, g_data_id):
config.change_basepath(basepath)

optimiser = config.optimiser_config.get_optimiser()
optimiser.set_nthreads(nthreads)

optimiser.init_bootstraps(problem)
problem.dump_problem_info(rundir)

Expand Down Expand Up @@ -582,16 +584,15 @@ class ResultStats(Object):
parameter_stats_list = List.T(ParameterStats.T())


def make_stats(problem, xs, misfits, pnames=None):
gms = problem.combine_misfits(misfits)
def make_stats(problem, models, gms, pnames=None):
ibest = num.argmin(gms)
rs = ResultStats(problem=problem)
if pnames is None:
pnames = problem.parameter_names

for pname in pnames:
iparam = problem.name_to_index(pname)
vs = problem.extract(xs, iparam)
vs = problem.extract(models, iparam)
mi, p5, p16, median, p84, p95, ma = map(float, num.percentile(
vs, [0., 5., 16., 50., 84., 95., 100.]))

Expand Down Expand Up @@ -676,9 +677,12 @@ def dump(x, gm, indices):

header = None
for rundir in rundirs:
problem, xs, misfits, bootstrap_misfits, _ = \
load_problem_info_and_data(
rundir, subset='harvest')
env = Environment(rundir)
history = env.get_history(subset='harvest')

problem = history.problem
models = history.models
misfits = history.get_primary_chain_misfits()

if type == 'vector':
pnames_take = pnames_clean or \
Expand All @@ -703,21 +707,25 @@ def dump(x, gm, indices):
indices = None

if what == 'best':
x_best, gm_best = stats.get_best_x_and_gm(problem, xs, misfits)
x_best = history.get_best_model()
gm_best = history.get_best_misfit()
dump(x_best, gm_best, indices)

elif what == 'mean':
x_mean, gm_mean = stats.get_mean_x_and_gm(problem, xs, misfits)
x_mean = history.get_mean_model()
gm_mean = history.get_mean_misfit(chain=0)
dump(x_mean, gm_mean, indices)

elif what == 'ensemble':
gms = problem.combine_misfits(misfits)
gms = misfits
isort = num.argsort(gms)
for i in isort:
dump(xs[i], gms[i], indices)
dump(models[i], gms[i], indices)

elif what == 'stats':
rs = make_stats(problem, xs, misfits, pnames_clean)
rs = make_stats(problem, models,
history.get_primary_chain_misfits(),
pnames_clean)
if shortform:
print(' ', format_stats(rs, pnames), file=out)
else:
Expand Down
Loading

0 comments on commit 43ced96

Please sign in to comment.