def plot_grid_volts_voronoi(net, lines=True, vmin=0.95, vmax=1.05, ax=None, dxy=0.1): # plotting lines: if ax is None: f, ax = plt.subplots() if lines: plot_lines_loading(net, ax=ax) # id bus ext_grid bext = net.ext_grid.bus # getting voronoi polys: polys = get_voronoi_polys(net.bus_geodata[['x', 'y']].drop(bext, axis=0).values) # computing colors cmap = plt.get_cmap('coolwarm') colors = cmap( (net.res_bus.drop(bext, axis=0).vm_pu - vmin) / (vmax - vmin)) util.plot_polygons(polys, color=colors, ax=ax) # centering on good area x0 = net.bus_geodata.x.min() x1 = net.bus_geodata.x.max() y0 = net.bus_geodata.y.min() y1 = net.bus_geodata.y.max() plt.xlim(x0 - (x1 - x0) * dxy, x1 + (x1 - x0) * dxy) plt.ylim(y0 - (y1 - y0) * dxy, y1 + (y1 - y0) * dxy) plt.xticks([]) plt.yticks([]) return ax
def _plot_gradient(self): """display the light dark domain.""" xmin, xmax = self._x_range ymin, ymax = self._y_range # Note that higher brightness has lower brightness value hi_brightness = self._env.const lo_brightness = max( 0.5 * (self._env.light - xmin)**2 + self._env.const, 0.5 * (self._env.light - xmax)**2 + self._env.const) # Plot a bunch of rectangular strips along the x axis # Check out: https://stackoverflow.com/questions/10550477 x = xmin verts = [] colors = [] while x < xmax: x_next = x + self._res verts.append([(x, ymin), (x_next, ymin), (x_next, ymax), (x, ymax)]) # compute brightness based on equation in the paper brightness = 0.5 * (self._env.light - x)**2 + self._env.const # map brightness to a grayscale color grayscale = int( round( util.remap(brightness, hi_brightness, lo_brightness, 255, 0))) grayscale_hex = util.rgb_to_hex((grayscale, grayscale, grayscale)) colors.append(grayscale_hex) x = x_next util.plot_polygons(verts, colors, ax=self._ax) self._ax.set_xlim(xmin, xmax) self._ax.set_ylim(ymin, ymax)
r=requests.get(ads + comm, proxies=proxies) if r.status_code == 200: if 'nom' in r.json()[0]: GRD.loc[i] = r.json()[0]['nom'] GRDnull = GRD[GRD.isnull()] #%% palette=['b','g','yellow','violet','purple','y','mediumslateblue','orange', 'c', 'silver'] f,ax= plt.subplots() i=0 dsos = ['Enedis', 'GEREDIS Deux-Sèvres', 'SRD', 'URM (Metz)', 'Electricité de Strasbourg', 'RSE - Régie Services Energie','Gaz électricité de Grenoble', 'SICAE-Oise', 'SICAE-Est', 'Autres'] for dso in dsos: if dso == 'Autres': ies = iris_poly[iris_poly.GRD.isin(dsos[:-1]) == False].index else: ies = iris_poly[iris_poly.GRD == dso].index polys = [p for pp in ies for p in polygons[pp]] util.plot_polygons(polys, facecolor=palette[i], ax=ax, label=dso) i=i+1 util.aspect_carte_france(ax, palette=palette, labels=dsos)
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') tranches = np.linspace(0, 1, 6) labels = ['{}%'.format(int(t * 100)) for t in tranches] colorslab = cmap(tranches) util.do_labels(labels, colorslab, ax) print('Loading Histograms of distance') folder_hdata = r'c:\user\U546416\Documents\PhD\Data\Mobilité' hhome = pd.read_csv(folder_hdata + r'\HistHomeModal.csv', engine='python', index_col=0) hwork = pd.read_csv(folder_hdata + r'\HistWorkModal.csv',
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: # Grand pole = 111
if i % 10 == 0: ts.append(time.time()) print(i, 'Elapsed time [s]:', np.round(ts[-1] - ts[0], 1), 'Lap [s]:', np.round(ts[-1] - ts[-2], 1)) if ss in edges: continue irises = iris[iris.SS == ss].index polys = [p for irs in irises for p in polygons[irs]] 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)
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) ] ax1 = util.plot_polygons(polyss, facecolors=colorss, edgecolors='k', linewidth=0.2) ax2 = util.plot_polygons(polys_idf, facecolors=colors_idf, edgecolors='k', linewidth=0.2) util.aspect_carte_france(ax1, palette=palette, labels=labels) util.aspect_carte_france(ax2, palette=palette, labels=labels, cns='idf') #%% Save #SS_profile.to_csv('SS_profiles.csv') #This is (way) too heavy (600MB, over 45s to load) #SS_load.to_excel('SS_load.xlsx') #%% Saving profiles one by one in a dedicated folder folder = r'c:\user\U546416\Documents\PhD\Data\Mobilité\Data_Traitee\Conso\SS_profiles\\' for ss in SS_profile: SS_profile[[ss]].to_csv(folder + ss + '.csv')
& (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) labels = ['{:.2f} MW'.format(i) for i in tranches] colors = cmap(tranches / maxpv) util.do_labels(labels, colors, ax, f=True) #f.title('PV installed capacity per IRIS') # Plot type IRIS
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) 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\SSFR_incpeak_{}.pdf'. format(name[c])) plt.savefig( r'c:\user\U546416\Pictures\SS - results\Thesis\SSFR_incpeak_{}.jpg'. format(name[c]), dpi=300) #%% plot increase in peak load brute force - IdF
} 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) print('Loading Conso per IRIS') #folder_consodata = r'c:\user\U546416\Documents\PhD\Data\Mobilité\Data_Traitee\Conso' #iris = pd.read_csv(folder_consodata + r'\IRIS_enedis_2017.csv', # engine='python', index_col=0)
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] colors = [palette[min(int(avgh[i]/(wbin/2)), len(palette)-1)] for i in idxs.index for p in polygons_comm[idxs[i]]] ax = util.plot_polygons(polys, facecolor=colors) #util.aspect_carte_france(ax, title='Average daily commuting distance [km]\n by commune of residence', palette=palette, labels=labels)
labels_kmv = [ str(i * 2 * kmvoit_base / 1000) + ' <k.km.veh< ' + str( (i + 1) * 2 * kmvoit_base / 1000) for i in range(len(palette)) ] polys = [p for i in iris.index for p in polygons[i]] kms = [ palette[int(means[iris.SS[i]] // km_base)] for i in iris.index for p in polygons[i] ] kmsv = [ palette[int(kmvoit[iris.SS[i]] // kmvoit_base)] for i in iris.index for p in polygons[i] ] util.plot_polygons(polys, ax1, facecolors=kms) #range every 15km of mean daily distance util.plot_polygons(polys, ax2, facecolors=kmsv) #range every 150k kmvoit util.aspect_carte_france( ax1, title='Average daily distance per Substation [km]\nFor Residents', palette=palette, labels=labels_km) util.aspect_carte_france(ax2, title='km' + r'$\bullet$' + 'Vehicles\nFor Residents', palette=palette, labels=labels_kmv) #%% Plot for work trips meansw = (SS_hwork * bins).transpose().sum(axis=0) / SS_hwork.sum(axis=1) kmvoitw = (SS_hwork * bins).transpose().sum(axis=0)
#%% Plot departments deps = iris.Departement.unique() deps.sort() f, ax = plt.subplots() f.set_size_inches(14,12) maxl = pd.Series(np.zeros(len(deps)), index=deps) for d in deps: #un/comment to do only one # d = 60 print('Dep ', d) ax.clear() ax.set_aspect('equal') #plot all irises: iriDep = iris_poly[(iris_poly.COMM_CODE>d*1000)&(iris_poly.COMM_CODE<(d+1)*1000)] util.plot_polygons([p for i in iriDep.index for p in polygons[i]], ax=ax, facecolor='white', edgecolor='k', linestyle='--') #Select subset to plot irises = iris[iris.Departement == d] SSs = SS[(SS.Departement == d) & (SS.GRD == 'Enedis')] #assignment = assigns[irises.index] assignment = irises.SS plot_polygon_assignment(irises, SSs, assignment, polygons, ax=ax) #Plot SS names maxload = compute_load_rate(irises.Load_GWh, SSs.Pmax, assignment).max() maxl[d] = maxload ax.set_title('{} {:.0f}, max SS load {:.2f} p.u.'.format(irises.DEP_NAME.iloc[0], d, maxload)) for ss in SSs.index: ax.text(SSs.Lon[ss], SSs.Lat[ss], ss, ha='center', path_effects=[pe.withStroke(linewidth=3, foreground='w')]) #un/commment to do only one f.savefig(r'c:\user\U546416\Pictures\SS\IRIS\Dep{}.png'.format(d))