Skip to content

Commit

Permalink
Merge pull request #109 from USEPA/release_v1.1.2
Browse files Browse the repository at this point in the history
Release v1.1.2
  • Loading branch information
bl-young authored Apr 23, 2024
2 parents 27ba917 + 1c41775 commit e7c9269
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 65 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
py-version: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# general Python setup
- name: Set up Python ${{ matrix.py-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py-version }}

Expand All @@ -52,6 +52,7 @@ jobs:
- name: Install package and dependencies
run: |
pip install .
pip install bibtexparser # for testing bibliographies via esupy
# - name: Install package and dependencies (Windows)
# if: matrix.os == 'windows-latest'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_methods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand All @@ -36,7 +36,7 @@ jobs:
- name: Upload files
if: always()
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v4
with:
# Artifact name
name: lciafmt_methods
Expand Down
15 changes: 15 additions & 0 deletions format specs/LCIAcompilation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## LCIA Compilation

Custom methods consisting of indicators from multiple indicators can be created using `lciafmt.generate_lcia_compilation()`.
This requires an input `.yaml` file with the following specifications.
See [compilation.yaml](../tests/compilation.yaml) for an example.

```
name: # Name given to new method
rename_indicators: # True or False
indicators: # Include as many unique indicators as desired as shown
Climate change: # The provided indicator name will be used if `rename_indicators` is `True`
method: IPCC # Method name from exisiting methods available in LCIAfmt
indicator: AR5-100 # Indicator name available within the selected method
code: GHG # (optional) code
```
5 changes: 3 additions & 2 deletions format specs/LCIAmethod.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ The flow name fields match those in the fedelemflowlist [FlowList](https://githu
Index | Field | Type | Required | Note |
| ---- | ------ | ---- | ---------| ----- |
0 | Method | string | Y | The LCIA method name, e.g. 'Traci 2.1' |
1 | Method UUID | string | Y | ID for the method |
1 | Method UUID | string | N | ID for the method, generated if not supplied |
2 | Indicator | string | Y | Name of indicator, e.g. 'Acidification Potential' |
3 | Indicator UUID| string | Y | ID for the indicator |
3 | Indicator UUID| string | N | ID for the indicator, generated if not supplied |
4 | Indicator unit | string | Y | The unit for the indicator, e.g. 'kg CO2 eq' |
5 | Flowable | string | Y | The flow name, e.g. 'Sulfur dioxide' |
6 | Flow UUID | string | Y | ID of the flow |
Expand All @@ -18,3 +18,4 @@ The flow name fields match those in the fedelemflowlist [FlowList](https://githu
10 | Location | string | N | Name of the location
11 | Location UUID | string | N | ID of the location
12 | Characterization factor | float | Y | LCIA characterization factor
13 | Code | string | N | string abbreviation for indicator
10 changes: 6 additions & 4 deletions lciafmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lciafmt.util as util
import lciafmt.endpoint as ep
import lciafmt.custom as custom
from lciafmt.custom import generate_lcia_compilation


from enum import Enum
Expand Down Expand Up @@ -153,10 +154,11 @@ def map_flows(df: pd.DataFrame, system=None, mapping=None,
x = mapped[mapped[['Method', 'Indicator', 'Flowable', 'Flow UUID']
].duplicated(keep=False)]
duplicates = list(set(zip(x.Indicator, x.Flowable)))
util.log.warn(f'Identified duplicate factors for {len(duplicates)} '
f'flow/indicator combinations and {len(x)} factors.')
util.log.debug(f'{duplicates}')
util.log.warn(f'Use collapse_indicators() to drop these duplicates.')
if len(duplicates) > 0:
util.log.warning(f'Identified duplicate factors for {len(duplicates)} '
f'flow/indicator combinations and {len(x)} factors.')
util.log.debug(f'{duplicates}')
util.log.warning('Use collapse_indicators() to drop these duplicates.')
return mapped


Expand Down
46 changes: 46 additions & 0 deletions lciafmt/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"""

import pandas as pd
from pathlib import Path
import yaml

import lciafmt
from lciafmt.df import lciafmt_cols
from lciafmt.util import datapath

def get_custom_method(file: str=None, input_df=None):
"""Converts a dataframe or a csv filepath to a dataframe suitable for
Expand All @@ -23,3 +27,45 @@ def get_custom_method(file: str=None, input_df=None):
else:
raise Exception


def generate_lcia_compilation(filename: str,
filepath: Path=None
) -> pd.DataFrame:
"""Generates a dataframe consisting of indicators from various LCIA methods
based on specs provided in yaml file.
"""
if not filepath:
filepath = datapath
with open(filepath / filename) as f:
build_file = yaml.safe_load(f)
build_df = pd.DataFrame(build_file['indicators']).transpose()

indicator_dict = (build_df.groupby('method')
.apply(lambda x: [y for y in x['indicator']])
.to_dict())
name_dict = build_df['indicator'].to_dict()
code_dict = {}
if 'code' in build_df:
code_dict = build_df['code'].to_dict()

method_list = []
for method, indicators in indicator_dict.items():
df = lciafmt.get_mapped_method(method_id = method,
indicators = indicators,
methods = [method])
method_list.append(df)

df = pd.concat(method_list, ignore_index=True)

df['category'] = df['Method']
df['source_method'] = df['Method']
df['Method'] = build_file.get('name')
if build_file.get('rename_indicators', False):
df['category'] = df['Method']
df['source_indicator'] = df['Indicator']
df['Indicator'] = df['Indicator'].replace({v: k for k, v in name_dict.items()})
if code_dict:
df['Code'] = df['Indicator'].map(code_dict)

return df

28 changes: 28 additions & 0 deletions lciafmt/data/ISO21930-LCIA-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ISO21930-LCIA-US
version: v0.1
rename_indicators: True
indicators:
Greenhouse Gases:
method: IPCC
indicator: AR5-100
code: GHG

Ozone depletion potential:
method: TRACI 2.1
indicator: Ozone depletion
code: ODP

Eutrophication potential:
method: TRACI 2.1
indicator: Eutrophication
code: EP

Acidification potential:
method: TRACI 2.1
indicator: Acidification
code: AP

Photochemical oxidant creation potential:
method: TRACI 2.1
indicator: Smog formation
code: POCP
35 changes: 18 additions & 17 deletions lciafmt/data/description.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
description:
'[Method][version] is built from LCIA Formatter v[LCIAfmt_version] and flows from the Federal
Elementary Flow List (FEDEFL) v[FEDEFL_version]
base: >+
[Method][version] is built from LCIA Formatter v[LCIAfmt_version] and
flows from the Federal Elementary Flow List (FEDEFL) v[FEDEFL_version]
description: >+
[Method] source file: [url]
Source citation: [citation]
[Method] flowable and context input files are maintained in the FEDEFL GitHub Repository:
https://github.com/USEPA/Federal-LCA-Commons-Elementary-Flow-List
[Method] flowable and context input files are maintained in the FEDEFL
GitHub Repository: https://github.com/USEPA/fedelemflowlist
The LCIA Formatter (https://github.com/USEPA/LCIAformatter) applies [Method]
characterization factors to flows using the mapping housed in the FEDEFL.
The flowable and context input files for [Method] are used by the LCIA Formatter
to translate the names from the [Method] source file and generate a mapping
file for the FEDEFL. This file contains all of the accepted flowable and context
The LCIA Formatter (https://github.com/USEPA/LCIAformatter) applies [Method]
characterization factors to flows using the mapping housed in the FEDEFL.
The flowable and context input files for [Method] are used by the LCIA Formatter
to translate the names from the [Method] source file and generate a mapping
file for the FEDEFL. This file contains all of the accepted flowable and context
combinations which can be mapped to [Method] characterization factors. It also
includes target UUID, units, and conversion factors as well as tracking
who mapped and verified each record and when they were last updated.
'
indicator:
'[Indicator] is built from LCIA Formatter v[LCIAfmt_version] for use with [Method]'
indicator: >
[Indicator] is built with LCIA Formatter v[LCIAfmt_version] for use with [Method]
source_indicator: >
[Indicator] is built with LCIA Formatter v[LCIAfmt_version] based on
[source_indicator] in [Method]
18 changes: 18 additions & 0 deletions lciafmt/data/lcia.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@article{bare_traci_2011,
title = {{TRACI} 2.0: the tool for the reduction and assessment of chemical and other environmental impacts 2.0},
volume = {13},
pages = {687--696},
number = {5},
journal = {Clean Technologies and Environmental Policy},
author = {Bare, Jane},
doi = {10.1007/s10098-010-0338-9},
year = {2011}
}

@article{huijbregts_recipe_2017,
title = {{ReCiPe} 2016: A harmonized life cycle impact assessment method at midpoint and endpoint level Report I: Characterization},
journaltitle = {International Journal of Life Cycle Assessment},
author = {Huijbregts, M. A. J. and Steinmann, Z. J. N. and Elshout, P. M. F. and Stam, G. and Verones, F. and Vieira, M. D. M. and Hollander, A. and Zijp, M. and {van Zelm}, R.},
year = {2017},
DOI = {10.1007/s11367-016-1246-y}
}
3 changes: 3 additions & 0 deletions lciafmt/data/methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"mapping": "TRACI2.1",
"case_insensitivity": "False",
"url": "https://www.epa.gov/sites/default/files/2015-12/traci_2_1_2014_dec_10_0.xlsx",
"bib_id": "bare_traci_2011",
"citation": "Bare 2012",
"source_type": "Excel file"
},
Expand All @@ -25,6 +26,7 @@
"path": "recipe",
"case_insensitivity": "True",
"url": "http://www.rivm.nl/sites/default/files/2018-11/ReCiPe2016_CFs_v1.1_20180117.xlsx",
"bib_id": "huijbregts_recipe_2017",
"citation": "Huijbregts 2017",
"source_type": "Excel file"
},
Expand Down Expand Up @@ -55,6 +57,7 @@
"id": "IPCC",
"name": "IPCC",
"mapping": "IPCC",
"detail_note": "Factors are based on those reported in Table 2.14 (AR4), Table 8.A.1 (AR5), and Table 7.SM.7 (AR6).",
"path": "ipcc",
"case_insensitivity": "False",
"url": "https://github.com/USEPA/LCIAformatter/blob/master/lciafmt/data/IPCC_GWP_values.csv",
Expand Down
2 changes: 1 addition & 1 deletion lciafmt/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def apply_endpoints(endpoints, matching_fields, download_from_remote=False):
method = pd.DataFrame()

for e in matching_fields:
endpoints[e].fillna("", inplace=True)
endpoints[e] = endpoints[e].fillna("")

for m in indicators['Method'].unique():
method_indicators = indicators[indicators['Method'] == m]
Expand Down
4 changes: 4 additions & 0 deletions lciafmt/ipcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from lciafmt.util import log, datapath
from lciafmt.df import lciafmt_cols

### IPCC data for each AR were sourced from the following:
## AR4: Table 2.14 (https://archive.ipcc.ch/publications_and_data/ar4/wg1/en/errataserrata-errata.html#table214)
## AR5: Table 8.A.1 (https://archive.ipcc.ch/pdf/assessment-report/ar5/wg1/WG1AR5_Chapter08_FINAL.pdf)
## AR6: Table 7.SM.7 (https://github.com/IPCC-WG1/Chapter-7/blob/main/data_output/7sm/metrics_supplement_cleaned.csv)

def get() -> pd.DataFrame:
"""Generate a method for IPCC in standard format.
Expand Down
Loading

0 comments on commit e7c9269

Please sign in to comment.