geographer.testing package¶
Submodules¶
geographer.testing.graph_df_compatibility module¶
Test compatibility of rasters, vectors, and graph.
- geographer.testing.graph_df_compatibility.check_graph_vertices_counts(connector)[source]¶
Test connector invariant.
Tests whether the set of vertices of the graph corresponds with the rasters and polygons in the connector and whether the number of edges leaving the polygon nodes corresponding to imagges fully containing the polygon are equal to the values in the vectors ‘raster_count’ column.
- Parameters:
connector (Connector)
geographer.testing.mock_download module¶
Mock RasterDownloadProcessor for testing.
Virtually ‘download’ from a dataset of rasters in a source directory.
- class geographer.testing.mock_download.MockDownloadProcessor(**data)[source]¶
Bases:
RasterDownloadProcessorMock raster raster download processor.
Just return the raster_dict, since no actual raster data is downloaded.
- Parameters:
source_connector (Connector)
- Return type:
None
- field source_connector: Connector [Required]¶
- process(raster_name, download_dir, rasters_dir, return_bounds_in_crs_epsg_code, **kwargs)[source]¶
Process “downloaded” file, i.e. does nothing.
- Return type:
dict[Union[Literal['raster_name','geometry','orig_crs_epsg_code'],str],Any]- Returns:
return dict
- Parameters:
raster_name (str)
download_dir (Path)
rasters_dir (Path)
return_bounds_in_crs_epsg_code (int)
kwargs (Any)
- class geographer.testing.mock_download.MockDownloaderForSingleVector(**data)[source]¶
Bases:
RasterDownloaderForSingleVectorMock downloader for single vector feature.
Just return the information from a source dataset’s rasters from a source directory. No actual raster data is copied.
- Parameters:
source_connector (Connector)
probability_of_download_error (float)
probability_raster_already_downloaded (float)
- Return type:
None
- field probability_of_download_error: float = 0.1¶
- field probability_raster_already_downloaded: float = 0.1¶
- field source_connector: Connector [Required]¶
- download(vector_name, vector_geom, download_dir, previously_downloaded_rasters_set, **kwargs)[source]¶
Mock download an raster.
Mock download an raster fully containing a vector feature or several rasters jointly containing it from the source_connector and return a dict with information to be updated in the connector, see below for details.
- Return type:
dict[Union[Literal['raster_name','raster_processed?'],str],Any]- Parameters:
vector_name (int | str) – name of vector feature
vector_geom (Polygon) – shapely geometry of vector feature
download_dir (Path) – directory that the raster file should be ‘downloaded’ to.
previously_downloaded_rasters_set (set[str | int]) – previously downloaded raster_names. In some use cases when it can’t be guaranteed that an raster can be downloaded that fully contains the vector feature it can happen that attempts will be made to download an raster that is already in the connector. Passing this argument allows the download function to make sure it doesn’t try downloading an raster that is already in the dataset.
**kwargs – optional keyword arguments depending on the application.
- Returns:
‘list_raster_info_dicts’: a list of dicts containing the information to be included in each row in the rasters of the calling connector, one for each newly downloaded raster. The keys should be the index and column names of the rasters and the values the indices or entries of those columns in row that will correspond to the new raster.
- Return type:
A dict with keys and values