diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 94dd2f09..ac3f8b07 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -794,7 +794,34 @@ class Corr: else: raise Exception("'save' has to be a string.") - return + def spaghetti_plot(self, logscale=True): + """Produces a spaghetti plot of the correlator suited to monitor exceptional configurations. + + Parameters + ---------- + logscale : bool + Determines whether the scale of the y-axis is logarithmic or standard. + """ + if self.N != 1: + raise Exception("Correlator needs to be projected first.") + + mc_names = list(set([item for sublist in [o[0].mc_names for o in self.content if o is not None] for item in sublist])) + x0_vals = [n for (n, o) in zip(np.arange(self.T), self.content) if o is not None] + + for name in mc_names: + data = np.array([o[0].deltas[name] + o[0].r_values[name] for o in self.content if o is not None]).T + + fig = plt.figure() + ax = fig.add_subplot(111) + for dat in data: + ax.plot(x0_vals, dat, ls='-', marker='') + + if logscale is True: + ax.set_yscale('log') + + ax.set_xlabel(r'$x_0 / a$') + plt.title(name) + plt.draw() def dump(self, filename, datatype="json.gz", **kwargs): """Dumps the Corr into a file of chosen type diff --git a/tests/correlators_test.py b/tests/correlators_test.py index 9a2e7ea1..8ebca6aa 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -325,10 +325,20 @@ def test_corr_vector_operations(): assert np.all([o == 0 for o in ((my_corr * my_vec) / my_vec) - my_corr]) assert np.all([o == 0 for o in ((my_corr / my_vec) * my_vec) - my_corr]) -def _gen_corr(val): + +def test_spaghetti_plot(): + corr = _gen_corr(12, 50) + corr += pe.pseudo_Obs(0.0, 0.1, 'another_ensemble') + corr += pe.cov_Obs(0.0, 0.01 ** 2, 'covobs') + + corr.spaghetti_plot(True) + corr.spaghetti_plot(False) + + +def _gen_corr(val, samples=2000): corr_content = [] for t in range(16): - corr_content.append(pe.pseudo_Obs(val, 0.1, 't', 2000)) + corr_content.append(pe.pseudo_Obs(val, 0.1, 't', samples)) return pe.correlators.Corr(corr_content)