def area_to_capacity(statistical_roof_model_area_based, power_density_flat, power_density_tilted):
    """Maps area shares to capacity shares of statistical roof model.

    The statistical roof model defines roof categories (e.g. south-facing with tilt 10°) and their
    shares in a population of roofs. This function maps areas shares to shares of installable pv
    capacity. It discriminates between flat and tilted roofs, i.e. the power density of flat roofs
    can be different than the one from tilted roofs.

    Parameters:
        * statistical_roof_model_area_based: model as described above, values are shares of total roof area
        * power_density_flat: power density of flat pv installations, unit must be consistent with next
        * power_density_tilted: power density of tilted pv installations, unit must be consistent with previous
    Returns:
        * statistical_roof_model_cpacity_based: model as described above, values are shares of total
        installable capacity
    """
    cap_based = statistical_roof_model_area_based.copy()
    flat_roofs = cap_based.index.get_level_values(0) == "flat"
    tilted_roofs = cap_based.index.get_level_values(0) != "flat"
    cap_based[flat_roofs] = cap_based[flat_roofs] * power_density_flat
    cap_based[tilted_roofs] = cap_based[tilted_roofs] * power_density_tilted
    return cap_based / cap_based.sum()