def test_rescale(method, simple_irradiance): # test basic functionality modeled = simple_irradiance measured = 1.05 * simple_irradiance rescaled = irradiance_rescale(measured, modeled, method=method) expected = measured assert_series_equal(rescaled, expected, check_exact=False)
def test_convergence_threshold(simple_irradiance): # can't converge if threshold is negative with pytest.raises(ConvergenceError): _ = irradiance_rescale( simple_irradiance, simple_irradiance * 1.05, max_iterations=5, # reduced count for speed convergence_threshold=-1, method='iterative')
def test_max_iterations_zero(simple_irradiance): # zero is sort of a special case, test it separately # test series already close enough true_factor = 1.0 + 1e-8 rescaled = irradiance_rescale(simple_irradiance, simple_irradiance * true_factor, max_iterations=0, method='iterative') assert_series_equal(rescaled, simple_irradiance, check_exact=False) # tighten threshold so that it isn't already close enough with pytest.raises(ConvergenceError): _ = irradiance_rescale(simple_irradiance, simple_irradiance * true_factor, max_iterations=0, convergence_threshold=1e-9, method='iterative')
def test_max_iterations(simple_irradiance): # use iterative method without enough iterations to converge measured = simple_irradiance * 100 # method expects irrad > 200 modeled = measured.copy() modeled.iloc[2] *= 1.1 modeled.iloc[3] *= 1.3 modeled.iloc[4] *= 0.8 with pytest.raises(ConvergenceError): _ = irradiance_rescale(measured, modeled, method='iterative', max_iterations=2) _ = irradiance_rescale(measured, modeled, method='iterative', max_iterations=10)
# The clear sky workflow is useful in that it avoids problems due to drift or recalibration of ground-based sensors. We use `pvlib` to model the clear sky irradiance. This is renormalized to align it with ground-based measurements. Finally we use `rdtools.get_clearsky_tamb()` to model the ambient temperature on clear sky days. This modeled ambient temperature is used to model cell temperature with `pvlib`. If high quality amabient temperature data is available, that can be used instead of the modeled ambient; we proceed with the modeled ambient temperature here for illustrative purposes # In this example, note that we have omitted wind data in the cell temperature calculations for illustrative purposes. Wind data can also be included when the data source is trusted for improved results # Clear Sky 0: Preliminary Calculations # Calculate the clear sky POA irradiance clearsky = loc.get_clearsky(df.index, solar_position=sun) cs_sky = pvlib.irradiance.isotropic(meta['tilt'], clearsky.dhi) cs_beam = pvlib.irradiance.beam_component(meta['tilt'], meta['azimuth'], sun.zenith, sun.azimuth, clearsky.dni) df['clearsky_poa'] = cs_beam + cs_sky # Renormalize the clear sky POA irradiance df['clearsky_poa'] = rdtools.irradiance_rescale(df.poa, df.clearsky_poa, method='iterative') # Calculate the clearsky temperature df['clearsky_Tamb'] = rdtools.get_clearsky_tamb(df.index, meta['latitude'], meta['longitude']) df_clearsky_temp = pvlib.pvsystem.sapm_celltemp(df.clearsky_poa, 0, df.clearsky_Tamb, model=meta['temp_model']) df['clearsky_Tcell'] = df_clearsky_temp.temp_cell # Clear Sky 1: Normalize # Normalize as in step 1 above, but this time using clearsky modeled irradiance and cell temperature clearsky_pvwatts_kws = {