@@ -2963,50 +2963,27 @@ def pvwatts_dc(effective_irradiance, temp_cell, pdc0, gamma_pdc, temp_ref=25.,
29632963
29642964 # apply Marion's correction if k is anything but zero
29652965 if k is not None :
2966+
2967+ # preserve input types
2968+ index = pdc .index if isinstance (pdc , pd .Series ) else None
2969+ is_scalar = np .isscalar (pdc )
2970+
29662971 # calculate error adjustments
29672972 err_1 = k * (1 - (1 - effective_irradiance / 200 )** 4 )
29682973 err_2 = k * (1000 - effective_irradiance ) / (1000 - 200 )
2974+ err = np .where (effective_irradiance <= 200 , err_1 , err_2 )
2975+ if cap_adjustment :
2976+ err = np .where (effective_irradiance >= 1000 , 0 , err )
29692977
2970- # if input is Series or array
2971- if hasattr (effective_irradiance , '__len__' ):
2972- # precalculate pdc before applying error adjustments
2973- pdc_marion = (effective_irradiance * 0.001 * pdc0 *
2974- (1 + gamma_pdc * (temp_cell - temp_ref )))
2975-
2976- # apply error adjustments
2977- pdc_marion [effective_irradiance <= 200 ] = (
2978- pdc [effective_irradiance <= 200 ] -
2979- (pdc0 * err_1 [effective_irradiance <= 200 ]))
2980- pdc_marion [effective_irradiance > 200 ] = (
2981- pdc [effective_irradiance > 200 ] -
2982- (pdc0 * err_2 [effective_irradiance > 200 ]))
2983-
2984- # "cap" Marion's correction at 1000 W/m^2
2985- if cap_adjustment :
2986- pdc_marion [effective_irradiance >= 1000 ] = (
2987- pdc [effective_irradiance >= 1000 ])
2988-
2989- # set negative power to zero
2990- pdc_marion [pdc_marion < 0 ] = 0
2991-
2992- # else (input is scalar)
2993- else :
2994- # apply error adjustments
2995- if effective_irradiance <= 200 :
2996- pdc_marion = pdc - (pdc0 * err_1 )
2997- elif effective_irradiance > 200 :
2998- pdc_marion = pdc - (pdc0 * err_2 )
2999-
3000- # "cap" Marion's correction at 1000 W/m^2 if needed
3001- if cap_adjustment :
3002- if effective_irradiance >= 1000 :
3003- pdc_marion = pdc
3004-
3005- # set negative power to zero
3006- if pdc_marion < 0 :
3007- pdc_marion = 0
3008-
3009- pdc = pdc_marion
2978+ pdc = pdc - pdc0 * err
2979+
2980+ # set negative power to zero
2981+ pdc = np .where (pdc < 0 , 0 , pdc )
2982+
2983+ if index is not None :
2984+ pdc = pd .Series (pdc , index = index )
2985+ elif is_scalar :
2986+ pdc = float (pdc )
30102987
30112988 return pdc
30122989
0 commit comments