Exemplo n.º 1
0
    def test_data_missing_in_predictors(self):
        """Recreation raise exception if predictor data missing."""
        from natcap.invest.recreation import recmodel_client

        response_vector_path = os.path.join(SAMPLE_DATA, 'andros_aoi.shp')
        table_path = os.path.join(SAMPLE_DATA, 'predictors_data_missing.csv')

        with self.assertRaises(ValueError):
            recmodel_client._validate_same_projection(response_vector_path,
                                                      table_path)
Exemplo n.º 2
0
    def test_data_different_projection(self):
        """Recreation raise exception if data in different projection."""
        from natcap.invest.recreation import recmodel_client

        response_vector_path = os.path.join(SAMPLE_DATA, 'andros_aoi.shp')
        table_path = os.path.join(
            REGRESSION_DATA, 'predictors_wrong_projection.csv')

        with self.assertRaises(ValueError):
            recmodel_client._validate_same_projection(
                response_vector_path, table_path)
Exemplo n.º 3
0
    def test_predictor_table_absolute_paths(self):
        """Recreation test validation from full path."""
        from natcap.invest.recreation import recmodel_client

        response_vector_path = os.path.join(self.workspace_dir,
                                            'no_grid_vector_path.shp')
        recmodel_client._copy_aoi_no_grid(
            os.path.join(SAMPLE_DATA, 'andros_aoi.shp'), response_vector_path)

        predictor_table_path = os.path.join(self.workspace_dir,
                                            'predictors.csv')

        # these are absolute paths for predictor data
        predictor_list = [
            ('ports',
             os.path.join(SAMPLE_DATA, 'predictors',
                          'dredged_ports.shp'), 'point_count'),
            ('airdist', os.path.join(SAMPLE_DATA, 'predictors',
                                     'airport.shp'), 'point_nearest_distance'),
            ('bonefish',
             os.path.join(SAMPLE_DATA, 'predictors',
                          'bonefish_simp.shp'), 'polygon_percent_coverage'),
            ('bathy',
             os.path.join(SAMPLE_DATA, 'predictors',
                          'dem90m_coarse.tif'), 'raster_mean'),
        ]

        with open(predictor_table_path, 'wb') as table_file:
            table_file.write('id,path,type\n')
            for predictor_id, path, predictor_type in predictor_list:
                table_file.write('%s,%s,%s\n' %
                                 (predictor_id, path, predictor_type))

        # The expected behavior here is that _validate_same_projection does
        # not raise a ValueError.  The try/except block makes that explicit
        # and also explicitly fails the test if it does. Note if a different
        # exception is raised the test will raise an error, thus differentiating
        # between a failed test and an error.
        try:
            recmodel_client._validate_same_projection(response_vector_path,
                                                      predictor_table_path)
        except ValueError:
            self.fail(
                "_validate_same_projection raised ValueError unexpectedly!")