Skip to content

Osm tile data collector

This module contains classes of strategy for handling downloaded tiles.

DataCollector

Bases: ABC

Store collected images.

store(idx, data)

abstractmethod

Apply action for object storage and returns data of it.

PARAMETER DESCRIPTION
idx

id of tile

TYPE: str

data

tile

TYPE: Image

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
@abstractmethod
def store(self, idx: str, data: "Image.Image") -> Any:
    """
    Apply action for object storage and returns data of it.

    Args:
        idx (str): id of tile
        data (Image.Image): tile
    """

SavingDataCollector(save_path, file_extension)

Bases: DataCollector

Save in disk collected images.

Store paths.

PARAMETER DESCRIPTION
save_path

root path for data

TYPE: Union[str, Path]

file_extension

file name extension

TYPE: str

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
def __init__(self, save_path: Union[str, Path], file_extension: str) -> None:
    """
    Initialize SavingDataCollector.

    Args:
        save_path (Union[str, Path]): root path for data
        file_extension (str): file name extension
    """
    super().__init__()
    if save_path is None or file_extension is None:
        raise ValueError
    self.save_path = Path(save_path)
    self.format = file_extension

store(idx, data)

Save image on disk. Returns path.

PARAMETER DESCRIPTION
idx

id of tile

TYPE: str

data

tile

TYPE: Image

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
def store(self, idx: str, data: "Image.Image") -> Path:
    """
    Save image on disk. Returns path.

    Args:
        idx (str): id of tile
        data (Image.Image): tile
    """
    path = self.save_path / f"{idx}.{self.format}"
    data.save(path)
    return path

InMemoryDataCollector()

Bases: DataCollector

Store data in object memory.

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
def __init__(self) -> None:
    """Initialize InMemoryDataCollector."""
    super().__init__()

store(idx, data)

Simply return object for usage.

PARAMETER DESCRIPTION
idx

id of tile

TYPE: str

data

tile

TYPE: Image

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
def store(self, idx: str, data: "Image.Image") -> "Image.Image":
    """
    Simply return object for usage.

    Args:
        idx (str): id of tile
        data (Image.Image): tile
    """
    return data

DataCollectorType

Bases: str, Enum

Define enums to choose one of known DataCollector implementations.

get_collector(collector_type, **kwargs)

Return DataCollector object of type specified by DataCollectorType enum.

PARAMETER DESCRIPTION
collector_type

If SAVE returns SavingDataCollector.

TYPE: DataCollectorType

**kwargs

Extra arguments used for SavingDataCollector object creation arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
DataCollector

newly created object

TYPE: DataCollector

Source code in srai/loaders/osm_loaders/osm_tile_data_collector.py
def get_collector(collector_type: Union[DataCollectorType, str], **kwargs: Any) -> DataCollector:
    """
    Return DataCollector object of type specified by DataCollectorType enum.

    Args:
        collector_type (DataCollectorType): If SAVE returns SavingDataCollector.
        If RETURN returns InMemoryDataCollector.
        **kwargs (Any): Extra arguments used for SavingDataCollector object creation arguments.

    Returns:
        DataCollector: newly created object
    """
    if collector_type == DataCollectorType.SAVE:
        return SavingDataCollector(**kwargs)
    elif collector_type == DataCollectorType.RETURN:
        return InMemoryDataCollector()
    else:
        raise ValueError