-
Notifications
You must be signed in to change notification settings - Fork 10
Using lciafmt
LCIA Methods as generated for the Federal LCA Commons can be generated using the scripts in the examples folder.
A data frame with the data of a method can be loaded with the
get_method(<method ID>)
function
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
This will download and cache the raw method data in a temporary folder
(~/temp/lciafmt
). Before downloading method data, lciafmt
will first
check if the method data are available in this cache folder. Alternatively,
a file path or web URL can be passed as arguments to the get_method
function
to load the data from other locations:
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI,
file="path/to/traci_2.1.xlsx")
traci = lciafmt.get_method(lciafmt.Method.TRACI,
url="http://.../path/to/traci_2.1.xlsx")
Also, it is possible to clear the cache to ensure that the newest version is downloaded from the internet:
import lciafmt
lciafmt.clear_cache()
traci = lciafmt.get_method(lciafmt.Method.TRACI)
The function supported_methods
returns a list of meta data objects that each
contain the information of LCIA methods that are currently supported:
import lciafmt
lciafmt.supported_methods()
The flow mappings defined in the
fedelemflowlist
can be directly applied on a data frame to generate a new data frame with mapped flows. A specific source system can be selected via
the system
parameter. The system parameter must match a specific mapping file available in fedelemflowlist :
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
traci_mapped = lciafmt.map_flows(traci, system="TRACI2.1")
The available systems can be retrieved via the supported_mapping_systems()
function:
import lciafmt
lciafmt.supported_mapping_systems()
Additionally, the map_flows
function accepts the following optional parameters:
-
mapping
: a data frame in the fedelemflowlist mapping format that contains the mapping that should be applied. Used instead of specifyingsystem
-
preserve_unmapped
: a Boolean value that indicates whether the unmapped flows should be preserved in the resulting data frame. -
case_insensitive
: a Boolean value that indicates if mapping should be case insensitive (True) or by default case sensitive (False)
Midpoint or endpoint indicators can be converted to custom endpoint or valuation methods based on user supplied data. For example, an indicator that tracks ecosystem impacts in species-years can be converted to a valuation. The input data for this conversion must be provided within the data subfolder as a csv file and in the format specified in the endpoint format specs.
import lciafmt
valuation_method = lciafmt.generate_endpoints(file = 'file_name', name = 'My Valuation Method')
The optional parameter matching_fields
can be used to indicate whether the new method should be converted and aggregated for each 'Indicator' (default) or each listed 'Indicator unit'. An example using 'Indicator unit' is shown for the Weidema Valuation method (Weidema 2009).
The method data are stored in a standard pandas data frame so that the standard export functions of pandas can be directly used:
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
traci.to_csv("output/traci_2.1.csv", index=False)
Additionally, a method can be stored as JSON-LD package that can be imported into an openLCA database:
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
lciafmt.to_jsonld(traci, "output/traci_2.1_jsonld.zip")
When also elementary flows should be written to the JSON-LD package the
write_flows
flag can be passed to the export call:
import lciafmt
traci = lciafmt.get_method(lciafmt.Method.TRACI)
lciafmt.to_jsonld(traci, "output/traci_2.1_jsonld.zip", write_flows=True)
Note that unit groups and flow properties are currently not added to the JSON-LD package so that the package can only be imported into a database where at least the standard openLCA unit groups and flow properties are available.
The lciafmt
module writes messages to the default logger of the logging
package. In order to see more details, you can set the log level to a finer
level:
import logging as log
log.basicConfig(level=log.INFO)
LCIAformatter is developed and maintained by Office of Research & Development (ORD), Center for Environmental Solutions & Emergency Response (CESER), Land Remediation & Technology Division (LRTD), Environmental Decision Analytics Branch (EDAB), U.S. Environmental Protection Agency, Cincinnati, OH 45268. See OMB Memorandum M-16-21 Section 4 & Releasing Open Source Code.