13
13
def wvm (clearsky_index , positions , cloud_speed , dt = None ):
14
14
"""
15
15
Compute spatial aggregation time series smoothing on clear sky index based
16
- on the Wavelet Variability model of Lave et al [1-2] . Implementation is
17
- basically a port of the Matlab version of the code [3].
16
+ on the Wavelet Variability model of Lave et al. [1]_, [2]_ . Implementation
17
+ is basically a port of the Matlab version of the code [3]_ .
18
18
19
19
Parameters
20
20
----------
@@ -48,16 +48,16 @@ def wvm(clearsky_index, positions, cloud_speed, dt=None):
48
48
49
49
References
50
50
----------
51
- [1] M. Lave, J. Kleissl and J.S. Stein. A Wavelet-Based Variability
52
- Model (WVM) for Solar PV Power Plants. IEEE Transactions on Sustainable
53
- Energy, vol. 4, no. 2, pp. 501-509, 2013.
51
+ .. [1] M. Lave, J. Kleissl and J.S. Stein. A Wavelet-Based Variability
52
+ Model (WVM) for Solar PV Power Plants. IEEE Transactions on Sustainable
53
+ Energy, vol. 4, no. 2, pp. 501-509, 2013.
54
54
55
- [2] M. Lave and J. Kleissl. Cloud speed impact on solar variability
56
- scaling - Application to the wavelet variability model. Solar Energy,
57
- vol. 91, pp. 11-21, 2013.
55
+ .. [2] M. Lave and J. Kleissl. Cloud speed impact on solar variability
56
+ scaling - Application to the wavelet variability model. Solar Energy,
57
+ vol. 91, pp. 11-21, 2013.
58
58
59
- [3] Wavelet Variability Model - Matlab Code:
60
- https://pvpmc.sandia.gov/applications/wavelet-variability-model/
59
+ .. [3] Wavelet Variability Model - Matlab Code:
60
+ https://github.com/sandialabs/wvm
61
61
"""
62
62
63
63
# Added by Joe Ranalli (@jranalli), Penn State Hazleton, 2019
@@ -128,13 +128,13 @@ def latlon_to_xy(coordinates):
128
128
129
129
References
130
130
----------
131
- [1] H. Moritz. Geodetic Reference System 1980, Journal of Geodesy, vol. 74,
132
- no. 1, pp 128–133, 2000.
131
+ .. [1] H. Moritz. Geodetic Reference System 1980, Journal of Geodesy, vol.
132
+ 74, no. 1, pp 128–133, 2000.
133
133
134
- [2] https://pypi.org/project/pyproj/
134
+ .. [2] https://pypi.org/project/pyproj/
135
135
136
- [3] Wavelet Variability Model - Matlab Code:
137
- https://pvpmc.sandia.gov/applications/wavelet-variability-model/
136
+ .. [3] Wavelet Variability Model - Matlab Code:
137
+ https://github.com/sandialabs/wvm
138
138
"""
139
139
140
140
# Added by Joe Ranalli (@jranalli), Penn State Hazleton, 2019
@@ -159,7 +159,12 @@ def latlon_to_xy(coordinates):
159
159
160
160
def _compute_wavelet (clearsky_index , dt = None ):
161
161
"""
162
- Compute the wavelet transform on the input clear_sky time series.
162
+ Compute the wavelet transform on the input clear_sky time series. Uses a
163
+ top hat wavelet [-1,1,1,-1] shape, based on the difference of successive
164
+ centered moving averages. Smallest scale (filter size of 2) is a degenerate
165
+ case that resembles a Haar wavelet. Returns one level of approximation
166
+ coefficient (CAn) and n levels of detail coefficients (CD1, CD2, ...,
167
+ CDn-1, CDn).
163
168
164
169
Parameters
165
170
----------
@@ -174,19 +179,20 @@ def _compute_wavelet(clearsky_index, dt=None):
174
179
Returns
175
180
-------
176
181
wavelet: numeric
177
- The individual wavelets for the time series
182
+ The individual wavelets for the time series. Format follows increasing
183
+ scale (decreasing frequency): [CD1, CD2, ..., CDn, CAn]
178
184
179
185
tmscales: numeric
180
186
The timescales associated with the wavelets in seconds [s]
181
187
182
188
References
183
189
----------
184
- [1] M. Lave, J. Kleissl and J.S. Stein. A Wavelet-Based Variability
185
- Model (WVM) for Solar PV Power Plants. IEEE Transactions on Sustainable
186
- Energy, vol. 4, no. 2, pp. 501-509, 2013.
190
+ .. [1] M. Lave, J. Kleissl and J.S. Stein. A Wavelet-Based Variability
191
+ Model (WVM) for Solar PV Power Plants. IEEE Transactions on
192
+ Sustainable Energy, vol. 4, no. 2, pp. 501-509, 2013.
187
193
188
- [3 ] Wavelet Variability Model - Matlab Code:
189
- https://pvpmc.sandia.gov/applications/wavelet-variability-model/
194
+ .. [2 ] Wavelet Variability Model - Matlab Code:
195
+ https://github.com/sandialabs/wvm
190
196
"""
191
197
192
198
# Added by Joe Ranalli (@jranalli), Penn State Hazleton, 2019
@@ -209,31 +215,37 @@ def _compute_wavelet(clearsky_index, dt=None):
209
215
210
216
# Compute wavelet time scales
211
217
min_tmscale = np .ceil (np .log (dt )/ np .log (2 )) # Minimum wavelet timescale
212
- max_tmscale = int (12 - min_tmscale ) # maximum wavelet timescale
218
+ max_tmscale = int (13 - min_tmscale ) # maximum wavelet timescale
213
219
214
220
tmscales = np .zeros (max_tmscale )
215
221
csi_mean = np .zeros ([max_tmscale , len (cs_long )])
222
+ # Skip averaging for the 0th scale
223
+ csi_mean [0 , :] = cs_long .values .flatten ()
224
+ tmscales [0 ] = 1
216
225
# Loop for all time scales we will consider
217
- for i in np .arange (0 , max_tmscale ):
218
- j = i + 1
219
- tmscales [i ] = 2 ** j * dt # Wavelet integration time scale
220
- intvlen = 2 ** j # Wavelet integration time series interval
226
+ for i in np .arange (1 , max_tmscale ):
227
+ tmscales [i ] = 2 ** i * dt # Wavelet integration time scale
228
+ intvlen = 2 ** i # Wavelet integration time series interval
221
229
# Rolling average, retains only lower frequencies than interval
230
+ # Produces slightly different end effects than the MATLAB version
222
231
df = cs_long .rolling (window = intvlen , center = True , min_periods = 1 ).mean ()
223
232
# Fill nan's in both directions
224
233
df = df .fillna (method = 'bfill' ).fillna (method = 'ffill' )
225
234
# Pop values back out of the dataframe and store
226
235
csi_mean [i , :] = df .values .flatten ()
236
+ # Shift to account for different indexing in MATLAB moving average
237
+ csi_mean [i , :] = np .roll (csi_mean [i , :], - 1 )
238
+ csi_mean [i , - 1 ] = csi_mean [i , - 2 ]
227
239
228
- # Calculate the wavelets by isolating the rolling mean frequency ranges
240
+ # Calculate detail coefficients by difference between successive averages
229
241
wavelet_long = np .zeros (csi_mean .shape )
230
242
for i in np .arange (0 , max_tmscale - 1 ):
231
243
wavelet_long [i , :] = csi_mean [i , :] - csi_mean [i + 1 , :]
232
- wavelet_long [max_tmscale - 1 , :] = csi_mean [max_tmscale - 1 , :] # Lowest freq
244
+ wavelet_long [- 1 , :] = csi_mean [- 1 , :] # Lowest freq (CAn)
233
245
234
246
# Clip off the padding and just return the original time window
235
247
wavelet = np .zeros ([max_tmscale , len (vals )])
236
248
for i in np .arange (0 , max_tmscale ):
237
- wavelet [i , :] = wavelet_long [i , len (vals )+ 1 : 2 * len (vals )+ 1 ]
249
+ wavelet [i , :] = wavelet_long [i , len (vals ): 2 * len (vals )]
238
250
239
251
return wavelet , tmscales
0 commit comments