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