23
23
'temp' , 'temp_flag' , 'rh' , 'rh_flag' , 'windspd' , 'windspd_flag' ,
24
24
'winddir' , 'winddir_flag' , 'pressure' , 'pressure_flag' ]
25
25
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 ):
28
47
"""Read in a daily NOAA SURFRAD[1] file.
29
48
30
49
Parameters
31
50
----------
32
51
filename: str
33
52
Filepath or url.
53
+ map_variables: bool
54
+ When true, renames columns of the Dataframe to pvlib variable names
55
+ where applicable.
34
56
35
57
Returns
36
58
-------
@@ -53,44 +75,47 @@ def read_surfrad(filename):
53
75
longitude Float site longitude
54
76
elevation Int site elevation
55
77
surfrad_version Int surfrad version
78
+ tz String Timezone (UTC)
56
79
=============== ====== ===============
57
80
58
81
Dataframe includes the following fields:
59
82
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)
71
96
**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
+ ======================= ====== = ==========================================
94
119
95
120
See README files located in the station directories in the SURFRAD
96
121
data archives[2] for details on SURFRAD daily data files.
@@ -116,10 +141,11 @@ def read_surfrad(filename):
116
141
metadata_list = file_metadata .split ()
117
142
metadata = {}
118
143
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'
123
149
124
150
data = pd .read_csv (file_buffer , delim_whitespace = True ,
125
151
header = None , names = SURFRAD_COLUMNS )
@@ -129,6 +155,8 @@ def read_surfrad(filename):
129
155
missing = data == - 9999.9
130
156
data = data .where (~ missing , np .NaN )
131
157
158
+ if map_variables :
159
+ data .rename (columns = VARIABLE_MAP , inplace = True )
132
160
return data , metadata
133
161
134
162
@@ -150,8 +178,7 @@ def format_index(data):
150
178
jday = data .jday .apply (lambda x : '{:03d}' .format (x ))
151
179
hours = data .hour .apply (lambda x : '{:02d}' .format (x ))
152
180
minutes = data .minute .apply (lambda x : '{:02d}' .format (x ))
153
-
154
181
index = pd .to_datetime (year + jday + hours + minutes , format = "%Y%j%H%M" )
155
182
data .index = index
156
- data .tz_localize ('UTC' )
183
+ data = data .tz_localize ('UTC' )
157
184
return data
0 commit comments