Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
    with open ('landCord.txt', 'a') as wt:
        wt.write ('{0}, {1}, '.format(event.x, event.y))
        print event.x, event.y
'''
# reading a table with landuse and coordinates
def readLandShape():
    landDict = {}
    with open ('input/land.txt', 'r') as rd:
        rows = csv.reader(rd)
        for row in rows:
            key = str(row[1:])
            land = row[0]
            landDict[key] = land
    return landDict

(x, y) = ld.read2dicts()
allDict = dict(zip(x, y))
dfSpaceHeat = pd.DataFrame(allDict["Space Heating"])
dfHeat = pd.DataFrame(allDict["Heating"])
dfElec = pd.DataFrame(allDict["Electricity:Facility"])
dfCool = pd.DataFrame(allDict["Cooling:Electricity"])
dfRecover = pd.DataFrame(allDict["Heat Recover"])
landDict = readLandShape()
initialDict = dict([(initDict[key], key) for key in initDict])

landSelection = []

def plotMethod():
    titleDict = {"space heat" : "Space Heating Demand (kBtu)",
                 "cool" : "Space Cooling Demand (kBtu)",
                 "heat" : "Heating Demand (kBtu)",
Ejemplo n.º 3
0
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)