generalized read_mesons, added ylabel to Corr.show

This commit is contained in:
Fabian Joswig 2021-10-05 17:06:03 +01:00
parent f2b8a9580b
commit b901dce582
2 changed files with 8 additions and 3 deletions

View file

@ -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()

View file

@ -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)