Commit 29b035ca authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

improved plots: contributions, fits, sequence

parent 953d8602
......@@ -11,9 +11,11 @@ from pyrocko import hudson
from grond import core
from matplotlib import pyplot as plt
from matplotlib import cm, patches
from pyrocko.cake_plot import mpl_init, labelspace, colors, \
from pyrocko.cake_plot import colors, \
str_to_mpl_color as scolor, light
from pyrocko.plot import mpl_init, mpl_papersize, mpl_margins
logger = logging.getLogger('grond.plot')
km = 1000.
......@@ -193,11 +195,30 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None):
else:
ibest = gms < misfit_cutoff
def config_axes(axes, nfx, nfy, impl, iplot, nplots):
if (impl - 1) % nfx != nfx - 1:
axes.get_yaxis().tick_left()
print iplot, nplots
if (impl - 1) >= (nfx * (nfy-1)) or iplot >= nplots - nfx:
axes.set_xlabel('Iteration')
if not (impl - 1) / nfx == 0:
axes.get_xaxis().tick_bottom()
elif (impl - 1) / nfx == 0:
axes.get_xaxis().tick_top()
axes.set_xticklabels([])
else:
axes.get_xaxis().set_visible(False)
fontsize = 10.0
nfx = 2
nfy = 4
nfy = 3
# nfz = (npar + ndep + 1 - 1) / (nfx*nfy) + 1
cmap = cm.YlOrRd
cmap = cm.jet
msize = 1.5
axes = None
figs = []
fig = None
......@@ -206,71 +227,83 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None):
impl = ipar % (nfx*nfy) + 1
if impl == 1:
fig = plt.figure()
fig = plt.figure(figsize=mpl_papersize('a5', 'landscape'))
labelpos = mpl_margins(fig, nw=nfx, nh=nfy, w=7., h=5., wspace=7.,
hspace=2., units=fontsize)
figs.append(fig)
par = problem.parameters[ipar]
axes = fig.add_subplot(nfy, nfx, impl, sharex=axes)
axes = fig.add_subplot(nfy, nfx, impl)
labelpos(axes, 2.5, 2.0)
axes.set_ylabel(par.get_label())
axes.get_yaxis().set_major_locator(plt.MaxNLocator(4))
if impl < (nfx*nfy-1):
axes.get_xaxis().set_visible(False)
else:
axes.set_xlabel('Iteration')
config_axes(axes, nfx, nfy, impl, ipar, npar+ndep+1)
axes.set_ylim(*fixlim(*par.scaled(bounds[ipar])))
axes.set_xlim(0, model.nmodels)
axes.axhline(par.scaled(xref[ipar]), color='black', alpha=0.3)
axes.scatter(
imodels[ibest], par.scaled(xs[ibest, ipar]), s=3, c=iorder[ibest],
lw=0, cmap=cmap, alpha=alpha)
imodels[ibest], par.scaled(xs[ibest, ipar]), s=msize,
c=iorder[ibest], edgecolors='none', cmap=cmap, alpha=alpha)
axes.axhline(par.scaled(xref[ipar]), color='black', alpha=0.3)
for idep in xrange(ndep):
# ifz, ify, ifx = num.unravel_index(ipar, (nfz, nfy, nfx))
impl = (npar+idep) % (nfx*nfy) + 1
if impl == 1:
fig = plt.figure()
fig = plt.figure(figsize=mpl_papersize('a5', 'landscape'))
labelpos = mpl_margins(fig, nw=nfx, nh=nfy, w=7., h=5., wspace=7.,
hspace=2., units=fontsize)
figs.append(fig)
par = problem.dependants[idep]
axes = fig.add_subplot(nfy, nfx, impl, sharex=axes)
axes = fig.add_subplot(nfy, nfx, impl)
labelpos(axes, 2.5, 2.0)
axes.set_ylabel(par.get_label())
axes.get_yaxis().set_major_locator(plt.MaxNLocator(4))
if impl < (nfx*nfy-1):
axes.get_xaxis().set_visible(False)
else:
axes.set_xlabel('Iteration')
config_axes(axes, nfx, nfy, impl, npar+idep, npar+ndep+1)
axes.set_ylim(*fixlim(*par.scaled(bounds[npar+idep])))
axes.set_xlim(0, model.nmodels)
y = problem.make_dependant(xref, par.name)
axes.axhline(par.scaled(y), color='black', alpha=0.3)
ys = problem.make_dependant(xs[ibest, :], par.name)
axes.scatter(
imodels[ibest], par.scaled(ys), s=3, c=iorder[ibest],
lw=0, cmap=cmap, alpha=alpha)
imodels[ibest], par.scaled(ys), s=msize, c=iorder[ibest],
edgecolors='none', cmap=cmap, alpha=alpha)
y = problem.make_dependant(xref, par.name)
axes.axhline(par.scaled(y), color='black', alpha=0.3)
impl = (npar+ndep) % (nfx*nfy) + 1
if impl == 1:
fig = plt.figure()
fig = plt.figure(figsize=mpl_papersize('a5', 'landscape'))
labelpos = mpl_margins(fig, nw=nfx, nh=nfy, w=7., h=5., wspace=7.,
hspace=2., units=fontsize)
figs.append(fig)
axes = fig.add_subplot(nfy, nfx, impl, sharex=axes)
axes = fig.add_subplot(nfy, nfx, impl)
labelpos(axes, 2.5, 2.0)
config_axes(axes, nfx, nfy, impl, npar+ndep, npar+ndep+1)
axes.set_ylim(0., 1.5)
axes.axhspan(1.0, 1.5, color=(0.8, 0.8, 0.8), alpha=0.2)
axes.axhline(1.0, color=(0.5, 0.5, 0.5), zorder=2)
axes.set_yticks([0., 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4])
axes.set_yticklabels(['0.0', '0.2', '0.4', '0.6', '0.8', '1', '10', '100'])
axes.scatter(
imodels[ibest], gms_softclip[ibest], c=iorder[ibest],
s=3, lw=0, cmap=cmap, alpha=alpha)
s=msize, edgecolors='none', cmap=cmap, alpha=alpha)
axes.axhspan(1.0, 1.5, color=(0.8, 0.8, 0.8), alpha=0.2)
axes.axhline(1.0, color=(0.5, 0.5, 0.5), zorder=2)
axes.set_xlim(0, model.nmodels)
axes.set_xlabel('Iteration')
......@@ -624,7 +657,11 @@ def draw_solution_figure(
def draw_contributions_figure(model, plt):
fig = plt.figure()
fontsize = 10.
fig = plt.figure(figsize=mpl_papersize('a5', 'landscape'))
labelpos = mpl_margins(fig, nw=2, nh=2, w=7., h=5., wspace=2.,
hspace=5., units=fontsize)
problem = model.problem
if not problem:
......@@ -656,12 +693,14 @@ def draw_contributions_figure(model, plt):
# nrows = ((problem.ntargets + 1) - 1) / ncols + 1
axes = fig.add_subplot(2, 2, 1)
labelspace(axes)
labelpos(axes, 2.5, 2.0)
axes.set_ylabel('Relative contribution (smoothed)')
axes.set_ylim(0.0, 1.0)
axes2 = fig.add_subplot(2, 2, 3, sharex=axes)
labelspace(axes2)
labelpos(axes2, 2.5, 2.0)
axes2.set_xlabel('Tested model, sorted descending by global misfit value')
axes2.set_ylabel('Square of misfit')
......@@ -682,7 +721,6 @@ def draw_contributions_figure(model, plt):
b /= num.sum(b)
a = [1]
ii = 0
for itarget in jsort:
target = problem.targets[itarget]
ms = gcms[:, itarget]
......@@ -700,11 +738,16 @@ def draw_contributions_figure(model, plt):
[rel_ms_smooth_sum[::-1], rel_ms_smooth_sum + rel_ms_smooth])
poly_x = num.concatenate([imodels[::-1], imodels])
add_args = {}
if ii < 20:
add_args['label'] = '%s (%.2g)' % (
target.string_id(), num.mean(rel_ms[-1]))
axes.fill(
poly_x, rel_poly_y,
alpha=0.5,
color=colors[ii % len(colors)],
label='%s (%.2g)' % (target.string_id(), num.mean(rel_ms[-1])))
**add_args)
poly_y = num.concatenate(
[ms_smooth_sum[::-1], ms_smooth_sum + ms_smooth])
......@@ -720,14 +763,13 @@ def draw_contributions_figure(model, plt):
ii += 1
axes.legend(
title='Contributions (large to small at minimal global misfit)',
title='Contributions (top twenty)',
bbox_to_anchor=(1.05, 0.0, 1.0, 1.0),
loc='upper left',
ncol=2, borderaxespad=0., prop={'size': 12})
ncol=1, borderaxespad=0., prop={'size': 9})
axes2.plot(imodels, gms_softclip, color='black')
axes2.axhline(1.0, color=(0.5, 0.5, 0.5))
fig.tight_layout()
return [fig]
......@@ -873,7 +915,8 @@ def plot_dtrace_vline(axes, t, space, **kwargs):
def draw_fits_figures(ds, model, plt):
fontsize = 10
fontsize = 8
fontsize_title = 10
problem = model.problem
......@@ -1073,7 +1116,17 @@ def draw_fits_figures(ds, model, plt):
ixx = ix/nxmax
iyy = iy/nymax
if (iyy, ixx) not in figures:
figures[iyy, ixx] = plt.figure(figsize=(16, 9))
figures[iyy, ixx] = plt.figure(
figsize=mpl_papersize('a4', 'landscape'))
figures[iyy, ixx].subplots_adjust(
left=0.03,
right=1.0 - 0.03,
bottom=0.03,
top=1.0 - 0.06,
wspace=0.2,
hspace=0.2)
figs.append(figures[iyy, ixx])
fig = figures[iyy, ixx]
......@@ -1083,12 +1136,13 @@ def draw_fits_figures(ds, model, plt):
amin, amax = trace_minmaxs[target.super_group, target.group]
absmax = max(abs(amin), abs(amax))
ny_this = min(ny, nymax)
nx_this = min(nx, nxmax)
ny_this = nymax # min(ny, nymax)
nx_this = nxmax # min(nx, nxmax)
i_this = (iy % ny_this) * nx_this + (ix % nx_this) + 1
axes2 = fig.add_subplot(ny_this, nx_this, i_this)
space = 0.5
space_factor = 1.0 + space
axes2.set_axis_off()
......@@ -1152,8 +1206,8 @@ def draw_fits_figures(ds, model, plt):
space, 0., asmax,
syn_color=syn_color,
obs_color=obs_color,
syn_lw=1.5,
obs_lw=1.0,
syn_lw=1.0,
obs_lw=0.75,
color_vline=tap_color_annot,
fontsize=fontsize)
......@@ -1165,19 +1219,22 @@ def draw_fits_figures(ds, model, plt):
plot_trace(
axes, result.filtered_syn,
color=syn_color_light, lw=1.5)
color=syn_color_light, lw=1.0)
plot_trace(
axes, result.filtered_obs,
color=obs_color_light)
color=obs_color_light, lw=0.75)
plot_trace(
axes, result.processed_syn,
color=syn_color, lw=1.5)
color=syn_color, lw=1.0)
plot_trace(
axes, result.processed_obs,
color=obs_color)
color=obs_color, lw=0.75)
xdata = result.filtered_obs.get_xdata()
axes.set_xlim(xdata[0], xdata[-1])
tmarks = [
result.processed_obs.tmin,
......@@ -1259,7 +1316,7 @@ def draw_fits_figures(ds, model, plt):
if len(figures) > 1:
title += ' (%i/%i, %i/%i)' % (iyy+1, nyy, ixx+1, nxx)
fig.suptitle(title, fontsize=fontsize)
fig.suptitle(title, fontsize=fontsize_title)
return figs
......@@ -1267,7 +1324,7 @@ def draw_fits_figures(ds, model, plt):
def draw_hudson_figure(model, plt):
color = 'black'
fontsize = 12.
fontsize = 10.
markersize = fontsize * 1.5
markersize_small = markersize * 0.2
beachballsize = markersize
......@@ -1428,7 +1485,9 @@ def plot_result(dirname, plotnames_want,
raise core.GrondError(
'unavailable plotname: %s' % ', '.join(unavailable))
mpl_init()
fontsize = 10.0
mpl_init(fontsize=fontsize)
fns = []
if 3 != len({'bootstrap', 'sequence', 'contributions'} - plotnames_want):
......
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