def test_scenario_gen_regression(self):
        """Scenario Gen Proximity: regression testing all functionality."""
        from natcap.invest import scenario_gen_proximity

        args = ScenarioProximityTests.generate_base_args(self.workspace_dir)
        args['convert_farthest_from_edge'] = True
        args['convert_nearest_to_edge'] = True

        scenario_gen_proximity.execute(args)
        ScenarioProximityTests._test_same_files(
            os.path.join(
                TEST_DATA_DIR, 'expected_file_list_regression.txt'),
            args['workspace_dir'])

        base_table = pandas.read_csv(
            os.path.join(self.workspace_dir, 'farthest_from_edge.csv'))
        expected_table = pandas.read_csv(
            os.path.join(
                TEST_DATA_DIR, 'farthest_from_edge_regression.csv'))
        pandas.testing.assert_frame_equal(base_table, expected_table)

        base_table = pandas.read_csv(
            os.path.join(self.workspace_dir, 'nearest_to_edge.csv'))
        expected_table = pandas.read_csv(
            os.path.join(
                TEST_DATA_DIR, 'nearest_to_edge_regression.csv'))
        pandas.testing.assert_frame_equal(base_table, expected_table)
Exemple #2
0
    def test_scenario_gen_small_far(self):
        """Scenario Gen Proximity: testing small far functionality."""
        from natcap.invest import scenario_gen_proximity

        args = {
            'aoi_path': os.path.join(SAMPLE_DATA,
                                     'scenario_proximity_aoi.shp'),
            'area_to_convert': '20000.0',
            'base_lulc_path': os.path.join(REGRESSION_DATA,
                                           'clipped_lulc.tif'),
            'convert_farthest_from_edge': True,
            'convert_nearest_to_edge': False,
            'convertible_landcover_codes': '1 2 3 4 5',
            'focal_landcover_codes': '1 2 3 4 5',
            'n_fragmentation_steps': '1',
            'replacment_lucode': '12',
            'workspace_dir': self.workspace_dir,
        }

        scenario_gen_proximity.execute(args)
        ScenarioProximityTests._test_same_files(
            os.path.join(REGRESSION_DATA,
                         'expected_file_list_small_farthest.txt'),
            args['workspace_dir'])

        natcap.invest.pygeoprocessing_0_3_3.testing.assertions.assert_csv_equal(
            os.path.join(self.workspace_dir, 'farthest_from_edge.csv'),
            os.path.join(REGRESSION_DATA,
                         'small_farthest_from_edge_regression.csv'),
            rel_tol=1e-6)
Exemple #3
0
    def test_scenario_gen_no_scenario(self):
        """Scenario Gen Proximity: no scenario should raise an exception."""
        from natcap.invest import scenario_gen_proximity

        args = {
            'aoi_path':
            os.path.join(SAMPLE_DATA, 'scenario_proximity_aoi.shp'),
            'area_to_convert':
            '20000.0',
            'base_lulc_path':
            os.path.join(SAMPLE_DATA, 'scenario_proximity_lulc.tif'),
            'convert_farthest_from_edge':
            False,
            'convert_nearest_to_edge':
            False,
            'convertible_landcover_codes':
            '1 2 3 4 5',
            'focal_landcover_codes':
            '1 2 3 4 5',
            'n_fragmentation_steps':
            '1',
            'replacment_lucode':
            '12',
            'workspace_dir':
            self.workspace_dir,
        }

        # both scenarios false should raise a value error
        with self.assertRaises(ValueError):
            scenario_gen_proximity.execute(args)
    def test_scenario_gen_no_scenario(self):
        """Scenario Gen Proximity: no scenario should raise an exception."""
        from natcap.invest import scenario_gen_proximity

        args = ScenarioProximityTests.generate_base_args(self.workspace_dir)
        args['convert_farthest_from_edge'] = False
        args['convert_nearest_to_edge'] = False

        # both scenarios false should raise a value error
        with self.assertRaises(ValueError):
            scenario_gen_proximity.execute(args)
    def test_scenario_gen_farthest(self):
        """Scenario Gen Proximity: testing small far functionality."""
        from natcap.invest import scenario_gen_proximity

        args = ScenarioProximityTests.generate_base_args(self.workspace_dir)
        args['convert_farthest_from_edge'] = True
        args['convert_nearest_to_edge'] = False
        # running without an AOI
        del args['aoi_path']
        scenario_gen_proximity.execute(args)
        ScenarioProximityTests._test_same_files(
            os.path.join(TEST_DATA_DIR, 'expected_file_list_farthest.txt'),
            args['workspace_dir'])

        pygeoprocessing.testing.assertions.assert_csv_equal(
            os.path.join(self.workspace_dir, 'farthest_from_edge.csv'),
            os.path.join(TEST_DATA_DIR, 'farthest_from_edge_farthest.csv'),
            rel_tol=1e-6)