Skip to content

Commit 43c3798

Browse files
committed
bump min pandas version to 0.15.0, update tests and docs, add map_variables option
1 parent 07d1b6c commit 43c3798

File tree

5 files changed

+103
-57
lines changed

5 files changed

+103
-57
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ install:
6969
pip uninstall numpy --yes;
7070
pip uninstall pandas --yes;
7171
pip install --no-cache-dir numpy==1.10.1;
72-
pip install --no-cache-dir pandas==0.14.0;
72+
pip install --no-cache-dir pandas==0.15.0;
7373
fi
7474
- conda list
7575
- echo $PATH

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ release.
99
**Python 2.7 support will end on June 1, 2019**. Releases made after this
1010
date will require Python 3. (:issue:`501`)
1111

12+
**Minimum pandas requirment bumped 0.14.0=>0.15.0**
13+
1214

1315
API Changes
1416
~~~~~~~~~~~

pvlib/iotools/surfrad.py

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,36 @@
2323
'temp', 'temp_flag', 'rh', 'rh_flag', 'windspd', 'windspd_flag',
2424
'winddir', 'winddir_flag', 'pressure', 'pressure_flag']
2525

26-
27-
def read_surfrad(filename):
26+
# Dictionary mapping surfrad variables to pvlib names
27+
VARIABLE_MAP = {
28+
'zen': 'solar_zenith',
29+
'dw_solar': 'ghi',
30+
'dw_solar_flag': 'ghi_flag',
31+
'direct_n': 'dni',
32+
'direct_n_flag': 'dni_flag',
33+
'diffuse': 'dhi',
34+
'diffuse_flag': 'dhi_flag',
35+
'temp': 'temp_air',
36+
'temp_flag': 'temp_air_flag',
37+
'windspd': 'wind_speed',
38+
'windspd_flag': 'wind_speed_flag',
39+
'winddir': 'wind_direction',
40+
'winddir_flag': 'wind_direction_flag',
41+
'rh': 'relative_humidity',
42+
'rh_flag': 'relative_humidity_flag'
43+
}
44+
45+
46+
def read_surfrad(filename, map_variables=True):
2847
"""Read in a daily NOAA SURFRAD[1] file.
2948
3049
Parameters
3150
----------
3251
filename: str
3352
Filepath or url.
53+
map_variables: bool
54+
When true, renames columns of the Dataframe to pvlib variable names
55+
where applicable.
3456
3557
Returns
3658
-------
@@ -53,44 +75,47 @@ def read_surfrad(filename):
5375
longitude Float site longitude
5476
elevation Int site elevation
5577
surfrad_version Int surfrad version
78+
tz String Timezone (UTC)
5679
=============== ====== ===============
5780
5881
Dataframe includes the following fields:
5982
60-
================== ====== ==========================================
61-
SURFRAD data Field Format Description
62-
================== ====== ==========================================
63-
year int year as 4 digit int
64-
jday int day of year 1-365(or 366)
65-
month int month (1-12)
66-
day int day of month(1-31)
67-
hour int hour (0-23)
68-
minute int minute (0-59)
69-
dt float decimal time i.e. 23.5 = 2330
70-
zen float solar zenith angle (deg)
83+
======================= ====== ===========================================
84+
raw, mapped Format Description
85+
======================= ====== ===========================================
86+
**Mapped field names are returned when the map_variables argument is True**
87+
----------------------------------------------------------------------------
88+
year int year as 4 digit int
89+
jday int day of year 1-365(or 366)
90+
month int month (1-12)
91+
day int day of month(1-31)
92+
hour int hour (0-23)
93+
minute int minute (0-59)
94+
dt float decimal time i.e. 23.5 = 2330
95+
zen, solar_zenith float solar zenith angle (deg)
7196
**Fields below have associated qc flags labeled <field>_flag.**
72-
-----------------------------------------------------------------------
73-
dw_solar float downwelling global solar(W/m^2)
74-
uw_solar float updownwelling global solar(W/m^2)
75-
direct_n float direct normal solar (W/m^2)
76-
diffuse float downwelling diffuse solar (W/m^2)
77-
dw_ir float downwelling thermal infrared (W/m^2)
78-
dw_casetemp float downwelling IR case temp (K)
79-
dw_dometemp float downwelling IR dome temp (K)
80-
uw_ir float upwelling thermal infrared (W/m^2)
81-
uw_casetemp float upwelling IR case temp (K)
82-
uw_dometemp float upwelling IR case temp (K)
83-
uvb float global uvb (miliWatts/m^2)
84-
par float photosynthetically active radiation(W/m^2)
85-
netsolar float net solar (dw_solar - uw_solar) (W/m^2)
86-
netir float net infrared (dw_ir - uw_ir) (W/m^2)
87-
totalnet float net radiation (netsolar+netir) (W/m^2)
88-
temp float 10-meter air temperature (?C)
89-
rh float relative humidity (%)
90-
windspd float wind speed (m/s)
91-
winddir float wind direction (deg, clockwise from north)
92-
pressure float station pressure (mb)
93-
================== ====== ==========================================
97+
----------------------------------------------------------------------------
98+
dw_solar, ghi float downwelling global solar(W/m^2)
99+
uw_solar float updownwelling global solar(W/m^2)
100+
direct_n, dni float direct normal solar (W/m^2)
101+
diffuse, dhi float downwelling diffuse solar (W/m^2)
102+
dw_ir float downwelling thermal infrared (W/m^2)
103+
dw_casetemp float downwelling IR case temp (K)
104+
dw_dometemp float downwelling IR dome temp (K)
105+
uw_ir float upwelling thermal infrared (W/m^2)
106+
uw_casetemp float upwelling IR case temp (K)
107+
uw_dometemp float upwelling IR case temp (K)
108+
uvb float global uvb (miliWatts/m^2)
109+
par float photosynthetically active radiation(W/m^2)
110+
netsolar float net solar (dw_solar - uw_solar) (W/m^2)
111+
netir float net infrared (dw_ir - uw_ir) (W/m^2)
112+
totalnet float net radiation (netsolar+netir) (W/m^2)
113+
temp, temp_air float 10-meter air temperature (?C)
114+
rh, relative_humidity float relative humidity (%)
115+
windspd, wind_speed float wind speed (m/s)
116+
winddir, wind_direction float wind direction (deg, clockwise from north)
117+
pressure float station pressure (mb)
118+
======================= ====== ===========================================
94119
95120
See README files located in the station directories in the SURFRAD
96121
data archives[2] for details on SURFRAD daily data files.
@@ -116,10 +141,11 @@ def read_surfrad(filename):
116141
metadata_list = file_metadata.split()
117142
metadata = {}
118143
metadata['name'] = station.strip()
119-
metadata['latitude'] = metadata_list[0]
120-
metadata['longitude'] = metadata_list[1]
121-
metadata['elevation'] = metadata_list[2]
122-
metadata['surfrad_version'] = metadata_list[-1]
144+
metadata['latitude'] = float(metadata_list[0])
145+
metadata['longitude'] = float(metadata_list[1])
146+
metadata['elevation'] = float(metadata_list[2])
147+
metadata['surfrad_version'] = int(metadata_list[-1])
148+
metadata['tz'] = 'UTC'
123149

124150
data = pd.read_csv(file_buffer, delim_whitespace=True,
125151
header=None, names=SURFRAD_COLUMNS)
@@ -129,6 +155,8 @@ def read_surfrad(filename):
129155
missing = data == -9999.9
130156
data = data.where(~missing, np.NaN)
131157

158+
if map_variables:
159+
data.rename(columns=VARIABLE_MAP, inplace=True)
132160
return data, metadata
133161

134162

@@ -150,8 +178,7 @@ def format_index(data):
150178
jday = data.jday.apply(lambda x: '{:03d}'.format(x))
151179
hours = data.hour.apply(lambda x: '{:02d}'.format(x))
152180
minutes = data.minute.apply(lambda x: '{:02d}'.format(x))
153-
154181
index = pd.to_datetime(year + jday + hours + minutes, format="%Y%j%H%M")
155182
data.index = index
156-
data.tz_localize('UTC')
183+
data = data.tz_localize('UTC')
157184
return data

pvlib/test/test_surfrad.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,53 @@
1313
'Alamosa_CO/2016/slv16001.dat')
1414

1515

16-
def test_read_surfrad():
17-
surfrad.read_surfrad(testfile)
18-
19-
2016
@network
2117
def test_read_surfrad_network():
22-
surfrad.read_surfrad(network_testfile)
18+
# If this test begins failing, SURFRAD's data structure or data
19+
# archive may have changed.
20+
local_data, _ = surfrad.read_surfrad(testfile)
21+
network_data, _ = surfrad.read_surfrad(network_testfile)
22+
assert local_data.equals(network_data)
2323

2424

25-
def test_read_surfrad_columns_exist():
26-
data, _ = surfrad.read_surfrad(testfile)
25+
def test_read_surfrad_columns_no_map():
26+
data, _ = surfrad.read_surfrad(testfile, map_variables=False)
2727
assert 'zen' in data.columns
2828
assert 'temp' in data.columns
2929
assert 'par' in data.columns
3030
assert 'pressure' in data.columns
3131

3232

33+
def test_read_surfrad_columns_map():
34+
data, _ = surfrad.read_surfrad(testfile)
35+
assert 'solar_zenith' in data.columns
36+
assert 'ghi' in data.columns
37+
assert 'ghi_flag' in data.columns
38+
assert 'dni' in data.columns
39+
assert 'dni_flag' in data.columns
40+
assert 'dhi' in data.columns
41+
assert 'dhi_flag' in data.columns
42+
assert 'wind_direction' in data.columns
43+
assert 'wind_direction_flag' in data.columns
44+
assert 'wind_speed' in data.columns
45+
assert 'wind_speed_flag' in data.columns
46+
assert 'temp_air' in data.columns
47+
assert 'temp_air_flag' in data.columns
48+
49+
3350
def test_format_index():
3451
start = Timestamp('20160101 00:00')
35-
expected_index = DatetimeIndex(start=start, periods=1440, freq='1min')
36-
expected_index.tz_localize('UTC')
52+
expected = DatetimeIndex(start=start, periods=1440, freq='1min', tz='UTC')
3753
actual, _ = surfrad.read_surfrad(testfile)
38-
assert actual.index.equals(expected_index)
54+
assert actual.index.equals(expected)
3955

4056

4157
def test_read_surfrad_metadata():
4258
expected = {'name': 'Alamosa',
43-
'latitude': '37.70',
44-
'longitude': '105.92',
45-
'elevation': '2317',
46-
'surfrad_version': '1'}
59+
'latitude': 37.70,
60+
'longitude': 105.92,
61+
'elevation': 2317,
62+
'surfrad_version': 1,
63+
'tz': 'UTC'}
4764
_, metadata = surfrad.read_surfrad(testfile)
4865
assert metadata == expected

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
URL = 'https://github.com/pvlib/pvlib-python'
3939

4040
INSTALL_REQUIRES = ['numpy >= 1.10.1',
41-
'pandas >= 0.14.0',
41+
'pandas >= 0.15.0',
4242
'pytz',
4343
'six',
4444
]

0 commit comments

Comments
 (0)