lcia_results
This object replaces the LciaResult types spelled out in Antelope-- instead, it serializes to an LCIA result directly.
AggregateLciaResult
Bases: object
contains an entityId which could be a process or a fragment (but presents as a process, i.e. with exchanges) The Aggregate score is constructed from individual LCIA Details (exchange value x characterization factor)
details()
generator of nonzero detailed results
Returns:
Type | Description |
---|---|
|
serialize(detailed=False)
If detailed is True, this should return DisaggregatedLciaScores If detailed is False, this should return SummaryLciaScores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed |
|
False
|
Returns:
Type | Description |
---|---|
|
DetailedLciaResult
Bases: object
Contains exchange, factor, result
__init__(lc_result, exchange, qrresult)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc_result |
|
required | |
exchange |
|
required | |
qrresult |
meets the QRResult spec: has properties 'flowable', 'ref', 'query', 'context', 'locale', 'origin', 'value' 'ref' has to have property 'unit' 'context' has to be a context (with 'sense') |
required |
LciaResult
Bases: object
An LCIA result object contains a collection of LCIA results for a related set of entities, called components. Each component is an AggregateLciaResult, which itself is a collection of either detailed LCIA results or summary scores.
Each component which is a FragmentFlow represents a specific traversal scenario and is thus static.
Each component which is a process will contain actual exchanges and factors, which are scenario-sensitive, and so is (theoretically) dynamic. This is not yet useful in practice. LCIA Results are in sharp need of testing / refactoring.
failed_summaries
property
A list of Summary results that failed to be added to an existing summary. This is mainly diagnostic and should be removed soon. Note the difiference from self.errors(), which is meant to store input exchanges that could not be converted to the query quantity during LCIA.
Returns:
Type | Description |
---|---|
|
__init__(quantity, scenario=None, private=False, scale=1.0, autorange=False)
If private, the LciaResult will not return any unaggregated results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity |
|
required | |
scenario |
|
None
|
|
private |
|
False
|
a_total()
I don't want any logic in total()
Returns:
Type | Description |
---|---|
|
aggregate(key=lambda x: x.get('StageName'), entity_id=None)
returns a new LciaResult object in which the components of the original LciaResult object are aggregated into static values according to a key. The key is a lambda expression that is applied to each AggregateLciaResult component's entity property (components where the lambda fails will all be grouped together).
The special key '*' will aggregate all components together. 'entity_id' argument is required in this case to provide a distinguishing key for the result (falls back to "aggregated result").
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
default: lambda x: x.fragment['StageName'] -- assuming the payload is a FragmentFlow |
lambda x: get('StageName')
|
|
entity_id |
a descriptive string for the entity, to allow the aggregation to be distinguished in subsequent aggregations. Use 'None' at your peril |
None
|
Returns:
Type | Description |
---|---|
|
contrib(percent=False, count=None)
Convert the LCIA result to a result with a unitary value. If the score is an Aggregated score, it will first be aggregated by flow name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent |
[False] if True, the score will add up to 100 |
False
|
|
count |
[None] number of distinct categories to report (plus remainder) |
None
|
Returns:
Type | Description |
---|---|
|
contrib_new(*args, autorange=None)
re-implement contrib query with a better spec.
Queries are specified as entries from self.keys(). One way to get the keys to be more legible is to first perform an aggregation using self.aggregate().
The current getitem method, which uses a fuzzy match (self._match_keys()) is not currently used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
A sequential list of components to query. The special component '*' can be used to select the balance of results. |
()
|
|
autorange |
[None] do not alter autorange settings. [True / False]: activate or deactivate auto-ranging. |
None
|
Returns:
Type | Description |
---|---|
a 2-tuple: results, balance where results is a list having the same length as the number of arguments, and balance is a float reporting the remainder. sum(results, balance) == self.total(). If '*' is specified as one of the queries, balance will always be 0. |
contrib_query(stages=None)
returns a list of scores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stages |
[None] a list of stages to query, or None to return all components. Specify '*' to return a 1-item list containing just the total. |
None
|
Returns:
Type | Description |
---|---|
|
cutoffs()
Generates exchanges for which no factor was found during LCIA.
Returns:
Type | Description |
---|---|
|
errors()
generates exchanges that could not be converted to the target quantity due to a conversion error. Note the difference from self.failed_summaries, which reports summary scores that could not be added.
Returns:
Type | Description |
---|---|
|
flatten(_apply_scale=1.0)
Return a new LciaResult in which all groupings have been replaced by a set of AggregatedLciaScores, one per elementary flow. Performs some inline testing via equality assertions, but this still really needs unit testing, especially around matters of internal scale versus applied scale
Returns:
Type | Description |
---|---|
|
scale_result(scale)
why is this a function?
serialize_components(detailed=False)
If detailed is True, this should return DisaggregatedLciaScores If detailed is False, this should return SummaryLciaScores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed |
|
False
|
Returns:
Type | Description |
---|---|
|
set_autorange(value=None, **kwargs)
Update the AutoRange object. Should be done before results are presented, if auto-ranging is in use.
Auto-ranging affects the following outputs: * any show() or printed string * the results of contrib_new() * a_total()
No other outputs are affected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
|
None
|
Returns:
Type | Description |
---|---|
|
show_components(percent=False, count=100, threshold=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent |
|
False
|
|
count |
[None] a maximum number of components to print |
100
|
|
threshold |
[None] an absolute value below which scores are aggregated |
None
|
Returns:
Type | Description |
---|---|
|
show_details(key=None, count=100, threshold=None)
Sorting by parts is not ideal but it will have to do.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
|
None
|
|
count |
|
100
|
|
threshold |
|
None
|
Returns:
Type | Description |
---|---|
|
MixedComponents
Bases: Exception
We are now suddenly deciding that an LciaResult may not contain a mixture of AggregateLciaScores and SummaryLciaScores
StringEntity
Bases: object
To be used in cases where a component's entity is a plain string, to still allow aggregation
SummaryLciaResult
Bases: object
A container for a separately computed Lcia result, especially for the results of a fragment LCIA. Includes a node weight and a unit score-- its cumulative result is the product of these. If the unit score is a number, the summary is static.
However, the unit_score can itself be an LciaResult, making the datatype recursive.
This has add functionality, for merging repeated instances of the same fragment during traversal
result
property
must workalike with both AggregateLciaScores and DetailedLciaResults
Returns:
Type | Description |
---|---|
|
__add__(other)
Add two summary LCIA results together. This only works under the following circumstances: * different instances of the same entity are being added (e.g. two instances of the same flow). In this case, the two summaries' entities must compare as equal and their unit scores must be equal. The node weights are added. Scale is ignored (scale is inherited from the primary summary)
- Two static-valued summaries are added together. In this case, either the scores must be equal (in which case the node weights are summed) or the node weights must be equal, and the unit scores are summed.
This is the sort of garbage that should be unittested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
|
required |
Returns:
Type | Description |
---|---|
|
__init__(lc_result, entity, node_weight, unit_score)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc_result |
who "owns" you. scale report by their scale. entity_id must either have get_uuid() or be hashable |
required | |
entity |
a hashable identifier |
required | |
node_weight |
stand-in for exchange value |
required | |
unit_score |
stand-in for factor value |
required |
serialize(detailed=False)
If detailed is True, this should return DisaggregatedLciaScores If detailed is False, this should return SummaryLciaScores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed |
|
False
|
Returns:
Type | Description |
---|---|
|
show_lcia(lcia_results)
Takes in a dict of uuids to lcia results, and summarizes them in a neat table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lcia_results |
|
required |
Returns:
Type | Description |
---|---|
|