示例#1
0

def get_idx_tranches(tranches, data):
    idxs = []
    for t in range(len(tranches) - 1):
        idxs.append(data[(data >= tranches[t])
                         & (data < tranches[t + 1])].index)
    return idxs


cmap = plt.get_cmap('plasma')
tranches_size = [0, 1, 7, 9, 10, 11]
idxs = get_idx_tranches(tranches_size, iris_poly.AU_SIZE)
f, ax = plt.subplots()
for i in range(len(idxs)):
    ps = util.list_polygons(polygons, idxs[i])
    util.plot_polygons(ps, color=cmap(i / (len(idxs) - 1)), ax=ax)
plt.title('Taille Aire Urbaine')
labels = ['Rural', 'AU<100k', '100k<AU<500k', '500k<AU', 'Paris']
cols = cmap([i / (len(idxs) - 1) for i in range(len(idxs))])
util.aspect_carte_france(ax, palette=cols, labels=labels)
#ax.set_title('Population of Urban Area (AU)')
plt.xticks([])
plt.yticks([])
f.set_size_inches(4.67, 4.06)
plt.tight_layout()
plt.savefig(r'c:\user\U546416\Pictures\SS - results\Thesis\aireUrbaine.pdf')
plt.savefig(r'c:\user\U546416\Pictures\SS - results\Thesis\aireUrbaine.jpg',
            dpi=300)

#%% Plot 2 according to Category of commune:
# Base profiles
print('\tloading base profiles')
folder_profiles = r'c:\user\U546416\Documents\PhD\Data\MVGrids\Boriette\Profiles\\'
profiles_load = pd.read_csv(folder_profiles + r'profiles_iris.csv',
                            engine='python',
                            index_col=0)
# Load IRIS polygons
print('Loading IRIS polygons')
folder_iris = r'c:\user\U546416\Documents\PhD\Data\DataGeo\\'
file_iris = 'IRIS_all_geo_' + str(2016) + '.csv'
iris_poly = pd.read_csv(folder_iris + file_iris, engine='python', index_col=0)
# Plot supply zone
iris_ss = net.load.zone.astype(int).unique()
polygons = util.do_polygons(iris_poly.loc[iris_ss], plot=False)
polys = util.list_polygons(polygons, iris_ss)
cmap = plt.get_cmap('plasma')
nb_bt_b = net.load[net.load.type_load == 'Base'].groupby(
    'zone').type_load.count()[
        iris_ss]  # Number of supplied LV trafos per IRIS by SS
nb_bt = lv_iris.Nb_BT[iris_ss]  # Total number of trafos per IRIS
supply = 1 - ((nb_bt - nb_bt_b) / nb_bt)  # Ratio of supply
colors = cmap(supply[iris_ss])

ax = util.plot_polygons(polys,
                        color=colors,
                        edgecolor='darkgrey',
                        linestyle='--')
plot_lines(net.line_geodata, col='coords', ax=ax, color='k', linewidth=0.3)
plt.plot(net.bus_geodata.x[0], net.bus_geodata.y[0], 'o', color='red')
            net_res.load[net_res.load.bus.isin(bss)].p_mw.sum(),
            net_res.sgen[(net_res.sgen.type == 'RES_PV')
                         & (net_res.sgen.bus.isin(bss))].p_mw.sum(),
            net_res.sgen[(net_res.sgen.type == 'Comm_PV')
                         & (net_res.sgen.bus.isin(bss))].p_mw.sum(),
            net_res.sgen[(net_res.sgen.type == 'Farm_PV')
                         & (net_res.sgen.bus.isin(bss))].p_mw.sum()
        ]
conso_prod_iris = pd.DataFrame(
    conso_prod_iris,
    index=['Conso_MWh', 'PV_Home_MW', 'PV_Commercial_MW', 'PV_farm_MW']).T

#%% Plot  interesting things about the grid

