Ejemplo n.º 1
0
def landName(event):
    titleDict = {"space heat" : "Space Heating Demand (kBtu)",
                 "cool" : "Space Cooling Demand (kBtu)",
                 "heat" : "Heating Demand (kBtu)",
                 "electricity" : "Electricity Demand (kBtu)",
                 "recover": "Energy Recovery Potential (kBtu)",
                 "single" : "", "group" : "Total ", "community":"Community "}
    typeDict = {"space heat" : dfSpaceHeat, "cool" : dfCool,"heat" : dfHeat,
                "recover" : dfRecover, "electricity" : dfElec}
    pt = (event.x, event.y)
    for key in landDict:
        key2list = [int(x) for x in ast.literal_eval(key)]
        if geo.pointInPolygon(pt, key2list):
            landInit = landDict[key]
            bdtype = initialDict[landInit]
            hmap.g.create_polygon(tuple(key2list), fill = 'red', tag = 'a')
            landSelection.append(landInit)
            print 'Selection Set: {0}'.format(landSelection)
            print "landuse is {0}".format(landDict[key])
            idx = allyear.get()
            (num, choice, period, step, title, stat) = plotMethod()
            numPeriod = 8760 // step

            # plot for single building
            if num == "single":
                title = '{0} {1}'.format(bdtype, title)
                f, axarr = plt.subplots(2, 1, sharex=False, sharey = False)
                g1 = typeDict[choice][bdtype][idx:(min(idx+step, 8760))].plot(ax = axarr[0], title = title)
                g1.set_xlim(idx, min(idx+step, 8760) - 1)

                building = typeDict[choice][bdtype]
                if stat == "exact":
                    sr = pd.Series([building[idx%step + i*step]
                                    for i in range(numPeriod)])
                    title = '{0} with step {1}'.format(title, period)
                else:
                    if stat == "peak":
                        sr = pd.Series([max(building[i*step:(i + 1)*step])
                                        for i in range(numPeriod)])
                    if stat == "total":
                        sr = pd.Series([sum(building[i*step:(i + 1)*step])
                                        for i in range(numPeriod)])
                    if stat == "average":
                        sr = pd.Series([ar.getAve(building[i*step:(i + 1)*step])
                                        for i in range(numPeriod)])
                    title = '{0} {1} {2}'.format(stat.capitalize(), (period+"ly").capitalize(), title)
                g2 = sr.plot(ax = axarr[1],title = title)
                g2.set_xlim(0, numPeriod - 1)
                g2.axvline(idx//step, color = 'red', linestyle='--')
                g2.annotate('current', xy = (idx//step, sr[idx//step]))
            else:
                title = '{0} {1}'.format(landSelection, titleDict[choice])
                f, axarr = plt.subplots(2, 1, sharex=False, sharey = False)
                bdtypelst = [initialDict[x] for x in landSelection]
                selectDF = pd.DataFrame(typeDict[choice], columns = bdtypelst)
                print list(selectDF.columns.values)
                selectDF['agg'] = selectDF.sum(axis = 1)
                g1 = selectDF['agg'][idx:(min(idx+step, 8760))].plot(ax = axarr[0], title = title)
                g1.set_xlim(idx, min(idx+step, 8760) - 1)
                if stat == "exact":
                    sr = pd.Series([selectDF['agg'][idx%step + i*step]
                                    for i in range(numPeriod)])
                    title = '{0} with step {1}'.format(title, period)
                else:
                    if stat == "peak":
                        sr = pd.Series([max(selectDF['agg'][i*step:(i+1)*step])
                                       for i in range(numPeriod)])
                    elif stat == "average":
                        sr = pd.Series([ar.getAve(selectDF['agg'][i*step:(i+1)*step]) for i in range(numPeriod)])
                    elif stat == "total":
                        sr = pd.Series([sum(selectDF['agg'][i*step:(i+1)*step])
                                       for i in range(numPeriod)])

                    title = '{0} {1} {2}'.format(stat.capitalize(), (period+"ly").capitalize(), title)
                g2 = sr.plot(ax = axarr[1], title = title)
                g2.set_xlim(0, numPeriod - 1)
                g2.axvline(idx//step, color = 'red', linestyle='--')
                g2.annotate('current', xy = (idx//step, sr[idx//step]))
            plt.xlabel('time')
            title = titleDict[num] + titleDict[choice]
            plt.ylabel(titleDict[choice])
            plt.show()

            return
    print "invalid selection"
Ejemplo n.º 2
0
def plotBuilding():
    dirname = "energyData/Community_"
    fileDict = {"space heat" : "spaceheat.csv", "cool" : "c_elec.csv",
                "recover" : "recov.csv", "electricity" : "elec.csv",
                "heat" : "heat.csv"}
    typeDict = {"space heat" : dfSpaceHeat, "cool" : dfCool,"heat" : dfHeat,
                "recover" : dfRecover, "electricity" : dfElec}
    (num, choice, period, step, title, stat) = plotMethod()
    filename = dirname + fileDict[choice]
    df = typeDict[choice]
    idx = allyear.get()
    numPeriod = 8760 // step
    if num == "single":
        f, axarr = plt.subplots(4, 4, sharex=True, sharey = True)
        for i in range(16):
            if stat == "exact":
                data = df.ix[idx: min(idx + step, 8760), i]
                windowTitle = "Single Building " + title
                g = data.plot(ax=axarr[i/4, i%4], title = bdTypelist[i])
                g.set_xlim(idx, min(idx + step, 8760) - 1)
            else:
                if stat == "peak":
                    data = pd.Series([(df.ix[y * step:(y + 1)*step, i]).max()
                                      for y in range(numPeriod)])
                elif stat == "average":
                    data = pd.Series([(df.ix[y * step:(y + 1)*step, i]).mean()
                                      for y in range(numPeriod)])
                elif stat == "total":
                    data = pd.Series([(df.ix[y * step:(y + 1)*step, i]).sum()
                                      for y in range(numPeriod)])
                windowTitle = 'Single Building {0} {1}'.format(stat.capitalize(), title)
                g = data.plot(ax=axarr[i/4, i%4], title = bdTypelist[i])
                g.set_xlim(0, numPeriod + 1)
    else:
        f, axarr = plt.subplots(2, 1, sharex = False, sharey = False)
        sr = pd.Series(np.genfromtxt(filename, delimiter = ','))

        g1 = sr[idx:(min(idx+step, 8760))].plot(ax = axarr[0], title = title)
        g1.set_xlim(idx, min(idx+step, 8760) - 1)

        if stat == "exact":
            sr2 = pd.Series([sr[idx%step + i*step] for i in range(numPeriod)])
            title = '{0} with step {1}'.format(title, period)
        else:
            if stat == "peak":
                sr2 = pd.Series([max(sr[i*step:(i + 1)*step])
                                for i in range(numPeriod)])
            if stat == "total":
                sr2 = pd.Series([sum(sr[i*step:(i + 1)*step])
                                for i in range(numPeriod)])
            if stat == "average":
                sr2 = pd.Series([ar.getAve(sr[i*step:(i + 1)*step])
                                for i in range(numPeriod)])
            title = '{0} {1} {2}'.format(stat.capitalize(), period+"ly", title)

        g2 = sr2.plot(ax = axarr[1], title = title)
        g2.set_xlim(0, numPeriod - 1)
        g2.axvline(idx//step, color = 'red', linestyle='--')
        g2.annotate('current', xy = (idx//step, sr[idx//step]))
        windowTitle = "Community " + title
    f.canvas.set_window_title(windowTitle)
    plt.show()