diff --git a/lciafmt/data/lcia.bib b/lciafmt/data/lcia.bib index 1fd71f2..5f96129 100644 --- a/lciafmt/data/lcia.bib +++ b/lciafmt/data/lcia.bib @@ -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}, +} diff --git a/lciafmt/data/methods.json b/lciafmt/data/methods.json index 92314dc..d971d5f 100644 --- a/lciafmt/data/methods.json +++ b/lciafmt/data/methods.json @@ -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" } diff --git a/lciafmt/jsonld.py b/lciafmt/jsonld.py index b2b0f0c..560b1cd 100644 --- a/lciafmt/jsonld.py +++ b/lciafmt/jsonld.py @@ -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' @@ -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 @@ -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) @@ -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) @@ -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 @@ -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