@@ -268,11 +268,9 @@ def martin_ruiz_spectral_modifier(clearness_index, airmass_absolute,
268
268
upper case. If not specified, ``model_parameters`` must be provided.
269
269
270
270
model_parameters : dict-like, optional
271
- In case you computed the model parameters for any specified
272
- components. Result keys will be the same as the input keys with each
273
- component in ``model_parameters``, so it can easily be used when some
274
- parameters are unknown. Provide either a dict or a ``pd.DataFrame`` as
275
- follows:
271
+ In case you computed the model parameters. In case any component is not
272
+ specified, result will have a ``None`` value in its corresponding key.
273
+ Provide either a dict or a ``pd.DataFrame`` as follows:
276
274
277
275
.. code-block:: python
278
276
@@ -283,22 +281,24 @@ def martin_ruiz_spectral_modifier(clearness_index, airmass_absolute,
283
281
'sky_diffuse': {'c': c2, 'a': a2, 'b': b2},
284
282
'ground_diffuse': {'c': c3, 'a': a3, 'b': b3}
285
283
}
286
- # Using a pd.DataFrame and grouping sky and ground diffuse
287
- # Yields result with 'direct' & 'diffuse' keys only
284
+ # Using a pd.DataFrame
288
285
model_parameters = pd.DataFrame({
289
286
'direct': [c1, a1, b1],
290
- 'diffuse': [c2, a2, b2]},
287
+ 'sky_diffuse': [c2, a2, b2],
288
+ 'ground_diffuse': [c3, a3, b3]},
291
289
index=('c', 'a', 'b'))
292
290
293
291
``c``, ``a`` and ``b`` must be scalar.
294
292
295
293
Returns
296
294
-------
297
- Mismatch modifiers : pd.Series of numeric
295
+ Mismatch modifiers : pd.Series of numeric or None
298
296
Modifiers for direct, sky diffuse and ground diffuse irradiances, with
299
297
indexes ``direct``, ``sky_diffuse``, ``ground_diffuse``.
300
298
Each mismatch modifier should be multiplied by its corresponding
301
299
POA component.
300
+ Returns None for a component if provided ``model_parameters`` does not
301
+ include its coefficients.
302
302
303
303
Raises
304
304
------
@@ -333,11 +333,11 @@ def martin_ruiz_spectral_modifier(clearness_index, airmass_absolute,
333
333
"""
334
334
# Note tests for this function are prefixed with test_martin_ruiz_mm_*
335
335
336
- irrad_components = ('direct' , 'sky_diffuse' , 'ground_diffuse' )
336
+ IRRAD_COMPONENTS = ('direct' , 'sky_diffuse' , 'ground_diffuse' )
337
337
# Fitting parameters directly from [1]_
338
338
MARTIN_RUIZ_PARAMS = pd .DataFrame (
339
339
index = ('monosi' , 'polysi' , 'asi' ),
340
- columns = pd .MultiIndex .from_product ([irrad_components ,
340
+ columns = pd .MultiIndex .from_product ([IRRAD_COMPONENTS ,
341
341
('c' , 'a' , 'b' )]),
342
342
data = [ # Direct(c,a,b) | Sky diffuse(c,a,b) | Ground diffuse(c,a,b)
343
343
[1.029 , - .313 , 524e-5 , .764 , - .882 , - .0204 , .970 , - .244 , .0129 ],
@@ -359,11 +359,9 @@ def martin_ruiz_spectral_modifier(clearness_index, airmass_absolute,
359
359
raise TypeError ('You must pass at least "cell_type" '
360
360
'or "model_parameters" as arguments!' )
361
361
elif model_parameters is not None : # Use user-defined model parameters
362
- # Overwrite components with user-specified ones
363
- irrad_components = model_parameters .keys ()
364
362
# Validate 'model_parameters' sub-dicts keys
365
363
if any ([{'a' , 'b' , 'c' } != set (model_parameters [component ].keys ())
366
- for component in irrad_components ]):
364
+ for component in model_parameters . keys () ]):
367
365
raise ValueError ("You must specify model parameters with keys "
368
366
"'a','b','c' for each irradiation component." )
369
367
@@ -376,12 +374,15 @@ def martin_ruiz_spectral_modifier(clearness_index, airmass_absolute,
376
374
kt_delta = clearness_index - 0.74
377
375
am_delta = airmass_absolute - 1.5
378
376
379
- modifiers = pd .Series ()
377
+ modifiers = pd .Series (index = IRRAD_COMPONENTS , data = [ None , None , None ] )
380
378
381
379
# Calculate mismatch modifier for each irradiation
382
- for irrad_type in irrad_components :
380
+ for irrad_type in IRRAD_COMPONENTS :
381
+ # Skip irradiations not specified in 'model_params'
382
+ if irrad_type not in _params .keys ():
383
+ continue
384
+ # Else, calculate the mismatch modifier
383
385
_coeffs = _params [irrad_type ]
384
-
385
386
modifier = _coeffs ['c' ] * np .exp (_coeffs ['a' ] * kt_delta
386
387
+ _coeffs ['b' ] * am_delta )
387
388
modifiers [irrad_type ] = modifier
0 commit comments