Commit 6447037c authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

improved subcommand check

parent c40cbacd
......@@ -199,6 +199,10 @@ def command_check(args):
'comma-separated list of target IDs. Target IDs have the '
'form SUPERGROUP.GROUP.NETWORK.STATION.LOCATION.CHANNEL.')
parser.add_option(
'--plot', dest='show_plot', action='store_true',
help='plot sample synthetics and data')
parser, options, args = cl_parse('check', args, setup)
if len(args) < 2:
help_and_die(parser, 'missing arguments')
......@@ -215,7 +219,8 @@ def command_check(args):
grond.check(
config,
event_names=event_names,
target_string_ids=target_string_ids)
target_string_ids=target_string_ids,
show_plot=options.show_plot)
def command_go(args):
......
......@@ -1576,10 +1576,9 @@ def check_problem(problem):
if len(problem.targets) == 0:
raise GrondError('no targets available')
g_state = {}
def check(config, event_names=None, target_string_ids=None):
def check(config, event_names=None, target_string_ids=None, show_plot=False):
from matplotlib import pyplot as plt
from grond.plot import colors
......@@ -1589,13 +1588,21 @@ def check(config, event_names=None, target_string_ids=None):
try:
problem = config.get_problem(event)
_, ngroups = problem.get_group_mask()
logger.info('number of target supergroups: %i' % ngroups)
logger.info('number of targets (total): %i' % len(problem.targets))
if target_string_ids:
problem.targets = [
target for target in problem.targets
if target.string_id() in target_string_ids]
if util.match_nslc(target_string_ids, target.string_id())]
logger.info('number of targets (selected): %i' % len(problem.targets))
check_problem(problem)
xbounds = num.array(problem.bounds(), dtype=num.float)
results_list = []
......@@ -1604,67 +1611,88 @@ def check(config, event_names=None, target_string_ids=None):
ms, ns, results = problem.evaluate(x, result_mode='full')
results_list.append(results)
for itarget, target in enumerate(problem.targets):
yabsmaxs = []
for results in results_list:
result = results[itarget]
if not isinstance(result, gf.SeismosizerError):
yabsmaxs.append(
num.max(num.abs(result.filtered_obs.get_ydata())))
if show_plot:
for itarget, target in enumerate(problem.targets):
yabsmaxs = []
for results in results_list:
result = results[itarget]
if not isinstance(result, gf.SeismosizerError):
yabsmaxs.append(
num.max(num.abs(
result.filtered_obs.get_ydata())))
if yabsmaxs:
yabsmax = max(yabsmaxs) or 1.0
else:
yabsmax = None
fig = None
ii = 0
for results in results_list:
result = results[itarget]
if not isinstance(result, gf.SeismosizerError):
if fig is None:
fig = plt.figure()
axes = fig.add_subplot(1, 1, 1)
axes.set_ylim(0., 4.)
axes.set_title('%s' % target.string_id())
xdata = result.filtered_obs.get_xdata()
ydata = result.filtered_obs.get_ydata() / yabsmax
axes.plot(xdata, ydata*0.5 + 3.5, color='black')
color = colors[ii % len(colors)]
xdata = result.filtered_syn.get_xdata()
ydata = result.filtered_syn.get_ydata()
ydata = ydata / (num.max(num.abs(ydata)) or 1.0)
axes.plot(xdata, ydata*0.5 + 2.5, color=color)
xdata = result.processed_syn.get_xdata()
ydata = result.processed_syn.get_ydata()
ydata = ydata / (num.max(num.abs(ydata)) or 1.0)
axes.plot(xdata, ydata*0.5 + 1.5, color=color)
if result.tsyn_pick:
axes.axvline(
result.tsyn_pick,
color=(0.7, 0.7, 0.7),
zorder=2)
t = result.processed_syn.get_xdata()
taper = result.taper
y = num.ones(t.size) * 0.9
taper(y, t[0], t[1] - t[0])
y2 = num.concatenate((y, -y[::-1]))
t2 = num.concatenate((t, t[::-1]))
axes.plot(t2, y2 * 0.5 + 0.5, color='gray')
ii += 1
else:
logger.info(str(result))
if fig:
plt.show()
if yabsmaxs:
yabsmax = max(yabsmaxs) or 1.0
else:
yabsmax = None
fig = None
ii = 0
for results in results_list:
result = results[itarget]
if not isinstance(result, gf.SeismosizerError):
if fig is None:
fig = plt.figure()
axes = fig.add_subplot(1, 1, 1)
axes.set_ylim(0., 4.)
axes.set_title('%s' % target.string_id())
xdata = result.filtered_obs.get_xdata()
ydata = result.filtered_obs.get_ydata() / yabsmax
axes.plot(xdata, ydata*0.5 + 3.5, color='black')
color = colors[ii % len(colors)]
xdata = result.filtered_syn.get_xdata()
ydata = result.filtered_syn.get_ydata()
ydata = ydata / (num.max(num.abs(ydata)) or 1.0)
axes.plot(xdata, ydata*0.5 + 2.5, color=color)
xdata = result.processed_syn.get_xdata()
ydata = result.processed_syn.get_ydata()
ydata = ydata / (num.max(num.abs(ydata)) or 1.0)
axes.plot(xdata, ydata*0.5 + 1.5, color=color)
if result.tsyn_pick:
axes.axvline(
result.tsyn_pick,
color=(0.7, 0.7, 0.7),
zorder=2)
t = result.processed_syn.get_xdata()
taper = result.taper
y = num.ones(t.size) * 0.9
taper(y, t[0], t[1] - t[0])
y2 = num.concatenate((y, -y[::-1]))
t2 = num.concatenate((t, t[::-1]))
axes.plot(t2, y2 * 0.5 + 0.5, color='gray')
ii += 1
else:
for itarget, target in enumerate(problem.targets):
nok = 0
for results in results_list:
result = results[itarget]
if not isinstance(result, gf.SeismosizerError):
nok += 1
if nok == 0:
sok = 'not used'
elif nok == len(results_list):
sok = 'ok'
else:
logger.info(str(result))
sok = 'not used (%i/%i ok)' % (nok, len(results_list))
if fig:
plt.show()
logger.info('%-40s %s' % (
(target.string_id() + ':', sok)))
except GrondError, e:
logger.error('event %i, %s: %s' % (
......@@ -1672,6 +1700,8 @@ def check(config, event_names=None, target_string_ids=None):
event.name or util.time_to_str(event.time),
str(e)))
g_state = {}
def go(config, event_names=None, force=False, nparallel=1, status=('state',)):
......
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