def data2breakpoints(cate, method, topic): (x, y) = ld.read2dicts() allDict = dict(zip(x, y)) if (topic == "energy recovery"): heatDict = allDict["Space Heating"] coolDict = allDict["Cooling:Electricity"] else: heatDict = allDict["Heating"] coolDict = allDict["Electricity:Facility"] countDict = ld.bdCountDict totalheat = ld.total_count(countDict, heatDict) totalheat = [x for x in totalheat if x != 0.0] totalcool = ld.total_count(countDict, coolDict) totalcool = [x for x in totalcool if x != 0.0] breakpt_heat = ld.breakpt(totalheat, cate, method, False) breakpt_cool = ld.breakpt(totalcool, cate, method, False) coloridDict = {} for key in heatDict: if countDict[key] > 0: coloridDict[key] = zip(ar.bucket(heatDict[key], breakpt_heat), ar.bucket(coolDict[key], breakpt_cool)) return(breakpt_heat, breakpt_cool, coloridDict)
def writeColor(topic, method, category, dirname, istocga, length=None): (breakpt_heat, breakpt_cool, x) = data2breakpoints(category, "quantile", topic) (x, y) = ld.read2dicts() allDict = dict(zip(x, y)) if (topic == "energy recovery"): heatDict = allDict["Space Heating"] coolDict = allDict["Cooling:Electricity"] colorGrid = colorRamp_2d(category, [255, 255, 255], [255, 0, 0], [0, 0, 255]) colorHeat = colorRamp_1d(category, [255, 255, 255], [255, 0, 0]) colorCool = colorRamp_1d(category, [255, 255, 255], [0, 0, 255]) else: heatDict = allDict["Heating"] coolDict = allDict["Electricity:Facility"] colorGrid = colorRamp_2d(category, [255, 255, 255], [255, 0, 0], [0, 255, 0]) colorHeat = colorRamp_1d(category, [255, 255, 255], [255, 0, 0]) colorCool = colorRamp_1d(category, [255, 255, 255], [0, 255, 0]) countDict = ld.bdCountDict # length = 20 if length is None: length = 8760 colorDict = {} colorHeatDict = {} colorCoolDict = {} for key in heatDict: # breakpoint calculated with "quantile" method cannot be used # to classify other data if countDict[key] != 0: heat_class = ar.bucket(heatDict[key], breakpt_heat) cool_class = ar.bucket(coolDict[key], breakpt_cool) color_profile = [] color_pro_heat = [] color_pro_cool = [] for i in range(length): heatId = heat_class[i] coolId = cool_class[i] color_profile.append(colorGrid[coolId][heatId]) color_pro_heat.append(colorHeat[heatId]) color_pro_cool.append(colorHeat[coolId]) colorHeatDict[key] = color_pro_heat colorCoolDict[key] = color_pro_cool if not istocga: for key in colorDict: filename = dirname + key + topic + "Color.txt" with open (filename, "w") as wt: mywriter = csv.writer(wt, delimiter=";") mywriter.writerow(colorDict[key]) print("write to file: " + filename) else: # write to a file directly pasted to cga half = length/2 filename = dirname + topic + "Color.txt" with open (filename, "w") as wt: mywriter = csv.writer(wt, delimiter=";") for key in colorDict: # in classification, max value might not be encountered mix = colorDict[key][:half] mix[0] = key + "_01 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) mix = colorDict[key][half:] mix[0] = key + "_02 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) print("write to row: " + key) filename = dirname + topic + "-heat-Color.txt" with open (filename, "w") as wt: mywriter = csv.writer(wt, delimiter=";") for key in colorHeatDict: # in classification, max value might not be encountered mix = colorHeatDict[key][:half] mix[0] = key + "_01 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) mix = colorHeatDict[key][half:] mix[0] = key + "_02 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) print("write to row: " + key) filename = dirname + topic + "-cool-Color.txt" with open (filename, "w") as wt: mywriter = csv.writer(wt, delimiter=";") for key in colorCoolDict: # in classification, max value might not be encountered mix = colorHeatDict[key][:half] mix[0] = key + "_01 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) mix = colorCoolDict[key][half:] mix[0] = key + "_02 = '" + mix[0] mix[-1] = mix[-1] + "'" mywriter.writerow(mix) print("write to row: " + key)
totalheat = ld.total_count(countDict, heatDict) totalcool = ld.total_count(countDict, coolDict) totalheat = [x for x in totalheat if x != 0.0] totalcool = [x for x in totalcool if x != 0.0] heat_breakpt = ld.breakpt(totalheat, category, "quantile", False) cool_breakpt = ld.breakpt(totalcool, category, "quantile", False) # create 2d colorRamp colorGrid = cl.colorRamp_2d(category,[255, 255, 255], [255, 0, 0], [0, 255, 0]) color_2d = createColorScheme(category, 0, dim, size) heatColorDict = {} for key in heatDict: if countDict[key] != 0: heatColorDict[key] = ar.bucket(heatDict[key], heat_breakpt) coolColorDict = {} for key in coolDict: if countDict[key] != 0: coolColorDict[key] = ar.bucket(coolDict[key], cool_breakpt) # slider row_time = max(dim, category + 2) row_slider = row_time + 1 grid_horizontal = dim + category + 2 w_slider = grid_horizontal * size allyear = Scale(master, from_= 0, length = w_slider, to = 8759, tickinterval=1000, orient=HORIZONTAL, command = changeColor, font = ot_font, fg = font_color) allyear.set(0)
def classify(data, breakpoints): return ar.bucket(data, breakpoints)