def test_isotropic_ordered_transparency_spacing(params_irr): """Check that module transparency and spacing params are applied correctly in IsotropicOrdered""" # Apply irradiance model DNI = 1000. DHI = 100. ts = dt.datetime(2019, 6, 14, 11) irr_parameters = {'module_transparency': 0.1, 'module_spacing_ratio': 0.1} irr_model = IsotropicOrdered(**irr_parameters) irr_model.fit(ts, DNI, DHI, params_irr['solar_zenith'], params_irr['solar_azimuth'], params_irr['surface_tilt'], params_irr['surface_azimuth'], params_irr['rho_ground']) # Create, fit, and transform pv array pvarray = OrderedPVArray.fit_from_dict_of_scalars( params_irr, param_names=IsotropicOrdered.params) irr_model.transform(pvarray) gnd_seg = pvarray.ts_ground pvrow_front = pvarray.ts_pvrows[1].front # check that front is shaded assert pvrow_front.shaded_length > 0 # Run some checks surf_gnd_shaded = gnd_seg.shaded.list_ts_surfaces[0] surf_gnd_illum = gnd_seg.illum.list_ts_surfaces[0] np.testing.assert_allclose(surf_gnd_illum.get_param('direct') * 0.19, surf_gnd_shaded.get_param('direct')) # Run check on pvrow surfaces surf_pvrow_shaded = (pvrow_front.list_segments[0] .shaded.list_ts_surfaces[0]) surf_pvrow_illum = (pvrow_front.list_segments[0] .illum.list_ts_surfaces[0]) np.testing.assert_allclose(surf_pvrow_illum.get_param('direct') * 0.19, surf_pvrow_shaded.get_param('direct'))
def test_isotropic_model_front(params_irr): """Direct shading on front surface""" # Create and fit irradiance model DNI = 1000. DHI = 100. irr_model = IsotropicOrdered() irr_model.fit(None, DNI, DHI, params_irr['solar_zenith'], params_irr['solar_azimuth'], params_irr['surface_tilt'], params_irr['surface_azimuth'], params_irr['rho_ground']) # Expected values expected_dni_pvrow = DNI * cosd(45) expected_dni_ground = DNI * cosd(65) # Check irradiance fitting np.testing.assert_almost_equal(irr_model.direct['ground_illum'][0], expected_dni_ground) np.testing.assert_almost_equal(irr_model.direct['front_illum_pvrow'][0], expected_dni_pvrow) assert irr_model.direct['back_illum_pvrow'][0] == 0. # Create, fit, and transform pv array pvarray = OrderedPVArray.fit_from_dict_of_scalars( params_irr, param_names=IsotropicOrdered.params) irr_model.transform(pvarray) pvarray.transform(idx=0) # there should be some direct shading assert pvarray.pvrows[0].front.shaded_length # Get modeling vectors irradiance_vec, rho_vec, invrho_vec, total_perez_vec = \ irr_model.get_full_modeling_vectors(pvarray, 0) # Check transform expected_irradiance_vec = [ 422.61826174069944, 422.61826174069944, 422.61826174069944, 422.61826174069944, 422.61826174069944, 0.0, 707.10678118654744, 0.0, 0.0, 707.10678118654744, 0.0, 0.0, 707.10678118654744, 0.0, 100. ] # pvrow np.testing.assert_almost_equal( pvarray.pvrows[2].front.get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.pvrows[1].front.list_segments[0].illum_collection. get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.pvrows[1].front.list_segments[0].shaded_collection. get_param_weighted('direct'), 0.) np.testing.assert_almost_equal( pvarray.pvrows[0].back.get_param_weighted('direct'), 0.) # ground np.testing.assert_almost_equal( pvarray.ground.list_segments[0].illum_collection.get_param_weighted( 'direct'), expected_dni_ground) np.testing.assert_almost_equal( pvarray.ground.list_segments[0].shaded_collection.get_param_weighted( 'direct'), 0.) np.testing.assert_array_almost_equal(expected_irradiance_vec, irradiance_vec) # Check invrho_vec expected_invrho_vec = np.array([ 5., 5., 5., 5., 5., 5., 100., 100., 33.333333, 100., 100., 33.333333, 100., 33.333333, 1. ]) np.testing.assert_array_almost_equal(invrho_vec, expected_invrho_vec) np.testing.assert_almost_equal( pvarray.pvrows[0].front.get_param_weighted('rho'), params_irr['rho_front_pvrow']) np.testing.assert_almost_equal( pvarray.pvrows[0].back.get_param_weighted('rho'), params_irr['rho_back_pvrow']) np.testing.assert_almost_equal(pvarray.ground.get_param_weighted('rho'), params_irr['rho_ground']) # Check total perez vec expected_total_perez_vec = [ 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 100., 807.243186, 100.13640481, 0., 807.243186, 100.13640481, 0., 807.243186, 0., 100. ] np.testing.assert_array_almost_equal(total_perez_vec, expected_total_perez_vec)
def test_isotropic_model_front(params_irr): """Direct shading on front surface""" # Create and fit irradiance model DNI = 1000. DHI = 100. irr_model = IsotropicOrdered() irr_model.fit(None, DNI, DHI, params_irr['solar_zenith'], params_irr['solar_azimuth'], params_irr['surface_tilt'], params_irr['surface_azimuth'], params_irr['rho_ground']) # Expected values expected_dni_pvrow = DNI * cosd(45) expected_dni_ground = DNI * cosd(65) # Check irradiance fitting np.testing.assert_almost_equal(irr_model.direct['ground_illum'][0], expected_dni_ground) np.testing.assert_almost_equal(irr_model.direct['front_illum_pvrow'][0], expected_dni_pvrow) assert irr_model.direct['back_illum_pvrow'][0] == 0. # Create, fit, and transform pv array pvarray = OrderedPVArray.fit_from_dict_of_scalars( params_irr, param_names=IsotropicOrdered.params) irr_model.transform(pvarray) # there should be some direct shading assert pvarray.ts_pvrows[0].front.shaded_length # Get modeling vectors irradiance_mat, rho_mat, invrho_mat, total_perez_mat = \ irr_model.get_ts_modeling_vectors(pvarray) # Check transform expected_irradiance_vec = [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 707.10678119, 0., 0., 0., 707.10678119, 0., 0., 0., 707.10678119, 0., 0., 0. ] # pvrow np.testing.assert_almost_equal( pvarray.ts_pvrows[2].front.get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.ts_pvrows[1].front.list_segments[0].illum.get_param_weighted( 'direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.ts_pvrows[1].front.list_segments[0].shaded.get_param_weighted( 'direct'), 0.) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].back.get_param_weighted('direct'), 0.) # ground np.testing.assert_almost_equal( pvarray.ts_ground.illum.get_param_weighted('direct'), expected_dni_ground) np.testing.assert_almost_equal( pvarray.ts_ground.shaded.get_param_weighted('direct'), 0.) np.testing.assert_array_almost_equal(expected_irradiance_vec, np.squeeze(irradiance_mat)) # Check invrho_vec expected_invrho_vec = [ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 100., 100., 33.33333333, 33.33333333, 100., 100., 33.33333333, 33.33333333, 100., 100., 33.33333333, 33.33333333 ] np.testing.assert_array_almost_equal(np.squeeze(invrho_mat), expected_invrho_vec) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].front.get_param_weighted('rho'), params_irr['rho_front_pvrow']) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].back.get_param_weighted('rho'), params_irr['rho_back_pvrow']) np.testing.assert_almost_equal(pvarray.ts_ground.get_param_weighted('rho'), params_irr['rho_ground']) # Check total perez vec expected_total_perez_vec = [ 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 807.243186, 100.13640481, 0., 0., 807.243186, 100.13640481, 0., 0., 807.243186, 100.13640481, 0., 0. ] np.testing.assert_array_almost_equal(np.squeeze(total_perez_mat), expected_total_perez_vec) # check that 2 dimensional assert np.shape(irradiance_mat) == (40, 1) # check faoi modifiers assert irr_model.faoi_back['direct'] == 0.97 assert irr_model.faoi_front['direct'] == 0.99 assert irr_model.faoi_ground == 0.8 # get absorbed sum of sky components irr_comp_absorbed = irr_model.get_summed_components(pvarray, absorbed=True) assert np.shape(irr_comp_absorbed) == (40, 1) # Check a ground surface value np.testing.assert_allclose( np.array(irr_comp_absorbed)[12, 0], (1. - params_irr['rho_ground']) * np.array(irradiance_mat)[12, 0])
def test_isotropic_model_back(params_irr): """Direct shading on back surface""" params_irr.update({'surface_azimuth': 270, 'surface_tilt': 160}) # Apply irradiance model DNI = 1000. DHI = 100. irr_model = IsotropicOrdered() irr_model.fit(None, DNI, DHI, params_irr['solar_zenith'], params_irr['solar_azimuth'], params_irr['surface_tilt'], params_irr['surface_azimuth'], params_irr['rho_ground']) # Expected values expected_dni_pvrow = DNI * cosd(45) expected_dni_ground = DNI * cosd(65) # Check fitting np.testing.assert_almost_equal(irr_model.direct['ground_illum'][0], expected_dni_ground) np.testing.assert_almost_equal(irr_model.direct['back_illum_pvrow'][0], expected_dni_pvrow) assert irr_model.direct['front_illum_pvrow'][0] == 0. # Create, fit, and transform pv array pvarray = OrderedPVArray.fit_from_dict_of_scalars( params_irr, param_names=IsotropicOrdered.params) irr_model.transform(pvarray) # there should be some direct shading assert pvarray.ts_pvrows[0].back.shaded_length # Get modeling vectors irradiance_mat, rho_mat, invrho_mat, total_perez_mat = \ irr_model.get_ts_modeling_vectors(pvarray) # Check expected_irradiance_mat = [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 422.61826174, 0., 0., 707.10678119, 0., 0., 0., 707.10678119, 0., 0., 0., 707.10678119, 0. ] # pvrow np.testing.assert_almost_equal( pvarray.ts_pvrows[2].back.get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.ts_pvrows[1].back.list_segments[0].illum.get_param_weighted( 'direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.ts_pvrows[1].back.list_segments[0].shaded.get_param_weighted( 'direct'), 0.) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].front.get_param_weighted('direct'), 0.) # ground np.testing.assert_almost_equal( pvarray.ts_ground.illum.get_param_weighted('direct'), expected_dni_ground) np.testing.assert_almost_equal( pvarray.ts_ground.shaded.get_param_weighted('direct'), 0.) np.testing.assert_array_almost_equal(expected_irradiance_mat, np.squeeze(irradiance_mat)) # Check invrho_mat expected_invrho_mat = [ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 100., 100., 33.33333333, 33.33333333, 100., 100., 33.33333333, 33.33333333, 100., 100., 33.33333333, 33.33333333 ] np.testing.assert_array_almost_equal(np.squeeze(invrho_mat), expected_invrho_mat) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].front.get_param_weighted('rho'), params_irr['rho_front_pvrow']) np.testing.assert_almost_equal( pvarray.ts_pvrows[0].back.get_param_weighted('rho'), params_irr['rho_back_pvrow']) np.testing.assert_almost_equal(pvarray.ts_ground.get_param_weighted('rho'), params_irr['rho_ground']) # Check total perez vec expected_total_perez_mat = [ 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 100., 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 522.61826174, 104.38724754, 104.38724754, 0., 0., 104.38724754, 104.38724754, 0., 0., 104.38724754, 104.38724754, 0., 0. ] np.testing.assert_array_almost_equal(np.squeeze(total_perez_mat), expected_total_perez_mat) # Get ts modeling matrices irradiance_mat, rho_mat, invrho_mat, total_perez_mat = \ irr_model.get_full_ts_modeling_vectors(pvarray) # check that 2 dimensional assert irradiance_mat.shape == (41, 1)
def test_isotropic_model_back(params_irr): """Direct shading on back surface""" params_irr.update({'surface_azimuth': 270, 'surface_tilt': 160}) # pvarray pvarray = OrderedPVArray.from_dict(params_irr, surface_params=IsotropicOrdered.params) pvarray.cast_shadows() pvarray.cuts_for_pvrow_view() # there should be some direct shading assert pvarray.pvrows[0].back.shaded_length # Apply irradiance model DNI = 1000. DHI = 100. irr_model = IsotropicOrdered() irr_model.fit(None, DNI, DHI, params_irr['solar_zenith'], params_irr['solar_azimuth'], params_irr['surface_tilt'], params_irr['surface_azimuth'], params_irr['rho_front_pvrow'], params_irr['rho_back_pvrow'], params_irr['rho_ground']) # Expected values expected_dni_pvrow = DNI * cosd(45) expected_dni_ground = DNI * cosd(65) # Check fitting np.testing.assert_almost_equal(irr_model.direct['ground'][0], expected_dni_ground) np.testing.assert_almost_equal(irr_model.direct['back_pvrow'][0], expected_dni_pvrow) assert irr_model.direct['front_pvrow'][0] == 0. # Transform irradiance_vec, rho_vec, invrho_vec, total_perez_vec = \ irr_model.transform(pvarray) # Check expected_irradiance_vec = [ 422.61826174069944, 422.61826174069944, 422.61826174069944, 422.61826174069944, 422.61826174069944, 0.0, 0.0, 707.10678118654755, 0.0, 0.0, 707.10678118654755, 0.0, 0.0, 707.10678118654755, 100. ] # pvrow np.testing.assert_almost_equal( pvarray.pvrows[2].back.get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.pvrows[1].back.list_segments[0].illum_collection. get_param_weighted('direct'), expected_dni_pvrow) np.testing.assert_almost_equal( pvarray.pvrows[1].back.list_segments[0].shaded_collection. get_param_weighted('direct'), 0.) np.testing.assert_almost_equal( pvarray.pvrows[0].front.get_param_weighted('direct'), 0.) # ground np.testing.assert_almost_equal( pvarray.ground.list_segments[0].illum_collection.get_param_weighted( 'direct'), expected_dni_ground) np.testing.assert_almost_equal( pvarray.ground.list_segments[0].shaded_collection.get_param_weighted( 'direct'), 0.) np.testing.assert_array_almost_equal(expected_irradiance_vec, irradiance_vec) # Check invrho_vec expected_invrho_vec = np.array([ 5., 5., 5., 5., 5., 5., 100., 33.333333, 33.333333, 100., 33.333333, 33.333333, 100., 33.333333, 1. ]) np.testing.assert_array_almost_equal(invrho_vec, expected_invrho_vec) np.testing.assert_almost_equal( pvarray.pvrows[0].front.get_param_weighted('rho'), params_irr['rho_front_pvrow']) np.testing.assert_almost_equal( pvarray.pvrows[0].back.get_param_weighted('rho'), params_irr['rho_back_pvrow']) np.testing.assert_almost_equal(pvarray.ground.get_param_weighted('rho'), params_irr['rho_ground']) # Check total perez vec expected_total_perez_vec = [ 522.618262, 522.618262, 522.618262, 522.618262, 522.618262, 100., 104.387248, 0., 0., 104.387248, 0., 0., 104.387248, 0., 100. ] np.testing.assert_array_almost_equal(total_perez_vec, expected_total_perez_vec)