def export_kenya_constituencies_map(constituency_frequencies, file_path):
    """
    Exports a choropleth map of Kenya's constituencies, with each constituency shaded according to the given frequency
    for each constituency.

    :param constituency_frequencies: Dictionary of Kenya constituency code -> frequency count
    :type constituency_frequencies: dict of str -> int
    :param file_path: Path to write the generated map to.
    :type file_path: str
    """
    constituencies_map = mapping_utils.get_standard_geodata("kenya", "constituencies")
    lakes_map = mapping_utils.get_standard_geodata("kenya", "lakes")
    lakes_map = lakes_map[lakes_map.LAKE_AVF.isin({"lake_turkana", "lake_victoria"})]

    fig, ax = plt.subplots()

    # Draw the base map
    mapping_utils.plot_frequency_map(constituencies_map, "ADM2_AVF", constituency_frequencies, ax=ax)

    # Draw a zoomed inset map of Nairobi because the constituencies here are really small
    mapping_utils.plot_inset_frequency_map(
        constituencies_map, "ADM2_AVF", constituency_frequencies,
        inset_region=(36.62, -1.46, 37.12, -1.09), zoom=3, inset_position=(35.60, -2.95), ax=ax
    )

    # Draw Kenya's lakes
    mapping_utils.plot_water_bodies(lakes_map, ax=ax)

    plt.savefig(file_path, dpi=1200, bbox_inches="tight")
    plt.close()
def export_kenya_counties_map(county_frequencies, file_path):
    """
    Exports a choropleth map of Kenya's counties, with each county shaded and labelled according to the given frequency
    for each county.

    :param county_frequencies: Dictionary of Kenya county code -> frequency count
    :type county_frequencies: dict of str -> int
    :param file_path: Path to write the generated map to.
    :type file_path: str
    """
    counties_map = mapping_utils.get_standard_geodata("kenya", "counties")
    lakes_map = mapping_utils.get_standard_geodata("kenya", "lakes")
    lakes_map = lakes_map[lakes_map.LAKE_AVF.isin({"lake_turkana", "lake_victoria"})]

    fig, ax = plt.subplots()

    # Draw the base map
    mapping_utils.plot_frequency_map(counties_map, "ADM1_AVF", county_frequencies, ax=ax,
                                     # labels=labels,  TODO: Find out what this is
                                     label_position_columns=("ADM1_LX", "ADM1_LY"),
                                     callout_position_columns=("ADM1_CALLX", "ADM1_CALLY"))

    # Draw Kenya's lakes
    mapping_utils.plot_water_bodies(lakes_map, ax=ax)

    plt.savefig(file_path, dpi=1200, bbox_inches="tight")
    plt.close()
Esempio n. 3
0
    def test_export_kenya_counties_frequencies_map(self):
        counties = mapping_utils.get_standard_geodata("kenya", "counties")["ADM1_AVF"]
        frequencies = self.generate_distributions(counties)

        file_path = path.join(self.test_dir, "counties.png")
        kenya_mapper.export_kenya_counties_map(frequencies, file_path)

        self.assertIsNone(compare_images(file_path, "tests/analysis/mapping/resources/kenya/counties.png", _IMAGE_TOLERANCE))
Esempio n. 4
0
    def test_export_mogadishu_sub_district_frequencies_map(self):
        regions = mapping_utils.get_standard_geodata(
            "somalia", "mogadishu_sub_districts")["ADM3_AVF"]
        frequencies = self.generate_distributions(regions)

        file_path = path.join(self.test_dir, "mogadishu_sub_districts.png")
        somalia_mapper.export_mogadishu_sub_district_frequencies_map(
            frequencies, file_path)

        self.assertIsNone(
            compare_images(
                file_path,
                "tests/analysis/mapping/resources/somalia/mogadishu_sub_districts.png",
                _IMAGE_TOLERANCE))
Esempio n. 5
0
def export_somalia_district_frequencies_map(district_frequencies, file_path):
    """
    Exports a choropleth map of Somalia's regions, with each region shaded and labelled according to the given
    frequency for each region.

    :param district_frequencies: Dictionary of Somalia district code -> frequency count
    :type district_frequencies: dict of str -> int
    :param file_path: Path to write the generated map to.
    :type file_path: str
    """
    districts_map = mapping_utils.get_standard_geodata("somalia", "districts")

    fig, ax = plt.subplots()
    mapping_utils.plot_frequency_map(districts_map,
                                     "ADM2_AVF",
                                     district_frequencies,
                                     ax=ax)
    plt.savefig(file_path, dpi=1200, bbox_inches="tight")
    plt.close()
Esempio n. 6
0
def export_somalia_region_frequencies_map(region_frequencies, file_path):
    """
    Exports a choropleth map of Somalia's regions, with each region shaded and labelled according to the given
    frequency for each region.

    :param region_frequencies: Dictionary of Somalia region code -> frequency count
    :type region_frequencies: dict of str -> int
    :param file_path: Path to write the generated map to.
    :type file_path: str
    """
    regions_map = mapping_utils.get_standard_geodata("somalia", "regions")

    fig, ax = plt.subplots()
    mapping_utils.plot_frequency_map(regions_map,
                                     "ADM1_AVF",
                                     region_frequencies,
                                     label_position_columns=("ADM1_LX",
                                                             "ADM1_LY"),
                                     callout_position_columns=("ADM1_CALLX",
                                                               "ADM1_CALLY"),
                                     ax=ax)
    plt.savefig(file_path, dpi=1200, bbox_inches="tight")
    plt.close()