Skip to content

The Images module

ImageSourceBase

Bases: SourceBase, ABC

TODO: Add docstrings

__init__(env, root_dir=None, url=None)

A generic interface to an image source.

Args:

env:
    An Env object containing loaded configuration options.

root_dir:
    The directory where images for this source are stored.
    Defaults to None.

url:
    The base URL of the source. Defaults to None.

check_image_status(image_ids)

Extract the set of IDs for images that have not been downloaded yet.

Parameters:

Name Type Description Default
image_ids set | list | tuple

A container of image IDs.

required

Returns:

Type Description
tuple[set[Path], set[int | str]]

A tuple containing: 1. A set of paths to existing images. 2. A set of IDs of missing images (can be used to determine which images to download).

create_session()

Create an (authenticated) session for the supplied source.

Returns:

Type Description
Session

A requests session.

download_image(image_id, url=None, overwrite=False)

Download a single image.

Parameters:

Name Type Description Default
image_id str | int

The image ID.

required
url str

The image URL. Defaults to None.

None
overwrite bool

Download the image even if it exists. Defaults to False.

False

Returns:

Name Type Description
Path Path

The path to the downloaded image file.

download_images(image_ids, urls)

Download a set of images concurrently.

Parameters:

Name Type Description Default
dataset

A dataset containing image IDs.

required
sample

Only download a sample of the images. Defaults to None.

required

Returns:

Type Description
list[Path]

A list of paths to the saved images.

get_image_url(image_id) abstractmethod

Retrieve the URL for an image with the given ID.

Parameters:

Name Type Description Default
image_id int | str

The image ID.

required

Returns:

Type Description
str

The URL to query.

images property

Return a list of paths to all images in the root directory.

AmsterdamPanorama

Bases: ImageSourceBase

TODO: Add docstrings

__init__(env, root_dir=None)

An interface for downloading and manipulating street view images from the Amsterdam repository.

Parameters:

Name Type Description Default
env Env

An Env object containing loaded configuration options.

required
root_dir str | Path | None

An optional custom root directory. Defaults to None.

None

Google

Bases: ImageSourceBase

TODO: Add docstrings

__init__(env, root_dir=None)

An interface for downloading and manipulating street view images from Google StreetView.

Parameters:

Name Type Description Default
env Env

An Env object containing loaded configuration options.

required
root_dir str | Path | None

An optional custom root directory. Defaults to None.

None

KartaView

Bases: ImageSourceBase

TODO: Add docstrings

__init__(env, root_dir=None)

An interface for downloading and manipulating street view images from Kartaview.

Parameters:

Name Type Description Default
env Env

An Env object containing loaded configuration options.

required
root_dir str | Path | None

An optional custom root directory. Defaults to None.

None

fetch_image_ids(lat, lon, radius)

Fetch Kartaview image ids within radius of a given point.

Uses old openstreecam API (https://api.openstreetcam.org/api/doc.html) as it seems not available on latest kartaview API (https://doc.kartaview.org/#section/API-Resources).

Returns:

Type Description

pd.DataFrame

get_image_url(image_id)

Retrieve the URL for an image with the given ID.

Args:

image_id:
    The image ID.

Returns:

Type Description
str

The URL to download the image.

Mapillary

Bases: ImageSourceBase

TODO: Add docstrings

__init__(env=None, root_dir=None)

An interface for downloading and manipulating street view images from Mapillary.

Args:

env:
    An Env object containing loaded configuration options.

root_dir:
    An optional custom root directory. Defaults to None.

create_session()

Create an (authenticated) session for the supplied source.

Returns:

Type Description
Session

A requests session.

fetch_image_ids(bbox, fields=None, limit=500, extract_latlon=True)

Fetch Mapillary image IDs within a bounding box.

See https://www.mapillary.com/developer/api-documentation/#image

Parameters:

Name Type Description Default
bbox list[float]

[west, south, east, north]

required
fields list[str] | None

List of fields to include in the results. If None, a standard set of fields is returned.

None
limit int

Number of images to request per page (pagination size).

500
extract_latlon bool

Whether to extract latitude and longitude from computed_geometry.

True

Returns:

Type Description

Ibis table containing image data for the selected fields.

get_image_url(image_id)

Retrieve the URL for an image with the given ID.

Parameters:

Name Type Description Default
image_id int | str

The image ID.

required

Returns:

Name Type Description
str str | None

The URL to query.