Skip to content

Build cutout

Functions to download ERA5/SARAH data and build the atlite cutout for the atlite. These functions linked to the build_cutout rule.

cutout_timespan(config, weather_year)

Build the cutout timespan. Note that the coutout requests are in UTC (TBC)

Parameters:

Name Type Description Default
config dict

the snakemake config

required
weather_year dict

the coutout weather year

required

Returns:

Name Type Description
tuple list

end and start of the cutout timespan

Source code in workflow/scripts/build_cutout.py
def cutout_timespan(config: dict, weather_year: int) -> list:
    """Build the cutout timespan. Note that the coutout requests are in UTC (TBC)

    Args:
        config (dict): the snakemake config
        weather_year (dict): the coutout weather year

    Returns:
        tuple: end and start of the cutout timespan
    """
    snapshot_cfg = config["snapshots"]
    # make snapshots for TZ and then convert to naive UTC for atlite
    snapshots = (
        make_periodic_snapshots(
            year=weather_year,
            freq=snapshot_cfg["freq"],
            start_day_hour=snapshot_cfg["start"],
            end_day_hour=snapshot_cfg["end"],
            bounds=snapshot_cfg["bounds"],
            # here we need to convert UTC to local
            tz=TIMEZONE,
            end_year=(None if not snapshot_cfg["end_year_plus1"] else weather_year + 1),
        )
        .tz_convert("UTC")
        .tz_localize(None)
    )

    return [snapshots[0], snapshots[-1]]