From fb9328c6dfa7f136e601d715c328ef5cc7c1f15e Mon Sep 17 00:00:00 2001 From: Jakob Gebler Date: Mon, 22 Apr 2024 23:34:05 -1100 Subject: [PATCH] Update readme and examples (#113) * Update README.md * Update README.md * Update example.py change the example to a dynamic timestamp * change the examples to use dynamic timestamps. --------- Co-authored-by: Jakob Gebler --- README.md | 9 +++++---- examples/example.py | 8 ++++---- examples/example_notebook.ipynb | 9 +++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index da7b7e83..53d1f20b 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,16 @@ The current model uses GFS or ICON NWPs to predict the solar generation at a sit ```python from quartz_solar_forecast.forecast import run_forecast from quartz_solar_forecast.pydantic_models import PVSite +from datetime import datetime # make a pv site object site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25) -# run model, uses ICON NWP data by default -predictions_df = run_forecast(site=site, ts='2023-11-01') +# run model for today, using ICON NWP data +predictions_df = run_forecast(site=site, ts=datetime.today(), nwp_source="icon") ``` -Which gives the following prediction +which should result in a time series similar to this one: ![https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/blob/main/predictions.png?raw=true](https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/blob/main/predictions.png?raw=true) @@ -91,7 +92,7 @@ The model also uses the following variables, which are currently all set to nan ## Known restrictions - The model is trained on [UK MetOffice](https://www.metoffice.gov.uk/services/data/met-office-weather-datahub) NWPs, but when running inference we use [GFS](https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast) data from [Open-meteo](https://open-meteo.com/). The differences between GFS and UK MetOffice could led to some odd behaviours. -- It looks like the GFS data on Open-Meteo is only available for free for the last 3 months. +- Depending, whether the timestamp for the prediction lays more than 90 days in the past or not, different data sources for the NWP are used. If we predict within the last 90 days, we can use ICON or GFS from the open-meteo Weather Forecast API. Since ICON doesn't provide visibility, this parameter is queried from GFS in any case. If the date for the prediction is further back in time, a reanalysis model of historical data is used (open-meteo | Historical Weather API). The historical weather API doesn't't provide visibility at all, that's why it's set to a maximum of 24000 meter in this case. This can lead to some loss of precision. ## Evaluation diff --git a/examples/example.py b/examples/example.py index d52fe0fb..d76d2796 100644 --- a/examples/example.py +++ b/examples/example.py @@ -1,14 +1,14 @@ """ Example code to run the forecast""" from quartz_solar_forecast.forecast import run_forecast from quartz_solar_forecast.pydantic_models import PVSite - +from datetime import datetime, timedelta def main(): # make input data site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25) - - # run model - predictions_df = run_forecast(site=site, ts="2023-10-30") + + ts = datetime.today() - timedelta(weeks=1) + predictions_df = run_forecast(site=site, ts=ts, nwp_source="icon") print(predictions_df) print(f"Max: {predictions_df['power_wh'].max()}") diff --git a/examples/example_notebook.ipynb b/examples/example_notebook.ipynb index e720fe80..d13f200d 100644 --- a/examples/example_notebook.ipynb +++ b/examples/example_notebook.ipynb @@ -26,6 +26,7 @@ "# Import forecast script and PVSite class.\n", "from quartz_solar_forecast.forecast import run_forecast\n", "from quartz_solar_forecast.pydantic_models import PVSite\n", + "from datetime import datetime, timedelta\n", "\n", "# Import matplotlib and plotly for plotting.\n", "import plotly.express as px\n", @@ -49,9 +50,9 @@ "outputs": [], "source": [ "# Run the forecast for a specific initial timestamp.\n", - "# This generates a forecast at 15 minute intervals for the following 48 hours.\n", - "predictions_df = run_forecast(site=site, ts='2023-11-01')\n", - "print(predictions_df)" + "# This generates a forecast at 15 minute intervals for 48 hours.\n", + "ts = datetime.today() - timedelta(weeks=1)\n", + "predictions_df = run_forecast(site=site, ts=ts, nwp_source=\"icon\")" ] }, { @@ -93,7 +94,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.0" + "version": "3.10.12" } }, "nbformat": 4,