tyba-client 0.3.6__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tyba-client might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tyba-client
3
- Version: 0.3.6
3
+ Version: 0.4.0
4
4
  Summary: A Python API client for the Tyba Public API
5
5
  License: MIT
6
6
  Author: Tyler Nisonoff
@@ -12,13 +12,14 @@ Classifier: Programming Language :: Python :: 3.8
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
- Requires-Dist: dataclasses-json (>=0.5.4,<0.6.0)
16
- Requires-Dist: generation-models (>=0.4.1,<0.5.0)
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: dataclasses-json (>=0.6.4,<0.7.0)
17
+ Requires-Dist: generation-models (>=0,<1)
17
18
  Requires-Dist: marshmallow (>=3.12.1,<4.0.0)
18
19
  Requires-Dist: pandas (>=1.3.2,<2.0.0)
19
20
  Requires-Dist: requests (>=2.25.1,<3.0.0)
20
- Requires-Dist: structlog (>=23.1.0,<24.0.0)
21
- Requires-Dist: tyba-financial-model (>=0.1.0,<0.2.0)
21
+ Requires-Dist: structlog (>=24.1.0,<25.0.0)
22
+ Requires-Dist: tyba-financial-model (>=0,<1)
22
23
  Description-Content-Type: text/markdown
23
24
 
24
25
  # Tyba API Client
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tyba-client"
3
- version = "0.3.6"
3
+ version = "0.4.0"
4
4
  description = "A Python API client for the Tyba Public API"
5
5
  authors = ["Tyler Nisonoff <tyler@tybaenergy.com>"]
6
6
  license = "MIT"
@@ -12,15 +12,15 @@ include = [
12
12
  [tool.poetry.dependencies]
13
13
  python = "^3.8"
14
14
  requests = "^2.25.1"
15
- dataclasses-json = "^0.5.4"
15
+ dataclasses-json = "^0.6.4"
16
16
  marshmallow = "^3.12.1"
17
17
  pandas = "^1.3.2"
18
- tyba-financial-model = "^0.1.0"
19
- structlog = "^23.1.0"
20
- generation-models = "^0.4.1"
18
+ tyba-financial-model = "^0"
19
+ structlog = "^24.1.0"
20
+ generation-models = "^0"
21
21
 
22
22
  [tool.poetry.group.dev.dependencies]
23
- pytest = "^5.2"
23
+ pytest = "^8.1.1"
24
24
  ipython = "^7.29.0"
25
25
  ipdb = "^0.13.9"
26
26
  sphinx = "^7.0.1"
@@ -0,0 +1 @@
1
+ __version__ = "0.4.0"
@@ -1,4 +1,5 @@
1
1
  from datetime import datetime, time
2
+ from typing import List
2
3
 
3
4
 
4
5
  class Forecast(object):
@@ -35,7 +36,7 @@ class Forecast(object):
35
36
  product: str,
36
37
  start_time: datetime,
37
38
  end_time: datetime,
38
- quantiles: list[float],
39
+ quantiles: List[float],
39
40
  forecast_type=None,
40
41
  ):
41
42
  return self.get(
@@ -81,7 +82,7 @@ class Forecast(object):
81
82
  product: str,
82
83
  start_time: datetime,
83
84
  end_time: datetime,
84
- quantiles: list[float],
85
+ quantiles: List[float],
85
86
  days_ago: int,
86
87
  before_time: time,
87
88
  exact_vintage: bool = False,
@@ -125,7 +126,7 @@ class Forecast(object):
125
126
  self,
126
127
  object_name: str,
127
128
  product: str,
128
- quantiles: list[float],
129
+ quantiles: List[float],
129
130
  vintage_start_time: datetime,
130
131
  vintage_end_time: datetime,
131
132
  forecast_type=None,
@@ -4,11 +4,7 @@ from generation_models import (
4
4
  ONDInverter,
5
5
  ONDEfficiencyCurve,
6
6
  ONDTemperatureDerateCurve,
7
- SolarResource,
8
- SolarResourceTimeSeries,
9
7
  )
10
- import pandas as pd
11
- import typing as t
12
8
 
13
9
 
14
10
  def read_pvsyst_file(path: str) -> dict:
@@ -160,48 +156,3 @@ def inverter_from_ond(ond_file: str, includes_xfmr: bool = True) -> ONDInverter:
160
156
  aux_loss_threshold=aux_loss_threshold,
161
157
  includes_xfmr=includes_xfmr,
162
158
  )
163
-
164
-
165
- psm_column_map = {
166
- "Year": "year",
167
- "Month": "month",
168
- "Day": "day",
169
- "Hour": "hour",
170
- "Minute": "minute",
171
- "GHI": "gh",
172
- "DNI": "dn",
173
- "DHI": "df",
174
- "POA": "poa",
175
- "Temperature": "tdry",
176
- # twet
177
- "Dew Point": "tdew",
178
- "Relative Humidity": "rhum",
179
- "Pressure": "pres",
180
- # Snow
181
- "Surface Albedo": "alb",
182
- # aod
183
- "Wind Speed": "wspd",
184
- "Wind Direction": "wdir",
185
- }
186
-
187
-
188
- def solar_resource_from_psm_csv(
189
- filename: str,
190
- typical: bool = True,
191
- monthly_albedo: t.Optional[t.List[float]] = None,
192
- ) -> SolarResource:
193
- """_"""
194
- with open(filename) as f:
195
- _meta = [f.readline().split(",") for _ in range(2)]
196
- _data = pd.read_csv(f)
197
- meta = {k: v for k, v in zip(*_meta)}
198
- data = _data.rename(columns=psm_column_map)
199
- return SolarResource(
200
- latitude=float(meta["Latitude"]),
201
- longitude=float(meta["Longitude"]),
202
- elevation=float(meta["Elevation"]),
203
- time_zone_offset=float(meta["Time Zone"]),
204
- data=SolarResourceTimeSeries(**data.to_dict(orient="list")),
205
- monthly_albedo=monthly_albedo,
206
- typical=typical,
207
- )
@@ -4,7 +4,8 @@ from enum import Enum
4
4
  from dataclasses_json import config, dataclass_json
5
5
  import pandas as pd
6
6
  import typing as t
7
- from .io import read_pvsyst_file, psm_column_map
7
+ from .io import read_pvsyst_file
8
+ from .solar_resource import psm_column_map
8
9
 
9
10
  from tyba_client.utils import string_enum
10
11
 
@@ -0,0 +1,117 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ import pandas as pd
6
+ import requests
7
+ from generation_models import SolarResource, SolarResourceTimeSeries
8
+ from requests.exceptions import HTTPError
9
+ import typing as t
10
+ from io import StringIO
11
+
12
+
13
+ @dataclass
14
+ class PSMClient:
15
+ api_key: str
16
+ email: str
17
+
18
+ def _get_solar_resource(
19
+ self,
20
+ source: str,
21
+ latitude: float,
22
+ longitude: float,
23
+ year: t.Union[str, int],
24
+ utc: bool,
25
+ ):
26
+ resp = requests.get(
27
+ url=f"https://developer.nrel.gov/api/nsrdb/v2/solar/{source}.csv",
28
+ params={
29
+ "api_key": self.api_key,
30
+ "email": self.email,
31
+ "wkt": f"POINT({longitude} {latitude})",
32
+ "names": year,
33
+ "utc": "true" if utc else "false",
34
+ },
35
+ )
36
+ if resp.status_code == 400:
37
+ raise HTTPError(resp.json()["errors"])
38
+ resp.raise_for_status()
39
+ return resp.text
40
+
41
+ @staticmethod
42
+ def _process_csv(raw: str) -> SolarResource:
43
+ with StringIO(raw) as f:
44
+ _meta = [f.readline().split(",") for _ in range(2)]
45
+ _data = pd.read_csv(f)
46
+ meta = {k: v for k, v in zip(*_meta)}
47
+ data = _data.rename(columns=psm_column_map)
48
+ return SolarResource(
49
+ latitude=float(meta["Latitude"]),
50
+ longitude=float(meta["Longitude"]),
51
+ elevation=float(meta["Elevation"]),
52
+ time_zone_offset=float(meta["Time Zone"]),
53
+ data=SolarResourceTimeSeries(**data.to_dict(orient="list")),
54
+ )
55
+
56
+ def get_historical(
57
+ self,
58
+ latitude: float,
59
+ longitude: float,
60
+ year: int,
61
+ utc: bool = False,
62
+ ) -> SolarResource:
63
+ raw = self._get_solar_resource(source="psm3-2-2-download", latitude=latitude, longitude=longitude, year=year, utc=utc)
64
+ return self._process_csv(raw)
65
+
66
+ def get_typical(
67
+ self,
68
+ latitude: float,
69
+ longitude: float,
70
+ year: str = "tgy-2022",
71
+ utc: bool = False,
72
+ ) -> SolarResource:
73
+ raw = self._get_solar_resource(source="psm3-2-2-tmy-download", latitude=latitude, longitude=longitude, year=year, utc=utc)
74
+ return self._process_csv(raw)
75
+
76
+
77
+ def solar_resource_from_psm_csv(
78
+ filename: str,
79
+ monthly_albedo: t.Optional[t.List[float]] = None,
80
+ ) -> SolarResource:
81
+ """_"""
82
+ with open(filename) as f:
83
+ _meta = [f.readline().split(",") for _ in range(2)]
84
+ _data = pd.read_csv(f)
85
+ meta = {k: v for k, v in zip(*_meta)}
86
+ data = _data.rename(columns=psm_column_map)
87
+ return SolarResource(
88
+ latitude=float(meta["Latitude"]),
89
+ longitude=float(meta["Longitude"]),
90
+ elevation=float(meta["Elevation"]),
91
+ time_zone_offset=float(meta["Time Zone"]),
92
+ data=SolarResourceTimeSeries(**data.to_dict(orient="list")),
93
+ monthly_albedo=monthly_albedo,
94
+ )
95
+
96
+
97
+ psm_column_map = {
98
+ "Year": "year",
99
+ "Month": "month",
100
+ "Day": "day",
101
+ "Hour": "hour",
102
+ "Minute": "minute",
103
+ "GHI": "gh",
104
+ "DNI": "dn",
105
+ "DHI": "df",
106
+ "POA": "poa",
107
+ "Temperature": "tdry",
108
+ # twet
109
+ "Dew Point": "tdew",
110
+ "Relative Humidity": "rhum",
111
+ "Pressure": "pres",
112
+ # Snow
113
+ "Surface Albedo": "alb",
114
+ # aod
115
+ "Wind Speed": "wspd",
116
+ "Wind Direction": "wdir",
117
+ }
@@ -1 +0,0 @@
1
- __version__ = "0.3.1"
File without changes
File without changes