def test_no_aoi_or_val(self): """WaveEnergy: testing Biophysical component w/o AOI or valuation.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) wave_energy.execute(args) raster_results = [ 'wp_rc.tif', 'wp_kw.tif', 'capwe_rc.tif', 'capwe_mwh.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, 'noaoi', raster_path)) numpy.testing.assert_allclose(model_array, reg_array) table_results = ['capwe_rc.csv', 'wp_rc.csv'] for table_path in table_results: model_df = pandas.read_csv( os.path.join(args['workspace_dir'], 'output', table_path)) reg_df = pandas.read_csv( os.path.join(REGRESSION_DATA, 'noaoi', table_path)) pandas.testing.assert_frame_equal(model_df, reg_df)
def test_incorrect_analysis_area_path_value(self): """WaveEnergy: testing incorrect analysis_area_path value.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) args['analysis_area_path'] = 'Incorrect Analysis Area' with self.assertRaises(ValueError) as cm: wave_energy.execute(args) expected_message = ( "'analysis_area_path'], 'Parameter must be a known analysis area.") actual_message = str(cm.exception) self.assertTrue(expected_message in actual_message, actual_message)
def test_missing_required_keys(self): """WaveEnergy: testing missing required keys from args.""" from natcap.invest import wave_energy args = {} with self.assertRaises(KeyError) as cm: wave_energy.execute(args) expected_message = ( "Keys are missing from args: ['workspace_dir', " + "'wave_base_data_path', 'analysis_area_path', " + "'machine_perf_path', 'machine_param_path', 'dem_path']") actual_message = str(cm.exception) self.assertTrue(expected_message in actual_message, actual_message)
def test_valuation(self): """WaveEnergy: testing valuation component.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_path'] = os.path.join(SAMPLE_DATA, 'AOI_WCVI.shp') args['valuation_container'] = True args['land_gridPts_path'] = os.path.join(SAMPLE_DATA, 'LandGridPts_WCVI.csv') args['machine_econ_path'] = os.path.join( SAMPLE_DATA, 'Machine_Pelamis_Economic.csv') args['number_of_machines'] = 28 # Testing if intermediate/output were overwritten _make_empty_files(args['workspace_dir']) wave_energy.execute(args) raster_results = [ 'wp_rc.tif', 'wp_kw.tif', 'capwe_rc.tif', 'capwe_mwh.tif', 'npv_rc.tif', 'npv_usd.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, 'valuation', raster_path)) numpy.testing.assert_allclose(model_array, reg_array) vector_results = ['GridPts_prj.shp', 'LandPts_prj.shp'] for vector_path in vector_results: WaveEnergyRegressionTests._assert_point_vectors_equal( os.path.join(args['workspace_dir'], 'output', vector_path), os.path.join(REGRESSION_DATA, 'valuation', vector_path)) table_results = ['capwe_rc.csv', 'wp_rc.csv', 'npv_rc.csv'] for table_path in table_results: model_df = pandas.read_csv( os.path.join(args['workspace_dir'], 'output', table_path)) reg_df = pandas.read_csv( os.path.join(REGRESSION_DATA, 'valuation', table_path)) pandas.testing.assert_frame_equal(model_df, reg_df)
def test_valuation_suffix(self): """WaveEnergy: testing suffix through Valuation.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_path'] = os.path.join(SAMPLE_DATA, 'AOI_WCVI.shp') args['valuation_container'] = True args['land_gridPts_path'] = os.path.join(SAMPLE_DATA, 'LandGridPts_WCVI.csv') args['machine_econ_path'] = os.path.join( SAMPLE_DATA, 'Machine_Pelamis_Economic.csv') args['number_of_machines'] = 28 args['suffix'] = 'val' wave_energy.execute(args) raster_results = [ 'wp_rc_val.tif', 'wp_kw_val.tif', 'capwe_rc_val.tif', 'capwe_mwh_val.tif', 'npv_rc_val.tif', 'npv_usd_val.tif' ] for raster_path in raster_results: self.assertTrue( os.path.exists( os.path.join(args['workspace_dir'], 'output', raster_path))) vector_results = ['GridPts_prj_val.shp', 'LandPts_prj_val.shp'] for vector_path in vector_results: self.assertTrue( os.path.exists( os.path.join(args['workspace_dir'], 'output', vector_path))) table_results = ['capwe_rc_val.csv', 'wp_rc_val.csv', 'npv_rc_val.csv'] for table_path in table_results: self.assertTrue( os.path.exists( os.path.join(args['workspace_dir'], 'output', table_path)))
def test_no_aoi_or_val(self): """WaveEnergy: testing Biophysical component w/o AOI or valuation.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) wave_energy.execute(args) raster_results = [ 'wp_rc.tif', 'wp_kw.tif', 'capwe_rc.tif', 'capwe_mwh.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) table_results = ['capwe_rc.csv', 'wp_rc.csv'] for table_path in table_results: pygeoprocessing.testing.assert_csv_equal( os.path.join(args['workspace_dir'], 'output', table_path), os.path.join(REGRESSION_DATA, 'noaoi', table_path), 1e-6)