Skip to content

Commit

Permalink
Added init.py for CI tests (#71)
Browse files Browse the repository at this point in the history
* Bump version: 1.0.9 → 1.0.10 [skip ci]

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

* Bump version: 1.0.10 → 1.0.11 [skip ci]

* Replace H with h inside pandas' floor function (#64)

Thanks @0xFrama for this

* Bump version: 1.0.11 → 1.0.12 [skip ci]

* Added Contribution Guide (#65)

* added contribution guide

* added reference to coding style

* Bump version: 1.0.12 → 1.0.13 [skip ci]

* docs: add roshnaeem as a contributor for doc (#67)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Test set analysis (#60)

* test set analysis

* added link to nbviewer in notebook

* deleted checkpoints

* Delete checkpoints

* delete metadata.csv

* using metadata from hugging face

* remove unused import

* Bump version: 1.0.13 → 1.0.14 [skip ci]

* docs: add bikramb98 as a contributor for code (#68)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* fetches live Enphase data at the moment it is called (#66)

* fetches live Enphase data at the moment it is called

replace 'user_enphase_api_key' and 'user_enphase_user_id' with the actual Enphase API key and user ID. The make_pv_data function now fetches live data from the Enphase API and combines it with the existing fake PV data
This "may" not be from the time of interference, do i add make use of timestamps to enable it?

* Added Flag indicating whether to use live Enphase data or not

Now the user will have an option whether to use live enphase data or the default data

* Updated site object to accomodate is_inverter option + created /inverters/enphase.py file

* added environment variables

* Bump version: 1.0.14 → 1.0.15 [skip ci]

* added init.py in invertors directory

* fixed the import of enphase_data

---------

Co-authored-by: BumpVersion Action <bumpversion@github-actions>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Peter Dudfield <[email protected]>
Co-authored-by: Francesco <[email protected]>
Co-authored-by: Bikram Baruah <[email protected]>
Co-authored-by: Aryan Bhosale <[email protected]>
  • Loading branch information
7 people authored Mar 4, 2024
1 parent 3eefdc8 commit d5fc1c5
Show file tree
Hide file tree
Showing 15 changed files with 5,026 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@
"contributions": [
"doc"
]
},
{
"login": "0xFrama",
"name": "Francesco",
"avatar_url": "https://avatars.githubusercontent.com/u/30957828?v=4",
"profile": "https://github.com/0xFrama",
"contributions": [
"code"
]
},
{
"login": "roshnaeem",
"name": "Rosheen Naeem",
"avatar_url": "https://avatars.githubusercontent.com/u/47316899?v=4",
"profile": "https://github.com/roshnaeem",
"contributions": [
"doc"
]
},
{
"login": "bikramb98",
"name": "Bikram Baruah",
"avatar_url": "https://avatars.githubusercontent.com/u/24806286?v=4",
"profile": "https://github.com/bikramb98",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = True
current_version = 1.0.9
current_version = 1.0.15
message = Bump version: {current_version} → {new_version} [skip ci]

[bumpversion:file:setup.py]
Expand Down
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# User needs to add their Enphase API details
ENPHASE_API_KEY = 'user_enphase_api_key'
ENPHASE_USER_ID = 'user_enphase_user_id'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quartz Solar Forecast
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

The aim of the project is to build an open source PV forecast that is free and easy to use.
Expand Down Expand Up @@ -141,6 +141,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="http://github.com/aryanbhosale"><img src="https://avatars.githubusercontent.com/u/36108149?v=4?s=100" width="100px;" alt="Aryan Bhosale"/><br /><sub><b>Aryan Bhosale</b></sub></a><br /><a href="https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/commits?author=aryanbhosale" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/0xFrama"><img src="https://avatars.githubusercontent.com/u/30957828?v=4?s=100" width="100px;" alt="Francesco"/><br /><sub><b>Francesco</b></sub></a><br /><a href="https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/commits?author=0xFrama" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/roshnaeem"><img src="https://avatars.githubusercontent.com/u/47316899?v=4?s=100" width="100px;" alt="Rosheen Naeem"/><br /><sub><b>Rosheen Naeem</b></sub></a><br /><a href="https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/commits?author=roshnaeem" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bikramb98"><img src="https://avatars.githubusercontent.com/u/24806286?v=4?s=100" width="100px;" alt="Bikram Baruah"/><br /><sub><b>Bikram Baruah</b></sub></a><br /><a href="https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/commits?author=bikramb98" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
51 changes: 51 additions & 0 deletions contribution_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contribution Guide

## Welcome
Welcome to Open Climate Fix project! Open Climate Fix fosters an inclusive open-source community, welcoming participation from everyone. We value all forms of contributions, whether to our codebase or documentation, and we appreciate your support.
Before you begin, make sure to go through the [README.md](https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/blob/main/README.md) file of project to understand the project.

## Environment Setup
`Open-Source-Quartz-Solar-Forecast` project is developed with Python, that supports our open-source PV forecast model's computational needs. To set up and contribute to the project, Python version 3 is required.

### Clone the Repository
Follow the following steps to setup the project on your machine.


1. Fork the [Open-Source-Quartz-Solar-Forecast repository](https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast) by clicking on the ‘Fork’ button. This creates a copy of the code under your GitHub user account. Your fork will have your own GitHub username.

2. Clone your fork of the project by running the following command:
```
git clone https://github.com/<Your GitHub handle>/Open-Source-Quartz-Solar-Forecast.git
```

3. Navigate to the directory.
```
cd Open-Source-Quartz-Solar-Forecast
```

4. Start contributing!!!


## How to Contribute

For contributing to Open Climate Fix project, we recommend following these detailed steps.

### Step 1: Find an Issue to Work On
Begin by exploring the issues listed on the project's GitHub [issues](https://github.com/openclimatefix/Open-Source-Quartz-Solar-Forecast/issues) page. If you're new to the project, look for issues tagged with `good first issue`, these are specifically selected to be more accessible for newcomers. Selecting an issue that aligns with your interests or expertise is a great way to contribute effectively.

### Step 2: Communicate Your Interest
Before diving into coding, it's a good practice to comment on the issue you're interested in. This lets the maintainers know you're working on it and prevents duplicate efforts. It's also an excellent opportunity to ask any clarifying questions and discuss your approach.

### Step 3: Create a New Branch
For every new contribution, create a branch in your local repository. A branch is a way to keep your changes seprate from the main part of the project called `main`. This branch should be based off the main project's latest main branch. Naming your branch with a convention like `feature/your-feature-name` or `fix/issue-description` can help identify its purpose.

### Step 4: Open a Pull Request (PR)
Once you're satisfied with your contribution, push your branch to your fork on GitHub and open a pull request against the original Open Climate Fix repository. In your pull request description, reference the issue you're addressing and provide a summary of your changes. Providing screenshots or output snippets can be particularly helpful for visual changes or user interface improvements.

### Step 5: Request a Review
After submitting your pull request, you can request a review from the project maintainers or specific contributors by mentioning them in your PR comments. Once your pull request is approved, a project maintainer will merge it into the main branch.

> Don't forget to keep your local repository and fork updated with the main project to ease future contributions.
## Code Style
For checking our coding style, please refer to [coding_style.md](https://github.com/openclimatefix/.github/blob/main/coding_style.md).
28 changes: 22 additions & 6 deletions quartz_solar_forecast/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
import json
import ssl
from datetime import datetime
import os # Add import for os module

import numpy as np
import pandas as pd
import requests
import xarray as xr

from quartz_solar_forecast.pydantic_models import PVSite
from quartz_solar_forecast.inverters.enphase import get_enphase_data # Added import for get_enphase_data from /inverters/enphase.py

ssl._create_default_https_context = ssl._create_unverified_context

# Load environment variables from .env file
from dotenv import load_dotenv

# Assigning secrets from the .env file
ENPHASE_API_KEY = os.getenv('ENPHASE_API_KEY')
ENPHASE_USER_ID = os.getenv('ENPHASE_USER_ID')

def get_nwp(site: PVSite, ts: datetime, nwp_source: str = "icon") -> xr.Dataset:
"""
Expand Down Expand Up @@ -111,20 +119,28 @@ def format_nwp_data(df: pd.DataFrame, nwp_source:str, site: PVSite):
)
return data_xr


def make_pv_data(site: PVSite, ts: pd.Timestamp) -> xr.Dataset:
"""
Make fake PV data for the site
Make PV data by combining Enphase live data and fake PV data
Later we could add PV history here
:param site: the PV site
:param ts: the timestamp of the site
:return: The fake PV dataset in xarray form
:return: The combined PV dataset in xarray form
"""

# make fake pv data, this is where we could add history of a pv system
generation_wh = [[np.nan]]
# Check if the site has an inverter and use_enphase_data flag accordingly
use_enphase_data = site.is_inverter

if use_enphase_data:
# Fetch live Enphase data and store it in live_generation_wh
live_generation_wh = get_enphase_data(ENPHASE_USER_ID, ENPHASE_API_KEY)
else:
live_generation_wh = np.nan # Default value if not using live Enphase data

# Combine live Enphase data with fake PV data, this is where we could add history of a pv system
generation_wh = [[live_generation_wh]]
lon = [site.longitude]
lat = [site.latitude]
timestamp = [ts]
Expand All @@ -145,4 +161,4 @@ def make_pv_data(site: PVSite, ts: pd.Timestamp) -> xr.Dataset:
)
da = da.to_dataset(name="generation_wh")

return da
return da
10 changes: 10 additions & 0 deletions quartz_solar_forecast/dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Test set analysis
The test set contains the data used for testing the solar forecast models developed. It contains 2500 data points, with `pv_id` and `timestamps` of when the data was collected. Upon analysing the dataset, the following observations were made:
1. The data is pretty evenly distrbuted throughout the year, with the highest number of data points from the month of May (256 data points)
2. Looking at distribution by hour of the day, the highest number of data points is from 19:00 hrs (132 data points), and the least from 00:00 hrs (87 data points)

By analysing the metadata, available at [Hugging Face](https://huggingface.co/datasets/openclimatefix/uk_pv), along with the test set, it can be observed that:
1. Most of the data in the test set has a tilt angle of 30-34 degrees
2. The maximum kwp is 4.0 & the minmum kwp is 2.25 in the test set.

A detailed anaysis of the test set can be found at quartz_solar_forecast/dataset/dataset_analysis/test_set_analysis.ipynb
4,880 changes: 4,880 additions & 0 deletions quartz_solar_forecast/dataset/dataset_analysis/test_set_analysis.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion quartz_solar_forecast/dataset/make_test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def filter_timestamps_if_hf_files_exists(timestamps_full: pd.DatetimeIndex):
fs = HfFileSystem()
# print(fs.ls("datasets/openclimatefix/dwd-icon-eu/data/2022/4/11/", detail=False))
for timestamp in timestamps_full:
timestamp_floor = timestamp.floor("6H")
timestamp_floor = timestamp.floor("6h")
_, huggingface_file = make_hf_filename(timestamp_floor)
huggingface_file = huggingface_file[14:]

Expand Down
2 changes: 1 addition & 1 deletion quartz_solar_forecast/eval/nwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_nwp_for_one_timestamp_one_location(
# print(fs.ls("datasets/openclimatefix/dwd-icon-eu/data/2022/4/11/", detail=False))

# round timestamp to 6 hours floor
timestamp_floor = timestamp.floor("6H")
timestamp_floor = timestamp.floor("6h")
date_and_hour, huggingface_file = make_hf_filename(timestamp_floor)

# dataset variables, note these are unique for ICON
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions quartz_solar_forecast/inverters/enphase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import requests

def get_enphase_data(enphase_user_id: str, enphase_api_key: str) -> float:
"""
Get live PV generation data from Enphase API
:param enphase_user_id: User ID for Enphase API
:param enphase_api_key: API Key for Enphase API
:return: Live PV generation in Watt-hours, assumes to be a floating-point number
"""
url = f'https://api.enphaseenergy.com/api/v2/systems/{enphase_user_id}/summary'
headers = {'Authorization': f'Bearer {enphase_api_key}'}

response = requests.get(url, headers=headers)
data = response.json()

# Extracting live generation data assuming it's in Watt-hours
live_generation_wh = data['current_power']['power']

return live_generation_wh
4 changes: 4 additions & 0 deletions quartz_solar_forecast/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ class PVSite(BaseModel):
ge=0,
le=360,
)
is_inverter: bool = Field(
default=False,
description="Flag indicating whether the site has an inverter (e.g., Enphase). If True, use_enphase_data will be considered.",
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="quartz_solar_forecast",
version="1.0.9",
version="1.0.15",
license="MIT",
author="Peter Dudfield",
author_email="[email protected]",
Expand Down

0 comments on commit d5fc1c5

Please sign in to comment.