Skip to content

Commit 50e1998

Browse files
ooprathammPratham ChauhanAdamRJensenkandersolar
authored
Add map_variables parameter to read_tmy3 function (#1623)
* Added map_variables param in read_tmy3 func * solved failing tests * solved failing tests * solving stickerly test fail * solving stickerly test fail * solving stickerly test fail * added variable_map * resolving formatting issues * Update pvlib/iotools/tmy.py Co-authored-by: Adam R. Jensen <[email protected]> * Update pvlib/iotools/tmy.py Co-authored-by: Adam R. Jensen <[email protected]> * Update pvlib/iotools/tmy.py Co-authored-by: Adam R. Jensen <[email protected]> * Update pvlib/iotools/tmy.py Co-authored-by: Adam R. Jensen <[email protected]> * Added tests to map_variables and check depreciation warning * resolving formatting issues * resolving formatting issues * Adding more test cases * updated VARIABLE_MAP * updates DOIs in tmy.py * Final changes as requested * Fix stickler * Update variables_style_rules.csv * Add missing map_variables=False * Add whatsnew deprecation entry * Apply suggestions from code review * Add separate if statement for warning * removed wrong whatsnew entry * Update pvlib/tests/iotools/test_tmy.py Co-authored-by: Kevin Anderson <[email protected]> * Update warning messages according to table * Update whatsnew * Set recolumn=None * Update tests * Update pvlib/iotools/tmy.py Co-authored-by: Kevin Anderson <[email protected]> * Update pvlib/iotools/tmy.py Co-authored-by: Kevin Anderson <[email protected]> * Update docs/sphinx/source/whatsnew/v0.9.6.rst Co-authored-by: Kevin Anderson <[email protected]> * Implement updated error message logic from kansersolar * Clean up deprecation warnings * Fix clearsky.rst * Update aod variable mapping * Fix stickler * Update tmy3 variables names in field,description table * Update table * More table stuff * Table stuff galore --------- Co-authored-by: Pratham Chauhan <[email protected]> Co-authored-by: Adam R. Jensen <[email protected]> Co-authored-by: Kevin Anderson <[email protected]> Co-authored-by: Kevin Anderson <[email protected]>
1 parent 30c62e3 commit 50e1998

File tree

13 files changed

+225
-127
lines changed

13 files changed

+225
-127
lines changed

docs/examples/adr-pvarray/plot_simulate_system.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
PVLIB_DIR = pvlib.__path__[0]
3030
DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV')
3131

32-
tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990)
32+
tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990,
33+
map_variables=True)
3334

34-
df = pd.DataFrame({'ghi': tmy['GHI'], 'dhi': tmy['DHI'], 'dni': tmy['DNI'],
35-
'temp_air': tmy['DryBulb'], 'wind_speed': tmy['Wspd'],
35+
df = pd.DataFrame({'ghi': tmy['ghi'], 'dhi': tmy['dhi'], 'dni': tmy['dni'],
36+
'temp_air': tmy['temp_air'],
37+
'wind_speed': tmy['wind_speed'],
3638
})
3739

3840
# %%

docs/examples/irradiance-decomposition/plot_diffuse_fraction.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
# of data measured from 1990 to 2010. Therefore we change the timestamps to a
2828
# common year, 1990.
2929
DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data'
30-
greensboro, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990)
30+
greensboro, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990,
31+
map_variables=True)
3132

3233
# Many of the diffuse fraction estimation methods require the "true" zenith, so
3334
# we calculate the solar positions for the 1990 at Greensboro, NC.
@@ -36,8 +37,8 @@
3637
solpos = get_solarposition(
3738
greensboro.index.shift(freq="-30T"), latitude=metadata['latitude'],
3839
longitude=metadata['longitude'], altitude=metadata['altitude'],
39-
pressure=greensboro.Pressure*100, # convert from millibar to Pa
40-
temperature=greensboro.DryBulb)
40+
pressure=greensboro.pressure*100, # convert from millibar to Pa
41+
temperature=greensboro.temp_air)
4142
solpos.index = greensboro.index # reset index to end of the hour
4243

4344
# %%
@@ -56,10 +57,10 @@
5657
# an exponential relation with airmass.
5758

5859
out_disc = irradiance.disc(
59-
greensboro.GHI, solpos.zenith, greensboro.index, greensboro.Pressure*100)
60+
greensboro.ghi, solpos.zenith, greensboro.index, greensboro.pressure*100)
6061
# use "complete sum" AKA "closure" equations: DHI = GHI - DNI * cos(zenith)
6162
df_disc = irradiance.complete_irradiance(
62-
solar_zenith=solpos.apparent_zenith, ghi=greensboro.GHI, dni=out_disc.dni,
63+
solar_zenith=solpos.apparent_zenith, ghi=greensboro.ghi, dni=out_disc.dni,
6364
dhi=None)
6465
out_disc = out_disc.rename(columns={'dni': 'dni_disc'})
6566
out_disc['dhi_disc'] = df_disc.dhi
@@ -72,11 +73,11 @@
7273
# developed by Richard Perez and Pierre Ineichen in 1992.
7374

7475
dni_dirint = irradiance.dirint(
75-
greensboro.GHI, solpos.zenith, greensboro.index, greensboro.Pressure*100,
76-
temp_dew=greensboro.DewPoint)
76+
greensboro.ghi, solpos.zenith, greensboro.index, greensboro.pressure*100,
77+
temp_dew=greensboro.temp_dew)
7778
# use "complete sum" AKA "closure" equation: DHI = GHI - DNI * cos(zenith)
7879
df_dirint = irradiance.complete_irradiance(
79-
solar_zenith=solpos.apparent_zenith, ghi=greensboro.GHI, dni=dni_dirint,
80+
solar_zenith=solpos.apparent_zenith, ghi=greensboro.ghi, dni=dni_dirint,
8081
dhi=None)
8182
out_dirint = pd.DataFrame(
8283
{'dni_dirint': dni_dirint, 'dhi_dirint': df_dirint.dhi},
@@ -91,7 +92,7 @@
9192
# splits kt into 3 regions: linear for kt <= 0.22, a 4th order polynomial
9293
# between 0.22 < kt <= 0.8, and a horizontal line for kt > 0.8.
9394

94-
out_erbs = irradiance.erbs(greensboro.GHI, solpos.zenith, greensboro.index)
95+
out_erbs = irradiance.erbs(greensboro.ghi, solpos.zenith, greensboro.index)
9596
out_erbs = out_erbs.rename(columns={'dni': 'dni_erbs', 'dhi': 'dhi_erbs'})
9697

9798
# %%
@@ -102,7 +103,7 @@
102103
# exponential correlation that is continuously differentiable and bounded
103104
# between zero and one.
104105

105-
out_boland = irradiance.boland(greensboro.GHI, solpos.zenith, greensboro.index)
106+
out_boland = irradiance.boland(greensboro.ghi, solpos.zenith, greensboro.index)
106107
out_boland = out_boland.rename(
107108
columns={'dni': 'dni_boland', 'dhi': 'dhi_boland'})
108109

@@ -118,20 +119,20 @@
118119
# file together to make plotting easier.
119120

120121
dni_renames = {
121-
'DNI': 'TMY3', 'dni_disc': 'DISC', 'dni_dirint': 'DIRINT',
122+
'dni': 'TMY3', 'dni_disc': 'DISC', 'dni_dirint': 'DIRINT',
122123
'dni_erbs': 'Erbs', 'dni_boland': 'Boland'}
123124
dni = [
124-
greensboro.DNI, out_disc.dni_disc, out_dirint.dni_dirint,
125+
greensboro.dni, out_disc.dni_disc, out_dirint.dni_dirint,
125126
out_erbs.dni_erbs, out_boland.dni_boland]
126127
dni = pd.concat(dni, axis=1).rename(columns=dni_renames)
127128
dhi_renames = {
128-
'DHI': 'TMY3', 'dhi_disc': 'DISC', 'dhi_dirint': 'DIRINT',
129+
'dhi': 'TMY3', 'dhi_disc': 'DISC', 'dhi_dirint': 'DIRINT',
129130
'dhi_erbs': 'Erbs', 'dhi_boland': 'Boland'}
130131
dhi = [
131-
greensboro.DHI, out_disc.dhi_disc, out_dirint.dhi_dirint,
132+
greensboro.dhi, out_disc.dhi_disc, out_dirint.dhi_dirint,
132133
out_erbs.dhi_erbs, out_boland.dhi_boland]
133134
dhi = pd.concat(dhi, axis=1).rename(columns=dhi_renames)
134-
ghi_kt = pd.concat([greensboro.GHI/1000.0, out_erbs.kt], axis=1)
135+
ghi_kt = pd.concat([greensboro.ghi/1000.0, out_erbs.kt], axis=1)
135136

136137
# %%
137138
# Winter

docs/examples/irradiance-transposition/plot_seasonal_tilt.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ def get_orientation(self, solar_zenith, solar_azimuth):
4444
# like we expect:
4545

4646
DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data'
47-
tmy, metadata = iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990)
47+
tmy, metadata = iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990,
48+
map_variables=True)
4849
# shift from TMY3 right-labeled index to left-labeled index:
4950
tmy.index = tmy.index - pd.Timedelta(hours=1)
5051
weather = pd.DataFrame({
51-
'ghi': tmy['GHI'], 'dhi': tmy['DHI'], 'dni': tmy['DNI'],
52-
'temp_air': tmy['DryBulb'], 'wind_speed': tmy['Wspd'],
52+
'ghi': tmy['ghi'], 'dhi': tmy['dhi'], 'dni': tmy['dni'],
53+
'temp_air': tmy['temp_air'], 'wind_speed': tmy['wind_speed'],
5354
})
5455
loc = location.Location.from_tmy(metadata)
5556
solpos = loc.get_solarposition(weather.index)

docs/examples/irradiance-transposition/plot_transposition_gain.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data'
3333

3434
# get TMY3 dataset
35-
tmy, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990)
35+
tmy, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990,
36+
map_variables=True)
3637
# TMY3 datasets are right-labeled (AKA "end of interval") which means the last
3738
# interval of Dec 31, 23:00 to Jan 1 00:00 is labeled Jan 1 00:00. When rolling
3839
# up hourly irradiance to monthly insolation, a spurious January value is
@@ -60,9 +61,9 @@ def calculate_poa(tmy, solar_position, surface_tilt, surface_azimuth):
6061
poa = irradiance.get_total_irradiance(
6162
surface_tilt=surface_tilt,
6263
surface_azimuth=surface_azimuth,
63-
dni=tmy['DNI'],
64-
ghi=tmy['GHI'],
65-
dhi=tmy['DHI'],
64+
dni=tmy['dni'],
65+
ghi=tmy['ghi'],
66+
dhi=tmy['dhi'],
6667
solar_zenith=solar_position['apparent_zenith'],
6768
solar_azimuth=solar_position['azimuth'],
6869
model='isotropic')
@@ -97,7 +98,7 @@ def calculate_poa(tmy, solar_position, surface_tilt, surface_azimuth):
9798
df_monthly['SAT-0.4'] = poa_irradiance.resample('m').sum()
9899

99100
# calculate the percent difference from GHI
100-
ghi_monthly = tmy['GHI'].resample('m').sum()
101+
ghi_monthly = tmy['ghi'].resample('m').sum()
101102
df_monthly = 100 * (df_monthly.divide(ghi_monthly, axis=0) - 1)
102103

103104
df_monthly.plot()

docs/examples/soiling/plot_greensboro_kimber_soiling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data'
4141

4242
# get TMY3 data with rain
43-
greensboro, _ = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990)
43+
greensboro, _ = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990,
44+
map_variables=True)
4445
# get the rain data
45-
greensboro_rain = greensboro.Lprecipdepth
46+
greensboro_rain = greensboro['Lprecip depth (mm)']
4647
# calculate soiling with no wash dates and cleaning threshold of 25-mm of rain
4748
THRESHOLD = 25.0
4849
soiling_no_wash = kimber(greensboro_rain, cleaning_threshold=THRESHOLD)

docs/sphinx/source/user_guide/clearsky.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,26 @@ wavelengths [Bir80]_, and is implemented in
216216

217217
In [1]: tmy_file = os.path.join(pvlib_data, '703165TY.csv') # TMY file
218218

219-
In [1]: tmy_data, tmy_header = read_tmy3(tmy_file, coerce_year=1999) # read TMY data
219+
In [1]: tmy_data, tmy_header = read_tmy3(tmy_file, coerce_year=1999, map_variables=True)
220220

221221
In [1]: tl_historic = clearsky.lookup_linke_turbidity(time=tmy_data.index,
222222
...: latitude=tmy_header['latitude'], longitude=tmy_header['longitude'])
223223

224224
In [1]: solpos = solarposition.get_solarposition(time=tmy_data.index,
225225
...: latitude=tmy_header['latitude'], longitude=tmy_header['longitude'],
226-
...: altitude=tmy_header['altitude'], pressure=tmy_data['Pressure']*mbars,
227-
...: temperature=tmy_data['DryBulb'])
226+
...: altitude=tmy_header['altitude'], pressure=tmy_data['pressure']*mbars,
227+
...: temperature=tmy_data['temp_air'])
228228

229229
In [1]: am_rel = atmosphere.get_relative_airmass(solpos.apparent_zenith)
230230

