Solar radiation data

Author
Affiliation

Beniamino Sartini

University of Bologna

Published

May 1, 2024

Modified

June 16, 2024

1 Copernicus Data

This functions provide a wrap for CAMS solar radiation time-series. The data can be download manually on the website or it is possible to use the CDS API and the wrapping package in python.

# import cdsapi
# import datetime as dt
# c = cdsapi.Client()
def cams_solar_radiation_ts(latitude, longitude, start = None, end = None, altitude = None, filename = None):
  # Default start time for time series 
  if start is None:
    start = "2005-01-01"
    print('The argument "start" is missing, default is '+ start)
  else: 
    start = dt.datetime.strptime(start, "%Y-%m-%d").strftime("%Y-%m-%d")
  # Default end time for time series 
  if end is None:
    end = dt.date.today().strftime("%Y-%m-%d")
    print('The argument "end" is missing, default is '+ end)
  else: 
    end = dt.datetime.strptime(end, "%Y-%m-%d").strftime("%Y-%m-%d")
  # Default altitude (-999 default)
  if altitude is None:
    altitude = '-999.'
    print('The argument "altitude" is missing, default is '+ altitude)
  else: 
    altitude = str(altitude)
  # Default file name 
  if filename is None:
    filename = 'cams-'+str(latitude)+'_'+str(longitude)+'_'+start+'_'+end+'.csv'
    print('The argument "filename" is missing, default is '+ filename)
  else: 
    filename = str(filename)
  # Call API with custom arguments 
  c.retrieve(
      'cams-solar-radiation-timeseries',
      {
          'sky_type': 'observed_cloud',
          'location': {
              'latitude': latitude,
              'longitude': longitude,
          },
          'altitude': altitude,
          'date': start+'/'+end,
          'time_step': '1day',
          'time_reference': 'universal_time',
          'format': 'csv',
      }, filename)
# Required packages 
# library(lubridate)
# library(dplyr)
# library(tidyr)
getCAMS <- function(place, lat, lon, alt, from = "2005-01-01", to = Sys.Date()){

  # Default from and to data 
  from <- as.character(from)
  to <- as.character(to)

  # File Name in Temp (as csv file)
  file_name <- paste0("cams-", place)
  # Create a temporary csv file in the temporary directory
  temp <- base::tempfile(pattern = file_name, fileext = ".csv")
  # Download the file
  cams_solar_radiation_ts(latitude = lat, longitude = lon, 
                          start = from, end = to, altitude = alt, 
                          filename = temp)
  # Read the file
  response <- readr::read_csv(temp, show_col_types = FALSE)
  # Extract metadata
  meta <- readr::read_delim(temp,  skip = 0, n_max = 40, progress = FALSE,
                            delim = ":", show_col_types = FALSE)
  # Clean metadata 
  var_names <- c("from", "to", "lat", "lon", "alt", "tz")
  meta <- dplyr::bind_cols(variable = var_names, meta[9:14, 2]) %>%
    dplyr::mutate(variable = stringr::str_trim(variable, side = "both")) %>%
    tidyr::spread("variable", ` utf-8`) %>%
    dplyr::mutate(alt = as.numeric(alt),
                  lat = as.numeric(lat),
                  lon = as.numeric(lon),
                  to = as.POSIXct(to),
                  from = as.POSIXct(from),
                  tz = dplyr::case_when(
                    tz == " Universal time (UT)" ~ "UTC",
                    TRUE ~ tz))
  # Read temp data
  data <- readr::read_delim(temp, skip = 42, delim = ";", 
                            show_col_types = FALSE, progress = FALSE)
  # Standard col names
  colnames(data) <- c("date","TOA","clearsky_GHI","clearsky_BHI",
                      "clearsky_DHI", "clearsky_BNI","GHI","BHI",
                      "DHI","BNI","reliability")
  # Add metadata to solar data 
  data$lat <- meta$lat  # latitude   
  data$place <- place   # place   
  data$lon <- meta$lon  # longitude   
  data$alt <- meta$alt  # altitude   
  # Add date index 
  data$date <- purrr::map_chr(strsplit(data$date, "/"), ~.x[1])
  data$date <- as.POSIXct(data$date, tz = meta$tz)
  # Add seasonal data 
  data$Year <- lubridate::year(data$date)   # Year
  data$Month <- lubridate::month(data$date) # Number of month  
  data$Day <- lubridate::day(data$date)     # Number of day of month  
  data$date <- as.Date(data$date)           # Dates in YYYY-MM-DD
  # Reorder dataset 
  data <- dplyr::select(data, date, place, lat, lon, alt, Year, Month, Day,
                        TOA, GHI, clearsky_GHI, BHI, clearsky_BHI, DHI,
                        clearsky_DHI, BNI, clearsky_BNI, reliability)
  # Unlink and close the connection with temp
  base::unlink(temp)
  return(data)
}

2 PVGIS data

3 PVGIS Data and Solar Measurements

Another source of open data on temperature and solar radiation for Europe is provided by Photovoltaic Geographical Information System (PVGIS) maintained by the European Commission, that is a tool for citizens to evaluate their roof’s PV potential. It is a free database developed and maintained by the European Commission’s Joint Research Center, it provides the information about solar radiation and PV system performance for any location in Europe. There is little doubt that the very best way to measure solar radiation is to use high-quality sensors on the ground such as measurements stations. But to be useful, these measurements should fulfill a number of conditions:

  • Only high quality measurement sensors should be used.
  • Measurements should be performed at least every hour.
  • Sensors should be calibrated and cleaned regularly.
  • Data should be available for a long time period.

Nowadays the number of ground-based radiation measurements that fulfill these criteria is low and the stations often are very spaced making the connection between spaces even more difficult. For these reasons the use of satellite data to estimate the solar radiation at the earth surface is become a popular methods. Moreover the sources used are mostly geostationary meteorological satellites, such as the METEOSAT. The disadvantage of using satellite data is that the solar radiation at ground level must be calculated using a number of fairly complicated mathematical algorithms which do not use just satellite data, but also data on atmospheric water vapor, aerosols (dust, particles) and ozone. Some conditions can cause the calculations to lose accuracy, e.g. snow which can be mistaken for clouds, dust storms which can be difficult to detect in the satellite images. Nevertheless, the accuracy of satellite-based solar radiation data is now generally very good. For this reason, most of the solar radiation used in PVGIS are based on the satellite algorithms.

Back to top

Citation

BibTeX citation:
@online{sartini2024,
  author = {Sartini, Beniamino},
  title = {Solar Radiation Data},
  date = {2024-05-01},
  url = {https://greenfin.it/solar/solar-radiation-data.html},
  langid = {en}
}
For attribution, please cite this work as:
Sartini, Beniamino. 2024. “Solar Radiation Data.” May 1, 2024. https://greenfin.it/solar/solar-radiation-data.html.