def histMedian(h, bins): # Assume you only want to operate on the last dimension nx, ny = h.shape median, sigL, sigR, var = np.zeros((4,nx)) binMids = getMids(bins, infvalue=100) for i in range(nx): median[i] = histPercentile(h[i], 50, binMids) sigL[i] = histPercentile(h[i], 16, binMids) sigR[i] = histPercentile(h[i], 84, binMids) var[i] = histVar(h[i], binMids) return median, sigL, sigR, var
try: i = paramList.index([config, str(emin), str(emax)]) except ValueError: found = False # If it exists, option to overwrite if found and not args.overwrite: print 'Info for', config, emin, emax, 'already exists...' continue if found and args.overwrite: table.remove(table[i]) # Calculate information for energy range idx0 = np.where(args.eList==emin)[0][0] idx1 = np.where(args.eList==emax)[0][0] h = ehists[idx0:idx1].sum(axis=0) emids = (ebins[:-1] + ebins[1:]) / 2. median = histPercentile(h, 50, emids) sigL = histPercentile(h, 16, emids) sigR = histPercentile(h, 84, emids) var = histVar(h, emids) counts = h.sum() # Append to file newLine = [config, emin, emax, median, sigL, sigR, var, counts] newLine = ['%s' % i for i in newLine] table.append(newLine) # Write as you go lines = [' '.join(line) for line in table] lines = [line + '\n' for line in lines] lines.sort()