4  Data

4.1 Data Sources

4.1.1 Energy Production Data

SwissEnergyCharts provides comprehensive energy market and production data, including real-time and historical insights into electricity generation, renewable contributions, and emissions. The data can be accesssed via a open and free API endpoint.

4.1.1.1 Example of Querying the Solar production data for Switzerland

Show Code
# Define base parameters
base_url <- "https://api.energy-charts.info/public_power"
power_type <- "Solar"
start_date <- as.Date("2024-07-01")
end_date <- as.Date("2024-07-31")

# Function to fetch solar generation data
fetch_solar_generation <- function(base_url, power_type, start_date, end_date) {
  query_url <- paste0(
    base_url,
    "?type=", power_type,
    "&start=", format(start_date, "%Y-%m-%d"),
    "&end=", format(end_date, "%Y-%m-%d")
  )
  
  response <- httr::GET(query_url, add_headers("accept" = "application/json"))
  if (httr::http_status(response)$category == "Success") {
    data <- httr::content(response, as = "text", encoding = "UTF-8")
    parsed_data <- jsonlite::fromJSON(data)
     # Extract timestamps and production data
    timestamps <- parsed_data$unix_seconds
    production_data <- parsed_data$production_types %>%
      dplyr::filter(name == power_type) %>% 
      dplyr::pull(data) %>% unlist()
    
    # Combine into a data frame
    if (!is.null(timestamps) && !is.null(production_data)) {
      df <- data.frame(
        timestamp = as.POSIXct(timestamps, origin = "1970-01-01", tz = "UTC"),
        generation = production_data
      )
      return(df)
    } else {
      stop("Production data or timestamps are missing in the API response.")
    }
    return(df)
  } else {
    stop("Failed to fetch data: ", http_status(response)$message)
  }
}

# Fetch the solar generation data
solar_data <- fetch_solar_generation(base_url, power_type, start_date, end_date)



# Plot the solar generation data for visualization
ggplot(solar_data, aes(x = timestamp, y = generation)) +
  geom_line(color = "orange") +
  labs(
    title = "Net Solar Power Generation (July 2024)",
    x = "Timestamp",
    y = "Generation (MW)"
  ) +
  theme_minimal()

You can explore SwissEnergyCharts’ API documentation for details on available endpoints, parameters, and response formats.


4.1.2 Energy Market Data

SwissEnergyCharts provides comprehensive energy market and production data, including real-time and historical insights into electricity generation, renewable contributions, and emissions. The data can be accesssed via a open and free API endpoint.

4.1.2.1 Example of Querying the Day-Ahead Prices for Switzerland

Show Code
# Define base parameters
base_url <- "https://api.energy-charts.info/price"
bidding_zone <- "CH"
start_date <- as.Date("2024-11-01")
end_date <- as.Date("2024-11-30")

# Function to fetch data from the API
fetch_prices <- function(base_url, bidding_zone, start_date, end_date) {
  query_url <- paste0(
    base_url,
    "?bzn=", bidding_zone,
    "&start=", format(start_date, "%Y-%m-%d"),
    "&end=", format(end_date, "%Y-%m-%d")
  )
  
  response <- httr::GET(query_url, add_headers("accept" = "application/json"))
  
  if (http_status(response)$category == "Success") {
    data <- content(response, as = "text", encoding = "UTF-8")
    parsed_data <- fromJSON(data)
    df <- data.frame(
      timestamp = as.POSIXct(parsed_data$unix_seconds, origin = "1970-01-01", tz = "UTC"),
      price = parsed_data$price
    )
    return(df)
  } else {
    stop("Failed to fetch data: ", http_status(response)$message)
  }
}

# Fetch the price data
price_data <- fetch_prices(base_url, bidding_zone, start_date, end_date)

# Plot the prices
ggplot2::ggplot(price_data, aes(x = timestamp, y = price)) +
  geom_line(color="#FF0000") +
  labs(
    title = "Day-Ahead Prices for Switzerland (November 2024)",
    x = "",
    y = "Price (EUR/MWh)"
  ) +
  theme_minimal()

You can explore SwissEnergyCharts’ API documentation for details on available endpoints, parameters, and response formats.


4.1.3 Weather Data

Meteomatics provides a high-resolution Weather API with global coverage and extensive parameters, such as temperature, wind, solar radiation, and precipitation. We obtained a free test access.

Example: Fetching Solar Radiation Data

curl -X GET "https://api.meteomatics.com/solar_radiation/2024-12-14T00:00:00Z--2024-12-14T23:59:59Z:P1H/46.94809,7.44744/json" \
-u "username:password"

Example Response:

{
  "data": [
    {
      "valid_time": "2024-12-14T12:00:00Z",
      "value": 550.5
    },
    {
      "valid_time": "2024-12-14T13:00:00Z",
      "value": 670.8
    }
  ]
}

Visit Meteomatics API Documentation for detailed integration guides and examples.


4.1.4 Bookmark for Data Enthusiasts

Handy Resources: - SwissEnergyCharts API Documentation - Meteomatics Weather API Documentation

By integrating these powerful data sources into their systems, energy utility companies can achieve higher forecasting accuracy, optimize grid operations, and support the energy transition effectively.