mole: setup of general running procedure
- modules contain specific tasks - modules are scheduled - offline mode is enabled using an eventidpull/5/head
parent
a448a9c1e9
commit
621c0443ce
Binary file not shown.
@ -0,0 +1,77 @@
|
||||
# GPLv3
|
||||
#
|
||||
# The Developers, 21st Century
|
||||
import logging
|
||||
|
||||
import numpy as num
|
||||
|
||||
import grond
|
||||
from grond.environment import Environment
|
||||
from grond.problems.base import ProblemDataNotAvailable
|
||||
|
||||
from pyrocko import guts # noqa
|
||||
from pyrocko import moment_tensor as pmt
|
||||
from pyrocko import orthodrome as pod
|
||||
|
||||
logger = logging.getLogger('ewrica.io.grond')
|
||||
|
||||
|
||||
def history_to_sources(problem, history):
|
||||
'''Convert grond history into ewrica.sources of appropiate type
|
||||
|
||||
'''
|
||||
from ewrica import sources as ewsources
|
||||
|
||||
xs = history.get_sorted_primary_models()
|
||||
bootstrap_misfits = history.get_sorted_primary_misfits()
|
||||
|
||||
base_source = problem.base_source
|
||||
|
||||
if isinstance(problem, grond.problems.cmt.problem.CMTProblem):
|
||||
source = ewsources.MTSource
|
||||
|
||||
stf = base_source.stf.T.cls
|
||||
|
||||
moments = pmt.magnitude_to_moment(xs[:, 4])
|
||||
xs[:, 5:11] *= moments[:, num.newaxis]
|
||||
|
||||
lats, lons = pod.ne_to_latlon(
|
||||
base_source.lat, base_source.lon, xs[:, 1], xs[:, 2])
|
||||
xs[:, 1] = lats
|
||||
xs[:, 2] = lons
|
||||
|
||||
return [source(
|
||||
time=base_source.time + i[0],
|
||||
lat=i[1],
|
||||
lon=i[2],
|
||||
depth=i[3],
|
||||
m6=i[5:11],
|
||||
stf=stf(duration=i[11]),
|
||||
stf_mode=base_source.stf_mode,
|
||||
misfit=mf)
|
||||
for i, mf in zip(xs, bootstrap_misfits)]
|
||||
|
||||
else:
|
||||
# TODO
|
||||
raise TypeError('Not implemented yet for the current problem type.')
|
||||
|
||||
|
||||
def grond_to_sources(rundir, subset='harvest'):
|
||||
'''Extract models from the grond run directory
|
||||
|
||||
'''
|
||||
env = Environment(rundir)
|
||||
|
||||
problem = env.get_problem()
|
||||
|
||||
try:
|
||||
history = env.get_history(subset=subset)
|
||||
except ProblemDataNotAvailable:
|
||||
# TODO Check behaviour
|
||||
grond.harvest(
|
||||
rundir, problem=None, nbest=10, force=False, weed=0,
|
||||
export_fits=[])
|
||||
|
||||
history = env.get_history(subset=subset)
|
||||
|
||||
return history_to_sources(problem, history)
|
Loading…
Reference in New Issue