# -*- coding: utf-8 -*- """ Created on Thu Jan 30 11:28:32 2020 @author: Rory Morrison """ import selenium # selenium for web driving from selenium import webdriver import time # time for pausing between navigation import os # for renaming the file import pandas as pd import numpy as np azimuth = np.linspace(-30, 30, 5).tolist() # 7 tilt = np.linspace(15, 45, 4).tolist() # 11 azimuth = azimuth*len(tilt) # 77 azimuth.sort() # 77 tilt = tilt*int(len(azimuth)/len(tilt)) df = pd.DataFrame( {"azimuth" : azimuth, "tilt" : tilt, "annual_yield" : [np.nan]*len(tilt)}) print(df) driver = webdriver.Chrome('C:/Users/Rory/.spyder-py3/chromedriver_win32/chromedriver.exe') # replace with your own path # Open the website driver.get('https://re.jrc.ec.europa.eu/pvg_tools/en/tools.html#PVP') # click to accept cookies driver.find_element_by_xpath('/html/body/div[1]/div[1]/a').click() time.sleep(1) postcode_box = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[1]/div[4]/div/form/div[1]/div[2]/input') postcode_box.send_keys("G2 1DH") driver.find_element_by_xpath('//*[@id="tr_go"]').click() time.sleep(3) def PVGIS_automate_repeat(azimuth, tilt, driver): driver = driver azimuth_box = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div/div[1]/form/fieldset/div/div/div/div/div/div[12]/div[2]/input') azimuth_box.clear() azimuth_box.send_keys(azimuth) tilt_box = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div/div[1]/form/fieldset/div/div/div/div/div/div[10]/div[2]/input') tilt_box.clear() tilt_box.send_keys(tilt) # click "Vizualize results" driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[3]/div/div/div[1]/div[1]/div/div/span[2]').click() time.sleep(1) generation = driver.find_element_by_id('PVGrid_energy') generation = generation.text return generation for i in df.index: print('\tRun ' + str(i+1) + '/' + str(len(df))) generation = PVGIS_automate_repeat(str(df.iloc[i].azimuth), str(df.iloc[i].tilt), driver) df.iloc[i].annual_yield = generation print(df[df.index==i]) print('\t\t' + str(round((100*(i+1)/len(df)),2)) + "% complete") driver.close() os.chdir('C://Users//Rory//.spyder-py3//PVGIS automate') # replace with your own path df.to_csv('PVGIS_automate_results.csv') import seaborn as sns import matplotlib.pyplot as plt heat = df.pivot("tilt", "azimuth", "annual_yield") plt.figure(figsize = (14, 7)) ax = sns.heatmap(heat) ax = sns.heatmap(heat, linewidths=.7, annot=True, fmt='.1f').set_title('PVGIS automation - George Square [kWh/year] ') fig = ax.get_figure() fig.savefig('PVGIS_automate_George_Square.png')