Skip to content

Instantly share code, notes, and snippets.

@WesIngwersen
Last active November 23, 2024 01:00
Show Gist options
  • Save WesIngwersen/90fcb8be085c8554231913188577876e to your computer and use it in GitHub Desktop.
Save WesIngwersen/90fcb8be085c8554231913188577876e to your computer and use it in GitHub Desktop.
Write IPCC GWPs to csv and openLCA schema JSON-LD
# -*- coding: utf-8 -*-
"""
Retrieve IPCC global warming potential factors in kg CO23 per kg GHG using LCIA Formatter
Map to FEDEFL
Write out with all relevant FEDEFL flows to openLCA schema JSON-LD
Simplify and condense table and write to csv
Output available at http://doi.org/10.23719/1529821
"""
# See https://github.com/USEPA/LCIAformatter/ to install LCIA formatter (lciafmt)
import lciafmt
import pandas as pd
import pkg_resources
print("Using LCIAFormatter version ",pkg_resources.get_distribution("lciafmt").version)
ipcc = lciafmt.get_method("IPCC")
print("Loaded IPCC method.")
print("IPCC indicators are ",pd.unique(ipcc["Indicator"]))
print("IPCC has ",str(len(ipcc))," unique characterization factors.")
ipcc = lciafmt.map_flows(ipcc, system="IPCC")
print ("Mapped flows to FEDEFL version ",pkg_resources.get_distribution("fedelemflowlist").version)
ipcc = lciafmt.util.collapse_indicators(ipcc)
#Optionally store it locally
#lciafmt.util.store_method(ipcc,method_id=lciafmt.Method.IPCC)
lciafmt.to_jsonld(ipcc,"IPCC_FEDEFL_JSON-LD_no_flows.zip",write_flows=False)
print("Writing IPCC Methods to JSON-LD without including flows to IPCC_FEDEFL_JSON-LD_no_flows.zip")
# Subset the flows just to use GHG names, indicators and factors for easier tabular data use
ipcc_simple = ipcc[['Indicator','Flowable','Characterization Factor']].drop_duplicates().sort_values(by=["Indicator","Flowable"])
ipcc_simple = ipcc_simple.rename(columns={'Flowable':'GHG','Characterization Factor':'GWP kgCO2e/kg GHG'})
print("Getting a simplified table with just the indicator, GHG name, and characterization factor.")
ipcc_simple.to_excel("IPCC_AR4-AR6_GWPs.xlsx",index=False)
print("Wrote the simplified table to IPCC_AR4-AR6_GWPs.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment