Skip to content

Commit feb9964

Browse files
committed
default to no_loss
1 parent 2680b4e commit feb9964

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

pvlib/modelchain.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Optional keys to communicate temperature data. If provided,
3131
# 'cell_temperature' overrides ModelChain.temperature_model and sets
32-
# ModelChain.cell_temperature to the data. If 'module_temperature' is provdied,
32+
# ModelChain.cell_temperature to the data. If 'module_temperature' is provided,
3333
# overrides ModelChain.temperature_model with
3434
# pvlib.temperature.sapm_celL_from_module
3535
TEMPERATURE_KEYS = ('module_temperature', 'cell_temperature')
@@ -330,7 +330,7 @@ class ModelChain:
330330
'interp' and 'no_loss'. The ModelChain instance will be passed as the
331331
first argument to a user-defined function.
332332
333-
spectral_model : str or function, optional
333+
spectral_model : str or function, default ``'no_loss'``
334334
Valid strings are:
335335
336336
- ``'sapm'``
@@ -340,8 +340,6 @@ class ModelChain:
340340
The ModelChain instance will be passed as the first argument to
341341
a user-defined function.
342342
343-
By default, it will be inferred from the system attributes only.
344-
345343
See :py:func:`~pvlib.modelchain.ModelChain.infer_spectral_model` to
346344
infer the spectral model from system and weather information.
347345
@@ -369,7 +367,7 @@ def __init__(self, system, location,
369367
solar_position_method='nrel_numpy',
370368
airmass_model='kastenyoung1989',
371369
dc_model=None, ac_model=None, aoi_model=None,
372-
spectral_model=None, temperature_model=None,
370+
spectral_model='no_loss', temperature_model=None,
373371
dc_ohmic_model='no_loss',
374372
losses_model='no_loss', name=None):
375373

@@ -873,9 +871,9 @@ def spectral_model(self, model):
873871
else:
874872
raise ValueError(model + ' is not a valid spectral loss model')
875873
elif model is None:
876-
# uses recursive setter to infer model, which returns a string
877-
self.spectral_model = self.infer_spectral_model(weather=None)
878-
else: # assume model is a callable
874+
# not setting a model is equivalent to setting no_loss
875+
self._spectral_model = self.no_spectral_loss
876+
else: # assume model is callable with 1st argument = the MC instance
879877
self._spectral_model = partial(model, self)
880878

881879
def infer_spectral_model(self, weather=None):

pvlib/tests/test_modelchain.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_with_pvwatts(pvwatts_dc_pvwatts_ac_system, location, weather):
346346

347347

348348
def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location):
349-
mc = ModelChain(sapm_dc_snl_ac_system, location)
349+
mc = ModelChain(sapm_dc_snl_ac_system, location, spectral_model='sapm')
350350
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
351351
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
352352
index=times)
@@ -629,9 +629,13 @@ def test_run_model_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
629629

630630

631631
def test_run_model_perez(sapm_dc_snl_ac_system, location):
632-
mc = ModelChain(sapm_dc_snl_ac_system, location,
633-
transposition_model='perez')
634-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
632+
mc = ModelChain(
633+
sapm_dc_snl_ac_system,
634+
location,
635+
transposition_model="perez",
636+
spectral_model="sapm",
637+
)
638+
times = pd.date_range("20160101 1200-0700", periods=2, freq="6h")
635639
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
636640
index=times)
637641
ac = mc.run_model(irradiance).results.ac
@@ -642,10 +646,14 @@ def test_run_model_perez(sapm_dc_snl_ac_system, location):
642646

643647

644648
def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location):
645-
mc = ModelChain(sapm_dc_snl_ac_system, location,
646-
airmass_model='gueymard1993',
647-
transposition_model='perez')
648-
times = pd.date_range('20160101 1200-0700', periods=2, freq='6h')
649+
mc = ModelChain(
650+
sapm_dc_snl_ac_system,
651+
location,
652+
airmass_model="gueymard1993",
653+
transposition_model="perez",
654+
spectral_model="sapm",
655+
)
656+
times = pd.date_range("20160101 1200-0700", periods=2, freq="6h")
649657
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
650658
index=times)
651659
ac = mc.run_model(irradiance).results.ac
@@ -1271,12 +1279,16 @@ def test_infer_spectral_model(location, sapm_dc_snl_ac_system,
12711279
def test_infer_spectral_model_with_weather(location, sapm_dc_snl_ac_system,
12721280
cec_dc_snl_ac_system, weather):
12731281
# instantiate example ModelChain to get the default spectral model
1274-
# inferred without weather available by default
1275-
# - should resolve to sapm
1282+
# default should resolve to no loss
12761283
mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='physical')
12771284
assert mc.spectral_model == mc.sapm_spectral_loss
1278-
# - should resolve to no loss
1279-
mc = ModelChain(cec_dc_snl_ac_system, location, aoi_model='physical')
1285+
# - next inference should resolve to no loss
1286+
mc = ModelChain(
1287+
cec_dc_snl_ac_system,
1288+
location,
1289+
aoi_model="physical",
1290+
spectral_model=None,
1291+
)
12801292
assert mc.spectral_model == mc.no_spectral_loss
12811293

12821294
# infer spectral model from weather
@@ -2008,9 +2020,9 @@ def test__irrad_for_celltemp():
20082020

20092021

20102022
def test_ModelChain___repr__(sapm_dc_snl_ac_system, location):
2011-
2012-
mc = ModelChain(sapm_dc_snl_ac_system, location,
2013-
name='my mc')
2023+
mc = ModelChain(
2024+
sapm_dc_snl_ac_system, location, name="my mc", spectral_model="sapm"
2025+
)
20142026

20152027
expected = '\n'.join([
20162028
'ModelChain: ',

0 commit comments

Comments
 (0)