Skip to content

Commit

Permalink
Merge pull request #99 from USEPA/develop
Browse files Browse the repository at this point in the history
Release v1.1.1
  • Loading branch information
bl-young authored Nov 3, 2023
2 parents 8097cfb + 8324f99 commit 27ba917
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
13 changes: 10 additions & 3 deletions lciafmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import json
import pkg_resources
from typing import Union

import pandas as pd
Expand Down Expand Up @@ -77,7 +76,7 @@ def get_class(name: str):

def supported_methods() -> list:
"""Return a list of dictionaries of supported method meta data."""
json_file = pkg_resources.resource_filename("lciafmt", 'data/methods.json')
json_file = util.datapath / 'methods.json'
with open(json_file, "r", encoding="utf-8") as f:
return json.load(f)

Expand Down Expand Up @@ -150,7 +149,15 @@ def map_flows(df: pd.DataFrame, system=None, mapping=None,
mapper = fmap.Mapper(df, system=system, mapping=mapping,
preserve_unmapped=preserve_unmapped,
case_insensitive=case_insensitive)
return mapper.run()
mapped = mapper.run()
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.')
return mapped


def supported_mapping_systems() -> list:
Expand Down
1 change: 1 addition & 0 deletions lciafmt/ipcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ def get() -> pd.DataFrame:
method = lciafmt.Method.IPCC
df = lciafmt.get_method(method)
mapped_df = lciafmt.map_flows(df, system=method.get_metadata().get('mapping'))
mapped_df2 = lciafmt.util.collapse_indicators(mapped_df)
18 changes: 9 additions & 9 deletions lciafmt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import pandas as pd
import numpy as np
import yaml
import pkg_resources
from pathlib import Path
from esupy.processed_data_mgmt import Paths, FileMeta, load_preprocessed_output,\
write_df_to_file, write_metadata_to_file, download_from_remote, \
Expand All @@ -22,7 +21,7 @@


# set version number of package, needs to be updated with setup.py
pkg_version_number = '1.1.0'
pkg_version_number = '1.1.1'
MODULEPATH = Path(__file__).resolve().parent
datapath = MODULEPATH / 'data'

Expand All @@ -36,7 +35,6 @@
paths.local_path = paths.local_path / 'lciafmt'
OUTPUTPATH = paths.local_path

pkg = pkg_resources.get_distribution('lciafmt')
GIT_HASH = get_git_hash()

method_metadata = {
Expand All @@ -58,7 +56,7 @@ def set_lcia_method_meta(method_id):
lcia_method_meta.category = ""
else:
lcia_method_meta.name_data = method_id
lcia_method_meta.tool = pkg.project_name
lcia_method_meta.tool = "lciafmt"
lcia_method_meta.tool_version = pkg_version_number
lcia_method_meta.ext = write_format
lcia_method_meta.git_hash = GIT_HASH
Expand Down Expand Up @@ -155,11 +153,13 @@ def collapse_indicators(df) -> pd.DataFrame:
"""
cols = ['Method', 'Indicator', 'Indicator unit', 'Flow UUID']
duplicates = df[df.duplicated(subset=cols, keep=False)]
cols_to_keep = [c for c in df.columns.values.tolist()]
cols_to_keep.remove('Characterization Factor')
df2 = df.groupby(cols_to_keep, as_index=False)['Characterization Factor'].mean()
log.info(str(len(duplicates))+" duplicate factors consolidated to "
+ str(len(duplicates)-(len(df)-len(df2))))
cols_to_keep = [c for c in df.columns.values.tolist() if
c not in ('Characterization Factor', 'CAS No')]
df2 = (df.groupby(cols_to_keep, as_index=False)
.agg({'Characterization Factor': 'mean',
'CAS No': 'first'}))
log.info(f'{len(duplicates)} duplicate factors consolidated to '
f'{(len(duplicates)-(len(df)-len(df2)))}')

return df2

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="lciafmt",
version="1.1.0",
version="1.1.1",
packages=["lciafmt"],
package_dir={'lciafmt': 'lciafmt'},
package_data={'lciafmt': ["data/*.*"]},
Expand Down

0 comments on commit 27ba917

Please sign in to comment.