help="file to read the zfactors") parser.add_argument("-m", "--masses", type=float, nargs="+", required=True, help="list of masses for each level") parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity") args = parser.parse_args() if args.verbose: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) logging.debug("Verbose debuging mode activated") else: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) N = len(args.masses) raw_Zs = zfactor.read_coeffs_file(args.overlapsfile) assert len(raw_Zs)==N*N, "Length missmatch in levels and coeffs" print raw_Zs Zs = np.matrix(raw_Zs.identities.values.reshape((N, N))).T print Zs print "blah" for i in range(N): for j in range(N): print "Correlator_{}{}".format(i,j) amps = [Zs[i,level]*Zs[j,level] for level in range(N)] print "newaps", amps cor = fakecor.make_fake_cor(args.configs, args.times, amps, args.masses) cor.writefullfile(args.output_stub+"{}_{}".format(i,j), comp=True) logging.info("done")
def sh_optimized_zfacts(): shops = readops(args.single_hadron_ops) mhops = readops(args.full_hadron_ops) rotco = overlaps(read_coeffs_file(args.rotation_coeffs)) fullz = overlaps(read_file(args.full_zfactors)) indicies = [mhops.index(o)+1 for o in shops] OptZ = {} # Main calculation below # TODO this should be done as matrix multiplication, would be WAY faster but this works. for m in range(1,rotco.levels+1): value = np.array([np.abs(np.array(np.matrix( np.conj(rotco.get_level(m))) * np.matrix([fullz.get_entry(i,l) for i in indicies]).T))**2 for l in range(1,fullz.levels+1)]).flatten() if np.all(value==0): break OptZ[m] = value with open(args.ordering) as orderfile: ordering = [int(i.strip()) for i in orderfile.readlines()] N = len(OptZ.keys()) if args.number: N = min(N,args.number) if args.columns: Ncols = args.columns else: Ncols = ncols(N) rows = int(math.ceil(float(N)/Ncols)) if not args.seperate: fig, ax = plt.subplots(ncols=Ncols, nrows=rows) with open(args.SHordering) as SHorderfile: SHordering = [int(i.strip()) for i in SHorderfile.readlines()] for index, m in enumerate(SHordering): if index >= N: break i = (index)/Ncols j = (index) % Ncols if args.seperate: fig, axe = plt.subplots(1) else: if N <= Ncols: axe=ax[j] else: axe=ax[i][j] reordered = [OptZ[m+1][reorderedlevel] for reorderedlevel in ordering] axe.bar(range(len(reordered)), reordered, 1.0, color="b") # axe.set_title("SH-opt level{}".format(index)) axe.set_ylim((0,max(reordered))) axe.set_ylabel("$|Z|^2$", fontweight='bold', fontsize=30) axe.set_xlabel("Level", fontweight='bold', fontsize=30) axe.tick_params(axis='both', which='major', labelsize=20) plt.tight_layout() if args.seperate: outfilename = args.output_stub+"_{}.eps".format(index) logging.info("Saving plot to {}".format(outfilename)) plt.savefig(outfilename) plt.clf() if args.seperate: return if args.output_stub: logging.info("Saving unreordered shopt_zfactors to {}".format(args.output_stub+".nonreordered.out")) with open(args.output_stub+".out", 'w') as outfile: for level,d in OptZ.iteritems(): outfile.write("{}, {}\n".format(level, ", ".join(map(str,d)))) logging.info("Saving shcandidates to {}".format(args.output_stub+".singleresonances")) with open(args.output_stub+".singleresonances", 'w') as resfile: for level,d in OptZ.iteritems(): fixd = np.nan_to_num(d) if max(fixd) > 0: resfile.write("{}, {}\n".format(level, np.argmax(fixd))) plt.rcParams.update({'font.size': 10}) fig.set_size_inches(18.5,8.5) plt.tight_layout() if args.eps: logging.info("Saving plot to {}".format(args.output_stub+".eps")) plt.savefig(args.output_stub+".eps") else: logging.info("Saving plot to {}".format(args.output_stub+".png")) plt.savefig(args.output_stub+".png",dpi=100) else: plt.tight_layout() plt.show()
def alt_zfactor(corwild, zrotfile, rotfile, ops, t0, outputstub, maxlevels=None, normalize=False, reconstruct_stub=None, inputemass=None): # zrots = read_zrots(zrotfile) fit_values = read_level_fits(zrotfile) N = len(fit_values) N = len(ops) levels_to_make = range(min(N, maxlevels, len(fit_values))) 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 cormat, errmat = build_cor_mat_error(corwild, ops, t0) Zs = {} err = {} ABS = np.abs def nothing(a): return a if args.complex: ABS = nothing for level in levels_to_make: 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] = [ABS((cormat[j]*(v_n)).flat[0])*np.sqrt(zr) for j in range(len(ops))] err[level] = [ABS((cormat[j]*(v_n)).flat[0])*np.sqrt(fit_values.amp_error[level]) + ABS((errmat[j]*(v_n)).flat[0])*np.sqrt(zr) for j in range(len(ops))] #err[level] = np.sqrt(fit_values.amp_error[level])*ABS(v_n)+np.sqrt(zr)*ABS(ev_n) # normalized_Zs = zfactor.normalize_Zs(Zs, normalize) A = np.array(Zs.values()) if normalize: maximums = np.array([max(np.abs(A[:, i])) for i in range(len(Zs[0]))]) 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 # print err # print normalized_err if(outputstub): logging.info("Writing alt_zfactors to {}".format(outputstub+".out")) with open(outputstub+".out", 'w') as outfile: outfile.write("# normalized Zfactors\n") for level in levels_to_make: for j in range(N): if args.complex: outfile.write("{:d}{:03d} ({},{}) ({},{})\n".format(j+1, level+1, np.real(normalized_Zs[level][j]), np.imag(normalized_Zs[level][j]), np.real(normalized_err[level][j]), np.imag(normalized_err[level][j]))) else: outfile.write("{:d}{:03d} {} {}\n".format(j+1, level+1, normalized_Zs[level][j], normalized_err[level][j])) if(reconstruct_stub): reconstructed_correaltors(Zs, err, fit_values, ops, reconstruct_stub)