Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Heimann
grond
Commits
c25df056
Commit
c25df056
authored
Mar 01, 2017
by
marius
Browse files
wip
parent
70ee2234
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/grond
View file @
c25df056
...
...
@@ -24,7 +24,7 @@ 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'
,
...
...
@@ -35,7 +35,7 @@ subcommand_descriptions = {
}
subcommand_usages
=
{
'init'
:
'init [options]'
,
'init'
:
'init [options]
<project_dir>
'
,
'events'
:
'events <configfile>'
,
'check'
:
'check <configfile> <eventnames> ... [options]'
,
'go'
:
'go <configfile> <eventnames> ... [options]'
,
...
...
@@ -145,10 +145,20 @@ def command_init(args):
parser
,
options
,
args
=
cl_parse
(
'init'
,
args
,
setup
)
dir_struct
=
[
'gf_store'
]
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
:
dir_struct
+=
[
'data'
]
config_type
=
'waveform'
sub_dirs
+=
[
'data'
]
empty_files
+=
[
'stations.xml'
]
dataset_config
=
grond
.
DatasetConfig
(
stations_path
=
'stations.txt'
,
events_path
=
'events.txt'
,
...
...
@@ -188,7 +198,9 @@ def command_init(args):
)
elif
options
.
static
:
dir_struct
+=
[
'scenes'
]
config_type
=
'static'
sub_dirs
+=
[
'scenes'
]
dataset_config
=
grond
.
DatasetConfig
(
events_path
=
'events.txt'
,
kite_scene_paths
=
[
'scenes'
],
...
...
@@ -236,22 +248,26 @@ depth = 8000
region = Myanmar
--------------------------------------------'''
def
create_struct
(
dirname
):
if
project_dir
is
not
None
:
logger
.
info
(
'Creating empty %s project in folder %s'
%
(
config_type
,
args
[
0
]))
def
p
(
fn
):
op
.
abspath
(
op
.
join
(
dirname
,
fn
)
)
return
op
.
join
(
project_dir
,
fn
)
os
.
mkdir
(
op
.
abspath
(
dirname
))
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
)
open
(
'stations.txt'
,
'a'
).
close
()
for
d
in
dir_struct
:
os
.
mkdir
(
p
(
d
))
print
config
for
fn
in
empty_files
:
open
(
p
(
fn
),
'w'
).
close
()
else
:
print
config
def
command_events
(
args
):
...
...
src/baraddur/__init__.py
0 → 100644
View file @
c25df056
from
.server
import
# noqa
\ No newline at end of file
src/baraddur/server.py
View file @
c25df056
import
tornado.ioloop
import
grond
import
os
import
os.path
as
op
import
logging
import
numpy
as
num
...
...
@@ -45,6 +46,67 @@ class BaraddurBokehHandler(BokehHandler):
self
.
config
=
config
class
GrondBokehModel
(
object
):
def
__init__
(
self
,
config
):
self
.
config
=
config
self
.
set_rundir
(
self
.
config
.
rundir
)
def
set_rundir
(
self
,
rundir
):
logger
.
debug
(
'Loading problem from %s'
%
rundir
)
self
.
rundir
=
rundir
self
.
problem
=
grond
.
core
.
load_problem_info
(
self
.
rundir
)
self
.
parameters
=
self
.
problem
.
parameters
self
.
nparameters
=
self
.
problem
.
nparameters
self
.
ntargets
=
self
.
problem
.
ntargets
def
get_models
(
self
,
skip_nmodels
=
0
):
fn
=
op
.
join
(
self
.
rundir
,
'models'
)
with
open
(
fn
,
'r'
)
as
f
:
nmodels
=
os
.
fstat
(
f
.
fileno
()).
st_size
/
(
self
.
nparameters
*
8
)
nmodels
-=
skip_nmodels
f
.
seek
(
skip_nmodels
*
self
.
nparameters
*
8
)
data
=
num
.
fromfile
(
f
,
dtype
=
'<f8'
,
count
=
nmodels
*
self
.
nparameters
)
\
.
astype
(
num
.
float
)
nmodels
=
data
.
size
/
self
.
nparameters
-
skip_nmodels
models
=
data
.
reshape
((
nmodels
,
self
.
nparameters
))
mods_dict
=
{}
for
ip
,
par
in
enumerate
(
self
.
parameters
):
mods_dict
[
par
.
name
]
=
models
[:,
ip
]
mods_dict
[
'niter'
]
=
num
.
arange
(
nmodels
,
dtype
=
num
.
int
)
+
(
nmodels
+
1
)
return
nmodels
,
mods_dict
def
get_misfits
(
self
,
skip_nmodels
=
0
):
fn
=
op
.
join
(
self
.
rundir
,
'misfits'
)
with
open
(
fn
,
'r'
)
as
f
:
nmodels
=
os
.
fstat
(
f
.
fileno
()).
st_size
/
(
self
.
nparameters
*
8
)
nmodels
-=
skip_nmodels
f
.
seek
(
skip_nmodels
*
self
.
ntargets
*
2
*
8
)
data
=
num
.
fromfile
(
f
,
dtype
=
'<f8'
,
count
=
nmodels
*
self
.
ntargets
*
2
)
\
.
astype
(
num
.
float
)
data
=
data
.
reshape
((
nmodels
,
self
.
ntargets
*
2
))
combi
=
num
.
empty_like
(
data
)
combi
[:,
0
::
2
]
=
data
[:,
:
self
.
ntargets
]
combi
[:,
1
::
2
]
=
data
[:,
self
.
ntargets
:]
assert
(
data
.
size
/
self
.
nparameters
-
skip_nmodels
==
nmodels
)
misfits
=
combi
.
reshape
((
nmodels
,
self
.
ntargets
,
2
))
mf_dict
=
{}
for
it
in
xrange
(
self
.
ntargets
):
mf_dict
[
'target_%03d'
%
it
]
=
misfits
[:,
it
,
0
]
mf_dict
[
'target_mean'
]
=
num
.
mean
(
misfits
[:,
:,
0
])
mf_dict
[
'niter'
]
=
num
.
arange
(
nmodels
,
dtype
=
num
.
int
)
+
(
nmodels
+
1
)
return
nmodels
,
misfits
class
Status
(
BaraddurRequestHandler
):
class
MisfitsPlot
(
BaraddurBokehHandler
):
...
...
@@ -52,8 +114,8 @@ class Status(BaraddurRequestHandler):
def
modify_document
(
self
,
doc
):
self
.
nmodels
=
0
self
.
source
=
ColumnDataSource
(
data
=
{
'n'
:
[]
,
'gm'
:
[]
})
data
=
{
'n'
:
num
.
ndarray
(
0
)
,
'gm'
:
num
.
ndarray
(
0
)
})
self
.
update_misfits
()
plot
=
figure
(
webgl
=
True
,
...
...
@@ -101,7 +163,7 @@ class Parameters(BaraddurRequestHandler):
self
.
source
=
ColumnDataSource
()
for
p
in
[
'n'
]
+
[
p
.
name
for
p
in
problem
.
parameters
]:
self
.
source
.
add
(
[]
,
p
)
self
.
source
.
add
(
num
.
ndarray
(
0
)
,
p
)
self
.
update_parameters
()
plots
=
[]
...
...
@@ -231,7 +293,7 @@ class BaraddurConfig(Object):
String
.
T
(),
default
=
[
'*'
],
optional
=
True
,
help
=
'List of allowed hosts.'
)
help
=
'List of allowed hosts
, default is all
\'
*
\'
.'
)
port
=
Int
.
T
(
default
=
8080
,
optional
=
True
,
...
...
src/problems.py
View file @
c25df056
...
...
@@ -126,7 +126,7 @@ class Problem(Object):
guts
.
dump
(
self
,
filename
=
fn
)
def
dump_problem_data
(
self
,
dirname
,
x
,
ms
,
ns
):
fn
=
op
.
join
(
dirname
,
'
x
'
)
fn
=
op
.
join
(
dirname
,
'
models
'
)
if
not
isinstance
(
x
,
num
.
ndarray
):
x
=
num
.
array
(
x
)
with
open
(
fn
,
'ab'
)
as
f
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment