def test_distance_plot(): x = [0, 50, 100, 100] y = [100, 100, 100, 0] h = [0, 10, 20, 30] wdirs = [0, 30, 90] Distance = StraightDistance() distances = Distance.distances dw_ijl, hcw_ijl, dh_ijl, dw_indices_l = distances( src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=[0], dst_y_j=[0], dst_h_j=[0], wd_il=np.array(wdirs)[na]) Distance.plot(src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=[0], dst_y_j=[0], dst_h_j=[0], wd_il=np.array(wdirs)[na]) if 0: import matplotlib.pyplot as plt plt.show()
def test_WaspGridSiteDistanceClass(site): wgs = WaspGridSite( site._ds, distance=TerrainFollowingDistance(distance_resolution=2000)) assert wgs.distance.distance_resolution == 2000 assert wgs.distance.__call__.__func__ == TerrainFollowingDistance( ).__call__.__func__ wgs = WaspGridSite(site._ds, distance=StraightDistance()) assert wgs.distance.__call__.__func__ == StraightDistance( ).__call__.__func__
def test_distance_plot(): x = [0, 50, 100, 100] y = [100, 100, 100, 0] h = [0, 10, 20, 30] wdirs = [0, 30, 90] distance = StraightDistance() distance.plot(None, src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=[0], dst_y_j=[0], dst_h_j=[0], wd_il=np.array(wdirs)[na]) if 0: import matplotlib.pyplot as plt plt.show()
def test_YZGrid_terrain_perpendicular(): site = ParqueFicticioSite(distance=StraightDistance()) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wind_farm_model = IEA37SimpleBastankhahGaussian(site, windTurbines) simulation_result = wind_farm_model(x, y, wd=270, ws=10) x = x.max() + 10 fm = simulation_result.flow_map( grid=YZGrid(x, z=110, resolution=20, extend=0)) y = fm.X[0] x = np.zeros_like(y) + x z = site.elevation(x, y) simulation_result.flow_map(XYGrid(extend=.005)).plot_wake_map() plt.plot(x, y, '.') plt.figure() simulation_result.flow_map(grid=YZGrid( fm.x.item(), y=fm.y, z=np.arange(30, 210, 10))).plot_wake_map() plt.plot(y, z + 110, '.') plt.plot(y, fm.WS_eff_xylk[:, 0, 0, 0] * 100, label="ws*100") plt.legend() if 0: print(np.round(fm.WS_eff_xylk[:, 0, 0, 0], 2).values.tolist()) plt.show() plt.close('all') npt.assert_array_almost_equal(fm.WS_eff_xylk[:, 0, 0, 0], [ 5.39, 8.48, 8.42, 6.42, 5.55, 11.02, 4.99, 11.47, 5.32, 10.22, 13.39, 8.79, 8.51, 12.4, 5.47, 10.78, 10.12, 6.54, 10.91, 7.18 ], 2)
def test_YZGrid_terrain_parallel(): site = ParqueFicticioSite(distance=StraightDistance()) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wind_farm_model = IEA37SimpleBastankhahGaussian(site, windTurbines) simulation_result = wind_farm_model(x, y, wd=0, ws=10) x = 264000 fm = simulation_result.flow_map( grid=YZGrid(x, z=110, resolution=20, extend=0)) y = fm.X[0] x = np.zeros_like(y) + x z = site.elevation(x, y) simulation_result.flow_map(XYGrid(extend=0.005)).plot_wake_map() plt.plot(x, y, '.') plt.figure() simulation_result.flow_map(grid=YZGrid( fm.x.item(), fm.y, z=np.arange(30, 210, 10))).plot_wake_map() plt.plot(y, z + 110, '.') plt.plot(y, fm.WS_eff_xylk[:, 0, 0, 0] * 100, label="ws*100") plt.legend() if 0: print(np.round(fm.WS_eff_xylk[:, 0, 0, 0], 2).values.tolist()) plt.show() plt.close('all') npt.assert_array_almost_equal(fm.WS_eff_xylk[:, 0, 0, 0], [ 4.55, 3.89, 3.15, 2.31, 4.41, 4.3, 7.41, 7.2, 7.03, 7.23, 7.32, 6.77, 6.83, 5.58, 11.01, 11.51, 11.93, 12.17, 11.03, 9.89 ], 2)
def load(filename, interp_method='nearest', shear=None, distance=StraightDistance()): ds = xr.load_dataset(filename) return XRSite(ds, interp_method=interp_method, shear=shear, distance=distance)
def from_flow_box(flowBox, interp_method='linear', distance=StraightDistance()): ds = flowBox.drop_vars(['WS', 'TI']).rename_vars(WS_eff='WS', TI_eff='TI').squeeze() ds = ds.transpose( *[n for n in ['x', 'y', 'h', 'wd', 'ws'] if n in ds.dims]) site = XRSite(ds, interp_method=interp_method, distance=distance) # Correct P from propability pr. deg to sector probability as expected by XRSite site.ds['P'] = site.ds.P * site.ds.sector_width return site
def __init__(self, ds, initial_position=None, interp_method='linear', shear=None, distance=StraightDistance(), default_ws=np.arange(3, 26), bounds='check'): assert interp_method in [ 'linear', 'nearest' ], 'interp_method "%s" not implemented. Must be "linear" or "nearest"' % interp_method assert bounds in ['check', 'limit', 'ignore' ], 'bounds must be "check", "limit" or "ignore"' self.interp_method = interp_method self.shear = shear self.bounds = bounds Site.__init__(self, distance) self.default_ws = default_ws if 'ws' not in ds.dims: ds.update({'ws': self.default_ws}) else: self.default_ws = ds.ws if 'wd' in ds and len(np.atleast_1d(ds.wd)) > 1: wd = ds.coords['wd'] sector_widths = np.diff(wd) assert np.allclose(sector_widths, sector_widths[0]), \ "all sectors must have same width" sector_width = sector_widths[0] else: sector_width = 360 if 'P' not in ds: assert 'Weibull_A' in ds and 'Weibull_k' in ds and 'Sector_frequency' in ds ds.attrs['sector_width'] = sector_width if initial_position is not None: ds.attrs['initial_position'] = initial_position # add 360 deg to all wd dependent datavalues if 'wd' in ds and ds.wd[-1] != 360 and 360 - ds.wd[-1] == sector_width: ds = xr.concat([ds, ds.sel(wd=0)], 'wd', data_vars='minimal') ds.update({'wd': np.r_[ds.wd[:-1], 360]}) if 'Elevation' in ds: self.elevation_interpolator = EqDistRegGrid2DInterpolator( ds.x.values, ds.y.values, ds.Elevation.values) self.ds = ds
def __init__(self, p_wd, ti, ws=12, interp_method='nearest', shear=None): super().__init__(StraightDistance()) self.default_ws = ws self.ti = get_sector_xr(ti, 'Turbulence intensity') self.p_wd = get_sector_xr(p_wd / np.mean(p_wd) / 360, "Probability of wind direction +/- 0.5deg") self.interp_method = interp_method.replace('piecewise', 'nearest').replace( 'spline', 'cubic') if self.interp_method not in [ 'linear', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', 'next' ]: raise NotImplementedError('interp_method=%s not implemented' % interp_method) self.shear = shear
def test_distance_plot(): x = [0, 50, 100, 100, 0] y = [100, 100, 100, 0, 0] h = [0, 10, 20, 30, 0] wdirs = [0, 30, 90] distance = StraightDistance() distance.setup(src_x_i=x, src_y_i=y, src_h_i=h) distance.plot(wd_il=np.array(wdirs)[na], src_idx=[0], dst_idx=[3]) if 0: plt.show() plt.close('all')
def __init__(self, ds, initial_position=None, interp_method='linear', shear=None, distance=StraightDistance()): self.interp_method = interp_method self.shear = shear self.distance = distance Site.__init__(self, distance) if 'ws' not in ds.dims: ds.update({'ws': self.default_ws}) if 'wd' in ds and len(np.atleast_1d(ds.wd)) > 1: wd = ds.coords['wd'] sector_widths = np.diff(wd) assert np.all(sector_widths == sector_widths[0]), \ "all sectors must have same width" sector_width = sector_widths[0] else: sector_width = 360 if 'P' not in ds: assert 'Weibull_A' in ds and 'Weibull_k' in ds and 'Sector_frequency' in ds ds.attrs['sector_width'] = sector_width if initial_position is not None: ds.attrs['initial_position'] = initial_position # add 360 deg to all wd dependent datavalues if 'wd' in ds and len( np.atleast_1d(ds.wd) ) > 1 and ds.wd[-1] != 360 and 360 - ds.wd[-1] == sector_width: ds = xr.concat([ds, ds.sel(wd=0)], 'wd', data_vars='minimal') ds.update({'wd': np.r_[ds.wd[:-1], 360]}) self.ds = ds
def test_YZGrid_terrain(): site = ParqueFicticioSite(distance=StraightDistance()) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wind_farm_model = IEA37SimpleBastankhahGaussian(site, windTurbines) simulation_result = wind_farm_model(x, y, wd=270, ws=10) x = x.max() + 10 fm = simulation_result.flow_map(grid=YZGrid(x, z=110, resolution=20)) y = fm.X[0] x = np.zeros_like(y) + x z = site.elevation(x, y) simulation_result.flow_map().plot_wake_map() plt.plot(x, y, '.') plt.figure() simulation_result.flow_map(grid=YZGrid(x.max() + 10)).plot_wake_map() plt.plot(y, z + 110, '.') if 0: print(np.round(fm.WS_eff_xylk[0, :, 0, 0], 2).tolist()) plt.show() plt.close() npt.assert_array_almost_equal(fm.WS_eff_xylk[:, 0, 0, 0], [10.0, 10.0, 11.69, 5.8, 8.7, 5.15, 10.63, 4.99, 10.73, 8.16, 13.24, 5.59, 12.4, 7.02, 10.91, 7.21, 8.77, 8.41, 9.99, 10.0], 2)
300) npt.assert_almost_equal(AEP_ilk.sum(), wasp_aep_no_density_correction_total, 3) @pytest.mark.parametrize( 'site,dw_ref', [(ParqueFicticioSite(distance=TerrainFollowingDistance2()), [ 0., 207.3842238, 484.3998264, 726.7130743, 1039.148129, 1263.1335982, 1490.3841602, 1840.6508086 ]), (ParqueFicticioSite(distance=TerrainFollowingDistance()), [ 0, 209.803579, 480.8335365, 715.6003233, 1026.9476322, 1249.5510034, 1475.1467251, 1824.1317343 ]), (ParqueFicticioSite(distance=StraightDistance()), [-0, 207, 477, 710, 1016, 1236, 1456, 1799])]) def test_distances(site, dw_ref): x, y = site.initial_position.T dw_ijl, cw_ijl, dh_ijl, _ = site.distances(src_x_i=x, src_y_i=y, src_h_i=np.array([70]), dst_x_j=x, dst_y_j=y, dst_h_j=np.array([70]), wd_il=np.array([[0]])) npt.assert_almost_equal(dw_ijl[0, :, 0], dw_ref) cw_ref = [236.1, 0., -131.1, -167.8, -204.5, -131.1, -131.1, -45.4] npt.assert_almost_equal(cw_ijl[:, 1, 0], cw_ref) npt.assert_almost_equal(dh_ijl, np.zeros_like(dh_ijl))
def __init__(self, p_wd, ti, ws=12, interp_method='piecewise', shear=NoShear()): super().__init__(StraightDistance()) self.default_ws = ws self.ti = Sector2Subsector(np.atleast_1d(ti), interp_method=interp_method) self.p_wd = Sector2Subsector(p_wd / np.sum(p_wd), interp_method=interp_method) / (360 / len(p_wd)) self.shear = shear
def elevation(self, x_i, y_i): return np.sqrt(np.maximum(self.height**2 - x_i**2, 0)) class Rectangle(TerrainFollowingDistance, UniformSite): def __init__(self, height, width, distance_resolution): self.height = height self.width = width super().__init__(p_wd=[1], ti=0) self.distance = TerrainFollowingDistance(distance_resolution=distance_resolution) def elevation(self, x_i, y_i): return np.where(np.abs(x_i) < self.width / 2, self.height, 0) @pytest.mark.parametrize('distance', [StraightDistance(), TerrainFollowingDistance() ]) def test_flat_distances(distance): x = [0, 50, 100, 100, 0] y = [100, 100, 100, 0, 0] h = [0, 10, 20, 30, 0] wdirs = [0, 30, 90] site = FlatSite(distance=distance) site.distance.setup(src_x_i=x, src_y_i=y, src_h_i=h) dw_ijl, hcw_ijl, dh_ijl = site.distance(wd_il=np.array(wdirs)[na], src_idx=[0, 1, 2, 3], dst_idx=[4]) dw_indices_l = site.distance.dw_order_indices(np.array(wdirs)) if 0: distance.plot(wd_il=np.array(wdirs)[na], src_i=[0, 1, 2, 3], dst_i=[4])
class Rectangle(TerrainFollowingDistance, UniformSite): def __init__(self, height, width, distance_resolution): self.height = height self.width = width super().__init__(p_wd=[1], ti=0) self.distance = TerrainFollowingDistance( distance_resolution=distance_resolution) def elevation(self, x_i, y_i): return np.where(np.abs(x_i) < self.width / 2, self.height, 0) @pytest.mark.parametrize( 'distance', [StraightDistance(), TerrainFollowingDistance()]) def test_flat_distances(distance): x = [0, 50, 100, 100] y = [100, 100, 100, 0] h = [0, 10, 20, 30] wdirs = [0, 30, 90] dw_ijl, hcw_ijl, dh_ijl, dw_indices_l = distance(FlatSite(), src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=[0], dst_y_j=[0], dst_h_j=[0], wd_il=np.array(wdirs)[na])
ti=0) # TerrainFollowingDistance.__init__(self, ) def elevation(self, x_i, y_i): return np.where(np.abs(x_i) < self.width / 2, self.height, 0) def ParqueFicticioSiteTerrainFollowingDistance2(): site = ParqueFicticioSite(distance=TerrainFollowingDistance2()) x, y = site.initial_position.T return site, x, y @pytest.mark.parametrize( 'Distance', [StraightDistance(), FlatTerrainFollowingDistance()]) def test_flat_distances(Distance): x = [0, 50, 100, 100] y = [100, 100, 100, 0] h = [0, 10, 20, 30] wdirs = [0, 30, 90] distances = Distance.distances dw_ijl, hcw_ijl, dh_ijl, dw_indices_l = distances( src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=[0], dst_y_j=[0], dst_h_j=[0], wd_il=np.array(wdirs)[na])