Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📊 forests: primary forest share #3301

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dag/forests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ steps:
- data://garden/regions/2023-01-01/regions
- data://garden/wb/2023-04-30/income_groups
data://grapher/forests/2024-07-10/tree_cover_loss_by_driver:
- data://garden/forests/2024-07-10/tree_cover_loss_by_driver
- data://garden/forests/2024-07-10/tree_cover_loss_by_driver

data://garden/forests/2024-09-17/primary_forest:
- data://garden/faostat/2024-03-14/faostat_rl
data://grapher/forests/2024-09-17/primary_forest:
- data://garden/forests/2024-09-17/primary_forest

34 changes: 34 additions & 0 deletions etl/steps/data/garden/forests/2024-09-17/primary_forest.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# NOTE: To learn more about the fields, hover over their names.
definitions:
common:
presentation:
topic_tags:
- Forests & Deforestation
processing_level: major

# Learn more about the available fields:
# http://docs.owid.io/projects/etl/architecture/metadata/reference/
dataset:
update_period_days: 365


tables:
primary_forest:
variables:
value_primary_forest:
title: Primary forest area
description_short: Primary forest is defined as naturally regenerated forest of native species, where there are no clearly visible indications of human activities and the ecological processes are not significantly disturbed.
display:
name: Primary forest area
unit: 1000 hectares
value_land_area:
title: Land area
unit: 1000 hectares
primary_forest_share:
title: Primary forest share
description_short: The share of primary forest out of total land area. Primary forest is defined as naturally regenerated forest of native species, where there are no clearly visible indications of human activities and the ecological processes are not significantly disturbed.
description_processing: This is calculated as the primary forest area divided by the total land area.
display:
name: Share of land that is primary forest
unit: "%"
short_unit: "%"
41 changes: 41 additions & 0 deletions etl/steps/data/garden/forests/2024-09-17/primary_forest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Load a meadow dataset and create a garden dataset."""
import owid.catalog.processing as pr

from etl.helpers import PathFinder, create_dataset

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)


def run(dest_dir: str) -> None:
#
# Load inputs.
#
# Load meadow dataset.
ds = paths.load_dataset("faostat_rl")
tb = ds["faostat_rl"].reset_index()
tb = tb[["country", "year", "element", "item", "unit", "value"]]
tb_primary = tb[(tb["item"] == "Primary Forest") & (tb["unit"] == "hectares")]
tb_land_area = tb[(tb["item"] == "Land area") & (tb["unit"] == "hectares")]

tb = pr.merge(
tb_primary,
tb_land_area,
how="left",
suffixes=("_primary_forest", "_land_area"),
validate="one_to_one",
on=["country", "year", "element", "unit"],
)
tb["primary_forest_share"] = (tb["value_primary_forest"] / tb["value_land_area"]) * 100
tb = tb.drop(columns=["item_primary_forest", "item_land_area", "unit", "element"])
tb = tb.format(
[
"country",
"year",
],
short_name="primary_forest",
)
# Create a new garden dataset with the same metadata as the meadow dataset.
ds_garden = create_dataset(dest_dir, tables=[tb], check_variables_metadata=True)
# Save changes in the new garden dataset.
ds_garden.save()
32 changes: 32 additions & 0 deletions etl/steps/data/grapher/forests/2024-09-17/primary_forest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Load a garden dataset and create a grapher dataset."""

from etl.helpers import PathFinder, create_dataset

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)


def run(dest_dir: str) -> None:
#
# Load inputs.
#
# Load garden dataset.
ds_garden = paths.load_dataset("primary_forest")

# Read table from garden dataset.
tb = ds_garden["primary_forest"]

#
# Process data.
#

#
# Save outputs.
#
# Create a new grapher dataset with the same metadata as the garden dataset.
ds_grapher = create_dataset(
dest_dir, tables=[tb], check_variables_metadata=True, default_metadata=ds_garden.metadata
)

# Save changes in the new grapher dataset.
ds_grapher.save()
Loading