31
31
}
32
32
33
33
34
- def get_meteonorm (latitude , longitude , start , end , api_key , endpoint ,
35
- parameters = 'all' , * , surface_tilt = 0 , surface_azimuth = 180 ,
36
- time_step = '15min' , horizon = 'auto' , interval_index = False ,
37
- map_variables = True , url = URL ):
34
+ def get_meteonorm_observation (
35
+ latitude , longitude , start , end , api_key , endpoint = 'training' ,
36
+ parameters = 'all' , * , surface_tilt = 0 , surface_azimuth = 180 ,
37
+ time_step = '15min' , horizon = 'auto' , interval_index = False ,
38
+ map_variables = True , url = URL ):
38
39
"""
39
- Retrieve irradiance and weather data from Meteonorm.
40
+ Retrieve historical and near real-time observational data from Meteonorm.
40
41
41
42
The Meteonorm data options are described in [1]_ and the API is described
42
43
in [2]_. A detailed list of API options can be found in [3]_.
43
44
44
- This function supports retrieval of historical and forecast data, but not
45
- TMY .
45
+ This function supports retrieval of observation data, either the
46
+ 'training' or the 'realtime' endpoints .
46
47
47
48
Parameters
48
49
----------
@@ -58,14 +59,11 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
58
59
specified, UTC is assumed.
59
60
api_key : str
60
61
Meteonorm API key.
61
- endpoint : str
62
+ endpoint : str, default : training
62
63
API endpoint, see [3]_. Must be one of:
63
64
64
- * ``'observation/training'`` - historical data with a 7-day delay
65
- * ``'observation/realtime'`` - near-real time (past 7-days)
66
- * ``'forecast/basic'`` - forecast with hourly resolution
67
- * ``'forecast/precision'`` - forecast with 1-min, 15-min, or hourly
68
- resolution
65
+ * ``'training'`` - historical data with a 7-day delay
66
+ * ``'realtime'`` - near-real time (past 7-days)
69
67
70
68
parameters : list or 'all', default : 'all'
71
69
List of parameters to request or `'all'` to get all parameters.
@@ -75,8 +73,7 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
75
73
Orientation (azimuth angle) of the (fixed) plane. Clockwise from north
76
74
(north=0, east=90, south=180, west=270).
77
75
time_step : {'1min', '15min', '1h'}, default : '15min'
78
- Frequency of the time series. The endpoint ``'forecast/basic'`` only
79
- supports ``time_step='1h'``.
76
+ Frequency of the time series.
80
77
horizon : str or list, default : 'auto'
81
78
Specification of the horizon line. Can be either 'flat', 'auto', or
82
79
a list of 360 integer horizon elevation angles.
@@ -87,8 +84,7 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
87
84
When true, renames columns of the Dataframe to pvlib variable names
88
85
where applicable. See variable :const:`VARIABLE_MAP`.
89
86
url : str, optional
90
- Base URL of the Meteonorm API. The ``endpoint`` parameter is
91
- appended to the url. The default is
87
+ Base URL of the Meteonorm API. The default is
92
88
:const:`pvlib.iotools.meteonorm.URL`.
93
89
94
90
Raises
@@ -107,11 +103,11 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
107
103
Examples
108
104
--------
109
105
>>> # Retrieve historical time series data
110
- >>> df, meta = pvlib.iotools.get_meteonorm ( # doctest: +SKIP
106
+ >>> df, meta = pvlib.iotools.get_meteonorm_observatrion ( # doctest: +SKIP
111
107
... latitude=50, longitude=10, # doctest: +SKIP
112
108
... start='2023-01-01', end='2025-01-01', # doctest: +SKIP
113
109
... api_key='redacted', # doctest: +SKIP
114
- ... endpoint='observation/ training') # doctest: +SKIP
110
+ ... endpoint='training') # doctest: +SKIP
115
111
116
112
See Also
117
113
--------
@@ -126,6 +122,120 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
126
122
.. [3] `Meteonorm API reference
127
123
<https://docs.meteonorm.com/api>`_
128
124
"""
125
+ endpoint_base = 'observation/'
126
+
127
+ data , meta = _get_meteonorm (
128
+ latitude , longitude , start , end , api_key ,
129
+ endpoint_base , endpoint ,
130
+ parameters , surface_tilt , surface_azimuth ,
131
+ time_step , horizon , interval_index ,
132
+ map_variables , url )
133
+ return data , meta
134
+
135
+
136
+ def get_meteonorm_forecast (
137
+ latitude , longitude , start , end , api_key , endpoint = 'precision' ,
138
+ parameters = 'all' , * , surface_tilt = 0 , surface_azimuth = 180 ,
139
+ time_step = '15min' , horizon = 'auto' , interval_index = False ,
140
+ map_variables = True , url = URL ):
141
+ """
142
+ Retrieve historical and near real-time observational data from Meteonorm.
143
+
144
+ The Meteonorm data options are described in [1]_ and the API is described
145
+ in [2]_. A detailed list of API options can be found in [3]_.
146
+
147
+ This function supports retrieval of forecasting data, either the
148
+ 'training' or the 'basic' endpoints.
149
+
150
+ Parameters
151
+ ----------
152
+ latitude : float
153
+ In decimal degrees, north is positive (ISO 19115).
154
+ longitude: float
155
+ In decimal degrees, east is positive (ISO 19115).
156
+ start : datetime like
157
+ First timestamp of the requested period. If a timezone is not
158
+ specified, UTC is assumed.
159
+ end : datetime like
160
+ Last timestamp of the requested period. If a timezone is not
161
+ specified, UTC is assumed.
162
+ api_key : str
163
+ Meteonorm API key.
164
+ endpoint : str, default : precision
165
+ API endpoint, see [3]_. Must be one of:
166
+
167
+ * ``'precision'`` - forecast with 1-min, 15-min, or hourly
168
+ resolution
169
+ * ``'basic'`` - forecast with hourly resolution
170
+
171
+ parameters : list or 'all', default : 'all'
172
+ List of parameters to request or `'all'` to get all parameters.
173
+ surface_tilt : float, default : 0
174
+ Tilt angle from horizontal plane.
175
+ surface_azimuth : float, default : 180
176
+ Orientation (azimuth angle) of the (fixed) plane. Clockwise from north
177
+ (north=0, east=90, south=180, west=270).
178
+ time_step : {'1min', '15min', '1h'}, default : '15min'
179
+ Frequency of the time series. The endpoint ``'basic'`` only
180
+ supports ``time_step='1h'``.
181
+ horizon : str or list, default : 'auto'
182
+ Specification of the horizon line. Can be either 'flat', 'auto', or
183
+ a list of 360 integer horizon elevation angles.
184
+ interval_index : bool, default : False
185
+ Index is pd.DatetimeIndex when False, and pd.IntervalIndex when True.
186
+ This is an experimental feature which may be removed without warning.
187
+ map_variables : bool, default : True
188
+ When true, renames columns of the Dataframe to pvlib variable names
189
+ where applicable. See variable :const:`VARIABLE_MAP`.
190
+ url : str, optional
191
+ Base URL of the Meteonorm API. The default is
192
+ :const:`pvlib.iotools.meteonorm.URL`.
193
+
194
+ Raises
195
+ ------
196
+ requests.HTTPError
197
+ Raises an error when an incorrect request is made.
198
+
199
+ Returns
200
+ -------
201
+ data : pd.DataFrame
202
+ Time series data. The index corresponds to the start (left) of the
203
+ interval unless ``interval_index`` is set to True.
204
+ meta : dict
205
+ Metadata.
206
+
207
+ See Also
208
+ --------
209
+ pvlib.iotools.get_meteonorm_observation,
210
+ pvlib.iotools.get_meteonorm_tmy
211
+
212
+ References
213
+ ----------
214
+ .. [1] `Meteonorm
215
+ <https://meteonorm.com/>`_
216
+ .. [2] `Meteonorm API
217
+ <https://docs.meteonorm.com/docs/getting-started>`_
218
+ .. [3] `Meteonorm API reference
219
+ <https://docs.meteonorm.com/api>`_
220
+ """
221
+ endpoint_base = 'forecast/'
222
+
223
+ data , meta = _get_meteonorm (
224
+ latitude , longitude , start , end , api_key ,
225
+ endpoint_base , endpoint ,
226
+ parameters , surface_tilt , surface_azimuth ,
227
+ time_step , horizon , interval_index ,
228
+ map_variables , url )
229
+ return data , meta
230
+
231
+
232
+ def _get_meteonorm (
233
+ latitude , longitude , start , end , api_key ,
234
+ endpoint_base , endpoint ,
235
+ parameters , surface_tilt , surface_azimuth ,
236
+ time_step , horizon , interval_index ,
237
+ map_variables , url ):
238
+
129
239
# Relative date strings are not yet supported
130
240
start = pd .Timestamp (start )
131
241
end = pd .Timestamp (end )
@@ -167,7 +277,8 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
167
277
headers = {"Authorization" : f"Bearer { api_key } " }
168
278
169
279
response = requests .get (
170
- urljoin (url , endpoint .lstrip ('/' )), headers = headers , params = params )
280
+ urljoin (url , endpoint_base + endpoint .lstrip ('/' )),
281
+ headers = headers , params = params )
171
282
172
283
if not response .ok :
173
284
# response.raise_for_status() does not give a useful error message
@@ -265,7 +376,8 @@ def get_meteonorm_tmy(latitude, longitude, api_key,
265
376
266
377
See Also
267
378
--------
268
- pvlib.iotools.get_meteonorm
379
+ pvlib.iotools.get_meteonorm_observation,
380
+ pvlib.iotools.get_meteonorm_forecast
269
381
270
382
References
271
383
----------
0 commit comments