Skip to content
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

30 add support for downloading capacity data #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ These methods include the following optional parameters:
|`period`|Set the desired temporal resolution (in minutes) for PV outturn estimates. Options are 30 (default) or 5.|
|`dataframe`|Set `dataframe=True` and the results will be returned as a Pandas DataFrame object which is generally much easier to work with. The columns of the DataFrame will be _pes_id_ or _gsp_id_, _datetime_gmt_, _generation_mw_, plus any extra fields specified.|

There is also a method for extracting PV deployment (a.k.a capacity) data:
|Method|Description|Docs Link|
|------|-----------|---------|
|`PVLive.deployment(region="gsp", include_history=False, by_system_size=False, release=0)`|Download PV deployment datasets from the API.|[🔗](https://sheffieldsolar.github.io/PV_Live-API/build/html/modules.html#pvlive_api.pvlive.PVLive.deployment)|


## Code Examples

See [pvlive_api_demo.py](https://github.com/SheffieldSolar/PV_Live-API/blob/master/pvlive_api_demo.py) for more example usage.
Expand Down Expand Up @@ -146,7 +152,7 @@ There is also a Docker Image hosted on Docker Hub which can be used to download
Sheffield Solar will endeavour to update this library in sync with the [PV_Live API](https://www.solar.sheffield.ac.uk/pvlive/api/ "PV_Live API webpage") and ensure the latest version of this library always supports the latest version of the PV_Live API, but cannot guarantee this. To make sure you are forewarned of upcoming changes to the API, you should email [[email protected]](mailto:[email protected]?subject=PV_Live%20API%20email%20updates "Email Sheffield Solar") and request to be added to the PV_Live user mailing list.

To upgrade the code:
* Run `pip install --upgrade git+https://github.com/SheffieldSolar/PV_Live-API`
* Run `pip install --upgrade pvlive-api`

## Notes on PV_Live GB national update cycle

Expand Down
84 changes: 62 additions & 22 deletions Tests/test_pvlive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ def setUp(self):
"""
self.api = PVLive()
self.expected_dtypes = {
'pes_id': ptypes.is_integer_dtype,
'gsp_id': ptypes.is_integer_dtype,
'datetime_gmt': ptypes.is_datetime64_any_dtype,
'generation_mw': ptypes.is_float_dtype,
'bias_error': ptypes.is_float_dtype,
'capacity_mwp': ptypes.is_float_dtype,
'installedcapacity_mwp': ptypes.is_float_dtype,
'lcl_mw': ptypes.is_float_dtype,
'stats_error': ptypes.is_float_dtype,
'ucl_mw': ptypes.is_float_dtype,
'uncertainty_MW': ptypes.is_float_dtype,
'site_count': ptypes.is_integer_dtype
"pes_id": ptypes.is_integer_dtype,
"gsp_id": ptypes.is_integer_dtype,
"datetime_gmt": ptypes.is_datetime64_any_dtype,
"generation_mw": ptypes.is_float_dtype,
"bias_error": ptypes.is_float_dtype,
"capacity_mwp": ptypes.is_float_dtype,
"installedcapacity_mwp": ptypes.is_float_dtype,
"lcl_mw": ptypes.is_float_dtype,
"stats_error": ptypes.is_float_dtype,
"ucl_mw": ptypes.is_float_dtype,
"uncertainty_MW": ptypes.is_float_dtype,
"site_count": ptypes.is_integer_dtype,
"release": ptypes.is_string_dtype,
"GSPs": ptypes.is_string_dtype,
"llsoa": ptypes.is_string_dtype,
"system_size": ptypes.is_string_dtype,
"install_month": ptypes.is_datetime64_dtype,
"dc_capacity_mwp": ptypes.is_float_dtype,
"system_count": ptypes.is_integer_dtype,
"cumul_capacity_mwp": ptypes.is_float_dtype,
}

def check_df_dtypes(self, api_df):
Expand All @@ -40,31 +48,32 @@ def check_df_dtypes(self, api_df):
against the expected dtypes from the API.
"""
for column in api_df.columns:
with self.subTest(column=column):
assert self.expected_dtypes[column](api_df[column])
if column in self.expected_dtypes:
with self.subTest(column=column):
assert self.expected_dtypes[column](api_df[column])

def check_gsp_tuple_dtypes(self, data):
"""
Check the dtypes of a gsp tuple
against the expected dtypes from the API.
"""
with self.subTest(column='gsp_id'):
with self.subTest(column="gsp_id"):
assert isinstance(data[0], int)
with self.subTest(column='datetime_gmt'):
with self.subTest(column="datetime_gmt"):
assert isinstance(data[1], str)
with self.subTest(column='generation_mw'):
with self.subTest(column="generation_mw"):
assert isinstance(data[2], float)

def check_pes_tuple_dtypes(self, data):
"""
Check the dtypes of a pes tuple
against the expected dtypes from the API.
"""
with self.subTest(column='pes_id'):
with self.subTest(column="pes_id"):
assert isinstance(data[0], int)
with self.subTest(column='datetime_gmt'):
with self.subTest(column="datetime_gmt"):
assert isinstance(data[1], str)
with self.subTest(column='generation_mw'):
with self.subTest(column="generation_mw"):
assert isinstance(data[2], float)

def check_pes_tuple(self, data):
Expand All @@ -89,8 +98,17 @@ def check_df_columns(self, data):
against the expected columns.
"""
with self.subTest():
assert (('pes_id' in data or 'gsp_id' in data) and 'datetime_gmt' in data
and 'generation_mw' in data)
assert (("pes_id" in data or "gsp_id" in data) and "datetime_gmt" in data
and "generation_mw" in data)

def check_deployment_df_columns(self, data):
"""
Check the columns of the returned DataFrame
against the expected columns.
"""
with self.subTest():
assert (("llsoa" in data or "GSPs" in data) and "release" in data
and "dc_capacity_mwp" in data)

def test_latest(self):
"""Tests the latest function."""
Expand Down Expand Up @@ -218,5 +236,27 @@ def test_at_time(self):
self.check_df_columns(data)
self.check_df_dtypes(data)

def test_deployment(self):
"""Tests the deployment function."""
# import pdb; pdb.set_trace()
data = self.api.deployment(region="gsp")
self.check_deployment_df_columns(data)
self.check_df_dtypes(data)
data = self.api.deployment(region="llsoa")
self.check_deployment_df_columns(data)
self.check_df_dtypes(data)
data = self.api.deployment(region="gsp", include_history=True)
self.check_deployment_df_columns(data)
self.check_df_dtypes(data)
with self.subTest(test_type="errors"):
with self.assertRaises(ValueError):
data = self.api.deployment(region="gsp", by_system_size=True)
data = self.api.deployment(region="gsp", include_history=True, by_system_size=True)
self.check_deployment_df_columns(data)
self.check_df_dtypes(data)
data = self.api.deployment(region="gsp", release=1)
self.check_deployment_df_columns(data)
self.check_df_dtypes(data)

if __name__ == "__main__":
unittest.main(verbosity=2)
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/modules.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 971e8579e9e318c2d31a6c3345838f85
config: d5c4fb8b6d44d4c8fa5f102585cf2a6c
tags: 645f666f9bcd5a90fca523b33c5a78b7
18 changes: 8 additions & 10 deletions docs/build/html/_modules/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; PV_Live API 1.2.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />


<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=fd7cadf9"></script>
<script src="../_static/doctools.js?v=888ff710"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
Expand Down
Loading
Loading