Commit b53a689e authored by Marius Isken's avatar Marius Isken
Browse files

wip barad-dur

parent 97a67800
......@@ -79,7 +79,7 @@ The content `<div>` is where all your content goes.
.content {
margin: 0 auto;
padding: 0 2em;
max-width: 800px;
max-width: 1200px;
margin-bottom: 50px;
line-height: 1.6em;
}
......@@ -252,4 +252,4 @@ Hides the menu at `48em`, but modify this based on your app's needs.
position: relative;
left: 150px;
}
}
\ No newline at end of file
}
import tornado.ioloop
import grond
import os.path as op
import numpy as np
import logging
import numpy as num # noqa
from collections import OrderedDict
from tornado.web import RequestHandler, Application
from tornado.web import RequestHandler, StaticFileHandler
from tornado import gen
from bokeh.application import Application as BokehApplication
from bokeh.embed import autoload_server
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.server.server import Server as BokehServer
from bokeh.application.handlers import Handler as BokehHandler
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.application.handlers import FunctionHandler
from bokeh.models import ColumnDataSource
from bokeh import layouts
from bokeh.plotting import figure
problem = grond.core.load_problem_info('.')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
rootLogger = logging.getLogger('')
rootLogger.addHandler(console)
rootLogger.setLevel(logging.DEBUG)
class Summary(RequestHandler):
from bokeh.models import map_plots
rundir = '/home/marius/Development/testing/grond/rundir'
problem = grond.core.load_problem_info(rundir)
def makeColorGradient(misfits, fr=1., fg=.5, fb=1.,
pr=0, pg=2.5, pb=4):
misfits /= misfits.max()
r = num.sin(fr * misfits + pr) * 127 + 128
g = num.sin(fg * misfits + pg) * 127 + 128
b = num.sin(fb * misfits + pb) * 127 + 128
return ['#%02x%02x%02x' % (r[i], g[i], b[i]) for i in xrange(misfits.size)]
class Status(RequestHandler):
class MisfitsPlot(BokehHandler):
def modify_document(self, doc):
self.source = ColumnDataSource(
data={'n': [],
'gm': [],
'bm': []})
self.update_misfits()
plot = figure(webgl=True,
x_axis_label='Iteration #',
y_axis_label='Misfit')
plot.scatter('n', 'gm',
source=self.source, alpha=.4)
doc.add_root(plot)
doc.add_periodic_callback(self.update_misfits, 1e3)
@gen.coroutine
def update_misfits(self):
mx, misfits = grond.core.load_problem_data(rundir, problem)
fits = num.mean(misfits, axis=1)
fits1 = fits[:, 0]
fits2 = fits[:, 1]
self.source.data = dict(gm=fits1,
bm=fits2,
n=num.arange(fits1.size) + 1)
bokeh_handlers = {'misfit_plot': MisfitsPlot}
@gen.coroutine
def get(self):
self.render('status.html',
pages=pages,
misfit_plot=autoload_server(None, url='/misfit_plot'),
problem=problem)
class Parameters(RequestHandler):
class ParameterPlots(BokehHandler):
ncols = 4
def modify_document(self, doc):
self.source = ColumnDataSource(
data=dict.fromkeys(
['n', 'color'] + [p.name for p in problem.parameters], []))
self.update_parameters()
plots = []
for par in problem.parameters:
fig = figure(webgl=True,
x_axis_label='Iteration #',
y_axis_label='%s [%s]' % (par.label, par.unit))
fig.scatter('n', par.name,
source=self.source, alpha=.4,
color='color')
plots.append(fig)
plots += ([None] * (self.ncols - (len(plots) % self.ncols)))
grid = layouts.gridplot(
plots,
responsive=True,
ncols=self.ncols)
doc.add_root(grid)
doc.add_periodic_callback(self.update_parameters, 15*1e3)
@gen.coroutine
def update_parameters(self):
mx, misfits = grond.core.load_problem_data(rundir, problem)
data = {}
for ip, par in enumerate(problem.parameters):
data[par.name] = mx[:, ip]
data['n'] = num.arange(mx.shape[0]) + 1
mf = num.mean(misfits, axis=1)[:, 0]
data['color'] = makeColorGradient(mf)
self.source.data = data
bokeh_handlers = {'parameter_plot': ParameterPlots}
@gen.coroutine
def get(self):
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy",
alpha=0.5)
script = autoload_server(p, url='http://localhost:5001')
self.render('parameter_plots.html',
pages=pages,
parameter_plot=autoload_server(
None,
url='/parameter_plot'),
problem=problem)
class Summary(RequestHandler):
@gen.coroutine
def get(self):
self.render('summary.html',
pages=pages,
problem=problem,
script=script)
problem=problem)
class MainHandler(RequestHandler):
@gen.coroutine
def get(self):
self.render('index.html',
......@@ -44,26 +155,45 @@ class MainHandler(RequestHandler):
pages = OrderedDict([
('Status', Status),
('Parameters', Parameters),
('Summary', Summary),
('Sequences', MainHandler),
('Tradeoffs', MainHandler),
])
bokeh_apps = {}
for cat, tornado_handler in pages.iteritems():
handler_docs = getattr(tornado_handler, 'bokeh_handlers', None)
if handler_docs is None:
continue
for url, bokeh_handler in handler_docs.iteritems():
bokeh_apps['/%s' % url] =\
Application(bokeh_handler())
if __name__ == '__main__':
bokeh_app = BokehApplication()
bokeh_server = Server({'/bokeh': bokeh_app},
ioloop=tornado.ioloop.IOLoop.instance(),
num_procs=1)
tornado_app = Application(
[(r'/', Summary)] +
[(r'/%s' % title, handler) for title, handler in pages.iteritems()],
debug=False,
autoreload=False,
compiled_template_cache=False,
static_path=op.join(op.dirname(__file__), 'static'),
template_path=op.join(op.dirname(__file__), 'tpl'),
)
tornado_app.listen(8888)
handlers = [(r'/', pages.values()[0])] +\
[(r'/%s' % title, handler)
for title, handler in pages.iteritems()] +\
[(r'/css/(.*)', StaticFileHandler,
{'path': op.join(op.dirname(__file__), 'css')})]
server = BokehServer(
bokeh_apps,
io_loop=tornado.ioloop.IOLoop.current(),
extra_patterns=handlers,
hosts='0.0.0.0')
tornado_app = server._tornado
tornado_app.settings['template_path'] = 'tpl'
tornado_app.settings.setdefault('autoreload', True)
tornado_app.settings.setdefault('compiled_template_cache', False)
tornado_app.settings.setdefault('static_hash_cache', False)
tornado_app.settings.setdefault('serve_traceback', True)
# Automatically reload modified modules
from tornado import autoreload
autoreload.start()
server.start()
tornado.ioloop.IOLoop.current().start()
......@@ -5,7 +5,9 @@
<title>Grond | Barad-dur</title>
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/grids-responsive-min.css">
<link rel="stylesheet" href="/static/site.css">
<link rel="stylesheet" href="/css/site.css">
{% block extra_head %}
{% end %}
</head>
<style>
.custom-restricted-width {
......@@ -33,16 +35,14 @@
</div>
</div>
</div>
<div id="main">
<div class="content pure-u-1 pure-u-md-4-5">
{% block content %}
<h1 class="content-subhead">Content not implemented.</h1>
{% end %}
</div>
<div class="footer pure-u-1">
Grond - <i>The earthquake buster</i> <a href="http://pyrocko.org" class="pure-button pure-button-primary" style="margin-left: 1em;">pyrocko.org</a>
</div>
<div id="main" class="content pure-u-1 pure-u-md-4-5">
{% block content %}
<h1 class="content-subhead">Content not implemented.</h1>
{% end %}
</div>
<div class="footer pure-u-1">
Grond - <i>The earthquake buster</i> <a href="http://pyrocko.org" class="pure-button pure-button-primary" style="margin-left: 1em;">pyrocko.org</a>
</div>
</div>
<script src="/static/ui.js"></script>
</html>
\ No newline at end of file
<script src="/css/ui.js"></script>
</html>
{% extends "index.html" %}
{% block extra_head %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
{% end %}
{% block content %}
<header>
<h1 class="content-subhead">Parameters <i>{{ problem.name }}</i></h1>
<p><span style="font-family: monospace;">{{ problem.__class__.__name__ }}</span> | <span style="font-family: monospace;">{{ problem.base_source.__class__.__name__ }}</span></p>
</header>
<h2 class="content-subhead">Parameter Plots</h3>
{% raw parameter_plot %}
{% end %}
{% extends "index.html" %}
{% block extra_head %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
{% end %}
{% block content %}
<header>
<h1 class="content-subhead">Status <i>{{ problem.name }}</i></h1>
<p><span style="font-family: monospace;">{{ problem.__class__.__name__ }}</span> | <span style="font-family: monospace;">{{ problem.base_source.__class__.__name__ }}</span></p>
</header>
<h2 class="content-subhead">Plot misfit</h3>
<p>Global misfit over iteration.</p>
{% raw misfit_plot %}
{% end %}
{% extends "index.html" %}
{% block extra_head %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
{% end %}
{% block content %}
<header>
<h1 class="content-subhead">Problem <i>{{ problem.name }}</i></h1>
<p><span style="font-family: monospace;">{{ problem.__class__.__name__ }}</span> | <span style="font-family: monospace;">{{ problem.base_source.__class__.__name__ }}</span></p>
</header>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1 pure-u-lg-1-1">
<h2 class="content-subhead">Targets</h3>
<p>Targets to optimize.</p>
<table class="pure-table pure-table-horizontal">
<thead>
<tr>
<td></td>
<td>id</td>
<td>Type</td>
</tr>
</thead>
<tbody>
{% for it, target in enumerate(problem.targets) %}
<tr{% if it % 2 == 1 %} class="pure-table-odd"{% end %}>
<td>{{ it+1 }}</td>
<td>{{ target.scene_id }}</td>
<td style="font-family: monospace;">{{ target.__class__.__name__ }}</td>
</tr>
{% end %}
</tbody>
</table>
</div>
<div class="pure-u-1 pure-u-md-1 pure-u-lg-1-2">
<h2 class="content-subhead">Initial model</h3>
<p>Initial at start of the optimization.</p>
......@@ -32,7 +59,8 @@
<table class="pure-table pure-table-horizontal">
<thead>
<tr>
<td colspan=2>Parameter</td>
<td></td>
<td>Parameter</td>
<td>Allowed Ranges</td>
<td>Unit</td>
</tr>
......@@ -49,11 +77,26 @@
</tbody>
</table>
</div>
<div class="pure-u-5-5">
<h2 class="content-subhead">Map of initial model</h2>
<div>
{% raw script %}
<div class="pure-u-1">
<h2 class="content-subhead">Map of initial model position</h2>
<div id="initial_model_map" class="pure-u-1" style="min-height: 250px;">
<script>
var map = L.map('initial_model_map').setView(
[{{ problem.base_source["lat"] }}, {{ problem.base_source["lon"] }}], 5);
L.tileLayer('http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
}).addTo(map);
var marker = L.marker([{{ problem.base_source["lat"] }}, {{ problem.base_source["lon"] }}],
{
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500
}).addTo(map);
marker.bindPopup("{{ problem.base_source["lat"] }}, {{ problem.base_source["lon"] }}<br>{{ problem.base_source["name"] }}")
</script>
</div>
</div>
</div>
{% end %}
\ No newline at end of file
{% end %}
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