-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create datapipe for resampled format #6
Open
vrym2
wants to merge
6
commits into
main
Choose a base branch
from
raj/create_datapipe_for_resampled_format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
default_language_version: | ||
python: python3 | ||
|
||
ci: | ||
skip: [pydocstyle, flake8] | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
# list of supported hooks: https://pre-commit.com/hooks.html | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: debug-statements | ||
- id: detect-private-key | ||
|
||
# python code formatting/linting | ||
- repo: https://github.com/PyCQA/pydocstyle | ||
rev: 6.1.1 | ||
hooks: | ||
- id: pydocstyle | ||
args: | ||
[ | ||
--convention=google, | ||
"--add-ignore=D200,D202,D210,D212,D415,D105", | ||
"ukpn", | ||
] | ||
files: ^ukpn/ | ||
- repo: https://github.com/PyCQA/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
args: | ||
[ | ||
--max-line-length, | ||
"100", | ||
--extend-ignore=E203, | ||
--per-file-ignores, | ||
"__init__.py:F401", | ||
"ukpn", | ||
] | ||
files: ^ukpn/ | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.11.4 | ||
hooks: | ||
- id: isort | ||
args: [--profile, black, --line-length, "100", "ukpn"] | ||
- repo: https://github.com/psf/black | ||
rev: 22.12.0 | ||
hooks: | ||
- id: black | ||
args: [--line-length, "100"] | ||
|
||
# yaml formatting | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v3.0.0-alpha.4 | ||
hooks: | ||
- id: prettier | ||
types: [yaml] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: uk_pv_solar_farm_forecasting | ||
channels: | ||
- pytorch | ||
- conda-forge | ||
- defaults | ||
dependencies: | ||
- pip | ||
- pytorch | ||
- rioxarray | ||
- torchdata | ||
- torchvision | ||
- xarray | ||
- fsspec | ||
- zarr | ||
- cartopy | ||
- dask | ||
- pyproj | ||
- pyresample | ||
- geopandas | ||
- h5netcdf | ||
- scipy | ||
- pip: | ||
- einops | ||
- pathy | ||
- git+https://github.com/SheffieldSolar/PV_Live-API | ||
- pyaml_env | ||
- nowcasting_datamodel | ||
- gitpython | ||
- tqdm | ||
- bottleneck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
loaders: | ||
- type: python | ||
search_path: [ukpn/] | ||
processors: | ||
- type: filter | ||
- type: smart | ||
renderer: | ||
type: mkdocs | ||
pages: | ||
- title: Home | ||
name: index | ||
source: README.md | ||
- title: API Documentation | ||
children: | ||
- title: Data | ||
contents: [data] | ||
mkdocs_config: | ||
site_name: PV solar farm forecasting | ||
theme: readthedocs | ||
repo_url: https://github.com/openclimatefix/pv-solar-farm-forecasting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
torch | ||
torchdata | ||
Cartopy>=0.20.3 | ||
xarray | ||
zarr | ||
fsspec | ||
einops | ||
numpy | ||
pandas | ||
rioxarray | ||
pathy | ||
pyaml_env | ||
nowcasting_datamodel | ||
gitpython | ||
geopandas | ||
dask | ||
pvlib | ||
jpeg_xl_float_with_nans | ||
h5netcdf | ||
tqdm | ||
bottleneck | ||
pyproj | ||
pyresample | ||
fastparquet | ||
scipy | ||
pytorch_lightning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from ukpn.scripts import construct_url, get_metadata | ||
|
||
|
||
def test_download_metadata(): | ||
cantubry_api_url = "https://ukpowernetworks.opendatasoft.com/api/records/1.0/search/?dataset=embedded-capacity-register&q=&facet=grid_supply_point&facet=licence_area&facet=energy_conversion_technology_1&facet=flexible_connection_yes_no&facet=connection_status&facet=primary_resource_type_group&refine.grid_supply_point=CANTERBURY+NORTH&refine.energy_conversion_technology_1=Photovoltaic" | ||
download = get_metadata(api_url=cantubry_api_url, print_data=True) | ||
|
||
|
||
def test_construct_url(): | ||
url = construct_url( | ||
list_of_facets=[ | ||
"grid_supply_point", | ||
"licence_area", | ||
"energy_conversion_technology_1", | ||
"flexible_connection_yes_no", | ||
"connection_status", | ||
"primary_resource_type_group", | ||
], | ||
refiners=["grid_supply_point", "energy_conversion_technology_1"], | ||
refine_values=["CANTERBURY+NORTH", "Photovoltaic"], | ||
) | ||
search_url = get_metadata(api_url=url, print_data=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""DataPipes""" | ||
from ukpn import scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""Import Functions""" | ||
from .download_data import construct_url, get_metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""This class is ued to retrieve data through API calls""" | ||
import json | ||
import logging | ||
from pprint import pprint | ||
|
||
import requests | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_metadata(api_url: str, print_data: bool = False): | ||
""" | ||
This function retrievs metadata through api calls | ||
|
||
Args: | ||
api_url: The api url link that emiits json format data | ||
print_data: Optional to choose printing the data | ||
""" | ||
|
||
response_api = requests.get(api_url) | ||
while True: | ||
if response_api == 200: | ||
logger.info(f"The api resposne {response_api} is successful") | ||
else: | ||
logger.warning(f"The api resposne {response_api} is unsuccessul") | ||
logger.info(f"Please enter the correct {'url'}") | ||
break | ||
|
||
# Get the data from the resposne | ||
raw_data = response_api.text | ||
|
||
# Parse the data into json format | ||
data_json = json.loads(raw_data) | ||
data_first_record = data_json["records"][0] | ||
|
||
if print_data: | ||
pprint(data_first_record) | ||
|
||
|
||
def construct_url( | ||
dataset_name: str = "embedded-capacity-register", | ||
list_of_facets=None, | ||
refiners=None, | ||
refine_values=None, | ||
): | ||
"""This function constructs a downloadble url of JSON data | ||
|
||
For more information, please visit | ||
- https://ukpowernetworks.opendatasoft.com/pages/home/ | ||
|
||
Args: | ||
dataset_name: Name of the dataset that needs to be downloaded, defined by UKPN | ||
list_of_facets: List of facets that needs to be included in the JSON data | ||
refiners: list of refiner terms that needs to refined from the JSON data | ||
refine_values: List of refine values of the refiners | ||
|
||
Note: | ||
refiners and refine values needs to be exactly mapped | ||
""" | ||
# Constructing a base url | ||
base_url = "https://ukpowernetworks.opendatasoft.com/api/records/1.0/search/?dataset=" | ||
base_url = base_url + dataset_name | ||
|
||
# A seperator in the url | ||
seperator = "&" | ||
|
||
# A questionare in the url | ||
questionare = "q=" | ||
|
||
# A facet questionare in the url | ||
facet_questionare = "facet=" | ||
|
||
# Constructing a facet string from the list of facets | ||
facet_str = [facet_questionare + x for x in list_of_facets] | ||
facet_str = seperator.join(facet_str) | ||
facet_str = str(questionare + seperator + facet_str) | ||
|
||
# Constructing a refiner string to refine the JSON data | ||
refine_questionare = "refine." | ||
refiners = [refine_questionare + x for x in refiners] | ||
refiners = list(map(lambda x, y: x + str("=") + y, refiners, refine_values)) | ||
refiners = seperator.join(refiners) | ||
|
||
# Constructing the final url | ||
final_url = [base_url, facet_str, refiners] | ||
final_url = seperator.join(final_url) | ||
return final_url |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these more util=y kinda ones, especially since they are the same between this PR and the other one, I would make them its own PR and merge that instead, so this PR is just focused on the datapipe bit, and not the extra formatting bits.