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

Allow different sources for specific indicators #110

Merged
merged 3 commits into from
Apr 26, 2024
Merged
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
29 changes: 29 additions & 0 deletions lciafmt/data/lcia.bib
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,32 @@ @article{huijbregts_recipe_2017
year = {2017},
DOI = {10.1007/s11367-016-1246-y}
}

@incollection{forster_changes_2007,
address = {Cambridge, UK and New York, NY},
title = {Changes in {Atmospheric} {Constituents} and in {Radiative} {Forcing}},
booktitle = {Climate {Change} 2007: {The} {Physical} {Science} {Basis}. {Contribution} of {Working} {Group} {I} to the {Fourth} {Assessment} {Report} of the {Intergovernmental} {Panel} on {Climate} {Change}},
publisher = {Cambridge University Press},
author = {Forster, Piers and Ramaswamy, Venkatachalam},
year = {2007},
}

@incollection{myhre_anthropogenic_2013,
address = {Cambridge, UK and New York, NY},
title = {Anthropogenic and {Natural} {Radiative} {Forcing}},
url = {https://archive.ipcc.ch/pdf/assessment-report/ar5/wg1/WG1AR5_Chapter08_FINAL.pdf},
booktitle = {Climate {Change} 2013: {The} {Physical} {Science} {Basis}. {Contribution} of {Working} {Group} {I} to the {Fifth} {Assessment} {Report} of the {Intergovernmental} {Panel} on {Climate} {Change}},
publisher = {Cambridge University Press},
author = {Myhre, Gunnar and Shindell, Drew},
year = {2013},
}

@incollection{smith_earths_2021,
address = {Cambridge, UK and New York, NY},
title = {The {Earth}'s {Energy} {Budget}, {Climate} {Feedbacks}, and {Climate} {Sensitivity} {Supplementary} {Material}},
url = {https://www.ipcc.ch/report/ar6/wg1/downloads/report/IPCC_AR6_WGI_Chapter07_SM.pdf},
booktitle = {Climate {Change} 2021: {The} {Physical} {Science} {Basis}. {Contribution} of {Working} {Group} {I} to the {Sixth} {Assessment} {Report} of the {Intergovernmental} {Panel} on {Climate} {Change}},
publisher = {Cambridge University Press},
author = {Smith, Chris and Nicholls, Zebedee R. J. and Armour, Kyle and Collins, William and Forster, Piers and Meinshausen, Malte and Palmer, Matthew D. and Watanabe, Masahiro},
year = {2021},
}
4 changes: 4 additions & 0 deletions lciafmt/data/methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
"path": "ipcc",
"case_insensitivity": "False",
"url": "https://github.com/USEPA/LCIAformatter/blob/master/lciafmt/data/IPCC_GWP_values.csv",
"bib_id": {"AR6": "smith_earths_2021",
"AR5": "myhre_anthropogenic_2013",
"AR4": "forster_changes_2007"
},
"citation": "Forster and Ramaswamy 2007 (AR4), Myhre and Shindell 2013 (AR5), Forster and Storelvmo 2021 (AR6)",
"source_type": "csv"
}
Expand Down
33 changes: 28 additions & 5 deletions lciafmt/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, zip_file: str):
self.__indicators = {}
self.__flows = {}
self.__sources = {}
self.__sources_to_write = {}
self.__bibids = {}
self.__bibpath = datapath / 'lcia.bib'

Expand All @@ -47,11 +48,24 @@ def write(self, df: pd.DataFrame, write_flows=False):
if 'category' not in df:
df['category'] = df['Method']

for method in df['source_method'].unique():
methods = pd.unique(
df[['Method', 'source_method']].values.ravel('K'))
indicators = pd.unique(
df[['Indicator', 'source_indicator']].values.ravel('K'))

# identify all relevant bib_ids and sources
for method in methods:
m = check_as_class(method)
if isinstance(m, str):
# not a recognized method, so no bib_id
continue
bib = m.get_metadata().get('bib_id')
if bib:
self.__bibids[bib] = m.value
if isinstance(bib, str):
self.__bibids[bib] = m.value
elif isinstance(bib, dict):
for k,v in bib.items():
self.__bibids[v] = f'{m.value} {k}'
for i in generate_sources(self.__bibpath, self.__bibids):
self.__sources[i.id] = i

Expand All @@ -69,7 +83,7 @@ def write(self, df: pd.DataFrame, write_flows=False):
dicts = [
self.__indicators,
self.__methods,
self.__sources
self.__sources_to_write
]
if write_flows:
dicts.append(self.__flows)
Expand Down Expand Up @@ -100,9 +114,14 @@ def __indicator(self, row) -> o.ImpactCategory:
row['source_indicator'])
ind.impact_factors = []
ind.version = pkg_version_number
source = self._return_source(row['Method'])
source = (self._return_source(row['source_method']) or
self._return_source(row['Method'] + ' ' +
row['Indicator']) or
self._return_source(row['source_method'] + ' ' +
row['source_indicator']))
if source:
ind.source = source.to_ref()
self.__sources_to_write[source.id] = source
self.__indicators[uid] = ind

method = self.__method(row)
Expand All @@ -121,6 +140,10 @@ def __method(self, row) -> o.ImpactMethod:
m.id = uid
m.name = row['Method']
m.version = pkg_version_number
source = self._return_source(row['Method'])
if source:
m.source = source.to_ref()
self.__sources_to_write[source.id] = source
m.impact_categories = []
m.description = generate_method_description(row['Method'])
self.__methods[uid] = m
Expand Down Expand Up @@ -160,6 +183,6 @@ def __flow(self, row):

def _return_source(self, name):
for uid, s in self.__sources.items():
if s.name == name:
if s.name == name or name.startswith(s.name):
return s
return None
Loading