20


0
shares

  • Author
  • Recent Posts
Javier Bonilla
Researcher at
CIEMAT – PSA PhD. in Computer Science / Solar Thermal Energy Researcher
Latest posts by Javier Bonilla
(see all)

  • Flutter on Raspberry Pi with flutter-pi – 26 November, 2019
  • ESP8266 NodeMCU pinout for Arduino IDE – 19 November, 2019
  • Cross-compile and deploy Qt 5.12 for Raspberry Pi – 17 November, 2019

Do you need weather data in Python for your next project? We got you covered! This tutorial shows how to get open weather data from PVGIS in Python from any location in the world. As an example, there is also a Python notebook that can be executed online from your browser in Google Colaboratory platform.

Outline

  • Photovoltaic Geographical Information System (PVGIS)
  • PVGIS Python class
  • GitHub repository
  • Colab Python notebook
  • Summary

Photovoltaic Geographical Information System (PVGIS)

PVGIS is a scientific open database and interactive tool for the geographical assessment of solar resource and performance of photovoltaic (PV) technology that has been developed for more than 10 years at the European Commission Joint Research Centre, at the JRC site in Ispra, Italy.

PVGIS interactive tool

PVGIS also offers web services that you can access through HTTP API calls. There are six different services with different output data formats. We will make use of the hourly time series web service.

Hourly time series web service

This PVGIS web service provides hourly values for the following variables.

  • Global solar irradiance (GHI)
  • Direct normal irradiance (DNI)
  • Diffuse solar irradiance (DHI)
  • Ambient temperature (TAmb)
  • Wind Speed (Ws)

The needed inputs to obtain this data are the following.

  • Latitude in decimal degrees (south is negative)
  • Longitude in decimal degrees (west is negative)
  • Radiation database: PVGIS-CMSAF (for Europe and Africa), PVGIS-SARAH (for Europe, Africa and Asia) or PVGIS-NSRDB (for the Americas between 60º N and 20º S)
  • Start date and time (from 2007 to 2016, range depends on the particular location)
  • End date and time (from 2007 to 2016, range depends on the particular location)

Check PVGIS hourly time series web service website for additional information.

PVGIS Python class

Our PVGIS Ptyhon class receives the inputs, make a HTTP API request call, process the results and provides them as a Pandas DataFrame or CSV file.

This is an example about how to set the needed inputs and execute the HTTP API request.

from datetime import datetime
from PvGis import PvGis

# Create PvGis object and set its inputs
pvGis = PvGis()
pvGis.latitude = 37.097
pvGis.longitude = -2.365
pvGis.start_date = datetime(2016, 6, 1, 00, 00, 00)
pvGis.end_date = datetime(2016, 6, 15, 23, 59, 59)
pvGis.rad_database = 'PVGIS-CMSAF'

# Get data
pvGis.request_hourly_time_series()

To save the weather data we have just obtained in a CSV file, we need to call the following method.

# Save weather data to a CSV file
pvGis.save_csv('weather_data.csv')

Some rows of the CSV file for this particular example are shown below.

Date,Time,GHI,DNI,DHI,TAmb,Ws
2016-06-01 08:54:00,731.5,612.45,119.05,21.5,3.88
2016-06-01 09:54:00,880.6,753.25,127.35,23.53,4.19
2016-06-01 10:54:00,981.0,848.95,132.05,24.15,4.52
2016-06-01 11:54:00,1023.75,889.9,133.85,24.77,4.86
............... 

But, we can also get the data in a Pandas DataFrame to process or plot it.

# Get Pandas DataFrame
df = pvGis.pandas_data_frame()

Now, we can use any library to plot the data obtained. Here, we are using Plotly to create an interactive JavaScript plot and save it in a HTML file (weather_data.html) than can be opened in any browser.

# Plot weather data
data_ghi = go.Scatter(x=df['DateTime'], y=df['GHI'], name='GHI (W/m^2)')
data_dni = go.Scatter(x=df['DateTime'], y=df['DNI'], name='DNI (W/m^2)')
data_dhi = go.Scatter(x=df['DateTime'], y=df['DHI'], name='DHI (W/m^2)')
data_tam = go.Scatter(x=df['DateTime'], y=df['TAmb'], name='Tamb (ºC)')
data_wsp = go.Scatter(x=df['DateTime'], y=df['Ws'], name='Wind (m/s)')
layout = go.Layout(title='Weather conditions', xaxis=dict(title='Date & time'), yaxis=dict(title='Value'))
fig = go.Figure(data=[data_ghi, data_dni, data_dhi, data_tam, data_wsp], layout=layout)
py.plot(fig, filename='weather_data.html')

GitHub repository

The PVGIS Python class (PvGis.py) is available in our GitHub repository. This repository also includes a Python script with the previous example (PyGis_example.py) and a Colab python notebook (PvGis_example.ipynb).

Colab Python notebook

You can test the previous example online in your browser without any additional tool thanks to Google Colaboratory notebooks.

Google Colaboratory Python notebook

Summary

We have learnt how to get meteorological data from PVGIS database in Python in this tutorial. The PVGIS Python class, an example Python script and a Colab notebook are available in our GitHub repository.

I hope you liked this tutorial, please consider to rate it with the starts you can find below and share it if you find it useful, this gives us feedback about how we are doing. Also, we would love to know which cool projects you are doing or planning to do with this data, so share your plans with us in the comments below :-).

5
1
vote Article Rating

Related

相关文章
为您推荐
各种观点

报歉!评论已关闭.