diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst
index 028b905003..812aee9c90 100644
--- a/docs/sphinx/source/whatsnew/v0.9.2.rst
+++ b/docs/sphinx/source/whatsnew/v0.9.2.rst
@@ -8,6 +8,9 @@ Deprecations
Enhancements
~~~~~~~~~~~~
+* :py:func:`pvlib.iotools.read_surfrad` now also accepts remote files
+ with https links in addition to files on the SURFRAD FTP server
+ (:pull:`1459`)
* Add :py:func:`pvlib.tracking.calc_surface_orientation` for calculating
single-axis tracker ``surface_tilt`` and ``surface_azimuth`` from
rotation angles. (:issue:`1471`, :pull:`1480`)
@@ -47,8 +50,9 @@ Requirements
Contributors
~~~~~~~~~~~~
+* Adam R. Jensen (:ghuser:`AdamRJensen`)
* Naman Priyadarshi (:ghuser:`Naman-Priyadarshi`)
* Chencheng Luo (:ghuser:`roger-lcc`)
* Prajwal Borkar (:ghuser:`PrajwalBorkar`)
* Kevin Anderson (:ghuser:`kanderso-nrel`)
-* Cliff Hansen (:ghuser:`cwhanse`)
\ No newline at end of file
+* Cliff Hansen (:ghuser:`cwhanse`)
diff --git a/pvlib/iotools/surfrad.py b/pvlib/iotools/surfrad.py
index b819923497..7f4d86e46a 100644
--- a/pvlib/iotools/surfrad.py
+++ b/pvlib/iotools/surfrad.py
@@ -44,7 +44,7 @@ def read_surfrad(filename, map_variables=True):
Parameters
----------
filename: str
- Filepath or url.
+ Filepath or URL. URL can be either FTP or HTTP.
map_variables: bool
When true, renames columns of the Dataframe to pvlib variable names
where applicable. See variable :const:`VARIABLE_MAP`.
@@ -113,7 +113,8 @@ def read_surfrad(filename, map_variables=True):
======================= ====== ==========================================
See README files located in the station directories in the SURFRAD
- data archives [2]_ for details on SURFRAD daily data files.
+ data archives [2]_ for details on SURFRAD daily data files. In addition to
+ the FTP server, the SURFRAD files are also available via HTTP access [3]_.
References
----------
@@ -122,8 +123,10 @@ def read_surfrad(filename, map_variables=True):
`SURFRAD Homepage `_
.. [2] NOAA SURFRAD Data Archive
`SURFRAD Archive `_
+ .. [3] `NOAA SURFRAD HTTP Index
+ `_
"""
- if str(filename).startswith('ftp'):
+ if str(filename).startswith('ftp') or str(filename).startswith('http'):
req = Request(filename)
response = urlopen(req)
file_buffer = io.StringIO(response.read().decode(errors='ignore'))
diff --git a/pvlib/tests/iotools/test_surfrad.py b/pvlib/tests/iotools/test_surfrad.py
index 6ef9fcab51..83f7ec7645 100644
--- a/pvlib/tests/iotools/test_surfrad.py
+++ b/pvlib/tests/iotools/test_surfrad.py
@@ -7,6 +7,8 @@
testfile = DATA_DIR / 'surfrad-slv16001.dat'
network_testfile = ('ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/'
'Alamosa_CO/2016/slv16001.dat')
+https_testfile = ('https://gml.noaa.gov/aftp/data/radiation/surfrad/'
+ 'Alamosa_CO/2016/slv16001.dat')
@pytest.mark.remote_data
@@ -19,6 +21,17 @@ def test_read_surfrad_network():
assert local_data.equals(network_data)
+@pytest.mark.remote_data
+@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
+def test_read_surfrad_https():
+ # Test reading of https files.
+ # If this test begins failing, SURFRAD's data structure or data
+ # archive may have changed.
+ local_data, _ = surfrad.read_surfrad(testfile)
+ network_data, _ = surfrad.read_surfrad(https_testfile)
+ assert local_data.equals(network_data)
+
+
def test_read_surfrad_columns_no_map():
data, _ = surfrad.read_surfrad(testfile, map_variables=False)
assert 'zen' in data.columns