# installed PV per IRIS
pls = util.list_polygons(polys.Polygon, ies)
f, axs = plt.subplots(1, 3)
cmap = plt.get_cmap('plasma')
for i, ax in enumerate(axs):
    maxpv = conso_prod_iris.iloc[:, 1:].max().max()
    colors = cmap(conso_prod_iris.iloc[:, i + 1].loc[ies] / maxpv)
    util.plot_polygons(pls, ax=ax, color=colors, alpha=0.8)
    plot_lines(lines, col='ShapeGPS', ax=ax, color='k', linewidth=0.5)
    ax.set_title('{}\nTotal {:.1f} MW'.format(
        conso_prod_iris.columns[i + 1], conso_prod_iris.iloc[:, i + 1].sum()))
f.set_size_inches(12.04, 4.76)
f.tight_layout()

# TODO: add legend
dv_pv = np.round(maxpv / 0.5, 0) * 0.5
tranches = np.arange(0, maxpv + 0.1, maxpv / 7)
    if len(irises) == 0:
        edges[ss] = [[]]
        continue
    sil = get_silhouette(polys, use4=True)
    edges[ss] = sil
    if (i + 2) % 200 == 0:
        f, ax = plt.subplots()
        util.plot_polygons(polys, ax, facecolors='lightgreen')
        util.plot_segments(sil, ax, color='k', linestyle='--')

edges = {ss: [p for p in edges[ss]] for ss in edges}
edges = pd.DataFrame(edges, index=['Polygon']).T

#%% Create SS polygons (& Plot SS)
polygons_ss = util.do_polygons(edges)
util.plot_polygons(util.list_polygons(polygons_ss, polygons_ss.keys()),
                   edgecolors='k',
                   linewidth=0.5)
util.plot_polygons(util.list_polygons(
    polygons_ss, SS[SS.Departement.isin(util.deps_idf)].index),
                   edgecolors='k',
                   linewidth=0.5)

#%% Do one - define outside shapes:
d = 0.00001
edges = {}
i = 0
ss = 'ITTEVILLE'

irises = iris[iris.SS == ss].index
polys = [p for irs in irises for p in polygons[irs]]
示例#5
0
#% Plot histogram of Pmax[pu]
f, ax = plt.subplots()
hi, bins = np.histogram(SS_load['SSCharge[pu]'],
                        bins=[i / 20 for i in range(21)])
ax.bar(bins[0:-1] + 0.025, hi, width=1 / 20)
ax.set_xlim(0, 1)
ax.set_ylabel('Number of SS')
ax.set_xlabel('Max load [pu of SS]')
ax.grid()
ax.set_title('Distribution of max load of Substation')

#%% Plot map of Pmax[pu]
palette = ['lightgreen', 'y', 'coral', 'r', 'maroon']
ranges = [0, 0.5, 0.6, 0.7, 0.8, 0.9, 1]

