@@ -226,43 +226,55 @@ def test_projected_solar_zenith_angle_datatypes(
226226
227227
228228@pytest .fixture
229- def expected_fs ():
230- # trivial case, 80% gcr, no slope, trackers & psz at 45-deg
231- z0 = np .sqrt (2 * 0.8 * 0.8 )
232- # another trivial case, 60% gcr, no slope, trackers & psz at 60-deg
233- z1 = 2 * 0.6
234- # 30-deg isosceles, 60% gcr, no slope, 30-deg trackers, psz at 60-deg
235- z2 = 0.6 * np .sqrt (3 )
236- z = np .array ([z0 , z1 , z2 ])
237- return 1 - 1 / z
238-
239-
240- def test_tracker_shade_fraction (expected_fs ):
241- """closes gh1690"""
242- fs = shading .tracker_shaded_fraction (45.0 , 0.8 , 45.0 )
243- assert np .isclose (fs , expected_fs [0 ])
244- # same trivial case with 40%, shadow is only 0.565-m long < 1-m r2r P
245- zero_fs = shading .tracker_shaded_fraction (45.0 , 0.4 , 45.0 )
246- assert np .isclose (zero_fs , 0 )
247- # test vectors
248- tracker_theta = [45.0 , 60.0 , 30.0 ]
249- gcr = [0.8 , 0.6 , 0.6 ]
250- psz = [45.0 , 60.0 , 60.0 ]
251- slope = [0 ]* 3
252- fs_vec = shading .tracker_shaded_fraction (
253- tracker_theta , gcr , psz , slope )
254- assert np .allclose (fs_vec , expected_fs )
255-
256-
257- def test_linear_shade_loss (expected_fs ):
258- loss = shading .linear_shade_loss (expected_fs [0 ], 0.2 )
259- assert np .isclose (loss , 0.09289321881345258 )
229+ def sf_premises_and_expected ():
230+ """Data comprised of solar position, tracker orientations, ground coverage
231+ ratios and terrain slopes with respective shade fractions (sf)"""
232+ # preserve tracker_shade_fraction's args order and append shadow depth, z
233+ premises_and_results = pd .DataFrame (
234+ columns = ["solar_zenith" , "solar_azimuth" , "tracker_tilt" ,
235+ "tracker_azimuth" , "gcr" , "cross_axis_slope" , "z" ],
236+ data = (
237+ # trivial case, 80% gcr, no slope, trackers & psz at 45-deg
238+ (45 , 90. , 45 , 90. , 0.8 , 0 , np .sqrt (2 * 0.8 * 0.8 )),
239+ # another trivial case, 60% gcr, no slope, trackers & psz at 60-deg
240+ (60 , 120 , 60 , 120 , 0.6 , 0 , 2 * 0.6 ),
241+ # 30-deg isosceles, 60% gcr, no slope, 30-deg trackers, psz 60-deg
242+ (60 , 135 , 30 , 135 , 0.6 , 0 , 0.6 * np .sqrt (3 )),
243+ # no shading, 40% gcr, shadow is only 0.565-m long < 1-m r2r P
244+ (45 , 180 , 45 , 180 , 0.4 , 0 , 1 ) # z := 1 means no shadow
245+ ))
246+ # append shaded fraction
247+ premises_and_results ["shaded_fraction" ] = 1 - 1 / premises_and_results ["z" ]
248+ return premises_and_results
249+
250+
251+ def test_tracker_shade_fraction (sf_premises_and_expected ):
252+ """Tests tracker_shade_fraction"""
253+ # unwrap sf_premises_and_expected values premises and expected results
254+ premises = sf_premises_and_expected .drop (columns = ["z" , "shaded_fraction" ])
255+ expected_sf_array = sf_premises_and_expected ["shaded_fraction" ]
256+ # test scalar inputs from the row iterator
257+ # series label := corresponding index in expected_sf_array
258+ for index , premise in premises .iterrows ():
259+ expected_result = expected_sf_array [index ]
260+ sf = shading .tracker_shaded_fraction (** premise )
261+ assert_allclose (sf , expected_result )
262+
263+ # test vector inputs
264+ sf_vec = shading .tracker_shaded_fraction (** premises )
265+ assert_allclose (sf_vec , expected_sf_array )
266+
267+
268+ def test_linear_shade_loss (sf_premises_and_expected ):
269+ expected_sf_array = sf_premises_and_expected ["shaded_fraction" ]
270+ loss = shading .linear_shade_loss (expected_sf_array [0 ], 0.2 )
271+ assert_allclose (loss , 0.09289321881345258 )
260272 # if no diffuse, shade fraction is the loss
261- loss_no_df = shading .linear_shade_loss (expected_fs [0 ], 0 )
262- assert np . isclose (loss_no_df , expected_fs [0 ])
273+ loss_no_df = shading .linear_shade_loss (expected_sf_array [0 ], 0 )
274+ assert_allclose (loss_no_df , expected_sf_array [0 ])
263275 # if all diffuse, no shade loss
264- no_loss = shading .linear_shade_loss (expected_fs [0 ], 1.0 )
265- assert np . isclose (no_loss , 0 )
266- vec_loss = shading .linear_shade_loss (expected_fs , 0.2 )
267- expected_loss = np .array ([0.09289322 , 0.13333333 , 0.03019964 ])
268- assert np . allclose (vec_loss , expected_loss )
276+ no_loss = shading .linear_shade_loss (expected_sf_array [0 ], 1.0 )
277+ assert_allclose (no_loss , 0 )
278+ vec_loss = shading .linear_shade_loss (expected_sf_array , 0.2 )
279+ expected_loss = np .array ([0.09289322 , 0.13333333 , 0.03019964 , 0.0 ])
280+ assert_allclose (vec_loss , expected_loss )
0 commit comments