From b901dce5825caaff9b3f646366fce2e3f29b04b1 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 5 Oct 2021 17:06:03 +0100 Subject: [PATCH] generalized read_mesons, added ylabel to Corr.show --- pyerrors/correlators.py | 4 +++- pyerrors/input/hadrons.py | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index dc5f181e..0b2a61ad 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -293,7 +293,7 @@ class Corr: #quick and dirty plotting function to view Correlator inside Jupyter #If one would not want to import pyplot, this could easily be replaced by a call to pe.plot_corrs #This might be a bit more flexible later - def show(self, x_range=None, comp=None, logscale=False, plateau=None, fit_res=None, save=None): + def show(self, x_range=None, comp=None, logscale=False, plateau=None, fit_res=None, save=None, ylabel=None): """Plots the correlator, uses tag as label if available. Parameters @@ -345,6 +345,8 @@ class Corr: , ls='-', marker=',', lw=2) ax1.set_xlabel(r'$x_0 / a$') + if ylabel: + ax1.set_ylabel(ylabel) ax1.set_xlim([x_range[0] - 0.5, x_range[1] + 0.5]) handles, labels = ax1.get_legend_handles_labels() diff --git a/pyerrors/input/hadrons.py b/pyerrors/input/hadrons.py index b63f385d..f4c0f50c 100644 --- a/pyerrors/input/hadrons.py +++ b/pyerrors/input/hadrons.py @@ -7,7 +7,7 @@ import numpy as np from ..pyerrors import Obs from ..correlators import Corr -def read_meson_hd5(path, filestem, ens_id, meson='meson_0'): +def read_meson_hd5(path, filestem, ens_id, meson='meson_0', tree='meson'): """Read hadrons meson hdf5 file and extract the meson labeled 'meson' Parameters @@ -28,6 +28,9 @@ def read_meson_hd5(path, filestem, ens_id, meson='meson_0'): if l.startswith(filestem): files.append(l) + if not files: + raise Exception('No files starting with', filestem, 'in folder', path) + # Sort according to configuration number get_cnfg_number = lambda x : int(x[len(filestem) + 1:-3]) files.sort(key=get_cnfg_number) @@ -44,7 +47,7 @@ def read_meson_hd5(path, filestem, ens_id, meson='meson_0'): for hd5_file in files: file = h5py.File(path + '/' + hd5_file, "r") - raw_data = list(file['meson/' + meson + '/corr']) + raw_data = list(file[tree + '/' + meson + '/corr']) real_data = [o[0] for o in raw_data] corr_data.append(real_data) corr_data = np.array(corr_data)