231-
In [1]: am_abs = atmosphere.get_absolute_airmass(am_rel, tmy_data['Pressure']*mbars)
231+
In [1]: am_abs = atmosphere.get_absolute_airmass(am_rel, tmy_data['pressure']*mbars)
232232

233233
In [1]: airmass = pd.concat([am_rel, am_abs], axis=1).rename(
234234
...: columns={0: 'airmass_relative', 1: 'airmass_absolute'})
235235

236236
In [1]: tl_calculated = atmosphere.kasten96_lt(
237-
...: airmass.airmass_absolute, tmy_data['Pwat'], tmy_data['AOD'])
237+
...: airmass.airmass_absolute, tmy_data['precipitable_water'],
238+
...: tmy_data['AOD (unitless)'])
238239

239240
In [1]: tl = pd.concat([tl_historic, tl_calculated], axis=1).rename(
240241
...: columns={0:'Historic', 1:'Calculated'})

docs/sphinx/source/user_guide/timetimezones.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Let's first examine how pvlib handles time when it imports a TMY3 file.
272272
# some gymnastics to find the example file
273273
pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(pvlib)))
274274
file_abspath = os.path.join(pvlib_abspath, 'data', '703165TY.csv')
275-
tmy3_data, tmy3_metadata = pvlib.iotools.read_tmy3(file_abspath)
275+
tmy3_data, tmy3_metadata = pvlib.iotools.read_tmy3(file_abspath, map_variables=True)
276276
277277
tmy3_metadata
278278
@@ -287,7 +287,7 @@ print just a few of the rows and columns of the large dataframe.
287287
288288
tmy3_data.index.tz
289289
290-
tmy3_data.loc[tmy3_data.index[0:3], ['GHI', 'DNI', 'AOD']]
290+
tmy3_data.loc[tmy3_data.index[0:3], ['ghi', 'dni', 'AOD (unitless)']]
291291
292292
The :py:func:`~pvlib.iotools.read_tmy2` function also returns a DataFrame
293293
with a localized DatetimeIndex.

docs/sphinx/source/whatsnew/v0.9.6.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ v0.9.6 (Anticipated June 2023)
88
Deprecations
99
~~~~~~~~~~~~
1010

11+
* The ``recolumn`` parameter in :py:func:`pvlib.iotools.read_tmy3`, which maps
12+
TMY3 column names to nonstandard alternatives, is now deprecated.
13+
We encourage using ``map_variables`` (which produces standard pvlib names) instead.
14+
(:issue:`1517`, :pull:`1623`)
1115

1216
Enhancements
1317
~~~~~~~~~~~~
18+
* Added ``map_variables`` argument to the :py:func:`pvlib.iotools.read_tmy3` in
19+
order to offer the option of mapping column names to standard pvlib names.
20+
(:issue:`1517`, :pull:`1623`)
1421
* Update the URL used in the :py:func:`pvlib.iotools.get_cams` function. The new URL supports load-balancing
1522
and redirects to the fastest server. (:issue:`1688`, :pull:`1740`)
1623
* :py:func:`pvlib.iotools.get_psm3` now has a ``url`` parameter to give the user
@@ -49,5 +56,6 @@ Contributors
4956
* Siddharth Kaul (:ghuser:`k10blogger`)
5057
* Kshitiz Gupta (:ghuser:`kshitiz305`)
5158
* Stefan de Lange (:ghuser:`langestefan`)
59+
* :ghuser:`ooprathamm`
5260
* Kevin Anderson (:ghuser:`kandersolar`)
5361

pvlib/data/variables_style_rules.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dni_extra;direct normal irradiance at top of atmosphere (extraterrestrial)
77
dhi;diffuse horizontal irradiance
88
bhi;beam/direct horizontal irradiance
99
ghi;global horizontal irradiance
10+
ghi_extra;horizontal irradiance at top of atmosphere (extraterrestrial)
1011
gri;ground-reflected irradiance
1112
aoi;angle of incidence between :math:`90\deg` and :math:`90\deg`
1213
aoi_projection;cos(aoi)
@@ -32,6 +33,8 @@ relative_humidity;relative humidity
3233
wind_speed;wind speed
3334
wind_direction;wind direction
3435
pressure;atmospheric pressure
36+
albedo;ratio of reflected solar irradiance to global horizontal irradiance, unitless
37+
precipitable_water;total precipitable water contained in a column of unit cross section from earth to top of atmosphere
3538
v_mp, i_mp, p_mp;module voltage, current, power at the maximum power point
3639
v_oc;open circuit module voltage
3740
i_sc;short circuit module current

0 commit comments

Comments
 (0)