def plot_entry_list(log_entry_list, binning=None, binning_dict=None, bin_widths=None, bin_widths_dict=None, support_dict=None, xlab=None, ylab="", normalize_log_space=True, xmin=None, xmax=None, main=None, bin_numbers=True): entries = convert_log_entries(log_entry_list) points = [] for entry in entries: number, fullname, tarray = entry this_ylab = ylab # Decide on which binning to use if binning_dict!=None and binning_dict.has_key(number): bins = binning_dict[number][2] elif binning!=None and len(binning)==1 and len(binning[0][2])-1==len(tarray): bins = binning[0][2] else: bins = None # Normalize by bin width, if the binwidh is available if bin_widths_dict!=None and bin_widths_dict.has_key(number): widths = bin_widths_dict[number][2] elif bin_widths!=None and len(bin_widths)==1 and len(bin_widths[0][2])==len(tarray): widths = bin_widths[0][2] else: widths = None if widths!=None: if normalize_log_space: tarray -= log(widths) this_ylab = r("expression(%s - ln(Delta[bin]))" % ylab) else: tarray = tarray/widths # Note, /= worn't work, since tarray might be an int array this_ylab = r("expression(%s / Delta[bin])" % ylab) # Decide on which support to use if support_dict!=None and support_dict.has_key(number): support = support_dict[number][2] else: support = None # Do the plotting p = plot_name_array(fullname, tarray, 1, counts=False, bins=bins, support=support, makenewplot=True, xlab=xlab, ylab=this_ylab, xmin=xmin, xmax=xmax, main=main, bin_numbers=bin_numbers) points.append((number, fullname, p)) return points
def plot_entry_list(pdf, log_entry_list, binning=None, binning_dict=None, bin_widths=None, bin_widths_dict=None, support_dict=None, xlab=None, ylab="", normalize_log_space=True, xmin=None, xmax=None, main=None, bin_numbers=True, color="blue"): entries = convert_log_entries(log_entry_list) points = [] for entry in entries: number, fullname, tarray = entry this_ylab = ylab # Decide on which binning to use if binning_dict!=None and binning_dict.has_key(number): bins = binning_dict[number][2] elif binning!=None and len(binning)==1 and len(binning[0][2])-1==len(tarray): bins = binning[0][2] else: bins = None # Normalize by bin width, if the binwidh is available if bin_widths_dict!=None and bin_widths_dict.has_key(number): widths = bin_widths_dict[number][2] elif bin_widths!=None and len(bin_widths)==1 and len(bin_widths[0][2])==len(tarray): widths = bin_widths[0][2] else: widths = None if widths!=None: if normalize_log_space: tarray -= log(widths) this_ylab = r"$%s - \ln(\Delta_\mathrm{bin})$" % ylab.replace("$", "") else: tarray = tarray/widths # Note, /= worn't work, since tarray might be an int array this_ylab = r"$%s / \Delta_\mathrm{bin}$" % ylab.replace("$", "") # Decide on which support to use if support_dict!=None and support_dict.has_key(number): support = support_dict[number][2] else: support = None # Do the plotting p = plot_name_array(pdf, fullname, tarray, 1, counts=False, bins=bins, support=support, fig=None, xlab=xlab, ylab=this_ylab, xmin=xmin, xmax=xmax, main=main, bin_numbers=bin_numbers, color=color) points.append((number, fullname, p)) return points
def plot_sum_N(log_entry_list, binning=None, binning_dict=None, bin_widths=None, bin_widths_dict=None, support_dict=None, xlab=None, ylab="", normalize_log_space=True, xmin=None, xmax=None, main=None, bin_numbers=True): entries = convert_log_entries(log_entry_list) if binning!=None and binning_dict!=None and len(binning_dict)>0: newest = sorted(binning_dict.keys())[-1] # Added up the entries in the entry list bins = binning_dict[newest][2] sums = zeros(bins.shape[0]-1, dtype=entries[0][2].dtype) for entry in entries: number, fullname, tarray = entry # See if we need to align the binning if binning_dict.has_key(number): this_bins = binning_dict[number][2] size_diff = bins.shape[0] - this_bins.shape[0] # Check that this is not larger than the bins array if size_diff < 0: print "Error aligning binning arrays: The newest array is smaller than a previous array." return # Find the best alignment norm = lambda v: numpy.sqrt(numpy.dot(v,v)) minimal = None for i in range(size_diff+1): alignment_diff = norm(bins[i:bins.shape[0]-(size_diff-i)] - this_bins) if minimal==None or alignment_diff < minimal[0]: minimal = (alignment_diff, i) if minimal[0]>0.1: print "Error aligning binning arrays: No good alignment found." return # Check that the count array has the right shape if (this_bins.shape[0]-1) != tarray.shape[0]: print "Mismatch in size for binning and count array for iteration %d" % number return # Add the counts to the sum sums[minimal[1]:((bins.shape[0]-1)-(size_diff-minimal[1]))] += tarray else: # No alignment needed # Check that the count array has the right shape if (bins.shape[0]-1) != tarray.shape[0]: print "Mismatch in size for binning and count array for iteration %d" % number return sums += tarray # Normalize by bin width, if the binwidh is available if bin_widths_dict!=None and bin_widths_dict.has_key(newest): widths = bin_widths_dict[newest][2] else: widths = None if widths!=None: if normalize_log_space: sums -= log(widths) this_ylab = r("expression(%s - ln(Delta[bin]))" % ylab) else: sums = sums/widths # Note, /= worn't work, since tarray might be an int array this_ylab = r("expression(%s / Delta[bin])" % ylab) counts = False name = "sum_n" else: this_ylab = ylab counts = True name = "sum_N" # Do the plotting p = plot_name_array("Accumulated", sums, 1, counts=counts, bins=bins, support=None, makenewplot=True, xlab=xlab, ylab=this_ylab, xmin=xmin, xmax=xmax, main=main, bin_numbers=bin_numbers) return [(None, name, p)]
if options.end<0: parser.error("Negative end value not allowed.") if options.indices!=[]: try: options.indices = map(int, options.indices) except ValueError: parser.error("Invalid index value used with option -i.") # Parse the log file log_dict = parse_statics_log(options.muninn_log_file, options.start, options.end, options.indices) # Convert the binning from strings to arrays and make a dictionary binning = convert_log_entries(log_dict.get('binning', [])) binning_dict = dict(map(lambda entry: (entry[0], entry), binning)) bin_widths = convert_log_entries(log_dict.get('bin_widths', [])) bin_widths_dict = dict(map(lambda entry: (entry[0], entry), bin_widths)) # Plot the required output r.pdf(options.output, width=options.width, height=options.height) r.par(cex=options.cex) xmin = options.xmin xmax = options.xmax points = []
def plot_sum_N(pdf, log_entry_list, binning=None, binning_dict=None, bin_widths=None, bin_widths_dict=None, support_dict=None, xlab=None, ylab="", normalize_log_space=True, xmin=None, xmax=None, main=None, bin_numbers=True, color="blue"): entries = convert_log_entries(log_entry_list) if binning!=None and binning_dict!=None and len(binning_dict)>0: newest = sorted(binning_dict.keys())[-1] # Added up the entries in the entry list bins = binning_dict[newest][2] sums = zeros(bins.shape[0]-1, dtype=entries[0][2].dtype) for entry in entries: number, fullname, tarray = entry # See if we need to align the binning if binning_dict.has_key(number): this_bins = binning_dict[number][2] size_diff = bins.shape[0] - this_bins.shape[0] # Check that this is not larger than the bins array if size_diff < 0: print "Error aligning binning arrays: The newest array is smaller than a previous array." return # Find the best alignment norm = lambda v: numpy.sqrt(numpy.dot(v,v)) minimal = None for i in range(size_diff+1): alignment_diff = norm(bins[i:bins.shape[0]-(size_diff-i)] - this_bins) if minimal==None or alignment_diff < minimal[0]: minimal = (alignment_diff, i) if minimal[0]>0.1: print "Error aligning binning arrays: No good alignment found." return # Check that the count array has the right shape if (this_bins.shape[0]-1) != tarray.shape[0]: print "Mismatch in size for binning and count array for iteration %d" % number return # Add the counts to the sum sums[minimal[1]:((bins.shape[0]-1)-(size_diff-minimal[1]))] += tarray else: # No alignment needed # Check that the count array has the right shape if (bins.shape[0]-1) != tarray.shape[0]: print "Mismatch in size for binning and count array for iteration %d" % number return sums += tarray # Normalize by bin width, if the binwidh is available if bin_widths_dict!=None and bin_widths_dict.has_key(newest): widths = bin_widths_dict[newest][2] else: widths = None if widths!=None: if normalize_log_space: sums -= log(widths) this_ylab = r"$%s - \ln(\Delta_\mathrm{bin})$" % ylab.replace("$", "") else: sums = sums/widths # Note, /= worn't work, since tarray might be an int array this_ylab = r"$%s / \Delta_\mathrm{bin}$" % ylab.replace("$", "") counts = False name = "sum_n" else: this_ylab = ylab counts = True name = "sum_N" # Do the plotting p = plot_name_array(pdf, "Accumulated", sums, 1, counts=counts, bins=bins, support=None, fig=None, xlab=xlab, ylab=this_ylab, xmin=xmin, xmax=xmax, main=main, bin_numbers=bin_numbers, color=color) return [(None, name, p)]
if args.end!=None: if args.end<0: parser.error("argument --end: negative end value not allowed.") if args.indices!=[]: try: args.indices = map(int, args.indices) except ValueError: parser.error("Invalid index value used with option -i.") # Parse the log file log_dict = parse_statics_log(args.muninn_log_file, args.start, args.end, args.indices) # Convert the binning from strings to arrays and make a dictionary binning = convert_log_entries(log_dict.get('binning', [])) binning_dict = dict(map(lambda entry: (entry[0], entry), binning)) bin_widths = convert_log_entries(log_dict.get('bin_widths', [])) bin_widths_dict = dict(map(lambda entry: (entry[0], entry), bin_widths)) # Plot the required output pdf = PdfPages(args.output) matplotlib.rc('font', size=args.fontsize) matplotlib.rc('figure', figsize=(args.width, args.height), max_open_warning=1000) xmin = args.xmin xmax = args.xmax points = []