Skip to content

input_preparation

Functions:

download_and_process

Download and process the weather data one or more RESKit workflows need.

A workflow may depend on several weather sources (see depends_on); each is prepared by its own registered preparer (see _SOURCE_PREPARERS) and contributes its outputs to the returned dict (e.g. the ERA5 preparer adds "era5_path"). Sources whose automated download is not implemented yet (e.g. GWA4) do not fail the call — they just print a notice that the data must be downloaded manually.

Parameters:

  • workflows

    (str or list of str) –

    Name of a registered RESKit workflow (a key of depends_on), or a list of such names. When a list is given, the union of their variable requirements is prepared in a single call.

  • start_date

    (str) –

    Inclusive date range to download ("YYYY-MM-DD").

  • end_date

    (str) –

    Inclusive date range to download ("YYYY-MM-DD").

  • boundary_box

    (dict) –

    Bounding box {"north", "south", "west", "east"} in degrees.

  • output_dir

    (str) –

    Directory to download/process into.

  • tiling

    (bool, default: False ) –

    If True, tile the processed data into the <zoom>/<x>/<y>/<year>/ structure.

  • zoom_level

    (int, default: 4 ) –

    Web-Mercator tiling zoom level, by default 4.

  • tile_output_dir

    (str, default: None ) –

    Override for the tile output directory (defaults to <output_dir>/tiles).

Returns:

  • dict

    Merged outputs of the workflows' sources' preparers.

Raises:

  • ValueError

    If any given workflow name is unknown.

Source code in reskit/util/input_preparation.py
def download_and_process(
    workflows,
    start_date,
    end_date,
    boundary_box,
    output_dir,
    tiling=False,
    zoom_level=4,
    tile_output_dir=None,
):
    """
    Download and process the weather data one or more RESKit workflows need.

    A workflow may depend on several weather sources (see ``depends_on``); each is prepared
    by its own registered preparer (see ``_SOURCE_PREPARERS``) and contributes its outputs to
    the returned dict (e.g. the ERA5 preparer adds ``"era5_path"``). Sources whose automated
    download is not implemented yet (e.g. GWA4) do not fail the call — they just print a
    notice that the data must be downloaded manually.

    Parameters
    ----------
    workflows : str or list of str
        Name of a registered RESKit workflow (a key of ``depends_on``), or a list of such
        names. When a list is given, the union of their variable requirements is prepared in
        a single call.
    start_date, end_date : str
        Inclusive date range to download (``"YYYY-MM-DD"``).
    boundary_box : dict
        Bounding box ``{"north", "south", "west", "east"}`` in degrees.
    output_dir : str
        Directory to download/process into.
    tiling : bool, optional
        If True, tile the processed data into the ``<zoom>/<x>/<y>/<year>/`` structure.
    zoom_level : int, optional
        Web-Mercator tiling zoom level, by default 4.
    tile_output_dir : str, optional
        Override for the tile output directory (defaults to ``<output_dir>/tiles``).

    Returns
    -------
    dict
        Merged outputs of the workflows' sources' preparers.

    Raises
    ------
    ValueError
        If any given workflow name is unknown.
    """
    workflows = [workflows] if isinstance(workflows, str) else list(workflows)
    required_sources = _merge_dependencies(workflows)
    context = dict(
        start_date=start_date,
        end_date=end_date,
        boundary_box=boundary_box,
        output_dir=output_dir,
        tiling=tiling,
        zoom_level=zoom_level,
        tile_output_dir=tile_output_dir,
    )

    result = {}
    for source, variables in required_sources.items():
        preparer = _SOURCE_PREPARERS.get(source)
        if preparer is None:
            print(f"NOTE: weather source '{source}' has no preparer registered; skipping.")
            continue
        partial = preparer(variables, **context)
        if partial:
            result.update(partial)
    return result