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) if not args.operators: logging.info("Operators not specified, attempting to automagically determine") ops = determine_operators.matching_operators(args.input_dir, args.filewild) logging.info("Operators automagically found to be {}".format(",".join(ops))) if not ops: logging.error("Error: no operators found") parser.print_help() parser.exit() args.operators = ops else: ops = readops(args.operators) logging.debug("found operators: {}".format(','.join(ops))) args.operators = ops cor_matrix = {} for snk in args.operators: for src in args.operators: filename = args.input_dir + args.filewild.format(snk, src) logging.info("reading {}".format(filename)) cor_matrix[snk+src] = pandas_reader.read_configcols_paraenformat(filename) correlator_pannel = pd.Panel(cor_matrix) length = correlator_pannel.shape[0] n = int(np.sqrt(length)) B = np.matrix(np.reshape(correlator_pannel.major_xs(args.time).mean().values, (n, n)))
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()
#!/usr/bin/env python import argparse import logging from level_identifier import readops if __name__ == "__main__": parser = argparse.ArgumentParser(description="oplist B is a sebset of oplist A") parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity") parser.add_argument('A', metavar='oplistA', type=str, help='OplistA') parser.add_argument('B', metavar='oplistB', type=str, help='OplistB') 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.WARN) if set(readops(args.B)) == (set([i for i in readops(args.A) if not i.startswith("iso")])): logging.debug("{} is the single particle subset of {}".format(args.B, args.A)) exit(0) else: logging.debug("{} is NOT the single subset of {} returning 1".format(args.B, args.A)) exit(1)