download_if_needed#

download_if_needed(uri: str, download_dir: str | None = None, fs: rastervision.pipeline.file_system.file_system.FileSystem | None = None, use_cache: bool = True) str[source]#

Download a file to a directory if remote and return its local path.

The full local path, within download_dir, is determined by get_local_path(). If a file doesn’t already exists at that path, it is downloaded.

Parameters:
  • uri (str) – URI of file to download. If this is a local path, it will be returned as is.

  • download_dir (str | None) – Local directory to download file into. If None, the file will be downloaded to cache dir as defined by RVConfig. Defaults to None.

  • fs (rastervision.pipeline.file_system.file_system.FileSystem | None) – If provided, use fs instead of the automatically chosen FileSystem for uri. Defaults to None.

  • use_cache (bool) – If False and the file is remote, download it regardless of whether it exists in cache. Defaults to True.

Returns:

Local path to file.

Raises:

NotReadableError – if URI cannot be read from.

Return type:

str