33import datetime
44import re
55import pandas as pd
6- import warnings
7- from pvlib ._deprecation import pvlibDeprecationWarning
86
97# Dictionary mapping TMY3 names to pvlib names
108VARIABLE_MAP = {
2422}
2523
2624
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 ):
2926 """Read a TMY3 file into a pandas dataframe.
3027
3128 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,
4441 If supplied, the year of the index will be set to ``coerce_year``, except
4542 for the last index value which will be set to the *next* year so that
4643 the index increases monotonically.
47- map_variables : bool, optional
44+ map_variables : bool, default True
4845 When True, renames columns of the DataFrame to pvlib variable names
4946 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``.
5447 encoding : str, optional
5548 Encoding of the file. For files that contain non-UTF8 characters it may
5649 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,
233226 # unit must be in (D,h,m,s,ms,us,ns), but pandas>=0.24 allows unit='hour'
234227 data .index = data_ymd + pd .to_timedelta (shifted_hour , unit = 'h' ) \
235228 + 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+
252230 if map_variables :
253231 data = data .rename (columns = VARIABLE_MAP )
254- elif recolumn or (recolumn is None and map_variables is None ):
255- data = _recolumn (data )
256232
257233 data = data .tz_localize (int (meta ['TZ' ] * 3600 ))
258234
259235 return data , meta
260236
261237
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-
304238def read_tmy2 (filename ):
305239 """
306240 Read a TMY2 file into a DataFrame.
0 commit comments