Skip to content

Commit

Permalink
Add p-code mappings to food security
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-mills committed Oct 15, 2024
1 parent c9e5926 commit 10d3d23
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/hapi/pipelines/configs/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ admin1:
"CMR|Far-North": "CM004"
"CMR|West": "CM008"
"CPV|Santo Antao": "CV06"
"DJI|Djibouti Ville": "DJ04"
"ETH|B. Gumuz": "ET06"
"HTI|Nord-Ouest": "HT09"
"HTI|Sud": "HT07"
Expand Down Expand Up @@ -90,6 +91,8 @@ admin2:
"AF08|Onaba": "AF0805"
"AF14|Khost": "AF1401"
"AF23|Chaghcharan": "AF2301"
"AO09|Município dos Gambos (ex-chiange)": "AO09073"
"AO16|Mocamedes": "AO16139"
"CD43|Ville de Gbadolite": "CD4301"
"CD83|Territoire de LODJA": "CD8303"
"CO08|Distrito Especial, Industrial Y Portuario De Barranquilla": "CO08001"
Expand Down Expand Up @@ -117,6 +120,10 @@ admin2:
"ET12|ZONE 3": "ET1201"
"ET13|HARAR/HUNDENE": "ET1301"
"ET14|AA ZONE1": "ET1401"
# "GH02|Ashanti": "GH02-XXX" TODO: this unit can't be added because of the unspecified admin2
# "GH03|Bono": "GH03-XXX" TODO: this unit can't be added because of the unspecified admin2
# "GH04|Bono east": "GH04-XXX" TODO: this unit can't be added because of the unspecified admin2
# "GH05|Central": "GH05-XXX" TODO: this unit can't be added because of the unspecified admin2
"GM05|Kombo Saint Mary": "GM0308" # TODO: this unit is not getting picked up because of the mismatched admin1
"GN005|Conakry": "GN002001" # TODO: this unit is not getting picked up because of the mismatched admin1
"GN005|Fria": "GN001005" # TODO: this unit is not getting picked up because of the mismatched admin1
Expand All @@ -132,6 +139,7 @@ admin2:
"NG027|Munya": "NG027018"
"PH08|Samar": "PH08060"
"PK2|Mekran": "PK211"
"PK5|Dera Ismail Khan": "PK509"
"PS01|Ramallah and Albireh": "PS0130"
"RUS|Sankt-peterburg": "RU004002"
"SD01|Sharq El Nile": "SD01004"
Expand All @@ -144,6 +152,7 @@ admin2:
"TD11|La kabbia": "TD1102"
"TD17|Iriba": "TD1703"
"TD22|Tibest-Ouest": "TD2202"
"TG05|Kpendial- Ouest": "TG0513"
"TZ12|Mbozi": "TZ2606" # TODO: this unit is not getting picked up because of the mismatched admin1
"UA12|Apostolivskyi": "UA1206"
"UA12|Marhanetska": "UA1208"
Expand Down
11 changes: 11 additions & 0 deletions src/hapi/pipelines/configs/food_security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ food_security:
# This is where all "Areas" are non-admin units and so there is only admin 1
# data available in "Level 1"
adm1_only:
- "DJI"
- "HTI"
- "MMR"
- "SOM"
Expand All @@ -34,6 +35,16 @@ food_security:
adm2_only:
- "PSE"

# This is where there is only admin 2 data available in "Level 1" whether
# "Area" is blank or not
adm2_in_level1:
- "LBN"

# This is where "Level 1" is non-admin units and so there is only admin 1
# data available in "Area"
adm1_in_area:
- "KEN"

# The errors below were picked up from the logging which outputs all the
# fuzzy matches
adm1_errors:
Expand Down
55 changes: 54 additions & 1 deletion src/hapi/pipelines/database/food_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,23 @@ def process_subnational(
admin_level == "admintwo"
and countryiso3 in food_sec_config["adm1_only"]
):
return None
self._country_status[countryiso3] = (
"Level 1: Admin 1, Area: ignored"
)
adminoneinfo = self.get_adminoneinfo(
food_sec_config["adm_ignore_patterns"],
warnings,
dataset_name,
countryiso3,
row["Level 1"],
)
return self.get_adminone_admin2_ref(
food_sec_config,
warnings,
errors,
dataset_name,
adminoneinfo,
)
# The YAML configuration "adm2_only" specifies locations where
# "Level 1" is not populated and "Area" is admin 2. (These are
# exceptions since "Level 1" would normally be populated if "Area" is
Expand All @@ -236,6 +252,43 @@ def process_subnational(
adminoneinfo,
)

if countryiso3 in food_sec_config["adm2_in_level1"]:
row["Area"] = row["Level 1"]
row["Level 1"] = None
adminoneinfo = AdminInfo(countryiso3, "NOT GIVEN", "", None, False)
self._country_status[countryiso3] = (
"Level 1: Admin 2, Area: ignored"
)
return self.get_admintwo_admin2_ref(
food_sec_config,
warnings,
errors,
dataset_name,
row,
adminoneinfo,
)

if countryiso3 in food_sec_config["adm1_in_area"]:
if admin_level == "adminone":
return None
self._country_status[countryiso3] = (
"Level 1: ignored, Area: Admin 1"
)
adminoneinfo = self.get_adminoneinfo(
food_sec_config["adm_ignore_patterns"],
warnings,
dataset_name,
countryiso3,
row["Area"],
)
return self.get_adminone_admin2_ref(
food_sec_config,
warnings,
errors,
dataset_name,
adminoneinfo,
)

adminone_name = row["Level 1"]

if not adminone_name:
Expand Down

0 comments on commit 10d3d23

Please sign in to comment.