From 4fd0508781f59f801793e07a823d31ffd6e05b11 Mon Sep 17 00:00:00 2001 From: Pablo Rosado Date: Wed, 22 May 2024 12:19:34 +0200 Subject: [PATCH] Adapt metadata of garden and grapher steps to be able to build an indicator based explorer --- .../2024-04-11/natural_disasters.meta.yml | 26 +++++++------- .../emdat/2024-04-11/natural_disasters.py | 35 +++++++++++++++++-- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/etl/steps/data/garden/emdat/2024-04-11/natural_disasters.meta.yml b/etl/steps/data/garden/emdat/2024-04-11/natural_disasters.meta.yml index 1f2cdb8e1ec..13111f4bde4 100644 --- a/etl/steps/data/garden/emdat/2024-04-11/natural_disasters.meta.yml +++ b/etl/steps/data/garden/emdat/2024-04-11/natural_disasters.meta.yml @@ -113,7 +113,7 @@ tables: # NOTE: This table contains AVERAGE decadal values, not total sums. variables: &variables-default total_dead: - title: Total deaths + title: Deaths unit: 'people' description_short: |- Total number of deaths as a result of a natural disaster. @@ -159,8 +159,6 @@ tables: title: Reconstruction costs short_unit: '$' unit: 'current US$' - description_short: |- - Reconstruction costs. description_key: - *definition-reconstruction-costs - *description-key-common @@ -174,7 +172,7 @@ tables: - *definition-insured-damage - *description-key-common total_damages: - title: Total economic damage from natural disasters + title: Total economic damages short_unit: '$' unit: 'current US$' description_short: |- @@ -183,7 +181,7 @@ tables: - *definition-total-damage - *description-key-common n_events: - title: Number of reported natural disasters + title: Natural disasters unit: 'events' description_short: |- Number of reported natural disasters. @@ -193,35 +191,35 @@ tables: title: Population unit: 'people' total_dead_per_100k_people: - title: Total number of deaths per 100,000 people + title: Deaths per 100,000 people unit: 'deaths per 100,000 people' description_processing: *description-processing-100k description_key: - *definition-dead - *description-key-common injured_per_100k_people: - title: Number of injured persons per 100,000 people + title: Injured per 100,000 people unit: 'injured per 100,000 people' description_processing: *description-processing-100k description_key: - *definition-injured - *description-key-common affected_per_100k_people: - title: Number of affected persons per 100,000 people + title: Affected per 100,000 people unit: 'affected per 100,000 people' description_processing: *description-processing-100k description_key: - *definition-affected - *description-key-common homeless_per_100k_people: - title: Number of homeless persons per 100,000 people + title: Homeless per 100,000 people unit: 'homeless per 100,000 people' description_processing: *description-processing-100k description_key: - *definition-homeless - *description-key-common total_affected_per_100k_people: - title: Total number of affected persons per 100,000 people + title: Total affected per 100,000 people unit: 'affected per 100,000 people' description_processing: *description-processing-100k description_key: @@ -231,7 +229,7 @@ tables: - *definition-total-affected - *description-key-common n_events_per_100k_people: - title: Number of events per 100,000 people + title: Natural disasters per 100,000 people unit: 'events per 100,000 people' description_processing: *description-processing-100k description_key: @@ -241,7 +239,7 @@ tables: unit: "current US$" short_unit: "$" reconstruction_costs_per_gdp: - title: "Reconstruction costs from natural disasters as a share of GDP" + title: "Reconstruction costs as a share of GDP" unit: "%" short_unit: "%" description_short: |- @@ -251,7 +249,7 @@ tables: - *definition-reconstruction-costs - *description-key-common insured_damages_per_gdp: - title: "Insured damages from natural disasters as a share of GDP" + title: "Insured damages as a share of GDP" unit: "%" short_unit: "%" description_short: |- @@ -261,7 +259,7 @@ tables: - *definition-insured-damage - *description-key-common total_damages_per_gdp: - title: "Total economic damages from natural disasters as a share of GDP" + title: "Total economic damages as a share of GDP" unit: "%" short_unit: "%" description_short: |- diff --git a/etl/steps/data/grapher/emdat/2024-04-11/natural_disasters.py b/etl/steps/data/grapher/emdat/2024-04-11/natural_disasters.py index 7d4a33e7606..6ebf5ee6159 100644 --- a/etl/steps/data/grapher/emdat/2024-04-11/natural_disasters.py +++ b/etl/steps/data/grapher/emdat/2024-04-11/natural_disasters.py @@ -4,6 +4,28 @@ paths = PathFinder(__file__) +# Map of variable titles to their corresponding public titles. +TITLE_MAPPING = { + "Natural disasters": "Annual number of natural disasters", + "Natural disasters per 100,000 people": "Annual rate of natural disasters", + "Affected": "Annual number of people requiring immediate assistance", + "Affected per 100,000 people": "Annual rate of people requiring immediate assistance", + "Deaths": "Annual number of deaths", + "Deaths per 100,000 people": "Annual rate of deaths", + "Homeless": "Annual number of people left homeless", + "Homeless per 100,000 people": "Annual rate of people left homeless", + "Injured": "Annual number of people injured", + "Injured per 100,000 people": "Annual rate of people injured", + "Total affected": "Annual number of people affected", + "Total affected per 100,000 people": "Annual rate of people affected", + "Insured damages": "Annual insured damages", + "Insured damages as a share of GDP": "Annual insured damages as a share of GDP", + "Reconstruction costs": "Annual reconstruction costs", + "Reconstruction costs as a share of GDP": "Annual reconstruction costs as a share of GDP", + "Total economic damages": "Annual economic damages", + "Total economic damages as a share of GDP": "Annual economic damages as a share of GDP", +} + def create_wide_tables(table: Table, is_decade: bool) -> Table: # Create wide tables. @@ -12,17 +34,24 @@ def create_wide_tables(table: Table, is_decade: bool) -> Table: table_wide = table_wide.pivot(index=["country", "year"], columns="type", join_column_levels_with="-") if is_decade: + variable_title_public_prefix = "Decadal average: " variable_name_suffix = "_decadal" variable_title_suffix = " (decadal)" else: + variable_title_public_prefix = "" variable_name_suffix = "_yearly" variable_title_suffix = "" # Improve variable names and titles. for column in table_wide.drop(columns=["country", "year"], errors="raise").columns: - table_wide[column].metadata.title += ( - " - " + column.split("-")[-1].capitalize().replace("_", " ") + variable_title_suffix - ) + old_title = table_wide[column].metadata.title + impact, disaster = column.split("-") + disaster = disaster.replace("_", " ") + new_title = old_title + " - " + disaster.capitalize() + variable_title_suffix + new_title_public = f"{variable_title_public_prefix}{TITLE_MAPPING[old_title]} from {disaster + 's' if disaster[-1] != 's' else disaster}" + table_wide[column].metadata.title = new_title + table_wide[column].metadata.display = {"name": disaster.capitalize()} + table_wide[column].metadata.presentation.title_public = new_title_public table_wide = table_wide.rename( columns={column: column.replace("-", "_") + variable_name_suffix}, errors="raise" )