def test_check_hh(): """Test that check hub height method will return the hh at the single windspeed""" h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_incomplete_2.h5') msg = ('Wind resource method _check_hub_height() failed! Should have ' 'returned 100 because theres only windspeed at 100m') with WindResource(h5) as wind: assert (wind._check_hub_height(120) == 100), msg
def test_group(): """ test WindResource class calls """ path = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_group.h5') with pytest.raises(ResourceKeyError): with WindResource(path) as res: check_res(res)
def test_single_hh(): """Test that resource with data at a single hub height will always return the data at that hub height (and also return a warning)""" h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_incomplete_1.h5') with WindResource(h5) as wind: # Existing datasets are P0m and T80m assert np.array_equal(wind['pressure_80m'], wind['pressure_0m']) assert np.array_equal(wind['temperature_10m'], wind['temperature_80m'])
def test_preload_sam_hh(): """Test the preload_SAM method with a single hub height windspeed in res. In this case, all variables should be loaded at the single windspeed hh """ h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_incomplete_2.h5') sites = slice(0, 200) hub_heights = 80 SAM_res = WindResource.preload_SAM(h5, sites, hub_heights) with WindResource(h5) as wind: p = wind['pressure_100m'] * 9.86923e-6 t = wind['temperature_100m'] msg1 = ('Error: pressure should have been loaded at 100m ' 'b/c there is only windspeed at 100m.') msg2 = ('Error: temperature should have been loaded at 100m ' 'b/c there is only windspeed at 100m.') assert np.allclose(SAM_res['pressure', :, :].values, p), msg1 assert np.allclose(SAM_res['temperature', :, :].values, t), msg2
def test_sam_df_hh(): """Test that if there's only windspeed at one HH, all data is returned from that hh """ h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_incomplete_2.h5') with WindResource(h5) as wind: sam_df = wind._get_SAM_df('pressure_80m', 0) arr1 = wind['pressure_100m', :, 0] * 9.86923e-6 arr2 = sam_df['pressure_100m'].values msg1 = ('Error: pressure should have been loaded at 100m ' 'b/c there is only windspeed at 100m.') assert np.array_equal(arr1, arr2), msg1
def test_max_ws(): """Test that max windspeed range enforcement works.""" h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_invalid.h5') # sites set with bad wind speeds. for site in [7, 54, 66, 89, 110, 149, 188]: with WindResource(h5) as wind: og_max = np.max(wind['windspeed_100m']) sam_df = wind._get_SAM_df('windspeed_100m', site) patched_max = np.max(sam_df['windspeed_100m'].values) msg1 = 'Not a good test set. Min wind speed is {}'.format(og_max) msg2 = ('Physical range enforcement failed. ' 'Original wind speed min was {}, ' 'patched min was {}'.format(og_max, patched_max)) assert og_max > 120, msg1 assert patched_max == 120, msg2
def test_min_temp(): """Test that minimum temperature range enforcement works.""" h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_invalid.h5') # sites set with bad temperature. for site in [5, 12, 45, 54, 97, 103, 142, 166]: with WindResource(h5) as wind: og_min = np.min(wind['temperature_100m']) sam_df = wind._get_SAM_df('temperature_100m', site) patched_min = np.min(sam_df['temperature_100m'].values) msg1 = 'Not a good test set. Min temp is {}'.format(og_min) msg2 = ('Physical range enforcement failed. ' 'Original temp min was {}, ' 'patched min was {}'.format(og_min, patched_min)) assert og_min < -200, msg1 assert patched_min == -200, msg2
def test_min_pressure(): """Test that minimum pressure range enforcement works.""" h5 = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_invalid.h5') # sites set with bad pressure. for site in [3, 7, 43, 79, 151, 179]: with WindResource(h5) as wind: og_min = np.min(wind['pressure_100m']) * 9.86923e-6 sam_df = wind._get_SAM_df('pressure_100m', site) patched_min = np.min(sam_df['pressure_100m'].values) msg1 = 'Not a good test set. Min pressure is {}'.format(og_min) msg2 = ('Physical range enforcement failed. ' 'Original pressure min was {}, ' 'patched min was {}'.format(og_min, patched_min)) assert og_min < 0.5, msg1 assert patched_min == 0.5, msg2
def wind_group(): """ Init WindResource resource handler """ path = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012_group.h5') return WindResource(path, group='group')
def WindResource_res(): """ Init WindResource resource handler """ path = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012.h5') return WindResource(path)