From 2671a2d994bb1569b8813d3cdba8133b6549ccbd Mon Sep 17 00:00:00 2001 From: hannahker Date: Tue, 24 Dec 2024 13:15:54 -0800 Subject: [PATCH 1/2] revert back to all admin levels --- exploration/admin_lookup.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/exploration/admin_lookup.md b/exploration/admin_lookup.md index 0a8a961..a983f77 100644 --- a/exploration/admin_lookup.md +++ b/exploration/admin_lookup.md @@ -56,23 +56,26 @@ with tempfile.TemporaryDirectory() as temp_dir: iso3 = row["iso3"] max_adm_level = row["max_adm_level"] load_shp_from_azure(iso3, temp_dir, MODE) - gdf = gpd.read_file(f"{temp_dir}/{iso3.lower()}_adm{max_adm_level}.shp") - - # Get name column and its language code - name_column = select_name_column(gdf, max_adm_level) - language_code = name_column[-2:] - name_columns = [f"ADM{i}_{language_code}" for i in range(0, max_adm_level + 1)] - - # Standardize column names and add language info - new_columns = [x.replace(f"_{language_code}", "_NAME") for x in name_columns] - gdf = gdf.rename(columns=dict(zip(name_columns, new_columns))) - gdf["NAME_LANGUAGE"] = language_code - gdf["ISO3"] = iso3 - gdf["ADM_LEVEL"] = max_adm_level - - # Keep only relevant columns - matching_cols = [col for col in gdf.columns if col in DEFAULT_COLS] - dfs.append(gdf[matching_cols]) + + name_columns = [] + for admin_level in range(max_adm_level + 1): + gdf = gpd.read_file(f"{temp_dir}/{iso3.lower()}_adm{admin_level}.shp") + + # Get name column and its language code + name_column = select_name_column(gdf, admin_level) + language_code = name_column[-2:] + name_columns.append(name_column) + + # Standardize column names and add language info + new_columns = [x.replace(f"_{language_code}", "_NAME") for x in name_columns] + gdf = gdf.rename(columns=dict(zip(name_columns, new_columns))) + gdf["NAME_LANGUAGE"] = language_code + gdf["ISO3"] = iso3 + gdf["ADM_LEVEL"] = max_adm_level + + # Keep only relevant columns + matching_cols = [col for col in gdf.columns if col in DEFAULT_COLS] + dfs.append(gdf[matching_cols]) df_all = pd.concat(dfs, ignore_index=True) ``` From 6708c6508ffa8ac10d2910d2efb94a345384aa60 Mon Sep 17 00:00:00 2001 From: hannahker Date: Mon, 6 Jan 2025 09:06:46 -0800 Subject: [PATCH 2/2] fix admin level column --- exploration/admin_lookup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exploration/admin_lookup.md b/exploration/admin_lookup.md index a983f77..f4d40eb 100644 --- a/exploration/admin_lookup.md +++ b/exploration/admin_lookup.md @@ -71,7 +71,7 @@ with tempfile.TemporaryDirectory() as temp_dir: gdf = gdf.rename(columns=dict(zip(name_columns, new_columns))) gdf["NAME_LANGUAGE"] = language_code gdf["ISO3"] = iso3 - gdf["ADM_LEVEL"] = max_adm_level + gdf["ADM_LEVEL"] = admin_level # Keep only relevant columns matching_cols = [col for col in gdf.columns if col in DEFAULT_COLS]