예제 #1
0
    def test_base_usle_p_nan(self):
        """SDR test expected exception for USLE_P not a number."""
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)
        args['biophysical_table_path'] = os.path.join(
            REGRESSION_DATA, 'biophysical_table_invalid_value.csv')

        with self.assertRaises(ValueError):
            sdr.execute(args)
예제 #2
0
    def test_base_regression(self):
        """SDR base regression test on sample data.

        Execute SDR with sample data and checks that the output files are
        generated and that the aggregate shapefile fields are the same as the
        regression case.
        """
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)
        # make args explicit that this is a base run of SWY
        sdr.execute(args)

        SDRTests._assert_regression_results_equal(
            args['workspace_dir'],
            os.path.join(REGRESSION_DATA, 'file_list_base.txt'),
            os.path.join(args['workspace_dir'], 'watershed_results_sdr.shp'),
            os.path.join(REGRESSION_DATA, 'agg_results_base.csv'))
예제 #3
0
    def test_non_square_dem(self):
        """SDR non-square DEM pixels.

        Execute SDR with a non-square DEM and get a good result back.
        """
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)
        args['dem_path'] = os.path.join(SAMPLE_DATA, 'dem_non_square.tif')
        # make args explicit that this is a base run of SWY
        sdr.execute(args)

        expected_results = {
            'sed_retent': 339973.96875,
            'sed_export': 0.6207485795,
            'usle_tot': 11.46732711792,
        }
        vector_path = os.path.join(args['workspace_dir'],
                                   'watershed_results_sdr.shp')
        assert_expected_results_in_vector(expected_results, vector_path)
예제 #4
0
    def test_base_regression(self):
        """SDR base regression test on sample data.

        Execute SDR with sample data and checks that the output files are
        generated and that the aggregate shapefile fields are the same as the
        regression case.
        """
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)
        # make args explicit that this is a base run of SWY
        sdr.execute(args)

        expected_results = {
            'sed_retent': 392771.84375,
            'sed_export': 0.77038854361,
            'usle_tot': 12.69931602478,
        }
        vector_path = os.path.join(args['workspace_dir'],
                                   'watershed_results_sdr.shp')
        assert_expected_results_in_vector(expected_results, vector_path)
예제 #5
0
    def test_drainage_regression(self):
        """SDR drainage layer regression test on sample data.

        Execute SDR with sample data and a drainage layer and checks that the
        output files are generated and that the aggregate shapefile fields
        are the same as the regression case.
        """
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)
        args['drainage_path'] = os.path.join(REGRESSION_DATA,
                                             'sample_drainage.tif')
        sdr.execute(args)

        expected_results = {
            'sed_retent': 425966.0,
            'sed_export': 0.91835135221,
            'usle_tot': 11.59875869751,
        }
        vector_path = os.path.join(args['workspace_dir'],
                                   'watershed_results_sdr.shp')
        assert_expected_results_in_vector(expected_results, vector_path)
예제 #6
0
    def test_output_exists_regression(self):
        """SDR test case where an output shapefile already exists.

        Execute SDR with sample data but workspace already contains
        "watershed_results_sdr.shp".  Model should delete file and proceed
        with report.
        """
        from natcap.invest import sdr

        # use predefined directory so test can clean up files during teardown
        args = SDRTests.generate_base_args(self.workspace_dir)

        # copy AOI on top of where the output shapefile should reside
        shutil.copy(
            args['watersheds_path'],
            os.path.join(self.workspace_dir, 'watershed_results_sdr.shp'))

        sdr.execute(args)

        SDRTests._assert_regression_results_equal(
            args['workspace_dir'],
            os.path.join(REGRESSION_DATA, 'file_list_base.txt'),
            os.path.join(args['workspace_dir'], 'watershed_results_sdr.shp'),
            os.path.join(REGRESSION_DATA, 'agg_results_base.csv'))