mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
Added submodule input/hadrons
This commit is contained in:
parent
b48326244e
commit
cb44675486
2 changed files with 57 additions and 0 deletions
|
@ -1,2 +1,3 @@
|
||||||
from .input import *
|
from .input import *
|
||||||
from . import bdio
|
from . import bdio
|
||||||
|
from . import hadrons
|
||||||
|
|
56
pyerrors/input/hadrons.py
Normal file
56
pyerrors/input/hadrons.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
import os
|
||||||
|
import h5py
|
||||||
|
import numpy as np
|
||||||
|
from ..pyerrors import Obs
|
||||||
|
from ..correlators import Corr
|
||||||
|
|
||||||
|
def read_meson_hd5(path, filestem, ens_id, meson='meson_0'):
|
||||||
|
"""Read hadrons meson hdf5 file and extract the meson labeled 'meson'
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-----------------
|
||||||
|
path -- path to the files to read
|
||||||
|
filestem -- namestem of the files to read
|
||||||
|
ens_id -- name of the ensemble, required for internal bookkeeping
|
||||||
|
meson -- label of the meson to be extracted, standard value meson_0 which corresponds to the pseudoscalar pseudoscalar two-point function.
|
||||||
|
"""
|
||||||
|
ls = []
|
||||||
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
|
ls.extend(filenames)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Clean up file list
|
||||||
|
files = []
|
||||||
|
for l in ls:
|
||||||
|
if l.startswith(filestem):
|
||||||
|
files.append(l)
|
||||||
|
|
||||||
|
# Sort according to configuration number
|
||||||
|
get_cnfg_number = lambda x : int(x[len(filestem) + 1:-3])
|
||||||
|
files.sort(key=get_cnfg_number)
|
||||||
|
|
||||||
|
# Check that configurations are evenly spaced
|
||||||
|
cnfg_numbers = []
|
||||||
|
for l in files:
|
||||||
|
cnfg_numbers.append(get_cnfg_number(l))
|
||||||
|
|
||||||
|
if not all(np.diff(cnfg_numbers)==np.diff(cnfg_numbers)[0]):
|
||||||
|
raise Exception('Configurations are not evenly spaced.')
|
||||||
|
|
||||||
|
corr_data = []
|
||||||
|
for hd5_file in files:
|
||||||
|
file = h5py.File(path + '/' + hd5_file, "r")
|
||||||
|
|
||||||
|
raw_data = list(file['meson/' + meson + '/corr'])
|
||||||
|
real_data = [o[0] for o in raw_data]
|
||||||
|
corr_data.append(real_data)
|
||||||
|
corr_data = np.array(corr_data)
|
||||||
|
|
||||||
|
l_obs = []
|
||||||
|
for c in corr_data.T:
|
||||||
|
l_obs.append(Obs([c], [ens_id]))
|
||||||
|
|
||||||
|
return Corr(l_obs)
|
Loading…
Add table
Add a link
Reference in a new issue