Solar Consumer

This code can be used to download solar forecasts and save them to a PostgreSQL database by retrieving solar generation estimates for embedded solar farms and preparing the data for analysis.
https://github.com/openclimatefix/solar-consumer

Category: Renewable Energy
Sub Category: Photovoltaics and Solar Energy

Keywords from Contributors

nowcasting eumetsat dbml pvsite pvoutput solar forecasting-models graph-neural-networks weather gan

Last synced: about 17 hours ago
JSON representation

Repository metadata

Pull and save solar generation and forecasts

README.md

Solar Consumer

All Contributors

ease of contribution: easy

This code can be used to download solar forecasts and save them to a PostgreSQL database. It fetches solar generation estimates for embedded solar farms and processes the data for analysis.
We currently collect

  • UK: Forecast can be retreived from NESO. Generation Data can be retrevied from PVLive.
  • NL: Generation values from Ned NL, both national and region. National Forecast values from Ned NL too.
  • DE: Generation values from ENTSOE for several TSOs.
  • BE: Solar PV forecast data (national and regional) from Elia Open Data API.
  • India (Rajasthan): Real-time solar and wind generation data from RUVNL (Rajasthan Urja Vikas Nigam Limited).

India – RUVNL (Rajasthan)

The solar consumer supports RUVNL (Rajasthan, India) real-time generation data.

  • Both solar and wind generation are supported
  • Data is fetched via solar-consumer
  • Generation data can be saved directly to the site_database
  • Separate sites are created for solar and wind generation
  • No separate ruvnl-consumer service is required

Here are the different sources of data, and which methods can be used to save the results

Source Country CSV Data Platform DB (Legacy) Site DB (Legacy)
PVLive 🇬🇧
NESO forecast 🇬🇧
Ned-nl 🇳🇱
Ned-nl forecast 🇳🇱
Germany (ENTSOE) 🇩🇪
Elia Open Data 🇧🇪
RUVNL (Rajasthan SLDC) 🇮🇳

Requirements

  • Docker
  • Docker Compose

Installation & Running

  1. Clone the repository:
git clone https://github.com/openclimatefix/neso-solar-consumer.git
cd neso-solar-consumer
  1. Copy the example environment file:
cp .example.env .env
  1. Start the application:
docker compose up -d

The above command will:

  • Start a PostgreSQL database container
  • Build and start the NESO Solar Consumer application
  • Configure all necessary networking between containers

To stop the application:

docker compose down

To view logs:

docker compose logs -f

Note: The PostgreSQL data is persisted in a Docker volume. To completely reset the database, use:

docker compose down -v

Documentation

The package provides three main functionalities:

  1. Data Fetching: Retrieves solar forecast data from the NESO API
  2. Data Formatting: Processes the data into standardized forecast objects
  3. Data Storage: Saves the formatted forecasts to a PostgreSQL database

Key Components:

  • fetch_data.py: Handles API data retrieval
  • format_forecast.py: Converts raw data into forecast objects
  • save_forecast.py: Manages database operations
  • app.py: Orchestrates the entire pipeline

Environment Variables: (Can be found in the .example.env / .env file)

  • DB_URL=postgresql://postgres:postgres@localhost:5432/neso_solar : Database Configuration
  • COUNTRY="gb" : Country code for fetching data. Currently, other options are ["be", "ind_rajasthan", "nl"]
  • SAVE_METHOD: Ways to store the data. Options are ["db", "csv", "site-db"].
    site-db is supported for NL, DE, and India (RUVNL).
  • CSV_DIR=None : Directory to save CSV files if SAVE_METHOD="csv".
  • UK_PVLIVE_REGIME=in-day: For UK PVLive, the regime. Can be "in-day" or "day-after"
  • UK_PVLIVE_N_GSPS=342: For UK PVLive, the amount of gsps we pull data for.
  • UK_PVLIVE_BACKFILL_HOURS=2: For UK PVLive, the amount of backfill hours we pull, when regime="in-day"

Adding a New Country

This guide explains how to add a new country data source to Solar Consumer.

Overview

Adding a country typically involves:

  • Identifying a reliable data source or API
  • Implementing a country-specific fetch function
  • Adding tests
  • Saving data locally (CSV) and/or to the data platform

Step 1: Find a Data Source / API

Identify a reliable data source for the country:

  • Prefer official grid operators or government-backed APIs
  • Ensure timestamps, units, and generation values are clearly defined

If the API requires credentials:

  • Add the variable to .example.env
  • Document the required environment variable name

Step 2: Create a Fetch Function

Add a new country-specific fetch module inside the solar_consumer package.

Example naming convention:

solar_consumer/data/fetch_<country>.py

Next Steps

