def test_no_aoi(self): """WindEnergy: testing base case w/o AOI, distances, or valuation.""" from natcap.invest import wind_energy args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) # Also test on input bathymetry that has equal x, y pixel sizes args['bathymetry_path'] = os.path.join( SAMPLE_DATA, 'resampled_global_dem_equal_pixel.tif') wind_energy.execute(args) raster_results = [ 'density_W_per_m2.tif', 'harvested_energy_MWhr_per_yr.tif' ] for raster_path in raster_results: pygeoprocessing.testing.assert_rasters_equal( os.path.join(args['workspace_dir'], 'output', raster_path), os.path.join(REGRESSION_DATA, 'noaoi', raster_path), 1E-6) vector_path = 'wind_energy_points.shp' WindEnergyRegressionTests._assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'noaoi', vector_path))
def test_no_distances(self): """WindEnergy: testing case w/ AOI and land poly, but w/o distances.""" from natcap.invest import wind_energy args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') args['land_polygon_vector_path'] = os.path.join( SAMPLE_DATA, 'simple_north_america_polygon.shp') wind_energy.execute(args) raster_results = [ 'density_W_per_m2.tif', 'harvested_energy_MWhr_per_yr.tif' ] for raster_path in raster_results: pygeoprocessing.testing.assert_rasters_equal( os.path.join(args['workspace_dir'], 'output', raster_path), os.path.join(REGRESSION_DATA, 'nodistances', raster_path)) vector_path = 'wind_energy_points.shp' WindEnergyRegressionTests._assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'nodistances', vector_path))
def test_clip_vector_value_error(self): """WindEnergy: Test AOI doesn't intersect Wind Data points.""" from natcap.invest import wind_energy from natcap.invest.utils import _assert_vectors_equal args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') # Make up some Wind Data points that live outside AOI wind_data_csv = os.path.join(args['workspace_dir'], 'temp-wind-data.csv') with open(wind_data_csv, 'w') as open_table: open_table.write('LONG,LATI,LAM,K,REF\n') open_table.write('-60.5,25.0,7.59,2.6,10\n') open_table.write('-59.5,24.0,7.59,2.6,10\n') open_table.write('-58.5,24.5,7.59,2.6,10\n') open_table.write('-58.95,24.95,7.59,2.6,10\n') open_table.write('-57.95,24.95,7.59,2.6,10\n') open_table.write('-57.95,25.95,7.59,2.6,10\n') args['wind_data_path'] = wind_data_csv # AOI and wind data should not overlap, leading to a ValueError in # clip_vector_by_vector with self.assertRaises(ValueError) as cm: wind_energy.execute(args) self.assertTrue( "returned 0 features. If an AOI was" in str(cm.exception))
def test_no_land_polygon(self): """WindEnergy: testing case w/ AOI but w/o land poly or distances.""" from natcap.invest import wind_energy from natcap.invest.utils import _assert_vectors_equal args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') wind_energy.execute(args) raster_results = [ 'density_W_per_m2.tif', 'harvested_energy_MWhr_per_yr.tif' ] for raster_path in raster_results: model_array = pygeoprocessing.raster_to_numpy_array( os.path.join(args['workspace_dir'], 'output', raster_path)) reg_array = pygeoprocessing.raster_to_numpy_array( os.path.join(REGRESSION_DATA, 'nolandpoly', raster_path)) numpy.testing.assert_allclose(model_array, reg_array) vector_path = 'wind_energy_points.shp' _assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'nolandpoly', vector_path))
def test_val_gridpts_windprice(self): """WindEnergy: testing Valuation w/ grid pts and wind price.""" from natcap.invest import wind_energy from natcap.invest.utils import _assert_vectors_equal args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') args['land_polygon_vector_path'] = os.path.join( SAMPLE_DATA, 'simple_north_america_polygon.shp') args['min_distance'] = 0 args['max_distance'] = 200000 args['valuation_container'] = True args['foundation_cost'] = 2 args['discount_rate'] = 0.07 # Test that only grid points are provided in grid_points_path args['grid_points_path'] = os.path.join(SAMPLE_DATA, 'resampled_grid_pts.csv') args['price_table'] = False args['wind_price'] = 0.187 args['rate_change'] = 0.2 wind_energy.execute(args) # Make sure the output files were created. vector_path = 'wind_energy_points.shp' self.assertTrue( os.path.exists( os.path.join(args['workspace_dir'], 'output', vector_path))) # Run through the model again, which should mean deleting shapefiles # that have already been made, but which need to be created again. wind_energy.execute(args) raster_results = [ 'carbon_emissions_tons.tif', 'levelized_cost_price_per_kWh.tif', 'npv_US_millions.tif' ] for raster_path in raster_results: model_array = pygeoprocessing.raster_to_numpy_array( os.path.join(args['workspace_dir'], 'output', raster_path)) reg_array = pygeoprocessing.raster_to_numpy_array( os.path.join(REGRESSION_DATA, 'pricevalgrid', raster_path)) numpy.testing.assert_allclose(model_array, reg_array) vector_path = 'wind_energy_points.shp' _assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'pricevalgrid', vector_path))
def test_val_land_grid_points(self): """WindEnergy: testing Valuation w/ grid/land pts and wind price.""" from natcap.invest import wind_energy from natcap.invest.utils import _assert_vectors_equal args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') args['land_polygon_vector_path'] = os.path.join( SAMPLE_DATA, 'simple_north_america_polygon.shp') args['min_distance'] = 0 args['max_distance'] = 200000 args['valuation_container'] = True args['foundation_cost'] = 2 args['discount_rate'] = 0.07 # there was no sample data that provided landing points, thus for # testing, grid points in 'resampled_grid_pts.csv' were duplicated and # marked as land points. So the distances will be zero, keeping the # result the same but testing that section of code args['grid_points_path'] = os.path.join(SAMPLE_DATA, 'resampled_grid_land_pts.csv') args['price_table'] = False args['wind_price'] = 0.187 args['rate_change'] = 0.2 wind_energy.execute(args) raster_results = [ 'carbon_emissions_tons.tif', 'levelized_cost_price_per_kWh.tif', 'npv_US_millions.tif' ] for raster_path in raster_results: model_array = pygeoprocessing.raster_to_numpy_array( os.path.join(args['workspace_dir'], 'output', raster_path)) reg_array = pygeoprocessing.raster_to_numpy_array( os.path.join(REGRESSION_DATA, 'pricevalgridland', raster_path)) # loosened tolerance to pass against GDAL 2.2.4 and 2.4.1 numpy.testing.assert_allclose(model_array, reg_array, rtol=1e-04) vector_path = 'wind_energy_points.shp' _assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'pricevalgridland', vector_path))
def test_valuation_taskgraph(self): """WindEnergy: testing Valuation with async TaskGraph.""" from natcap.invest import wind_energy from natcap.invest.utils import _assert_vectors_equal args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) # Also use an already projected bathymetry args['bathymetry_path'] = os.path.join( SAMPLE_DATA, 'resampled_global_dem_projected.tif') args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') args['land_polygon_vector_path'] = os.path.join( SAMPLE_DATA, 'simple_north_america_polygon.shp') args['min_distance'] = 0 args['max_distance'] = 200000 args['valuation_container'] = True args['foundation_cost'] = 2000000 args['discount_rate'] = 0.07 args['price_table'] = True args['wind_schedule'] = os.path.join(SAMPLE_DATA, 'price_table_example.csv') args['wind_price'] = 0.187 args['rate_change'] = 0.2 args['avg_grid_distance'] = 4 args['n_workers'] = 1 wind_energy.execute(args) raster_results = [ 'carbon_emissions_tons.tif', 'levelized_cost_price_per_kWh.tif', 'npv.tif' ] for raster_path in raster_results: model_array = pygeoprocessing.raster_to_numpy_array( os.path.join(args['workspace_dir'], 'output', raster_path)) reg_array = pygeoprocessing.raster_to_numpy_array( os.path.join(REGRESSION_DATA, 'priceval', raster_path)) numpy.testing.assert_allclose(model_array, reg_array, rtol=1e-6) vector_path = 'wind_energy_points.shp' _assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'priceval', vector_path))
def test_val_no_grid_land_pts(self): """WindEnergy: testing Valuation without grid or land points.""" from natcap.invest import wind_energy args = WindEnergyRegressionTests.generate_base_args(self.workspace_dir) # Also use an already projected bathymetry args['bathymetry_path'] = os.path.join( SAMPLE_DATA, 'resampled_global_dem_projected.tif') args['aoi_vector_path'] = os.path.join(SAMPLE_DATA, 'New_England_US_Aoi.shp') args['land_polygon_vector_path'] = os.path.join( SAMPLE_DATA, 'simple_north_america_polygon.shp') args['min_distance'] = 0 args['max_distance'] = 200000 args['valuation_container'] = True args['foundation_cost'] = 2 args['discount_rate'] = 0.07 args['price_table'] = True args['wind_schedule'] = os.path.join(SAMPLE_DATA, 'price_table_example.csv') args['wind_price'] = 0.187 args['rate_change'] = 0.2 args['avg_grid_distance'] = 4 wind_energy.execute(args) raster_results = [ 'carbon_emissions_tons.tif', 'levelized_cost_price_per_kWh.tif', 'npv_US_millions.tif' ] for raster_path in raster_results: pygeoprocessing.testing.assert_rasters_equal( os.path.join(args['workspace_dir'], 'output', raster_path), os.path.join(REGRESSION_DATA, 'priceval', raster_path), 1E-6) vector_path = 'wind_energy_points.shp' WindEnergyRegressionTests._assert_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'priceval', vector_path))