polyss = util.list_polygons(polygons_ss, polygons_ss.keys())
colorss = [
    palette[max(0, int((SS_load['SSCharge[pu]'][ss] - 0.5) // 0.1))]
    for ss in polygons_ss for p in polygons_ss[ss]
]

ssidf = SS[(SS.GRD == 'Enedis') & (SS.Departement.isin(util.deps_idf))].index
polys_idf = util.list_polygons(polygons_ss, ssidf)
colors_idf = [
    palette[max(0, int((SS_load['SSCharge[pu]'][ss] - 0.5) // 0.1))]
    for ss in ssidf for p in polygons_ss[ss]
]
#%%
labels = [
    str(ranges[i]) + '<PeakLoad<' + str(ranges[i + 1])
    for i in range(len(ranges) - 1)
示例#6
0
                   engine='python',
                   index_col=0)

ies = iris[iris.SS.isin(data[0].index)].index
idfdeps = [75, 78, 77, 91, 92, 93, 94, 95]
iesidf = iris[(iris.SS.isin(data[0].index))
              & (iris.Departement.isin(idfdeps))].index
polygons = util.do_polygons(iris_poly.loc[ies], plot=False)

#%% plot increase in peak load brute force-France
# list of polygons

cases = [0, 1]
name = {0: 'unc', 1: 'tou'}

polys = util.list_polygons(polygons, ies)
cmap = plt.get_cmap('YlOrRd')
pmax = 0.3
xpalette = np.arange(0, pmax, 0.05)
palette = cmap(xpalette / pmax)
labels = ['{}%'.format(int(i * 100)) for i in xpalette]

for c in cases:
    colors = cmap([
        data[c].IncreasePeak_pu[iris.SS[i]] / pmax for i in ies
        for p in polygons[i]
    ])

    f, ax = plt.subplots()
    util.plot_polygons(polys, color=colors, ax=ax)
    util.aspect_carte_france(ax, palette=palette, labels=labels)
        ]
    dep_parc_prod.columns = cols
    code = {
        'a-]0;36]': 'home_rooftop',
        'b-]36;100]': 'commercial_rooftop',
        'c-]100;250]': 'commercial_rooftop',
        'd-]250;...[': 'solar_farm'
    }
    dep_parc_prod['TYPE_PV'] = dep_parc_prod.TRANCHE.apply(lambda x: code[x])

dep_parc_prod = dep_parc_prod[dep_parc_prod.TYPE_PROD == 'Photovoltaïque']

#%% plot PV installed per departement
pv_inst = dep_parc_prod.groupby('Code Département')['Puissance MW'].sum()
cmap = plt.get_cmap('plasma')
polys = util.list_polygons(util.do_polygons(dep_polys, plot=False),
                           dep_polys.index)
color = cmap([
    pv_inst[d] / pv_inst.max() for d in pv_inst.index
    for p in dep_polys.Polygon[d]
])

ax = util.plot_polygons(polys, color=color)
tranches = np.arange(0, 7, 1) * 100
labels = ['{:3} MW'.format(t) for t in tranches]
palette = list(cmap([i / 600 for i in tranches]))
util.aspect_carte_france(ax,
                         title='PV Installed capacity',
                         palette=palette,
                         labels=labels)

#%% plot PV per installed per type (tranche)
示例#8
0
nevsh = hhome.sum(axis=1)
nevsw = hhome.sum(axis=1)
min_nev = 50
nevsh = nevsh[nevsh>min_nev]
nevsw = nevsw[nevsw>min_nev]
bins = np.array([i*2+1 for i in range(50)])
avgh = (hhome.loc[nevsh.index] * bins).sum(axis=1) / nevsh
avgw = (hwork.loc[nevsw.index] * bins).sum(axis=1) / nevsw

#%% Plot using colormap

idxs = comm2019.CODE_COMM_2019[nevsh.index].dropna()
idxs = idxs[idxs.isin(polygons_comm)]
cmap = plt.get_cmap('plasma')
polys = util.list_polygons(polygons_comm, idxs)
colors = cmap([avgh[i]/50 for i in idxs.index for p in polygons_comm[idxs[i]]])

ax = util.plot_polygons(polys, color=colors)
tranches = [10, 30, 50, 70, 90]
labels = ['{:3}km<d<{:3}km'.format(str(t-10),str(t+10)) for t in tranches]
palette = list(cmap([i/100 for i in tranches]))
util.aspect_carte_france(ax, title='Average daily commuting distance [km]\n by commune of residence', palette=palette, labels=labels)

#%% Plot using green-blue-red palette
palette = ['b','lightgreen', 'forestgreen', 'khaki', 'gold', 'orange', 'r']
wbin = 15 #km of daily distance
tranches = [i*wbin for i in range(len(palette))]
labels = ['{:3}km<d<{:3}km'.format(str(t),str(t+wbin)) for t in tranches]
labels[-1] = labels[-1][:-6]
示例#9
0
    palette=palette,
    labels=labels_km)
util.aspect_carte_france(ax2,
                         title='km' + r'$\bullet$' + 'Vehicles\nFor Workers',
                         palette=palette,
                         labels=labels_kmv)

#%% plot using SS
#Avg daily distance
#kmVehicle
f, ax2 = plt.subplots()
f, ax1 = plt.subplots()
#palette = ['b','lightgreen', 'forestgreen', 'khaki', 'gold', 'orange', 'r']
SSs = iris.SS.unique()

polyss = util.list_polygons(polygons_ss, SSs)

ss_km_res = [
    palette[int(means[ss] // km_base)] for ss in SSs for p in polygons_ss[ss]
]
ss_kmv_res = [
    palette[int(kmvoit[ss] // kmvoit_base)] for ss in SSs
    for p in polygons_ss[ss]
]

util.plot_polygons(polyss,
                   ax1,
                   facecolors=ss_km_res,
                   edgecolors='k',
                   linestyle='--',
                   linewidth=0.15)