Commit 9aa78392 authored by Marius Isken's avatar Marius Isken
Browse files

wip baraddur // performance DataModel update

parent b53a689e
...@@ -45,10 +45,10 @@ class Status(RequestHandler): ...@@ -45,10 +45,10 @@ class Status(RequestHandler):
class MisfitsPlot(BokehHandler): class MisfitsPlot(BokehHandler):
def modify_document(self, doc): def modify_document(self, doc):
self.nmodels = 0
self.source = ColumnDataSource( self.source = ColumnDataSource(
data={'n': [], data={'n': [],
'gm': [], 'gm': []})
'bm': []})
self.update_misfits() self.update_misfits()
plot = figure(webgl=True, plot = figure(webgl=True,
...@@ -62,13 +62,16 @@ class Status(RequestHandler): ...@@ -62,13 +62,16 @@ class Status(RequestHandler):
@gen.coroutine @gen.coroutine
def update_misfits(self): def update_misfits(self):
mx, misfits = grond.core.load_problem_data(rundir, problem) mx, misfits = grond.core.load_problem_data(
rundir, problem, skip_models=self.nmodels)
new_nmodels = mx.shape[0]
fits = num.mean(misfits, axis=1) fits = num.mean(misfits, axis=1)
fits1 = fits[:, 0] self.source.stream(dict(gm=fits[:, 0],
fits2 = fits[:, 1] n=num.arange(new_nmodels,
self.source.data = dict(gm=fits1, dtype=num.int) +
bm=fits2, self.nmodels + 1))
n=num.arange(fits1.size) + 1) self.nmodels += new_nmodels
bokeh_handlers = {'misfit_plot': MisfitsPlot} bokeh_handlers = {'misfit_plot': MisfitsPlot}
...@@ -87,9 +90,10 @@ class Parameters(RequestHandler): ...@@ -87,9 +90,10 @@ class Parameters(RequestHandler):
ncols = 4 ncols = 4
def modify_document(self, doc): def modify_document(self, doc):
self.source = ColumnDataSource( self.nmodels = 0
data=dict.fromkeys( self.source = ColumnDataSource()
['n', 'color'] + [p.name for p in problem.parameters], [])) for p in ['n'] + [p.name for p in problem.parameters]:
self.source.add([], p)
self.update_parameters() self.update_parameters()
plots = [] plots = []
...@@ -98,8 +102,7 @@ class Parameters(RequestHandler): ...@@ -98,8 +102,7 @@ class Parameters(RequestHandler):
x_axis_label='Iteration #', x_axis_label='Iteration #',
y_axis_label='%s [%s]' % (par.label, par.unit)) y_axis_label='%s [%s]' % (par.label, par.unit))
fig.scatter('n', par.name, fig.scatter('n', par.name,
source=self.source, alpha=.4, source=self.source, alpha=.4)
color='color')
plots.append(fig) plots.append(fig)
plots += ([None] * (self.ncols - (len(plots) % self.ncols))) plots += ([None] * (self.ncols - (len(plots) % self.ncols)))
...@@ -109,20 +112,22 @@ class Parameters(RequestHandler): ...@@ -109,20 +112,22 @@ class Parameters(RequestHandler):
ncols=self.ncols) ncols=self.ncols)
doc.add_root(grid) doc.add_root(grid)
doc.add_periodic_callback(self.update_parameters, 15*1e3) doc.add_periodic_callback(self.update_parameters, 2.5*1e3)
@gen.coroutine @gen.coroutine
def update_parameters(self): def update_parameters(self):
mx, misfits = grond.core.load_problem_data(rundir, problem) mx, misfits = grond.core.load_problem_data(
data = {} rundir, problem, skip_models=self.nmodels)
for ip, par in enumerate(problem.parameters): new_nmodels = mx.shape[0]
data[par.name] = mx[:, ip]
data['n'] = num.arange(mx.shape[0]) + 1
mf = num.mean(misfits, axis=1)[:, 0] new_data = {}
data['color'] = makeColorGradient(mf) for ip, par in enumerate(problem.parameters):
new_data[par.name] = mx[:, ip]
new_data['n'] = num.arange(new_nmodels, dtype=num.int) +\
self.nmodels + 1
self.source.data = data self.source.stream(new_data)
self.nmodels += new_nmodels
bokeh_handlers = {'parameter_plot': ParameterPlots} bokeh_handlers = {'parameter_plot': ParameterPlots}
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
<p><span style="font-family: monospace;">{{ problem.__class__.__name__ }}</span> | <span style="font-family: monospace;">{{ problem.base_source.__class__.__name__ }}</span></p> <p><span style="font-family: monospace;">{{ problem.__class__.__name__ }}</span> | <span style="font-family: monospace;">{{ problem.base_source.__class__.__name__ }}</span></p>
</header> </header>
<h2 class="content-subhead">Plot misfit</h3> <h2 class="content-subhead">Plot misfit</h3>
<p>Global misfit over iteration.</p> <p>Global misfit evolution.</p>
{% raw misfit_plot %} {% raw misfit_plot %}
{% end %} {% end %}
...@@ -141,21 +141,26 @@ def load_problem_info(dirname): ...@@ -141,21 +141,26 @@ def load_problem_info(dirname):
return guts.load(filename=fn) return guts.load(filename=fn)
def load_problem_data(dirname, problem): def load_problem_data(dirname, problem, skip_models=0):
fn = op.join(dirname, 'x') fn = op.join(dirname, 'x')
with open(fn, 'r') as f: with open(fn, 'r') as f:
nmodels = os.fstat(f.fileno()).st_size / (problem.nparameters * 8) nmodels = os.fstat(f.fileno()).st_size / (problem.nparameters * 8)
nmodels -= skip_models
f.seek(skip_models * problem.nparameters * 8)
data = num.fromfile( data = num.fromfile(
f, dtype='<f8', f, dtype='<f8',
count=nmodels*problem.nparameters).astype(num.float) count=nmodels * problem.nparameters)\
.astype(num.float)
nmodels = data.size/problem.nparameters nmodels = data.size/problem.nparameters - skip_models
xs = data.reshape((nmodels, problem.nparameters)) xs = data.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)
data = num.fromfile( data = num.fromfile(
f, dtype='<f8', count=nmodels*problem.ntargets*2).astype(num.float) f, dtype='<f8', count=nmodels*problem.ntargets*2)\
.astype(num.float)
data = data.reshape((nmodels, problem.ntargets*2)) data = data.reshape((nmodels, problem.ntargets*2))
......
Supports Markdown
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