Skip to content

Commit

Permalink
Adapt metadata of garden and grapher steps to be able to build an ind…
Browse files Browse the repository at this point in the history
…icator based explorer
  • Loading branch information
pabloarosado committed May 22, 2024
1 parent 64ef26e commit 4fd0508
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
26 changes: 12 additions & 14 deletions etl/steps/data/garden/emdat/2024-04-11/natural_disasters.meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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: |-
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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: |-
Expand All @@ -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: |-
Expand All @@ -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: |-
Expand Down
35 changes: 32 additions & 3 deletions etl/steps/data/grapher/emdat/2024-04-11/natural_disasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
)
Expand Down

0 comments on commit 4fd0508

Please sign in to comment.