Commit e4ce7284 authored by Sebastian Heimann's avatar Sebastian Heimann

wip refactor

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