Functions associated with the build_temperature_profiles rule.

build_temp_profiles(pop_map_path, cutout_path, temperature_out)

build the temperature profiles in the cutout, this converts the atlite temperature & weights the node building process by the population map

Note that atlite only supports a single time zone shift

Parameters:
  • pop_map_path (PathLike) –

    the map to the pop density grid cell data (hdf5)

  • cutout_path (PathLike) –

    the cutout path (atlite cutout)

  • temperature_out (PathLike) –

    the output path (hdf5)

Source code in workflow/scripts/build_temperature_profiles.py
def build_temp_profiles(pop_map_path: PathLike, cutout_path: PathLike, temperature_out: PathLike):
    """build the temperature profiles in the cutout, this converts the atlite temperature & weights
    the node building process by the population map

    Note that atlite only supports a single time zone shift

    Args:
        pop_map_path (PathLike): the map to the pop density grid cell data (hdf5)
        cutout_path (PathLike): the cutout path (atlite cutout)
        temperature_out (PathLike): the output path (hdf5)
    """
    with pd.HDFStore(pop_map_path, mode="r") as store:
        pop_map = store["population_gridcell_map"]

    # this one includes soil temperature
    cutout = atlite.Cutout(cutout_path)

    # build a sparse matrix of BUSxCUTOUT_gridcells to weigh the cutout->bus aggregation process
    pop_matrix = sp.sparse.csr_matrix(pop_map.T)
    index = pop_map.columns
    index.name = "provinces"

    temperature = cutout.temperature(matrix=pop_matrix, index=index)
    # TODO fix hard-coded
    temperature["time"] = temperature["time"].values + pd.Timedelta(
        8, unit="h"
    )  # UTC-8 instead of UTC

    with pd.HDFStore(temperature_out, mode="w", complevel=4) as store:
        store["temperature"] = temperature.to_pandas().divide(pop_map.sum())