[plotting] tests now compare the arrays of the figure, instead of the platform dependend png images
|
|
@ -112,7 +112,7 @@ def plot_latent_inducing(self,
|
||||||
which_indices=None,
|
which_indices=None,
|
||||||
legend=False,
|
legend=False,
|
||||||
plot_limits=None,
|
plot_limits=None,
|
||||||
marker='^',
|
marker=None,
|
||||||
num_samples=1000,
|
num_samples=1000,
|
||||||
projection='2d',
|
projection='2d',
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
@ -124,16 +124,18 @@ def plot_latent_inducing(self,
|
||||||
:param bool legend: whether to plot the legend on the figure
|
:param bool legend: whether to plot the legend on the figure
|
||||||
:param plot_limits: the plot limits for the plot
|
:param plot_limits: the plot limits for the plot
|
||||||
:type plot_limits: (xmin, xmax, ymin, ymax) or ((xmin, xmax), (ymin, ymax))
|
:type plot_limits: (xmin, xmax, ymin, ymax) or ((xmin, xmax), (ymin, ymax))
|
||||||
:param str marker: markers to use - cycle if more labels then markers are given
|
:param str marker: marker to use [default is custom arrow like]
|
||||||
:param kwargs: the kwargs for the scatter plots
|
:param kwargs: the kwargs for the scatter plots
|
||||||
"""
|
"""
|
||||||
canvas, projection, kwargs, sig_dims = _new_canvas(self, projection, kwargs, which_indices)
|
canvas, projection, kwargs, sig_dims = _new_canvas(self, projection, kwargs, which_indices)
|
||||||
|
|
||||||
Z = self.Z.values
|
if legend: label = 'inducing'
|
||||||
labels = np.array(['inducing'] * Z.shape[0])
|
else: label = None
|
||||||
kwargs['marker'] = marker
|
if marker is not None:
|
||||||
|
kwargs['marker'] = marker
|
||||||
update_not_existing_kwargs(kwargs, pl().defaults.inducing_2d) # @UndefinedVariable
|
update_not_existing_kwargs(kwargs, pl().defaults.inducing_2d) # @UndefinedVariable
|
||||||
scatters = _plot_latent_scatter(canvas, Z, sig_dims, labels, num_samples=num_samples, projection=projection, **kwargs)
|
from .data_plots import _plot_inducing
|
||||||
|
scatters = _plot_inducing(self, canvas, sig_dims[:2], projection, label, num_samples=num_samples, **kwargs)
|
||||||
return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ it gives back an empty default, when defaults are not defined.
|
||||||
# Data plots:
|
# Data plots:
|
||||||
data_1d = dict(lw=1.5, marker='x', color='k')
|
data_1d = dict(lw=1.5, marker='x', color='k')
|
||||||
data_2d = dict(s=35, edgecolors='none', linewidth=0., cmap=cm.get_cmap('hot'), alpha=.5)
|
data_2d = dict(s=35, edgecolors='none', linewidth=0., cmap=cm.get_cmap('hot'), alpha=.5)
|
||||||
inducing_1d = dict(lw=0, s=500, facecolors=Tango.colorsHex['darkRed'])
|
inducing_1d = dict(lw=0, s=500, color=Tango.colorsHex['darkRed'])
|
||||||
inducing_2d = dict(s=17, edgecolor='k', linewidth=.4, color='white', alpha=.5, marker='^')
|
inducing_2d = dict(s=17, edgecolor='k', linewidth=.4, color='white', alpha=.5, marker='^')
|
||||||
inducing_3d = dict(lw=.3, s=500, color=Tango.colorsHex['darkRed'], edgecolor='k')
|
inducing_3d = dict(lw=.3, s=500, color=Tango.colorsHex['darkRed'], edgecolor='k')
|
||||||
xerrorbar = dict(color='k', fmt='none', elinewidth=.5, alpha=.5)
|
xerrorbar = dict(color='k', fmt='none', elinewidth=.5, alpha=.5)
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
||||||
return ax.plot(X, Y, color=color, zs=Z, label=label, **kwargs)
|
return ax.plot(X, Y, color=color, zs=Z, label=label, **kwargs)
|
||||||
return ax.plot(X, Y, color=color, label=label, **kwargs)
|
return ax.plot(X, Y, color=color, label=label, **kwargs)
|
||||||
|
|
||||||
def plot_axis_lines(self, ax, X, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
def plot_axis_lines(self, ax, X, color=Tango.colorsHex['darkRed'], label=None, **kwargs):
|
||||||
from matplotlib import transforms
|
from matplotlib import transforms
|
||||||
from matplotlib.path import Path
|
from matplotlib.path import Path
|
||||||
if 'marker' not in kwargs:
|
if 'marker' not in kwargs:
|
||||||
|
|
@ -126,14 +126,14 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
||||||
bottom=bottom, label=label, color=color,
|
bottom=bottom, label=label, color=color,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def xerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
def xerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['darkRed'], label=None, **kwargs):
|
||||||
if not('linestyle' in kwargs or 'ls' in kwargs):
|
if not('linestyle' in kwargs or 'ls' in kwargs):
|
||||||
kwargs['ls'] = 'none'
|
kwargs['ls'] = 'none'
|
||||||
#if Z is not None:
|
#if Z is not None:
|
||||||
# return ax.errorbar(X, Y, Z, xerr=error, ecolor=color, label=label, **kwargs)
|
# return ax.errorbar(X, Y, Z, xerr=error, ecolor=color, label=label, **kwargs)
|
||||||
return ax.errorbar(X, Y, xerr=error, ecolor=color, label=label, **kwargs)
|
return ax.errorbar(X, Y, xerr=error, ecolor=color, label=label, **kwargs)
|
||||||
|
|
||||||
def yerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
def yerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['darkRed'], label=None, **kwargs):
|
||||||
if not('linestyle' in kwargs or 'ls' in kwargs):
|
if not('linestyle' in kwargs or 'ls' in kwargs):
|
||||||
kwargs['ls'] = 'none'
|
kwargs['ls'] = 'none'
|
||||||
#if Z is not None:
|
#if Z is not None:
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 196 KiB |
|
Before Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 191 KiB |
BIN
GPy/testing/baseline/coverage_3d_plot.npz
Normal file
|
Before Width: | Height: | Size: 50 KiB |
BIN
GPy/testing/baseline/coverage_annotation_interact.npz
Normal file
|
Before Width: | Height: | Size: 8.9 KiB |
BIN
GPy/testing/baseline/coverage_gradient.npz
Normal file
|
Before Width: | Height: | Size: 5.2 KiB |
BIN
GPy/testing/baseline/coverage_imshow_interact.npz
Normal file
|
Before Width: | Height: | Size: 10 KiB |
BIN
GPy/testing/baseline/gp_2d_data.npz
Normal file
|
Before Width: | Height: | Size: 13 KiB |
BIN
GPy/testing/baseline/gp_2d_in_error.npz
Normal file
|
Before Width: | Height: | Size: 11 KiB |
BIN
GPy/testing/baseline/gp_2d_inducing.npz
Normal file
|
Before Width: | Height: | Size: 12 KiB |
BIN
GPy/testing/baseline/gp_2d_mean.npz
Normal file
|
Before Width: | Height: | Size: 118 KiB |
BIN
GPy/testing/baseline/gp_3d_data.npz
Normal file
|
Before Width: | Height: | Size: 116 KiB |
BIN
GPy/testing/baseline/gp_3d_inducing.npz
Normal file
|
Before Width: | Height: | Size: 108 KiB |
BIN
GPy/testing/baseline/gp_3d_mean.npz
Normal file
|
Before Width: | Height: | Size: 178 KiB |
BIN
GPy/testing/baseline/gp_class_likelihood.npz
Normal file
|
Before Width: | Height: | Size: 36 KiB |
BIN
GPy/testing/baseline/gp_class_raw.npz
Normal file
|
Before Width: | Height: | Size: 50 KiB |
BIN
GPy/testing/baseline/gp_class_raw_link.npz
Normal file
|
Before Width: | Height: | Size: 55 KiB |
BIN
GPy/testing/baseline/gp_conf.npz
Normal file
|
Before Width: | Height: | Size: 29 KiB |
BIN
GPy/testing/baseline/gp_data.npz
Normal file
|
Before Width: | Height: | Size: 14 KiB |
BIN
GPy/testing/baseline/gp_density.npz
Normal file
|
Before Width: | Height: | Size: 115 KiB |
BIN
GPy/testing/baseline/gp_in_error.npz
Normal file
|
Before Width: | Height: | Size: 11 KiB |
BIN
GPy/testing/baseline/gp_mean.npz
Normal file
|
Before Width: | Height: | Size: 23 KiB |
BIN
GPy/testing/baseline/gp_out_error.npz
Normal file
|
Before Width: | Height: | Size: 9.2 KiB |
BIN
GPy/testing/baseline/gp_samples.npz
Normal file
|
Before Width: | Height: | Size: 36 KiB |
BIN
GPy/testing/baseline/gplvm_gradient.npz
Normal file
|
Before Width: | Height: | Size: 43 KiB |
BIN
GPy/testing/baseline/gplvm_latent.npz
Normal file
|
Before Width: | Height: | Size: 182 KiB |
BIN
GPy/testing/baseline/gplvm_latent_3d.npz
Normal file
|
Before Width: | Height: | Size: 121 KiB |
BIN
GPy/testing/baseline/gplvm_magnification.npz
Normal file
|
Before Width: | Height: | Size: 185 KiB |
BIN
GPy/testing/baseline/kern_ARD.npz
Normal file
|
Before Width: | Height: | Size: 14 KiB |
BIN
GPy/testing/baseline/kern_cov_1d.npz
Normal file
|
Before Width: | Height: | Size: 34 KiB |
BIN
GPy/testing/baseline/kern_cov_2d.npz
Normal file
|
Before Width: | Height: | Size: 78 KiB |
BIN
GPy/testing/baseline/kern_cov_3d.npz
Normal file
|
Before Width: | Height: | Size: 206 KiB |
BIN
GPy/testing/baseline/kern_cov_no_lim.npz
Normal file
|
Before Width: | Height: | Size: 58 KiB |
BIN
GPy/testing/baseline/sparse_gp_class_likelihood.npz
Normal file
|
Before Width: | Height: | Size: 40 KiB |
BIN
GPy/testing/baseline/sparse_gp_class_raw.npz
Normal file
|
Before Width: | Height: | Size: 86 KiB |
BIN
GPy/testing/baseline/sparse_gp_class_raw_link.npz
Normal file
|
Before Width: | Height: | Size: 92 KiB |
BIN
GPy/testing/baseline/sparse_gp_data_error.npz
Normal file
|
Before Width: | Height: | Size: 13 KiB |
|
|
@ -72,7 +72,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("Matplotlib not installed, not testing plots")
|
raise SkipTest("Matplotlib not installed, not testing plots")
|
||||||
|
|
||||||
extensions = ['png']
|
extensions = ['npz']
|
||||||
|
|
||||||
def _image_directories():
|
def _image_directories():
|
||||||
"""
|
"""
|
||||||
|
|
@ -93,39 +93,104 @@ baseline_dir, result_dir = _image_directories()
|
||||||
if not os.path.exists(baseline_dir):
|
if not os.path.exists(baseline_dir):
|
||||||
raise SkipTest("Not installed from source, baseline not available. Install from source to test plotting")
|
raise SkipTest("Not installed from source, baseline not available. Install from source to test plotting")
|
||||||
|
|
||||||
def _sequenceEqual(a, b):
|
def _image_comparison(baseline_images, extensions=['pdf','svg','png'], tol=11, decimal=6):
|
||||||
assert len(a) == len(b), "Sequences not same length"
|
|
||||||
for i, [x, y], in enumerate(zip(a, b)):
|
|
||||||
assert x == y, "element not matching {}".format(i)
|
|
||||||
|
|
||||||
def _notFound(path):
|
|
||||||
raise IOError('File {} not in baseline')
|
|
||||||
|
|
||||||
def _image_comparison(baseline_images, extensions=['pdf','svg','png'], tol=11):
|
|
||||||
for num, base in zip(plt.get_fignums(), baseline_images):
|
for num, base in zip(plt.get_fignums(), baseline_images):
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
fig = plt.figure(num)
|
fig = plt.figure(num)
|
||||||
|
fig.canvas.draw()
|
||||||
#fig.axes[0].set_axis_off()
|
#fig.axes[0].set_axis_off()
|
||||||
#fig.set_frameon(False)
|
#fig.set_frameon(False)
|
||||||
fig.canvas.draw()
|
if ext in ['npz']:
|
||||||
fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)),
|
figdict = flatten_axis(fig)
|
||||||
transparent=True,
|
np.savez_compressed(os.path.join(result_dir, "{}.{}".format(base, ext)), **figdict)
|
||||||
edgecolor='none',
|
fig.savefig(os.path.join(result_dir, "{}.{}".format(base, 'png')),
|
||||||
facecolor='none',
|
transparent=True,
|
||||||
#bbox='tight'
|
edgecolor='none',
|
||||||
)
|
facecolor='none',
|
||||||
|
#bbox='tight'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)),
|
||||||
|
transparent=True,
|
||||||
|
edgecolor='none',
|
||||||
|
facecolor='none',
|
||||||
|
#bbox='tight'
|
||||||
|
)
|
||||||
for num, base in zip(plt.get_fignums(), baseline_images):
|
for num, base in zip(plt.get_fignums(), baseline_images):
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
#plt.close(num)
|
#plt.close(num)
|
||||||
actual = os.path.join(result_dir, "{}.{}".format(base, ext))
|
actual = os.path.join(result_dir, "{}.{}".format(base, ext))
|
||||||
expected = os.path.join(baseline_dir, "{}.{}".format(base, ext))
|
expected = os.path.join(baseline_dir, "{}.{}".format(base, ext))
|
||||||
def do_test():
|
if ext == 'npz':
|
||||||
err = compare_images(expected, actual, tol, in_decorator=True)
|
def do_test():
|
||||||
if err:
|
if not os.path.exists(expected):
|
||||||
raise SkipTest("Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(actual, expected, err['rms'], tol))
|
import shutil
|
||||||
|
shutil.copy2(actual, expected)
|
||||||
|
#shutil.copy2(os.path.join(result_dir, "{}.{}".format(base, 'png')), os.path.join(baseline_dir, "{}.{}".format(base, 'png')))
|
||||||
|
raise IOError("Baseline file {} not found, copying result {}".format(expected, actual))
|
||||||
|
else:
|
||||||
|
exp_dict = dict(np.load(expected).items())
|
||||||
|
act_dict = dict(np.load(actual).items())
|
||||||
|
assert(len(exp_dict)==len(act_dict))
|
||||||
|
for name in exp_dict:
|
||||||
|
np.testing.assert_array_almost_equal(exp_dict[name], act_dict[name], decimal, "Mismatch in {}.{}".format(base, name))
|
||||||
|
else:
|
||||||
|
def do_test():
|
||||||
|
err = compare_images(expected, actual, tol, in_decorator=True)
|
||||||
|
if err:
|
||||||
|
raise SkipTest("Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(actual, expected, err['rms'], tol))
|
||||||
yield do_test
|
yield do_test
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
|
|
||||||
|
def flatten_axis(ax, prevname=''):
|
||||||
|
import inspect
|
||||||
|
members = inspect.getmembers(ax)
|
||||||
|
|
||||||
|
arrays = {}
|
||||||
|
|
||||||
|
def _flatten(l, pre):
|
||||||
|
arr = {}
|
||||||
|
if isinstance(l, np.ndarray):
|
||||||
|
if l.size:
|
||||||
|
arr[pre] = np.asarray(l)
|
||||||
|
elif isinstance(l, dict):
|
||||||
|
for _n in l:
|
||||||
|
_tmp = _flatten(l, pre+"."+_n+".")
|
||||||
|
for _nt in _tmp.keys():
|
||||||
|
arrays[_nt] = _tmp[_nt]
|
||||||
|
elif isinstance(l, list) and len(l)>0:
|
||||||
|
for i in range(len(l)):
|
||||||
|
_tmp = _flatten(l[i], pre+"[{}]".format(i))
|
||||||
|
for _n in _tmp:
|
||||||
|
arr["{}".format(_n)] = _tmp[_n]
|
||||||
|
else:
|
||||||
|
return flatten_axis(l, pre+'.')
|
||||||
|
return arr
|
||||||
|
|
||||||
|
|
||||||
|
for name, l in members:
|
||||||
|
if isinstance(l, np.ndarray):
|
||||||
|
arrays[prevname+name] = np.asarray(l)
|
||||||
|
elif isinstance(l, list) and len(l)>0:
|
||||||
|
for i in range(len(l)):
|
||||||
|
_tmp = _flatten(l[i], prevname+name+"[{}]".format(i))
|
||||||
|
for _n in _tmp:
|
||||||
|
arrays["{}".format(_n)] = _tmp[_n]
|
||||||
|
|
||||||
|
return arrays
|
||||||
|
|
||||||
|
def _a(x,y,decimal):
|
||||||
|
np.testing.assert_array_almost_equal(x, y, decimal)
|
||||||
|
|
||||||
|
def compare_axis_dicts(x, y, decimal=6):
|
||||||
|
try:
|
||||||
|
assert(len(x)==len(y))
|
||||||
|
for name in x:
|
||||||
|
_a(x[name], y[name], decimal)
|
||||||
|
except AssertionError as e:
|
||||||
|
raise SkipTest(e.message)
|
||||||
|
|
||||||
def test_figure():
|
def test_figure():
|
||||||
np.random.seed(1239847)
|
np.random.seed(1239847)
|
||||||
from GPy.plotting import plotting_library as pl
|
from GPy.plotting import plotting_library as pl
|
||||||
|
|
|
||||||