mapreader.spot_text.runner_base
Classes
Module Contents
- class mapreader.spot_text.runner_base.DetRunner
- check_georeferencing()
- run_all(return_dataframe=False, min_ioa=0.7)
Run the model on all images in the patch dataframe.
- Parameters:
return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- Returns:
A dictionary of predictions for each patch image or a DataFrame if return_dataframe is True.
- Return type:
dict or pd.DataFrame or gpd.GeoDataFrame
- run_on_images(img_paths, return_dataframe=False, min_ioa=0.7)
Run the model on a list of images.
- Parameters:
img_paths (str, pathlib.Path or list) – A list of image paths to run the model on.
return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- Returns:
A dictionary of predictions for each image or a DataFrame if return_dataframe is True.
- Return type:
dict or pd.DataFrame
- run_on_image(img_path, return_outputs=False, return_dataframe=False, min_ioa=0.7)
Run the model on a single image.
- Parameters:
img_path (str or pathlib.Path) – The path to the image to run the model on.
return_outputs (bool, optional) – Whether to return the outputs direct from the model, by default False
return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- Returns:
The predictions for the image or the outputs from the model if return_outputs is True.
- Return type:
dict or pd.DataFrame
- convert_to_parent_pixel_bounds(return_dataframe=False, deduplicate=False, min_ioa=0.7)
Convert the patch predictions to parent predictions by converting pixel bounds.
- Parameters:
return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False
deduplicate (bool, optional) – Whether to deduplicate the parent predictions, by default False. Depending on size of parent images, this can be slow.
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7 This is only used if deduplicate is True.
- Returns:
A dictionary of predictions for each parent image or a DataFrame if return_dataframe is True.
- Return type:
dict or pd.DataFrame
- convert_to_coords(return_dataframe=False)
Convert the parent predictions to georeferenced predictions by converting pixel bounds to coordinates.
- Parameters:
return_dataframe (bool, optional) – Whether to return the predictions as a geopandas GeoDataFrame, by default False
- Returns:
A dictionary of predictions for each parent image or a DataFrame if return_dataframe is True.
- Return type:
dict or gpd.GeoDataFrame
- save_to_geojson(path_save, centroid=False)
Save the georeferenced predictions to a GeoJSON file.
- Parameters:
path_save (str | pathlib.Path, optional) – Path to save the GeoJSON file
centroid (bool, optional) – Whether to convert the polygons to centroids, by default False. NOTE: The original polygon will still be saved as a separate column
- Return type:
None
- to_geojson(path_save, centroid=False)
Save the georeferenced predictions to a GeoJSON file.
- Parameters:
path_save (str | pathlib.Path, optional) – Path to save the GeoJSON file
centroid (bool, optional) – Whether to convert the polygons to centroids, by default False. NOTE: The original polygon will still be saved as a separate column
- Return type:
None
- to_csv(path_save, centroid=False)
Saves the patch, parent and georeferenced predictions to CSV files.
- Parameters:
path_save (str | pathlib.Path) – The path to save the CSV files. Files will be saved as patch_predictions.csv, parent_predictions.csv and geo_predictions.csv.
centroid (bool, optional) – Whether to convert polygons to centroids, by default False. NOTE: The original polygon will still be saved as a separate column.
- Return type:
None
Note
Use the save_to_geojson method to save georeferenced predictions to a GeoJSON file.
- show_predictions(image_id, figsize=(10, 10), border_color='r', text_color='b')
Show the predictions on an image.
- Parameters:
image_id (str) – The image ID to show the predictions on.
figsize (tuple | None, optional) – The size of the figure, by default (10, 10)
border_color (str | None, optional) – The color of the border of the polygons, by default “r”
text_color (str | None, optional) – The color of the text, by default “b”
- Raises:
ValueError – If the image ID is not found in the patch or parent predictions.
- Return type:
None
- explore_predictions(parent_id, xyz_url=None, style_kwargs=None)
- Parameters:
parent_id (str)
xyz_url (str | None)
style_kwargs (dict | None)
- load_geo_predictions(load_path)
Load georeferenced text predictions from a GeoJSON file.
- Parameters:
load_path (str | pathlib.Path) – The path to the GeoJSON file.
- Raises:
ValueError – If the path does not point to a GeoJSON file.
Note
This will overwrite any existing predictions!
- load_patch_predictions(patch_preds)
- Parameters:
patch_preds (str | pathlib.Path | pandas.DataFrame)
- Return type:
None
- class mapreader.spot_text.runner_base.DetRecRunner
Bases:
DetRunner- search_predictions(search_text, ignore_case=True, return_dataframe=False)
Search the predictions for specific text. Accepts regex.
- Parameters:
search_text (str) – The text to search for. Can be a regex pattern.
ignore_case (bool, optional) – Whether to ignore case when searching, by default True.
return_dataframe (bool, optional) – Whether to return the results as a pandas DataFrame, by default False.
- Returns:
A dictionary containing the search results or a DataFrame if return_dataframe is True.
- Return type:
dict | pd.DataFrame
- Raises:
ValueError – If no parent predictions are found.
- show_search_results(parent_id, figsize=(10, 10), border_color='r', text_color='b')
Show the search results on an image.
- Parameters:
parent_id (str) – The image ID to show the predictions on (must be parent level).
figsize (tuple | None, optional) – The size of the figure, by default (10, 10)
border_color (str | None, optional) – The color of the border of the polygons, by default “r”
text_color (str | None, optional) – The color of the text, by default “b”.
- Raises:
ValueError – If the image ID is not found in the patch or parent predictions.
- Return type:
None
- explore_search_results(parent_id, xyz_url=None, style_kwargs=None)
- Parameters:
parent_id (str)
xyz_url (str | None)
style_kwargs (dict | None)
- save_search_results_to_geojson(path_save, centroid=False)
Convert the search results to georeferenced search results and save them to a GeoJSON file.
- Parameters:
path_save (str | pathlib.Path) – The path to save the GeoJSON file.
centroid (bool, optional) – Whether to save the centroid of the polygons as the geometry column, by default False. Note: The original polygon will stil be saved as a separate column.
- Raises:
ValueError – If no search results are found.
- Return type:
None
- search_results_to_geojson(path_save, centroid=False)
Convert the search results to georeferenced search results and save them to a GeoJSON file.
- Parameters:
path_save (str | pathlib.Path) – The path to save the GeoJSON file.
centroid (bool, optional) – Whether to save the centroid of the polygons as the geometry column, by default False. Note: The original polygon will stil be saved as a separate column.
- Raises:
ValueError – If no search results are found.
- Return type:
None