17 from commoncode import getConfigParser, getConfigOption, getConfigIntOption, getConfigBoolOption
20 print "plotprofile: version 2.3"
26 usage = "usage: python %s infile outfile.png [--scale] [--max weightMax] [--ymin bottom] [--ymax top] [--subtractEvens]"
28 parser = makeParser(usage)
29 (options, args) = parser.parse_args(argv[1:])
38 plotprofile(infile, pngfilename, options.doScale, options.weightMax, options.ymin, options.ymax, options.subtractEvens)
41 def makeParser(usage=""):
42 parser = optparse.OptionParser(usage=usage)
43 parser.add_option("--scale", action="store_true", dest="doScale")
44 parser.add_option("--max", type="float", dest="weightMax")
45 parser.add_option("--ymin", type="float", dest="ymin")
46 parser.add_option("--ymax", type="float", dest="ymax")
47 parser.add_option("--subtractEvens", action="store_true", dest="subtractEvens")
49 configParser = getConfigParser()
50 section = "plotprofile"
51 doScale = getConfigBoolOption(configParser, section, "doScale", False)
52 weightMax = getConfigIntOption(configParser, section, "weightMax", -1)
53 ymin = getConfigOption(configParser, section, "ymin", None)
54 ymax = getConfigOption(configParser, section, "ymax", None)
55 subtractEvens = getConfigBoolOption(configParser, section, "subtractEvens", False)
57 parser.set_defaults(doScale=doScale, weightMax=weightMax, ymin=ymin, ymax=ymax, subtractEvens=subtractEvens)
62 def plotprofile(inFileName, pngfilename, doScale=False, weightMax=-1, ymin=None, ymax=None, subtractEvens=False):
63 infile = open(inFileName)
86 line = infile.readline()
87 fields = line.strip().split()
88 for data in fields[1:-1]:
89 datapoint = float(data)
96 xcoordList.append(datapoint)
100 fields = line.strip().split()
102 for data in fields[1:-1]:
103 datapointList.append(float(data))
105 if subtractEvens and index % 2 == 0:
106 for dataIndex in range(len(datapointList)):
107 dataList[-1][dataIndex] -= datapointList[dataIndex]
109 dataList.append(datapointList)
111 weight = float(fields[-1])
112 if subtractEvens and index % 2 == 0:
115 labelList.append(fields[0])
116 if weight > weightMax:
119 weightList.append(weight)
123 for index in range(len(dataList)):
126 scale = weightList[index] / weightMax
127 print weightList[index], weightMax, scale
128 for val in dataList[index]:
129 newList.append(val * scale)
131 newList = dataList[index]
133 plotList.append(plot(xcoordList, newList, linewidth=3.0))
135 xticks(xcoordList, rotation="vertical")
136 xlim(xmin - 0.1, xmax + 0.1)
140 legend(plotList, labelList)
144 if __name__ == "__main__":