@@ -873,8 +873,9 @@ def spectral_model(self, model):
873873 else :
874874 raise ValueError (model + ' is not a valid spectral loss model' )
875875 elif model is None :
876- self ._spectral_model = self .infer_spectral_model (weather = None )
877- else :
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
878879 self ._spectral_model = partial (model , self )
879880
880881 def infer_spectral_model (self , weather = None ):
@@ -891,21 +892,22 @@ def infer_spectral_model(self, weather=None):
891892
892893 Returns
893894 -------
894- Inferred spectral correction model : function
895+ Inferred spectral correction model : string key for model setter
895896
896897 Examples
897898 --------
898899 >>> mc = ModelChain(system, location)
899900 >>> mc.spectral_model = mc.infer_spectral_model(weather=weather)
900901 """
901902 module_parameters = tuple (
902- array .module_parameters for array in self .system .arrays )
903+ array .module_parameters for array in self .system .arrays
904+ )
903905 params = _common_keys (module_parameters )
904- if {'A4' , 'A3' , 'A2' , 'A1' , 'A0' } <= params :
905- return self . sapm_spectral_loss
906+ if {"A4" , "A3" , "A2" , "A1" , "A0" } <= params :
907+ return "sapm"
906908 elif "first_solar_spectral_coefficients" in params :
907909 # user explicitly sets spectral coefficients
908- return self . first_solar_spectral_loss
910+ return "first_solar"
909911 elif (
910912 # cell type is known or can be inferred
911913 ("Technology" in params or "Material" in params )
@@ -916,9 +918,9 @@ def infer_spectral_model(self, weather=None):
916918 # parameters, so we need to check if they are available.
917919 if weather is not None : # weather is available
918920 if "precipitable_water" in weather :
919- return self . first_solar_spectral_loss
921+ return "first_solar"
920922
921- return self . no_spectral_loss
923+ return "no_loss"
922924
923925 def first_solar_spectral_loss (self ):
924926 self .results .spectral_modifier = self .system .first_solar_spectral_loss (
0 commit comments