-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
31 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
workflow/scripts/osemosys_global/validation/climate_watch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Data handeling for Climate Watch validation | ||
https://www.climatewatchdata.org/ghg-emissions | ||
""" | ||
|
||
import pandas as pd | ||
|
||
### | ||
# public functions | ||
### | ||
|
||
|
||
def get_cw_emissions(csv_file: str, **kwargs) -> pd.DataFrame: | ||
"""Gets Climate Watch emissions data""" | ||
df = _read_cw_data(csv_file) | ||
return _format_cw_data(df) | ||
|
||
|
||
### | ||
# private functions | ||
### | ||
|
||
|
||
def _read_cw_data(csv_file: str) -> pd.DataFrame: | ||
"""Reads climate watch data | ||
https://www.climatewatchdata.org/ghg-emissions?end_year=2021&gases=all-ghg§ors=electricity-heat&start_year=1990 | ||
""" | ||
return pd.read_csv(csv_file, skipfooter=2, engine="python") | ||
|
||
|
||
def _format_cw_data(cw: pd.DataFrame) -> pd.DataFrame: | ||
df = cw.copy() | ||
df = df.drop(columns=["Country/Region", "unit"]).rename(columns={"iso": "EMISSION"}) | ||
df = df.melt(id_vars=["EMISSION"], var_name="YEAR", value_name="VALUE") | ||
df = df.fillna(0).replace("false", 0) | ||
df["YEAR"] = df.YEAR.astype(int) | ||
df["VALUE"] = df.VALUE.astype(float) | ||
df["REGION"] = "GLOBAL" | ||
return df.set_index(["REGION", "EMISSION", "YEAR"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters