Skip to content

Commit 100bc17

Browse files
authored
Add variable mapping to SRML iotools functions (#1773)
* Change wind_dir to wind_direction * Add variable mapping * Update v0.10.0.rst * Update v0.10.0.rst * Update v0.10.0.rst * Update v0.10.0.rst
1 parent 0ec9181 commit 100bc17

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Breaking changes
1313
:py:func:`pvlib.singlediode._lambertw_v_from_i` to match
1414
:py:func:`pvlib.pvsystem.singlediode`.
1515
(:issue:`1718`, :pull:`1719`)
16+
* Map wind direction to `wind_direction` instead of `wind_dir` in
17+
:py:func:`pvlib.iotools.read_srml` and
18+
:py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)
1619
* :func:`~pvlib.iotools.get_pvgis_tmy` and :func:`~pvlib.iotools.read_pvgis_tmy`
1720
now rename columns to standard pvlib names by default (``map_variables=True``)
1821
(:pull:`1772`)
@@ -23,7 +26,8 @@ Deprecations
2326

2427
Enhancements
2528
~~~~~~~~~~~~
26-
29+
* Added `map_variables` parameter to :py:func:`pvlib.iotools.read_srml`
30+
and :py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)
2731

2832
Bug fixes
2933
~~~~~~~~~

pvlib/iotools/srml.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'100': 'ghi',
1616
'201': 'dni',
1717
'300': 'dhi',
18-
'920': 'wind_dir',
18+
'920': 'wind_direction',
1919
'921': 'wind_speed',
2020
'930': 'temp_air',
2121
'931': 'temp_dew',
@@ -24,7 +24,7 @@
2424
}
2525

2626

27-
def read_srml(filename):
27+
def read_srml(filename, map_variables=True):
2828
"""
2929
Read University of Oregon SRML 1min .tsv file into pandas dataframe. The
3030
SRML is described in [1]_.
@@ -33,13 +33,14 @@ def read_srml(filename):
3333
----------
3434
filename: str
3535
filepath or url to read for the tsv file.
36+
map_variables: bool, default: True
37+
When true, renames columns of the DataFrame to pvlib variable names
38+
where applicable. See variable :const:`VARIABLE_MAP`.
3639
3740
Returns
3841
-------
3942
data: Dataframe
40-
A dataframe with datetime index and all of the variables listed
41-
in the `VARIABLE_MAP` dict inside of the map_columns function,
42-
along with their associated quality control flags.
43+
A dataframe with datetime index
4344
4445
Notes
4546
-----
@@ -64,7 +65,8 @@ def read_srml(filename):
6465
# Drop day of year and time columns
6566
data = data[data.columns[2:]]
6667

67-
data = data.rename(columns=map_columns)
68+
if map_variables:
69+
data = data.rename(columns=map_columns)
6870

6971
# Quality flag columns are all labeled 0 in the original data. They
7072
# appear immediately after their associated variable and are suffixed
@@ -166,7 +168,8 @@ def format_index(df):
166168
return df
167169

168170

169-
def read_srml_month_from_solardat(station, year, month, filetype='PO'):
171+
def read_srml_month_from_solardat(station, year, month, filetype='PO',
172+
map_variables=True):
170173
"""Request a month of SRML data from solardat and read it into
171174
a Dataframe. The SRML is described in [1]_.
172175
@@ -180,6 +183,9 @@ def read_srml_month_from_solardat(station, year, month, filetype='PO'):
180183
Month to request data for.
181184
filetype: string
182185
SRML file type to gather. See notes for explanation.
186+
map_variables: bool, default: True
187+
When true, renames columns of the DataFrame to pvlib variable names
188+
where applicable. See variable :const:`VARIABLE_MAP`.
183189
184190
Returns
185191
-------
@@ -214,5 +220,5 @@ def read_srml_month_from_solardat(station, year, month, filetype='PO'):
214220
year=year % 100,
215221
month=month)
216222
url = "http://solardat.uoregon.edu/download/Archive/"
217-
data = read_srml(url + file_name)
223+
data = read_srml(url + file_name, map_variables=map_variables)
218224
return data

pvlib/tests/iotools/test_srml.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ def test_read_srml_columns_exist():
2828
assert '7008_flag' in data.columns
2929

3030

31+
def test_read_srml_map_variables_false():
32+
data = srml.read_srml(srml_testfile, map_variables=False)
33+
assert '1000' in data.columns
34+
assert '1000_flag' in data.columns
35+
assert '2010' in data.columns
36+
assert '2010_flag' in data.columns
37+
assert '7008' in data.columns
38+
assert '7008_flag' in data.columns
39+
40+
3141
def test_read_srml_nans_exist():
3242
data = srml.read_srml(srml_testfile)
3343
assert isnan(data['dni_0'][1119])

0 commit comments

Comments
 (0)