3131}
3232
3333
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 ):
3839 """
39- Retrieve irradiance and weather data from Meteonorm.
40+ Retrieve historical and near real-time observational data from Meteonorm.
4041
4142 The Meteonorm data options are described in [1]_ and the API is described
4243 in [2]_. A detailed list of API options can be found in [3]_.
4344
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 .
4647
4748 Parameters
4849 ----------
@@ -58,14 +59,11 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
5859 specified, UTC is assumed.
5960 api_key : str
6061 Meteonorm API key.
61- endpoint : str
62+ endpoint : str, default : training
6263 API endpoint, see [3]_. Must be one of:
6364
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)
6967
7068 parameters : list or 'all', default : 'all'
7169 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,
7573 Orientation (azimuth angle) of the (fixed) plane. Clockwise from north
7674 (north=0, east=90, south=180, west=270).
7775 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.
8077 horizon : str or list, default : 'auto'
8178 Specification of the horizon line. Can be either 'flat', 'auto', or
8279 a list of 360 integer horizon elevation angles.
@@ -87,8 +84,7 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
8784 When true, renames columns of the Dataframe to pvlib variable names
8885 where applicable. See variable :const:`VARIABLE_MAP`.
8986 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
9288 :const:`pvlib.iotools.meteonorm.URL`.
9389
9490 Raises
@@ -107,11 +103,11 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
107103 Examples
108104 --------
109105 >>> # Retrieve historical time series data
110- >>> df, meta = pvlib.iotools.get_meteonorm ( # doctest: +SKIP
106+ >>> df, meta = pvlib.iotools.get_meteonorm_observatrion ( # doctest: +SKIP
111107 ... latitude=50, longitude=10, # doctest: +SKIP
112108 ... start='2023-01-01', end='2025-01-01', # doctest: +SKIP
113109 ... api_key='redacted', # doctest: +SKIP
114- ... endpoint='observation/ training') # doctest: +SKIP
110+ ... endpoint='training') # doctest: +SKIP
115111
116112 See Also
117113 --------
@@ -126,6 +122,120 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
126122 .. [3] `Meteonorm API reference
127123 <https://docs.meteonorm.com/api>`_
128124 """
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+
129239 # Relative date strings are not yet supported
130240 start = pd .Timestamp (start )
131241 end = pd .Timestamp (end )
@@ -167,7 +277,8 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
167277 headers = {"Authorization" : f"Bearer { api_key } " }
168278
169279 response = requests .get (
170- urljoin (url , endpoint .lstrip ('/' )), headers = headers , params = params )
280+ urljoin (url , endpoint_base + endpoint .lstrip ('/' )),
281+ headers = headers , params = params )
171282
172283 if not response .ok :
173284 # response.raise_for_status() does not give a useful error message
@@ -265,7 +376,8 @@ def get_meteonorm_tmy(latitude, longitude, api_key,
265376
266377 See Also
267378 --------
268- pvlib.iotools.get_meteonorm
379+ pvlib.iotools.get_meteonorm_observation,
380+ pvlib.iotools.get_meteonorm_forecast
269381
270382 References
271383 ----------
0 commit comments