Skip to content

Commit

Permalink
formated with flycheck
Browse files Browse the repository at this point in the history
  • Loading branch information
f4hy committed Sep 5, 2013
1 parent 0cdc76e commit 0c75956
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions alt_zfactor.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import logging
import argparse
import plot_files
import pandas as pd
import level_identifier
import pandas_reader
import re
import zfactor


def build_cor_mat_error(corwild, ops, to):
N = len(ops)
cormat = np.matrix(np.zeros((N,N)), dtype=np.complex128)
errmat = np.matrix(np.zeros((N,N)), dtype=np.complex128)
for col,src in enumerate(ops):
for row,snk in enumerate(ops):
logging.debug("Reading snk:{}, src:{}".format(snk,src))
raw_c = plot_files.read_file(corwild.format(snk,src))
cormat = np.matrix(np.zeros((N, N)), dtype=np.complex128)
errmat = np.matrix(np.zeros((N, N)), dtype=np.complex128)
for col, src in enumerate(ops):
for row, snk in enumerate(ops):
logging.debug("Reading snk:{}, src:{}".format(snk, src))
raw_c = plot_files.read_file(corwild.format(snk, src))
df = raw_c
Cij = df.ix[df['time'] == to, 'correlator']
cormat[row,col] = np.array(Cij)[0]
cormat[row, col] = np.array(Cij)[0]
Eij = df.ix[df['time'] == to, 'error']
errmat[row,col] = np.array(Eij)[0]
errmat[row, col] = np.array(Eij)[0]
return cormat, errmat


Expand All @@ -31,6 +28,7 @@ def read_zrots(filename):
df = pd.read_csv(txt, delimiter=',', names=["level", "amp", "error"], index_col=0)
return df


def read_level_fits(filename):
"""
Read in fit values to the levels. Fits should be single exp
Expand All @@ -52,10 +50,10 @@ def alt_zfactor(corwild, zrotfile, rotfile, ops, t0, outputstub,
fit_values = read_level_fits(zrotfile)
N = len(fit_values)
N = len(ops)
levels_to_make=levels_to_make = range(min(N,maxlevels))
levels_to_make = range(min(N, maxlevels))
raw_v = zfactor.read_coeffs_file(rotfile)
v = np.matrix(raw_v.identities.values.reshape((N,N))).T
roterror = np.matrix(raw_v.error.values.reshape((N,N))).T
v = np.matrix(raw_v.identities.values.reshape((N, N))).T
roterror = np.matrix(raw_v.error.values.reshape((N, N))).T
cormat, errmat = build_cor_mat_error(corwild, ops, t0)

Zs = {}
Expand All @@ -64,19 +62,19 @@ def alt_zfactor(corwild, zrotfile, rotfile, ops, t0, outputstub,
zr = fit_values.amp[level]
#err[level] = zrots.error[level]*np.ones(N)
for op in range(N):
v_n = (v[:,level])
ev_n = np.ravel(roterror[:,level])
Zs[level] = [np.abs((cormat[j]*(v_n)).flat[0])*np.sqrt(zr) for j in range(len(ops)) ]
err[level] = [np.abs((cormat[j]*(v_n)).flat[0])*np.sqrt(fit_values.amp_error[level])+
v_n = (v[:, level])
ev_n = np.ravel(roterror[:, level])
Zs[level] = [np.abs((cormat[j]*(v_n)).flat[0])*np.sqrt(zr) for j in range(len(ops))]
err[level] = [np.abs((cormat[j]*(v_n)).flat[0])*np.sqrt(fit_values.amp_error[level]) +
np.abs((errmat[j]*(v_n)).flat[0])*np.sqrt(zr)
for j in range(len(ops)) ]
for j in range(len(ops))]
#err[level] = np.sqrt(fit_values.amp_error[level])*np.abs(v_n)+np.sqrt(zr)*np.abs(ev_n)
normalized_Zs = zfactor.normalize_Zs(Zs, normalize)
A = np.array(Zs.values())
maximums = np.array([max(np.abs(A[:,i])) for i in range(len(Zs[0]))])
maximums = np.array([max(np.abs(A[:, i])) for i in range(len(Zs[0]))])
if normalize:
normalized_Zs = {k: np.abs(values)/maximums for k,values in Zs.iteritems()}
normalized_err = {k: np.abs(values)/maximums for k,values in err.iteritems()}
normalized_Zs = {k: np.abs(values)/maximums for k, values in Zs.iteritems()}
normalized_err = {k: np.abs(values)/maximums for k, values in err.iteritems()}
else:
normalized_Zs = Zs
normalized_err = err
Expand All @@ -101,17 +99,16 @@ def reconstructed_correaltors(Zs, error, fit_values, ops, stub):
emasses_err = fit_values.mass_error
for i in range(len(Zs[0])):
for j in range(len(Zs[0])):
with open("{}.{}.{}.cor".format(stub,ops[i],ops[j]),"w") as outfile:
with open("{}.{}.{}.cor".format(stub, ops[i], ops[j]), "w") as outfile:
for t in range(40):
C = sum((Zs[level][i]*np.conj(Zs[level][j]))*np.exp(-1.0*emasses[level]*t) for level in Zs.keys())
Cerr = sum((error[level][i]*np.conj(Zs[level][j]))*np.exp(-1.0*emasses[level]*t)+
(Zs[level][i]*np.conj(error[level][j]))*np.exp(-1.0*emasses[level]*t)+
Cerr = sum((error[level][i]*np.conj(Zs[level][j]))*np.exp(-1.0 * emasses[level] * t)+
(Zs[level][i]*np.conj(error[level][j]))*np.exp(-1.0 * emasses[level] * t)+
(Zs[level][i]*np.conj(Zs[level][j]))*np.exp(-1.0*emasses[level]*t)*(-1.0*emasses_err[level]*t)
for level in Zs.keys())
outfile.write("{} ({},{}) ({},{})\n".format(t, np.real(C), np.imag(C), np.real(Cerr), np.imag(Cerr)))



if __name__ == "__main__":

parser = argparse.ArgumentParser(description="Compute the Zfactors from the correlator and diagonalized coeffs")
Expand Down Expand Up @@ -143,4 +140,5 @@ def reconstructed_correaltors(Zs, error, fit_values, ops, stub):
else:
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)

alt_zfactor(args.inputcorrelatorformat, args.z_rot, args.inputrotationcoeffs, args.operators, args.tnaught, args.output_stub, args.number, args.normalize, args.reconstruct_stub)
alt_zfactor(args.inputcorrelatorformat, args.z_rot, args.inputrotationcoeffs, args.operators,
args.tnaught, args.output_stub, args.number, args.normalize, args.reconstruct_stub)

0 comments on commit 0c75956

Please sign in to comment.