Commit dbbc868a authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

Merge branch 'refactor' into solver_plot

Conflicts:
	apps/grond
	src/cmt.py
	src/core.py
	src/plot.py
parents d6da8fc4 a99867ad
......@@ -3,6 +3,8 @@
import math
import sys
import logging
import os
import os.path as op
from optparse import OptionParser
from pyrocko import util, marker
......@@ -11,8 +13,7 @@ from pyrocko.gf import Range
import grond
logger = logging.getLogger('main')
km = 1000.
km = 1e3
def d2u(d):
......@@ -23,19 +24,20 @@ def d2u(d):
subcommand_descriptions = {
'init': 'print example configuration',
'init': 'create project structure or print example configuration',
'events': 'print available event names for given configuration',
'check': 'check data and configuration',
'go': 'run Grond optimization',
'forward': 'run forward modelling',
'harvest': 'manually run harvesting',
'plot': 'plot optimization result',
'baraddur': 'start Barad-dur plotting, watching this directory',
'export': 'export results',
'qc-polarization': 'check sensor orientations with polarization analysis',
}
subcommand_usages = {
'init': 'init [options]',
'init': 'init [options] <project_dir>',
'events': 'events <configfile>',
'check': 'check <configfile> <eventnames> ... [options]',
'go': 'go <configfile> <eventnames> ... [options]',
......@@ -44,6 +46,7 @@ subcommand_usages = {
'forward <configfile> <eventnames> ... [options]'),
'harvest': 'harvest <rundir> [options]',
'plot': 'plot <plotnames> <rundir> [options]',
'baraddur': 'plot-server',
'export': 'export (best|mean|ensemble|stats) <rundirs> ... [options]',
'qc-polarization': 'qc-polarization <configfile> <eventname> '
'<targetconfigname> [options]',
......@@ -69,6 +72,7 @@ Subcommands:
plot %(plot)s
export %(export)s
qc-polarization %(qc_polarization)s
baraddur %(baraddur)s
To get further help and a list of available options for any subcommand run:
......@@ -136,48 +140,141 @@ def help_and_die(parser, message):
def command_init(args):
dataset_config = grond.DatasetConfig(
stations_path='stations.txt',
events_path='events.txt',
waveform_paths=['data'])
target_configs = [grond.TargetConfig(
distance_min=10*km,
distance_max=1000*km,
channels=['Z', 'R', 'T'],
interpolation='multilinear',
store_id='global_2s',
inner_misfit_config=grond.InnerMisfitConfig(
fmin=0.01,
fmax=0.1))]
s2 = math.sqrt(2.0)
problem_config = grond.CMTProblemConfig(
name_template='cmt_%(event_name)s',
distance_min=2.*km,
nbootstrap=100,
mt_type='deviatoric',
ranges=dict(
time=Range(0, 10.0, relative='add'),
north_shift=Range(-16*km, 16*km),
east_shift=Range(-16*km, 16*km),
depth=Range(1*km, 11*km),
magnitude=Range(4.0, 6.0),
rmnn=Range(-s2, s2),
rmee=Range(-s2, s2),
rmdd=Range(-s2, s2),
rmne=Range(-1.0, 1.0),
rmnd=Range(-1.0, 1.0),
rmed=Range(-1.0, 1.0),
duration=Range(1.0, 15.0)))
def setup(parser):
parser.add_option(
'--waveform', dest='waveform', action='store_true', default=True,
help='Create an example configuration for waveform inversion. '
'(default)')
parser.add_option(
'--static', dest='static', action='store_true',
help='Create an example configuration for static displacements'
' using kite scene containers.')
parser, options, args = cl_parse('init', args, setup)
project_dir = None
if len(args) == 1:
project_dir = op.join(op.curdir, args[0])
if op.exists(project_dir):
raise EnvironmentError('Directory %s already exists' % args[0])
sub_dirs = ['gf_store']
empty_files = []
if options.waveform and not options.static:
config_type = 'waveform'
sub_dirs += ['data']
empty_files += ['stations.xml']
dataset_config = grond.DatasetConfig(
stations_path='stations.txt',
events_path='events.txt',
waveform_paths=['data'])
target_configs = [grond.TargetConfig(
super_group='time_domain',
group='all',
distance_min=10*km,
distance_max=1000*km,
channels=['Z', 'R', 'T'],
interpolation='multilinear',
store_id='gf_store',
inner_misfit_config=grond.InnerMisfitConfig(
fmin=0.01,
fmax=0.1))]
s2 = math.sqrt(2.0)
problem_config = grond.CMTProblemConfig(
name_template='cmt_%(event_name)s',
distance_min=2.*km,
nbootstrap=100,
mt_type='deviatoric',
ranges=dict(
time=Range(0, 10.0, relative='add'),
north_shift=Range(-16*km, 16*km),
east_shift=Range(-16*km, 16*km),
depth=Range(1*km, 11*km),
magnitude=Range(4.0, 6.0),
rmnn=Range(-s2, s2),
rmee=Range(-s2, s2),
rmdd=Range(-s2, s2),
rmne=Range(-1.0, 1.0),
rmnd=Range(-1.0, 1.0),
rmed=Range(-1.0, 1.0),
duration=Range(1.0, 15.0))
)
elif options.static:
config_type = 'static'
sub_dirs += ['scenes']
dataset_config = grond.DatasetConfig(
events_path='events.txt',
kite_scene_paths=['scenes'],
)
target_configs = [grond.TargetConfig(
super_group='insar_target',
group='all',
interpolation='multilinear',
store_id='gf_store',
inner_satellite_misfit_config=grond.InnerSatelliteMisfitConfig(
use_weight_focal=False))]
problem_config = grond.RectangularProblemConfig(
name_template='rect_source',
ranges=dict(
north_shift=Range(-20*km, 20*km),
east_shift=Range(-20*km, 20*km),
depth=Range(0*km, 10*km),
length=Range(20*km, 40*km),
width=Range(5*km, 12*km),
dip=Range(20, 70),
strike=Range(0, 180),
rake=Range(0, 90),
slip=Range(1, 3))
)
engine_config = grond.EngineConfig(
gf_store_superdirs=['.'])
config = grond.Config(
rundir_template=op.join(op.abspath(op.curdir), 'rundir'),
dataset_config=dataset_config,
target_configs=target_configs,
problem_config=problem_config)
print config
problem_config=problem_config,
engine_config=engine_config)
events = '''name = 2011-myanmar
time = 2011-03-24 13:55:12.010
latitude = 20.687
longitude = 99.822
magnitude = 6.9
moment = 1.9228e+19
depth = 8000
region = Myanmar
--------------------------------------------'''
if project_dir is not None:
logger.info('Creating empty %s project in folder %s'
% (config_type, args[0]))
def p(fn):
return op.join(project_dir, fn)
os.mkdir(op.abspath(project_dir))
for d in sub_dirs:
os.mkdir(p(d))
with open(p('config.yml'), 'w') as cf:
cf.write(str(config))
with open(p('events.txt'), 'w') as ef:
ef.write(events)
for fn in empty_files:
open(p(fn), 'w').close()
else:
print config
def command_events(args):
......@@ -251,6 +348,10 @@ def command_go(args):
parser.add_option(
'--parallel', dest='nparallel', type='int', default=1,
help='set number of events to process in parallel')
parser.add_option(
'--baraddur', dest='baraddur', default=False,
action='store_true',
help='start the Barad-dur plotting server')
parser, options, args = cl_parse('go', args, setup)
if len(args) < 2:
......@@ -265,6 +366,11 @@ def command_go(args):
else:
status = tuple(options.status.split(','))
if options.baraddur:
from grond.baraddur import BaraddurProcess
baraddur = BaraddurProcess(project_dir=op.abspath(op.curdir))
baraddur.start()
grond.go(
config,
event_names=event_names,
......@@ -272,6 +378,11 @@ def command_go(args):
status=status,
nparallel=options.nparallel)
if options.baraddur:
logger.info('Grond finished processing %d events. '
'Ctrl+C to kill Barad-dur')
baraddur.join()
def command_forward(args):
def setup(parser):
......@@ -385,6 +496,31 @@ selected by specifying a comma-separated list.''' % (
die(str(e))
def command_baraddur(args):
from grond.baraddur import Baraddur, BaraddurConfig
import signal
def setup(parser):
parser.add_option(
'--address', dest='address', default='*',
help='Address listening on, default all \'*\'')
parser.add_option(
'--port', dest='port', type='int', default=8080,
help='Port to listen on, default 8080')
parser, options, args = cl_parse('baraddur', args, setup)
config = BaraddurConfig(
project_dir=op.abspath(op.curdir),
hosts=options.address,
port=options.port)
baraddur = Baraddur(config=config)
signal.signal(signal.SIGINT, baraddur.stop)
baraddur.start()
def command_export(args):
def setup(parser):
......
# bash-completion
# For grond, the earthquake buster!
_opt_filenames()
{
echo $(compgen -o filenames -A file -- $cur)
}
_opt_dirnames()
{
echo $(compgen -o plusdirs -f -- $cur)
}
_grond_options()
{
local cur opts std
COMPREPLY=()
opts=""
cur=${COMP_WORDS[COMP_CWORD]}
declare -A arg_sub
arg_sub["init"]=""
arg_sub["check"]="$(_opt_filenames)"
arg_sub["go"]="$(_opt_filenames)"
arg_sub["forward"]="$(_opt_dirnames)"
arg_sub["harvest"]="$(_opt_dirnames)"
arg_sub["map-geometry"]="$(_opt_filenames)"
arg_sub["plot"]="bootstrap sequence hudson solution jointpar fits contributions all"
arg_sub["export"]="best mean ensemble stats"
_std="--help -h --loglevel"
declare -A arg_subsub
arg_subsub["init"]=""
arg_subsub["check"]="--event $_std"
arg_subsub["go"]="--event --force --status --parallel $_std"
arg_subsub["forward"]="--event $_std"
arg_subsub["harvest"]="--force --neach --weed $_std"
arg_subsub["map-geometry"]=" $_std"
arg_subsub["plot"]="$(_opt_dirnames)"
arg_subsub["export"]="$(_opt_dirnames)"
declare -A arg_subsubsub
arg_subsubsub["plot"]="--save --format --dpi $_std"
arg_subsubsub["export"]="--type --parameters --output $_std"
if [ $COMP_CWORD = 1 ]; then
opts="init check go forward harvest map-geometry plot export"
elif [ $COMP_CWORD = 2 ]; then
opts=${arg_sub[${COMP_WORDS[1]}]}
elif [ $COMP_CWORD = 3 ]; then
opts=${arg_subsub[${COMP_WORDS[1]}]}
elif [ $COMP_CWORD = 4 ]; then
opts=${arg_subsubsub[${COMP_WORDS[1]}]}
fi
COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
return 0
}
complete -o nospace -o filenames -F _grond_options grond
......@@ -8,7 +8,11 @@ setup(
version='0.1',
author='Sebastian Heimann',
author_email='sebastian.heimann@gfz-potsdam.de',
packages=['grond'],
package_dir={'grond': 'src'},
packages=['grond', 'grond.baraddur'],
scripts=['apps/grond'],
package_data={'grond': []})
package_dir={'grond': 'src'},
package_data={'grond': [],
'grond': ['baraddur/templates/*.html',
'baraddur/res/*']},
data_files=[('/etc/bash_completion.d', ['extras/grond'])],
)
from core import * # noqa
from cmt import * # noqa
from double_dc import * # noqa
from dataset import * # noqa
from .core import * # noqa
from .dataset import * # noqa
from .problems import * # noqa
from .targets import * # noqa
from .meta import * # noqa
from .synthetic_tests import * #noqa
import multiprocessing as _mp
import signal as _signal
from .server import Baraddur, BaraddurConfig # noqa
class BaraddurProcess(_mp.Process):
def __init__(self, *args, **kwargs):
self.server = Baraddur(*args, **kwargs)
self.shutdown_signal = _mp.Queue(1)
_mp.Process.__init__(self)
def run(self):
_signal.signal(_signal.SIGINT, self.server.stop)
self.server.start(signal=self.shutdown_signal)
def stop(self):
self.shutdown_signal.put(True)
if __name__ == '__main__':
p = BaraddurProcess(project_dir='/home/marius/Development/testing/grond')
p.start()
function changeRundir(rundir) {
var form = document.createElement("form");
//Move the submit function to another variable
//so that it doesn't get overwritten.
form._submit_function_ = form.submit;
form.setAttribute("method", "post");
form.setAttribute("action", window.location.href);
var rundirField = document.createElement("input");
rundirField.setAttribute("type", "hidden");
rundirField.setAttribute("name", "rundir");
rundirField.setAttribute("value", rundir);
form.appendChild(rundirField);
document.body.appendChild(form);
form._submit_function_(); //Call the renamed function.
}
body {
color: #000;
}
.pure-img-responsive {
max-width: 100%;
height: auto;
}
/*
Add transition to containers so they can push in and out.
*/
#layout,
#menu,
.menu-link {
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
/*
This is the parent `<div>` that contains the menu and the content area.
*/
#layout {
position: relative;
left: 0;
padding-left: 0;
}
#layout.active #menu {
left: 200px;
width: 200px;
}
#layout.active .menu-link {
left: 200px;
}
/*
The content `<div>` is where all your content goes.
*/
div.footer {
margin: 1em 0em 0em 0em;
padding: 0em 0em 1em 0em;
line-height: 3em;
text-align: center;
color: #999;
background-color: #fbfbfb;
border-top: 1px solid #e8e8e8;
position: absolute;
bottom: 0px;
left: 0px;
font-size: 80%;
}
#menu div.footer a {
color: white;
border: none;
padding: 0.6em 0.6em 0.6em 0.6em;
letter-spacing: .15em;
}
}
.header {
margin: 0;
color: #666;
text-align: center;
padding: 2.5em 2em 0;
border-bottom: 1px solid #e3e3e3;
}
.header h1 {
margin: 0.2em 0;
font-size: 3em;
font-weight: 300;
}
.header h2 {
font-weight: 300;
color: #ccc;
padding: 0;
margin-top: 0;
}
.content-subhead {
margin: 50px 0 20px 0;
font-weight: 300;
color: #888;
}
.content {
margin: 0 auto;
padding: 0 2em;
max-width: 1200px;
margin-bottom: 50px;
line-height: 1.6em;
}
/*
The `#menu` `<div>` is the parent `<div>` that contains the `.pure-menu` that
appears on the left side of the page.
*/
#menu {
margin-left: -200px; /* "#menu" width */
width: 200px;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000; /* so the menu or its navicon stays above all content */
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
/*
All anchors inside the menu should be styled like this.
*/
#menu a {
color: #999;
border: none;
padding: 0.6em 0 0.6em 0.6em;
letter-spacing: .15em;
}
/*
Remove all background/borders, since we are applying them to #menu.
*/
#menu .pure-menu,
#menu .pure-menu ul {
border: none;
background: transparent;
}
/*
Add that light border to separate items into groups.
*/
#menu .pure-menu ul,
#menu .pure-menu .menu-item-divided {
border-top: 1px solid #333;
}
/*
Change color of the anchor links on hover/focus.
*/
#menu .pure-menu li a:hover,
#menu .pure-menu li a:focus {
background: #efefef;
}
/*
This styles the selected menu item `<li>`.
*/
#menu .pure-menu-selected, {
background: #;
}
/*
This styles a link within a selected menu item `<li>`.
*/
#menu .pure-menu-selected a {
color: #efefef;
}
/*
This styles the menu heading.
*/
#menu .pure-menu-heading {
font-size: 110%;
margin: 0;
letter-spacing: .4em;
padding: .5em 0em;
width: 200px;
text-align: center;
}
/* -- Dynamic Button For Responsive Menu -------------------------------------*/
/*
The button to open/close the Menu is custom-made and not part of Pure. Here's
how it works:
*/
/*
`.menu-link` represents the responsive menu toggle that shows/hides on
small screens.
*/
.menu-link {
position: fixed;
display: block; /* show this only on small screens */
top: 0;
left: 0; /* "#menu width" */
background: #000;
background: rgba(