Skip to content

Commit

Permalink
widlfires: area burnt by wildfire bug
Browse files Browse the repository at this point in the history
  • Loading branch information
veronikasamborska1994 committed Nov 25, 2024
1 parent d66931a commit 4ea6d29
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 42 deletions.
16 changes: 0 additions & 16 deletions etl/steps/data/garden/climate/latest/weekly_wildfires.meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,3 @@ tables:
description_key:
- CO₂ emissions contribute to the greenhouse effect, influencing global warming and climate change.


co2_ha_per_area:
title: Carbon dioxide emissions per hectare burnt
unit: tonnes
short_unit: t
description_short: Carbon dioxide emissions per hectare burnt by [wildfires](#dod:wildfires), in tonnes. {definitions.desc_update}
description_processing: The carbon dioxide emissions per hectare is calculated by dividing the carbon dioxide emissions by the area burnt by wildfires.
description_key: *desc_wildfires

pm2_5_ha_per_area:
title: PM2.5 emissions per hectare burnt
unit: tonnes
short_unit: t
description_short: PM2.5 emissions per hectare burnt by [wildfires](#dod:wildfires), in tonnes. {definitions.desc_update}
description_processing: The PM2.5 emissions per hectare is calculated by dividing the PM2.5 emissions by the area burnt by wildfires.
description_key: *desc_wildfires
8 changes: 0 additions & 8 deletions etl/steps/data/garden/climate/latest/weekly_wildfires.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Load a meadow dataset and create a garden dataset."""


import numpy as np
import owid.catalog.processing as pr
import pandas as pd

Expand Down Expand Up @@ -87,13 +86,6 @@ def run(dest_dir: str) -> None:
tb["share_area_ha"] = (tb["area_ha"] / tb["total_area_ha"]) * 100
tb["share_area_ha_cumulative"] = (tb["area_ha_cumulative"] / tb["total_area_ha"]) * 100

tb["co2_ha_per_area"] = tb["CO2"] / tb["area_ha"]
tb["pm2_5_ha_per_area"] = tb["PM2.5"] / tb["area_ha"]

tb[["co2_ha_per_area", "pm2_5_ha_per_area"]] = tb[["co2_ha_per_area", "pm2_5_ha_per_area"]].replace(
[float("inf"), -float("inf")], np.nan
)

tb = tb.drop(columns=["total_area_ha"])
tb = tb.set_index(["country", "date"], verify_integrity=True)

Expand Down
14 changes: 12 additions & 2 deletions etl/steps/data/grapher/climate/latest/wildfires_by_year.meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ tables:
description_key: *desc_wildfires

co2_ha_per_area:
title: Annual carbon dioxide emissions per area burnt
title: Carbon dioxide emissions per hectare burnt
unit: tonnes
short_unit: t
description_short: Carbon dioxide emissions per hectare burnt by [wildfires](#dod:wildfires), in tonnes. {definitions.desc_update}
description_processing: The carbon dioxide emissions per hectare is calculated by dividing the carbon dioxide emissions by the area burnt by wildfires.
description_key: *desc_wildfires

pm2_5_ha_per_area:
title: Annual PM2.5 emissions per area burnt
title: PM2.5 emissions per hectare burnt
unit: tonnes
short_unit: t
description_short: PM2.5 emissions per hectare burnt by [wildfires](#dod:wildfires), in tonnes. {definitions.desc_update}
description_processing: The PM2.5 emissions per hectare is calculated by dividing the PM2.5 emissions by the area burnt by wildfires.
description_key: *desc_wildfires
33 changes: 17 additions & 16 deletions etl/steps/data/grapher/climate/latest/wildfires_by_year.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Load a garden dataset and create a grapher dataset."""

import numpy as np
import owid.catalog.processing as pr

from etl.helpers import PathFinder, create_dataset
from etl.helpers import PathFinder, create_dataset, last_date_accessed

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)
Expand All @@ -22,20 +23,7 @@ def run(dest_dir: str) -> None:

# Get the year
tb["year"] = tb["date"].astype(str).str[0:4]
tb = tb[
[
"country",
"year",
"area_ha",
"events",
"pm2_5",
"co2",
"share_area_ha",
"area_ha_per_wildfire",
"co2_ha_per_area",
"pm2_5_ha_per_area",
]
]
tb = tb[["country", "year", "area_ha", "events", "pm2_5", "co2", "share_area_ha"]]
# Aggregate the data by year and country (ignore missing values when summing the columns)
tb_annual_sum = tb.groupby(["country", "year"]).sum(min_count=1).reset_index()

Expand All @@ -54,12 +42,25 @@ def run(dest_dir: str) -> None:
# Area per wildfire
tb["area_ha_per_wildfire"] = tb["area_ha"] / tb["events"]

tb["co2_ha_per_area"] = tb["co2"] / tb["area_ha"]
tb["pm2_5_ha_per_area"] = tb["pm2_5"] / tb["area_ha"]

tb[["co2_ha_per_area", "pm2_5_ha_per_area"]] = tb[["co2_ha_per_area", "pm2_5_ha_per_area"]].replace(
[float("inf"), -float("inf")], np.nan
)

tb = tb.set_index(["country", "year"], verify_integrity=True)

# Save outputs.
#
# Create a new grapher dataset with the same metadata as the garden dataset.
ds_grapher = create_dataset(dest_dir, tables=[tb], default_metadata=ds_garden.metadata)
ds_grapher = create_dataset(
dest_dir,
tables=[tb],
default_metadata=ds_garden.metadata,
yaml_params={"date_accessed": last_date_accessed(tb)},
)

ds_grapher.metadata.title = "Seasonal wildfire trends by year"

ds_grapher.save()

0 comments on commit 4ea6d29

Please sign in to comment.