Skip to content

Commit df97faf

Browse files
Pratham ChauhanPratham Chauhan
Pratham Chauhan
authored and
Pratham Chauhan
committed
added variable_map
1 parent 773b94e commit df97faf

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pvlib/iotools/tmy.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
import re
55
import pandas as pd
66
import warnings
7+
from pvlib._deprecation import pvlibDeprecationWarning
8+
9+
# Dictionary mapping TMY3 names to pvlib names
10+
VARIABLE_MAP = {
11+
'GHI': 'ghi',
12+
'DNI': 'dni',
13+
'DHI': 'dhi',
14+
'Pressure': 'pressure',
15+
'Wdir': 'wind_direction',
16+
'Wspd': 'wind_speed',
17+
}
718

819

920
def read_tmy3(filename, coerce_year=None, map_variables=None, recolumn=True):
@@ -203,16 +214,16 @@ def read_tmy3(filename, coerce_year=None, map_variables=None, recolumn=True):
203214
# NOTE: as of pvlib-0.6.3, min req is pandas-0.18.1, so pd.to_timedelta
204215
# unit must be in (D,h,m,s,ms,us,ns), but pandas>=0.24 allows unit='hour'
205216
data.index = data_ymd + pd.to_timedelta(shifted_hour, unit='h')
206-
207-
if map_variables:
217+
if map_variables is None:
208218
data = _recolumn(data) # rename to standard column names
209-
elif recolumn:
210-
if not map_variables: # silence warning if map_variables is false
211-
data = _recolumn(data)
212-
elif map_variables is None:
213-
data = _recolumn(data)
214-
warnings.warn("recolumn parameter will be retired starting version 0.9.5,"
215-
"please use map_variables parameter instead.",DeprecationWarning)
219+
warnings.warn(
220+
'TMY3 variable names will be renamed to pvlib conventions by '
221+
'default starting in pvlib 0.9.5. Specify map_variables=True '
222+
'to enable that behavior now, or specify map_variables=False '
223+
'to hide this warning.', pvlibDeprecationWarning)
224+
map_variables = False
225+
if map_variables:
226+
data = _recolumn(data).rename(columns=VARIABLE_MAP)
216227

217228
data = data.tz_localize(int(meta['TZ'] * 3600))
218229

0 commit comments

Comments
 (0)