Commit e4ce7284 authored by Sebastian Heimann's avatar Sebastian Heimann

wip refactor

parent 7609fc91
...@@ -69,12 +69,12 @@ class Analyser(object): ...@@ -69,12 +69,12 @@ class Analyser(object):
mean_ms = num.mean(mss, axis=0) mean_ms = num.mean(mss, axis=0)
weights = 1. / mean_ms weights = 1. / mean_ms
groups, ngroups = wproblem.get_group_mask() families, nfamilies = wproblem.get_family_mask()
for igroup in range(ngroups): for ifamily in range(nfamilies):
weights[groups == igroup] /= ( weights[families == ifamily] /= (
num.nansum(weights[groups == igroup]) / num.nansum(weights[families == ifamily]) /
num.nansum(num.isfinite(weights[groups == igroup]))) num.nansum(num.isfinite(weights[families == ifamily])))
for weight, target in zip(weights, problem.waveform_targets): for weight, target in zip(weights, problem.waveform_targets):
target.analysis_result = TargetAnalysisResult( target.analysis_result = TargetAnalysisResult(
......
...@@ -351,8 +351,8 @@ def check( ...@@ -351,8 +351,8 @@ def check(
try: try:
problem = config.get_problem(event) problem = config.get_problem(event)
_, ngroups = problem.get_group_mask() _, nfamilies = problem.get_family_mask()
logger.info('number of target supergroups: %i' % ngroups) logger.info('number of target families: %i' % nfamilies)
logger.info('number of targets (total): %i' % len(problem.targets)) logger.info('number of targets (total): %i' % len(problem.targets))
if target_string_ids: if target_string_ids:
......
import time import time
import logging import logging
import os.path as op
import numpy as num import numpy as num
from datetime import timedelta from datetime import timedelta
from pyrocko import util from pyrocko import util, guts
from grond.problems import ModelHistory from grond.problems import ModelHistory
from .base import Listener from .base import Listener
...@@ -56,8 +57,12 @@ class TerminalListener(Listener): ...@@ -56,8 +57,12 @@ class TerminalListener(Listener):
logger.info('Waiting to follow %s' % self.rundir) logger.info('Waiting to follow %s' % self.rundir)
self.history = ModelHistory.follow(self.rundir) self.history = ModelHistory.follow(self.rundir)
optimizer_fn = op.join(self.rundir, 'optimizer.yaml')
self.optimizer = guts.load(filename=optimizer_fn)
self.problem = self.history.problem self.problem = self.history.problem
self.niter = self.history.optimizer.niterations self.niter = self.optimizer.niterations
self.starttime = time.time() self.starttime = time.time()
self.last_update = self.starttime self.last_update = self.starttime
......
...@@ -5,7 +5,6 @@ import numpy as num ...@@ -5,7 +5,6 @@ import numpy as num
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from pyrocko.plot import mpl_init, mpl_margins from pyrocko.plot import mpl_init, mpl_margins
from grond import plot
logger = logging.getLogger('grond.optimizer.highscore.plot') logger = logging.getLogger('grond.optimizer.highscore.plot')
...@@ -83,6 +82,7 @@ class HighScoreOptimizerPlot(object): ...@@ -83,6 +82,7 @@ class HighScoreOptimizerPlot(object):
bounds = self.problem.get_combined_bounds() bounds = self.problem.get_combined_bounds()
from grond import plot
self.xlim = plot.fixlim(*xpar.scaled(bounds[ixpar])) self.xlim = plot.fixlim(*xpar.scaled(bounds[ixpar]))
self.ylim = plot.fixlim(*ypar.scaled(bounds[iypar])) self.ylim = plot.fixlim(*ypar.scaled(bounds[iypar]))
......
...@@ -526,7 +526,7 @@ class ModelHistory(object): ...@@ -526,7 +526,7 @@ class ModelHistory(object):
if self.nmodels == nmodels_available: if self.nmodels == nmodels_available:
return return
new_models, new_misfits = load_problem_data( new_models, new_misfits = load_problem_data(
self.path, self.problem, skip_models=self.nmodels) self.path, self.problem, nmodels_skip=self.nmodels)
self.extend(new_models, new_misfits) self.extend(new_models, new_misfits)
...@@ -543,7 +543,13 @@ class ModelHistory(object): ...@@ -543,7 +543,13 @@ class ModelHistory(object):
def get_nmodels(dirname, problem): def get_nmodels(dirname, problem):
fn = op.join(dirname, 'models') fn = op.join(dirname, 'models')
with open(fn, 'r') as f: with open(fn, 'r') as f:
return os.fstat(f.fileno()).st_size // (problem.nparameters * 8) nmodels1 = os.fstat(f.fileno()).st_size // (problem.nparameters * 8)
fn = op.join(dirname, 'misfits')
with open(fn, 'r') as f:
nmodels2 = os.fstat(f.fileno()).st_size // (problem.ntargets * 2 * 8)
return min(nmodels1, nmodels2)
def load_problem_info_and_data(dirname, subset=None): def load_problem_info_and_data(dirname, subset=None):
...@@ -562,27 +568,23 @@ def load_problem_info(dirname): ...@@ -562,27 +568,23 @@ def load_problem_info(dirname):
return guts.load(filename=fn) return guts.load(filename=fn)
def load_problem_data(dirname, problem, skip_models=None): def load_problem_data(dirname, problem, nmodels_skip=0):
if skip_models is None:
skip_models = 0 nmodels = get_nmodels(dirname, problem) - nmodels_skip
nmodels = get_nmodels(dirname, problem)
fn = op.join(dirname, 'models') fn = op.join(dirname, 'models')
with open(fn, 'r') as f: with open(fn, 'r') as f:
nmodels = os.fstat(f.fileno()).st_size // (problem.nparameters * 8) f.seek(nmodels_skip * problem.nparameters * 8)
nmodels -= skip_models
f.seek(skip_models * problem.nparameters * 8)
models = num.fromfile( models = num.fromfile(
f, dtype='<f8', f, dtype='<f8',
count=nmodels * problem.nparameters)\ count=nmodels * problem.nparameters)\
.astype(num.float) .astype(num.float)
nmodels = models.size // problem.nparameters
models = models.reshape((nmodels, problem.nparameters)) models = models.reshape((nmodels, problem.nparameters))
fn = op.join(dirname, 'misfits') fn = op.join(dirname, 'misfits')
with open(fn, 'r') as f: with open(fn, 'r') as f:
f.seek(skip_models * problem.ntargets * 2 * 8) f.seek(nmodels_skip * problem.ntargets * 2 * 8)
misfits = num.fromfile( misfits = num.fromfile(
f, dtype='<f8', f, dtype='<f8',
count=nmodels*problem.ntargets*2)\ count=nmodels*problem.ntargets*2)\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment