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

🚧 climate: test annual ONI index #3984

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 4 additions & 0 deletions dag/climate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@ steps:
- snapshot://climate/2025-02-12/sst.csv
data://garden/climate/2025-02-12/sst:
- data://meadow/climate/2025-02-12/sst
data://garden/climate/2025-02-12/sst_annual:
- data://garden/climate/2025-02-12/sst
data://grapher/climate/2025-02-12/sst:
- data://garden/climate/2025-02-12/sst
data://grapher/climate/2025-02-12/sst_by_month:
- data://garden/climate/2025-02-12/sst
data://grapher/climate/2025-02-12/sst_annual:
- data://garden/climate/2025-02-12/sst_annual


2 changes: 1 addition & 1 deletion etl/steps/data/garden/climate/2025-02-12/sst.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run(dest_dir: str) -> None:
tb["nino_classification"] = tb["nino_classification"].astype(int)

for col in ["nino_classification"]:
tb[col].metadata.origins = tb["nino3_4_anomaly"].metadata.origins
tb[col] = tb[col].copy_metadata(tb["nino3_4_anomaly"])

tb = tb.drop(columns={"nino4_anomaly", "nino3_4_anomaly"})

Expand Down
20 changes: 20 additions & 0 deletions etl/steps/data/garden/climate/2025-02-12/sst_annual.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# NOTE: To learn more about the fields, hover over their names.
definitions:
common:
processing_level: major

# Learn more about the available fields:
# http://docs.owid.io/projects/etl/architecture/metadata/reference/
dataset:
update_period_days: 31
title: Equatorial Pacific Sea Surface Temperatures (SST) data - El Niño or La Niña Annual Anomaly

tables:
sst:
variables:
annual_oni_anomaly:
title: Annual Oceanic Niño Index (ONI) anomaly
unit: ""
description_processing: |-
Annual anomalies of the Oceanic Niño Index (ONI) are calculated by taking the average of the monthly ONI values for a given year.

38 changes: 38 additions & 0 deletions etl/steps/data/garden/climate/2025-02-12/sst_annual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Load a meadow dataset and create a garden 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 meadow dataset.
ds_garden = paths.load_dataset("sst")

# Read table from meadow dataset.
tb = ds_garden.read("sst")

#
# Process data.
#
# Calculate the annual average for the dataset
tb_annual = tb.groupby(["country", "year"]).mean().reset_index()
tb_annual = tb_annual.rename(columns={"oni_anomaly": "annual_oni_anomaly"})
tb_annual = tb_annual.drop(columns={"month", "nino_classification"})

tb_annual = tb_annual.format(["country", "year"])

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

# Save changes in the new garden dataset.
ds_garden.save()
30 changes: 30 additions & 0 deletions etl/steps/data/grapher/climate/2025-02-12/sst_annual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""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("sst_annual")

# Read table from garden dataset.
tb = ds_garden.read("sst", reset_index=True)
tb["country"] = tb["country"].replace({"World": "Global"})
tb = tb.format(["year", "country"])

#
# 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()