3
3
import datetime
4
4
import re
5
5
import pandas as pd
6
- import warnings
7
- from pvlib ._deprecation import pvlibDeprecationWarning
8
6
9
7
# Dictionary mapping TMY3 names to pvlib names
10
8
VARIABLE_MAP = {
24
22
}
25
23
26
24
27
- def read_tmy3 (filename , coerce_year = None , map_variables = None , recolumn = None ,
28
- encoding = None ):
25
+ def read_tmy3 (filename , coerce_year = None , map_variables = True , encoding = None ):
29
26
"""Read a TMY3 file into a pandas dataframe.
30
27
31
28
Note that values contained in the metadata dictionary are unchanged
@@ -44,13 +41,9 @@ def read_tmy3(filename, coerce_year=None, map_variables=None, recolumn=None,
44
41
If supplied, the year of the index will be set to ``coerce_year``, except
45
42
for the last index value which will be set to the *next* year so that
46
43
the index increases monotonically.
47
- map_variables : bool, optional
44
+ map_variables : bool, default True
48
45
When True, renames columns of the DataFrame to pvlib variable names
49
46
where applicable. See variable :const:`VARIABLE_MAP`.
50
- recolumn : bool (deprecated, use map_variables instead)
51
- If ``True``, apply standard names to TMY3 columns. Typically this
52
- results in stripping the units from the column name.
53
- Cannot be used in combination with ``map_variables``.
54
47
encoding : str, optional
55
48
Encoding of the file. For files that contain non-UTF8 characters it may
56
49
be necessary to specify an alternative encoding, e.g., for
@@ -233,74 +226,15 @@ def read_tmy3(filename, coerce_year=None, map_variables=None, recolumn=None,
233
226
# unit must be in (D,h,m,s,ms,us,ns), but pandas>=0.24 allows unit='hour'
234
227
data .index = data_ymd + pd .to_timedelta (shifted_hour , unit = 'h' ) \
235
228
+ pd .to_timedelta (minutes , unit = 'min' )
236
- # shouldnt' specify both recolumn and map_variables
237
- if recolumn is not None and map_variables is not None :
238
- msg = "`map_variables` and `recolumn` cannot both be specified"
239
- raise ValueError (msg )
240
- elif map_variables is None and recolumn is not None :
241
- warnings .warn (
242
- 'The recolumn parameter is deprecated and will be removed in '
243
- 'pvlib 0.11.0. Use `map_variables` instead, although note that '
244
- 'its behavior is different from `recolumn`.' ,
245
- pvlibDeprecationWarning )
246
- elif map_variables is None and recolumn is None :
247
- warnings .warn (
248
- 'TMY3 variable names will be renamed to pvlib conventions by '
249
- 'default starting in pvlib 0.11.0. Specify map_variables=True '
250
- 'to enable that behavior now, or specify map_variables=False '
251
- 'to hide this warning.' , pvlibDeprecationWarning )
229
+
252
230
if map_variables :
253
231
data = data .rename (columns = VARIABLE_MAP )
254
- elif recolumn or (recolumn is None and map_variables is None ):
255
- data = _recolumn (data )
256
232
257
233
data = data .tz_localize (int (meta ['TZ' ] * 3600 ))
258
234
259
235
return data , meta
260
236
261
237
262
- def _recolumn (tmy3_dataframe ):
263
- """
264
- Rename the columns of the TMY3 DataFrame.
265
-
266
- Parameters
267
- ----------
268
- tmy3_dataframe : DataFrame
269
- inplace : bool
270
- passed to DataFrame.rename()
271
-
272
- Returns
273
- -------
274
- Recolumned DataFrame.
275
- """
276
- # paste in the header as one long line
277
- raw_columns = 'ETR (W/m^2),ETRN (W/m^2),GHI (W/m^2),GHI source,GHI uncert (%),DNI (W/m^2),DNI source,DNI uncert (%),DHI (W/m^2),DHI source,DHI uncert (%),GH illum (lx),GH illum source,Global illum uncert (%),DN illum (lx),DN illum source,DN illum uncert (%),DH illum (lx),DH illum source,DH illum uncert (%),Zenith lum (cd/m^2),Zenith lum source,Zenith lum uncert (%),TotCld (tenths),TotCld source,TotCld uncert (code),OpqCld (tenths),OpqCld source,OpqCld uncert (code),Dry-bulb (C),Dry-bulb source,Dry-bulb uncert (code),Dew-point (C),Dew-point source,Dew-point uncert (code),RHum (%),RHum source,RHum uncert (code),Pressure (mbar),Pressure source,Pressure uncert (code),Wdir (degrees),Wdir source,Wdir uncert (code),Wspd (m/s),Wspd source,Wspd uncert (code),Hvis (m),Hvis source,Hvis uncert (code),CeilHgt (m),CeilHgt source,CeilHgt uncert (code),Pwat (cm),Pwat source,Pwat uncert (code),AOD (unitless),AOD source,AOD uncert (code),Alb (unitless),Alb source,Alb uncert (code),Lprecip depth (mm),Lprecip quantity (hr),Lprecip source,Lprecip uncert (code),PresWth (METAR code),PresWth source,PresWth uncert (code)' # noqa: E501
278
-
279
- new_columns = [
280
- 'ETR' , 'ETRN' , 'GHI' , 'GHISource' , 'GHIUncertainty' ,
281
- 'DNI' , 'DNISource' , 'DNIUncertainty' , 'DHI' , 'DHISource' ,
282
- 'DHIUncertainty' , 'GHillum' , 'GHillumSource' , 'GHillumUncertainty' ,
283
- 'DNillum' , 'DNillumSource' , 'DNillumUncertainty' , 'DHillum' ,
284
- 'DHillumSource' , 'DHillumUncertainty' , 'Zenithlum' ,
285
- 'ZenithlumSource' , 'ZenithlumUncertainty' , 'TotCld' , 'TotCldSource' ,
286
- 'TotCldUncertainty' , 'OpqCld' , 'OpqCldSource' , 'OpqCldUncertainty' ,
287
- 'DryBulb' , 'DryBulbSource' , 'DryBulbUncertainty' , 'DewPoint' ,
288
- 'DewPointSource' , 'DewPointUncertainty' , 'RHum' , 'RHumSource' ,
289
- 'RHumUncertainty' , 'Pressure' , 'PressureSource' ,
290
- 'PressureUncertainty' , 'Wdir' , 'WdirSource' , 'WdirUncertainty' ,
291
- 'Wspd' , 'WspdSource' , 'WspdUncertainty' , 'Hvis' , 'HvisSource' ,
292
- 'HvisUncertainty' , 'CeilHgt' , 'CeilHgtSource' , 'CeilHgtUncertainty' ,
293
- 'Pwat' , 'PwatSource' , 'PwatUncertainty' , 'AOD' , 'AODSource' ,
294
- 'AODUncertainty' , 'Alb' , 'AlbSource' , 'AlbUncertainty' ,
295
- 'Lprecipdepth' , 'Lprecipquantity' , 'LprecipSource' ,
296
- 'LprecipUncertainty' , 'PresWth' , 'PresWthSource' ,
297
- 'PresWthUncertainty' ]
298
-
299
- mapping = dict (zip (raw_columns .split (',' ), new_columns ))
300
-
301
- return tmy3_dataframe .rename (columns = mapping )
302
-
303
-
304
238
def read_tmy2 (filename ):
305
239
"""
306
240
Read a TMY2 file into a DataFrame.
0 commit comments