After adding the fetch function:

  • Register the country in the main fetch dispatcher
  • Add unit and integration tests under tests/
  • Verify the data runs locally and can be saved to CSV
  • If supported, ensure data can be saved to the data platform
  • Open a pull request for review

Saving Data to the Data Platform

If the country supports saving data to the data platform:

  1. Clone the data platform repository:
    git clone https://github.com/openclimatefix/data-platform.git
    
  2. Follow the data-platform README to start it locally (Docker-based setup).
  3. Configure Solar Consumer to point to the local data-platform instance.
  4. Run the consumer and verify data is ingested successfully.

Development

  1. Set up the development environment:
pip install ".[dev]"
  1. Run tests:
pytest
  1. Format code:
black .
  1. Run linter:
ruff check .

Running the Test Suite

The test suite includes unit tests and integration tests:

# Run all tests
pytest

# Run specific test file
pytest tests/test_fetch_data.py

# Run with coverage
pytest --cov=neso_solar_consumer

Continuous Integration (CI)

This reposistory has 2 main CI workflows - branch-ci and merged-ci.

  • branch-ci is triggered on all pushes to any branch except main, and on any pull request that is opened, reopened or updated. It runs the tests suite, lints the project, and builds and pushes a dev image.
  • merged-ci is triggered on any pull request merged into main. It bumps the git tag, and builds and pushes a container with that tag.

FAQ

Q: What format is the data stored in?
A: The data is stored in PostgreSQL using SQLAlchemy models, with timestamps in UTC and power values in megawatts.

Q: How often should I run the consumer?
A: This depends on your use case and the NESO API update frequency. The consumer can be scheduled using cron jobs or other scheduling tools.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing and community

issues badge

Contributors

Part of the Open Climate Fix community.

OCF Logo


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 5 days ago

Total Commits: 335
Total Committers: 27
Avg Commits per committer: 12.407
Development Distribution Score (DDS): 0.663

Commits in past year: 262
Committers in past year: 22
Avg Commits per committer in past year: 11.909
Development Distribution Score (DDS) in past year: 0.603

Name Email Commits
Peter Dudfield p****d@h****m 113
allcontributors[bot] 4****] 38
BumpVersion Action b****n@g****s 27
Siddharth s****9@g****m 26
katyalmohit 1****t 16
Reem-Albadwy 1****y 12
Rahul Ahuja r****a@l****m 11
alirashidAR a****8@y****m 11
aca23si s****3@s****k 11
Vishal v****1@g****m 10
Pavan p****9@g****m 9
ram-from-tvl r****l@g****m 8
devsjc 4****c 7
anxkhn a****8@g****m 6
Pavan p****n@P****l 5
Rahul-JOON r****6@g****m 4
Alexandra Udaltsova 4****a 3
Peter Ireland p****d@w****m 3
michael-gendy 6****y 3
Satyam Agrawal l****m@g****m 3
Prafful Vyas p****7@g****m 2
rahul v****3@g****m 2
Conor O'Callaghan 4****n 1
James Fulton d****n@y****k 1
ManzoorAhmedShaikh m****4@g****m 1
Niaha lalwani n****i@N****l 1
Sagarpillai S****i@i****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 1 day ago

Total issues: 16
Total pull requests: 69
Average time to close issues: 20 days
Average time to close pull requests: 6 days
Total issue authors: 3
Total pull request authors: 17
Average comments per issue: 2.25
Average comments per pull request: 1.29
Merged pull request: 52
Bot issues: 0
Bot pull requests: 11

Past year issues: 15
Past year pull requests: 62
Past year average time to close issues: 13 days
Past year average time to close pull requests: 6 days
Past year issue authors: 3
Past year pull request authors: 14
Past year average comments per issue: 2.07
Past year average comments per pull request: 1.23
Past year merged pull request: 45
Past year bot issues: 0
Past year bot pull requests: 9

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/openclimatefix/solar-consumer

Top Issue Authors

  • peterdudfield (14)
  • rahul-ahuja (1)
  • Shohail-Ismail (1)

Top Pull Request Authors

  • peterdudfield (22)
  • allcontributors[bot] (11)
  • rahul-ahuja (7)
  • Shohail-Ismail (6)
  • michael-gendy (4)
  • CodeVishal-17 (3)
  • alirashidAR (2)
  • Prafful-Vyas (2)
  • ADIMANV (2)
  • Rahul-JOON (2)
  • lambaaryan011 (2)
  • ManzoorAhmedShaikh (1)
  • vashisthrahul13 (1)
  • katyalmohit (1)
  • pavankulkarni007 (1)

Top Issue Labels

  • contributions-welcome (9)
  • good first issue (3)
  • ocf-internal (2)
  • bug (1)
  • enhancement (1)
  • documentation (1)

Top Pull Request Labels

Score: 6.340359303727752