Skip to content

Add variable mapping to SRML iotools functions #1773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/sphinx/source/whatsnew/v0.10.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Breaking changes
:py:func:`pvlib.singlediode._lambertw_v_from_i` to match
:py:func:`pvlib.pvsystem.singlediode`.
(:issue:`1718`, :pull:`1719`)
* Map wind direction to `wind_direction` instead of `wind_dir` in
:py:func:`pvlib.iotools.read_srml` and
:py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)
* :func:`~pvlib.iotools.get_pvgis_tmy` and :func:`~pvlib.iotools.read_pvgis_tmy`
now rename columns to standard pvlib names by default (``map_variables=True``)
(:pull:`1772`)
Expand All @@ -23,7 +26,8 @@ Deprecations

Enhancements
~~~~~~~~~~~~

* Added `map_variables` parameter to :py:func:`pvlib.iotools.read_srml`
and :py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)

Bug fixes
~~~~~~~~~
Expand Down
22 changes: 14 additions & 8 deletions pvlib/iotools/srml.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'100': 'ghi',
'201': 'dni',
'300': 'dhi',
'920': 'wind_dir',
'920': 'wind_direction',
'921': 'wind_speed',
'930': 'temp_air',
'931': 'temp_dew',
Expand All @@ -24,7 +24,7 @@
}


def read_srml(filename):
def read_srml(filename, map_variables=True):
"""
Read University of Oregon SRML 1min .tsv file into pandas dataframe. The
SRML is described in [1]_.
Expand All @@ -33,13 +33,14 @@ def read_srml(filename):
----------
filename: str
filepath or url to read for the tsv file.
map_variables: bool, default: True
When true, renames columns of the DataFrame to pvlib variable names
where applicable. See variable :const:`VARIABLE_MAP`.

Returns
-------
data: Dataframe
A dataframe with datetime index and all of the variables listed
in the `VARIABLE_MAP` dict inside of the map_columns function,
along with their associated quality control flags.
A dataframe with datetime index

Notes
-----
Expand All @@ -64,7 +65,8 @@ def read_srml(filename):
# Drop day of year and time columns
data = data[data.columns[2:]]

data = data.rename(columns=map_columns)
if map_variables:
data = data.rename(columns=map_columns)

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


def read_srml_month_from_solardat(station, year, month, filetype='PO'):
def read_srml_month_from_solardat(station, year, month, filetype='PO',
map_variables=True):
"""Request a month of SRML data from solardat and read it into
a Dataframe. The SRML is described in [1]_.

Expand All @@ -180,6 +183,9 @@ def read_srml_month_from_solardat(station, year, month, filetype='PO'):
Month to request data for.
filetype: string
SRML file type to gather. See notes for explanation.
map_variables: bool, default: True
When true, renames columns of the DataFrame to pvlib variable names
where applicable. See variable :const:`VARIABLE_MAP`.

Returns
-------
Expand Down Expand Up @@ -214,5 +220,5 @@ def read_srml_month_from_solardat(station, year, month, filetype='PO'):
year=year % 100,
month=month)
url = "http://solardat.uoregon.edu/download/Archive/"
data = read_srml(url + file_name)
data = read_srml(url + file_name, map_variables=map_variables)
return data
10 changes: 10 additions & 0 deletions pvlib/tests/iotools/test_srml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_read_srml_columns_exist():
assert '7008_flag' in data.columns


def test_read_srml_map_variables_false():
data = srml.read_srml(srml_testfile, map_variables=False)
assert '1000' in data.columns
assert '1000_flag' in data.columns
assert '2010' in data.columns
assert '2010_flag' in data.columns
assert '7008' in data.columns
assert '7008_flag' in data.columns


def test_read_srml_nans_exist():
data = srml.read_srml(srml_testfile)
assert isnan(data['dni_0'][1119])
Expand Down