streetlevel.util

class CubemapStitchingMethod(value)

Stitching options for the faces of a cubemap.

NET = 1

The faces are combined into one image arranged as a net of a cube.

NONE = 0

The faces are returned as a list.

ROW = 2

The faces are combined into one image arranged in one row in the order front, right, back, left, top, bottom.

download_file(url, path, session=None)

Downloads a file to disk using requests.

Parameters:
  • url (str) – The URL.

  • path (str) – The output path.

  • session (Session | None) – (optional) A requests session.

Return type:

None

async download_file_async(url, path, session)

Downloads a file to disk using aiohttp.

Parameters:
  • url (str) – The URL.

  • path (str) – The output path.

  • session (ClientSession) – A ClientSession.

Return type:

None

async download_files_async(urls, session=None)

Downloads multiple files to a list of bytes.

Parameters:
  • urls (List[str]) – The URLs of the files to download.

  • session (ClientSession | None) – (optional) A ClientSession. If no session is passed, a new one will be created.

Returns:

The downloaded files as bytes.

Return type:

List[bytes]

download_tiles(tile_list)

Downloads tiles to bytes.

Parameters:

tile_list (List[Tile]) – The tiles to download.

Returns:

A dictionary containing the images as bytes with the key (x, y).

Return type:

dict

async download_tiles_async(tile_list, session)

Downloads tiles to bytes.

Parameters:
  • tile_list (List[Tile]) – The tiles to download.

  • session (ClientSession) – A ClientSession.

Returns:

A dictionary containing the images as bytes with the key (x, y).

get_equirectangular_panorama(width, height, tile_size, tile_list)

Downloads and stitches a tiled equirectangular panorama.

Parameters:
  • width (int) – Width of the panorama in pixels.

  • height (int) – Height of the panorama in pixels.

  • tile_size (Size) – Size of one tile.

  • tile_list (List[Tile]) – The tiles this panorama is made of.

Returns:

The stitched panorama as PIL image.

Return type:

Image

async get_equirectangular_panorama_async(width, height, tile_size, tile_list, session)

Downloads and stitches a tiled equirectangular panorama.

Parameters:
  • width (int) – Width of the panorama in pixels.

  • height (int) – Height of the panorama in pixels.

  • tile_size (Size) – Size of one tile.

  • tile_list (List[Tile]) – The tiles this panorama is made of.

  • session (ClientSession) – A ClientSession.

Returns:

The stitched panorama as PIL image.

Return type:

Image

get_image(url, session=None)

Fetches an image from a URL using requests.

Parameters:
  • url (str) – The URL.

  • session (Session | None) – (optional) A requests session.

Returns:

The image as PIL Image.

Return type:

Image

async get_image_async(url, session)

Fetches an image from a URL using aiohttp.

Parameters:
  • url (str) – The URL.

  • session (ClientSession) – A ClientSession.

Returns:

The image as PIL Image.

Return type:

Image

get_json(url, session=None, preprocess_function=None, headers=None)

Fetches JSON from a URL using requests.

Parameters:
  • url (str) – The URL.

  • session (Session | None) – (optional) A requests session.

  • preprocess_function (Callable | None) – (optional) A function to run on the text before passing it to the JSON parser.

  • headers (dict | None) – (optional) Request headers.

Returns:

The requested document as dictionary.

Return type:

dict

async get_json_async(url, session, json_function_parameters=None, preprocess_function=None, headers=None)

Fetches JSON from a URL using aiohttp.

Parameters:
  • url (str) – The URL.

  • session (ClientSession) – A ClientSession.

  • json_function_parameters (dict | None) – (optional) Parameters to pass to the ClientResponse.json function.

  • preprocess_function (Callable | None) – (optional) A function to run on the text before passing it to the JSON parser.

  • headers (dict | None) – (optional) Request headers.

Returns:

The requested document as dictionary.

Return type:

dict

save_cubemap_panorama(pano, path, pil_args)

Saves a cubemap to disk.

Parameters:
  • pano (List[Image] | Image) – A stitched cubemap, or the six faces of a cubemap.

  • path (str) – The output path.

  • pil_args (dict) – (optional) Additional arguments for PIL’s Image.save method, e.g. {"quality":100}. Defaults to {}.

Return type:

None

stitch_cubemap_face(face_tiles, tile_size, cols, rows)

Stitches one face of a cubemap.

Parameters:
  • face_tiles (dict) – Tiles of this face.

  • tile_size (int) – The side length of one tile in pixels.

  • cols (int) – Number of tile columns.

  • rows (int) – Number of tile rows.

Returns:

The stitched face.

stitch_cubemap_faces(faces, face_size, stitching_method)

Stitches the six faces of a cubemap into one image.

Parameters:
  • faces (List[Image]) – A list of faces in the order front, right, back, left, top, bottom.

  • face_size (int) – The side length of one face of the cubemap in pixels.

  • stitching_method (CubemapStitchingMethod) – The stitching method.

Returns:

A stitched image, or faces if the stitching method is NONE.

Return type:

Image | List[Image]

stitch_equirectangular_tiles(tile_images, width, height, tile_width, tile_height)

Stitches downloaded tiles of a tiled equirectangular panorama to a full image.

Parameters:
  • tile_images (dict) – The downloaded tiles.

  • width (int) – Width of the panorama in pixels.

  • height (int) – Height of the panorama in pixels.

  • tile_width (int) – Width of one tile in pixels.

  • tile_height (int) – Height of one tile in pixels.

Returns:

The stitched panorama as PIL image.

Return type:

Image

try_get(accessor)

QoL function for accessing an element of a nested list which may or may not exist, e.g. foo[1][0][2][3].

Parameters:

accessor – A function which attempts to access the element, e.g. lambda: foo[1][0][2][3].

Returns:

The return value of the accessor, unless an IndexError, TypeError or KeyError occurred, in which case the function returns None.