Draw a risk map
To draw a choropleth map, fetch the outlines once, fetch the scores for the month you want, and join the two on the area code.
What you need
Section titled “What you need”A key with the Risk scores and LGA boundaries scopes.
Join scores to shapes
Section titled “Join scores to shapes”| Map | Shapes | Scores | Join |
|---|---|---|---|
| National, by state | State boundaries | State risk | properties.code = state_code |
| One state, by LGA | LGA boundaries | LGA risk | properties.lgaCode = lga_code |
Example with GeoPandas
Section titled “Example with GeoPandas”import osimport geopandas as gpdimport pandas as pdfrom ai4m_sdk import AI4MClient
client = AI4MClient(api_key=os.environ["AI4M_API_KEY"])
shapes = gpd.GeoDataFrame.from_features(client.get_lga_boundaries("KN"), crs="EPSG:4326")report = client.get_lga_risk("KN")scores = pd.DataFrame([vars(lga) for lga in report.lgas])
kano = shapes.merge(scores, left_on="lgaCode", right_on="lga_code")kano.plot(column="score", cmap="YlOrRd", vmin=0, vmax=1, legend=True, edgecolor="white")Colours
Section titled “Colours”The AI4M dashboard uses these colours for the five levels. Using the same ones keeps your map consistent with it.
| Level | Colour |
|---|---|
very_low |
#FFF3B0 |
low |
#FDD35C |
moderate |
#F9A13B |
high |
#E0412B |
very_high |
#9E0B2B |
Good practice
Section titled “Good practice”- Fetch boundaries once and keep them. They do not change from month to month.
- The outlines are simplified for drawing, so do not use them to measure area or to decide which LGA a point falls in.
- Add a legend with the score bands, and say whether the month is an estimate or a forecast.
- Credit the boundaries: GADM, version 4.1.