Skip to content

mahmoud-40/uk-pv-national-gsp-api

 
 

Repository files navigation

UK PV National and GSP API

All Contributors

tags badge ease of contribution: medium Test Docker image

API for hosting nowcasting solar predictions. This is for GSP and National forecasts in the UK.

We use FastAPI.

Installation

Pull the docker image from

docker pull openclimatefix/nowcasting_api:latest

You will need to set the following environment variables:

  • AUTH0_DOMAIN - The Auth0 domain which can be collected from the Applications/Applications tab. It should be something like 'XXXXXXX.eu.auth0.com'
  • AUTH0_API_AUDIENCE - THE Auth0 api audience, this can be collected from the Applications/APIs tab. It should be something like https://XXXXXXXXXX.eu.auth0.com/api/v2/
  • DB_URL- The Forecast database URL used to get GSP forecast data
  • ORIGINS - Endpoints that are valid CORS origins. See FastAPI documentation.
  • N_HISTORY_DAYS - Default is just to load data from today and yesterday, but we can set this to 5, if we want the api always to return 5 days of data
  • FORECAST_ERROR_HOURS - using route /v0/system/GBstatus/check_last_forecast_run we can check if a forecast has been made in the last FORECAST_ERROR_HOURS hours
  • ADJUST_MW_LIMIT - the maximum the api is allowed to adjust the national forecast by
  • FAKE - This allows fake data to be used, rather than connecting to a database
  • QUERY_WAIT_SECONDS - The number of seconds to wait for an on going query
  • CACHE_TIME_SECONDS - The time in seconds to cache the data is used for
  • DELETE_CACHE_TIME_SECONDS - The time in seconds to after which the cache is delete
  • LOGLEVEL - The log level for the application.

Note you will need a database set up at DB_URL. This should use the datamodel in nowcasting_datamodel

There are several optional environment variables:

  • N_CALLS_PER_HOUR - API rate limit for most endpoints. Defaults to 3600 (1 per second).
  • N_SLOW_CALLS_PER_HOUR - API rate limit for slow endpoints. Defaults to 60 (1 per minute).

Documentation

Live documentation can be viewed at https://api.quartz.solar/docs or https://api.quartz.solar/swagger. This is automatically generated from the code.

Development

This can be done it two different ways: With Python or with Docker.

Python

Create a virtual env

python3 -m venv ./venv
source venv/bin/activate

Install Requirements and Run

pip install -r requirements.txt
cd src && uvicorn main:app --reload

Warning: If you don't have a local database set up, you can leave the DB_URL string empty (default not set) and set FAKE=True and the API will return fake data. This is a work in progress, so some routes might be need to be updated

Docker

🛑 Currently non-functional, needs updating to migrate database to match datamodel

  1. Make sure docker is installed on your system.
  2. Use docker-compose up in the main directory to start up the application.
  3. You will now be able to access it on http://localhost:80

Running the test suite

To run tests use the following command

docker stop $(docker ps -a -q)
docker-compose -f test-docker-compose.yml build
docker-compose -f test-docker-compose.yml run api

Routes to SQL tables

National

  graph TD;
      N1(national/forecast) --> Q1;
      Q1{Include metadata?>} -->|no| Q2;
      Q1 --> |yes| N2[NationalForecast];
      N4[ForecastValueLatest];
      Q2{forecast horizon <br> minutes not None}
      Q2-->|yes| N5[ForecastValueSevenDays];
      Q2-->|no| N4;

      NP1(national/pvlive)-->NP2;
      NP2[GSPYield];
Loading

GSP

  graph TD;
      G1(gsp/forecast/all);
      G1--> N3[ManyForecasts];

      G3(gsp/gsp_id/forecast) -->Q4;
      Q4{forecast horizon <br> minutes not None}
      Q4-->|yes| G7[ForecastValueSevenDays];
      Q4-->|no| G6[ForecastValueLatest];

      GP1(gsp/pvlive/all)-->GP2;
      GP2[LocationWithGSPYields];

      GP3(gsp/gsp_id/pvlive)-->GP4;
      GP4[GSPYield];
Loading

Extras

  graph TD;
      G1(status)-->G2;
      G2[Status];

      G3(gsp)-->G4
      G4[Location]

Loading

FAQ

TODO

Contributing and community

issues badge

Contributors

Thanks goes to these wonderful people (emoji key):

Peter Dudfield
Peter Dudfield

💻
Mohammed Faisal
Mohammed Faisal

💻
Bodale Denis
Bodale Denis

💻
Souhit Dey
Souhit Dey

💻
Flo
Flo

💻
Shanmukh
Shanmukh

💻
Sixte de Maupeou
Sixte de Maupeou

💻
rachel tipton
rachel tipton

💻
braddf
braddf

💻
Dorin
Dorin

👀
Peter Hull
Peter Hull

💻
Pedro Garcia Rodriguez
Pedro Garcia Rodriguez

💻
Richa
Richa

💻
Patrick de Mars
Patrick de Mars

💬
Vikram Pande
Vikram Pande

💻
Dr Ryan Pepper
Dr Ryan Pepper

💻
Parasa V Prajwal
Parasa V Prajwal

💻
Mahmoud Abdulmawlaa
Mahmoud Abdulmawlaa

💻

Part of the Open Climate Fix community.

About

API for hosting nowcasting solar predictions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 92.4%
  • Jupyter Notebook 7.3%
  • Dockerfile 0.3%