quantity
Each archive now has a TermManager which interprets query arguments as synonyms for canonical flows and contexts. This can also be upgraded to an LciaEngine, which extends the synonymization strategy to quantities as well
QuantityConversion
Bases: object
A stack of Quantity Relation results that are composed sequentially in order to render a flow-quantity conversion. The first QRR added should report the query quantity (numerator) in terms of some reference quantity (denominator); then each subsequent QRR should include the prior ref quantity as the query quantity.
QuantityConversion implements the interface of a QRResult (flowable, ref, query, context, value, locale, origin), 'context' is a cache of the [canonical] context used as query input; 'locale' is a '/' join of all found geographies; 'flowable' 'query' and 'origin' take from the first QR Result; 'ref' takes the last; value is computed as the product of all contained QRResults.
For instance, a Quantity conversion from moles of CH4 to GWP 100 might include first the GWP conversion and then the mol conversion: QuantityConversion(QRResult('methane', 'kg', 'kg CO2eq', 'emissions to air', 'GLO', 'ipcc.2007', 25.0), QRResult('methane', 'mol', 'kg', None, 'GLO', 'local.qdb', 0.016)) giving the resulting value of 0.4.
The QuantityConversion needs information to be fully defined: the query quantity and the query context, both of which should be canonical. The canonical context is especially needed to test directionality for LCIA.
For the context initially submitted, consult the exchange.
context
property
We want to return the canonical context if at all possible
Returns:
Type | Description |
---|---|
|
QuantityImplementation
Bases: BasicImplementation
, QuantityInterface
cf(flow, quantity, ref_quantity=None, context=None, locale='GLO', **kwargs)
Should Always return a number and catch errors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flow |
|
required | |
quantity |
|
required | |
ref_quantity |
[None] taken from flow.reference_entity if flow is entity or locally known external_ref |
None
|
|
context |
[None] taken from flow.reference_entity if flow is entity or locally known external_ref |
None
|
|
locale |
|
'GLO'
|
|
kwargs |
allow_proxy [False], strategy ['first'] -> passed to quantity_relation |
{}
|
Returns:
Type | Description |
---|---|
the value of the QRResult found by the quantity_relation |
characterize(flowable, ref_quantity, query_quantity, value, context=None, location='GLO', origin=None, **kwargs)
We gotta be able to do this
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flowable |
string |
required | |
ref_quantity |
string |
required | |
query_quantity |
string |
required | |
value |
float |
required | |
context |
string |
None
|
|
location |
string |
'GLO'
|
|
origin |
[self.origin] |
None
|
|
kwargs |
overwrite=False |
{}
|
Returns:
Type | Description |
---|---|
|
do_lcia(quantity, inventory, locale='GLO', group=None, dist=2, **kwargs)
This is almost static. Could be moved into interface, except that it requires LciaResult (which is core).
Successively implement the quantity relation over an iterable of exchanges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity |
|
required | |
inventory |
An iterable of exchange-like entries, having flow, direction, value, termination. Currently also uses process.external_ref for hashing purposes, but that could conceivably be abandoned. |
required | |
locale |
['GLO'] |
'GLO'
|
|
group |
How to group scores. Should be a lambda that operates on inventory items. Default x -> x.process |
None
|
|
dist |
[2] controls how strictly to interpret exchange context. 0 - exact context matches only; 1 - match child contexts (code default) 2 - match parent contexts [this default] 3 - match any ancestor context, including Null |
2
|
|
kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
|
get_canonical(quantity, **kwargs)
Retrieve a canonical quantity from a qdb; else raises EntityNotFound
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity |
external_id of quantity |
required |
Returns:
Type | Description |
---|---|
quantity entity |
lcia(process, ref_flow, quantity_ref, **kwargs)
Implementation of foreground LCIA -- moved from LcCatalog
Parameters:
Name | Type | Description | Default |
---|---|---|---|
process |
|
required | |
ref_flow |
|
required | |
quantity_ref |
|
required | |
kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
|
norm(quantity, region=None, **kwargs)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity |
|
required | |
region |
|
None
|
|
kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
|
profile(flow, ref_quantity=None, context=None, complete=False, **kwargs)
Generate characterizations for the named flow or flowable. The positional argument is first used to retrieve a flow, and if successful, the reference quantity and context are taken for that flow. Otherwise, the positional argument is interpreted as a flowable synonym and used to generate CFs, optionally filtered by context. In that case, if no ref quantity is given then the CFs are returned as-reported; if a ref quantity is given then a ref quantity conversion is attempted and the resulting QRResult objects are returned.
This whole interface desperately needs testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flow |
|
required | |
ref_quantity |
[None] |
None
|
|
context |
[None] |
None
|
|
complete |
[False] if True, report all results including errors and geographic proxies |
False
|
|
kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
|
quantity_conversions(flow, query_quantity, ref_quantity=None, context=None, locale='GLO', **kwargs)
Return a comprehensive set of conversion results for the provided inputs. This method catches errors and returns a null result if no factors are found.
This function is a wrapper to handle inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flow |
a string that is synonymous with a flowable characterized by the query quantity |
required | |
query_quantity |
convert to this quantity |
required | |
ref_quantity |
[None] convert for 1 unit of this quantity |
None
|
|
context |
[None] a string synonym for a context / "archetype"? (<== locale-specific?) |
None
|
|
locale |
handled by CF; default 'GLO' |
'GLO'
|
|
kwargs |
dist: CLookup distance (0=exact 1=subcompartments 2=parent compartment 3=all parents) |
{}
|
Returns:
Type | Description |
---|---|
a 3-tuple of lists of QuantityConversion objects: [valid conversions], [geographic proxy conversions], [mismatched ref unit conversions] |
do_lcia(quantity, inventory, locale=None, group=None, dist=2, quell_biogenic_co2=None, **kwargs)
Successively implement the quantity relation over an iterable of exchanges.
man, WHAT is the qdb DOING with all those LOC? (ans: seemingly a lot)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity |
|
required | |
inventory |
An iterable of exchange-like entries, having flow, direction, value, termination. Currently also uses process.external_ref for hashing purposes, but that could conceivably be abandoned. |
required | |
locale |
['GLO'] |
None
|
|
group |
How to group scores. Should be a lambda that operates on inventory items. Default x -> x.process |
None
|
|
dist |
[2] controls how strictly to interpret exchange context. 0 - exact context matches only; 1 - match child contexts (code default) 2 - match parent contexts [this default] 3 - match any ancestor context, including NullContext |
2
|
|
quell_biogenic_co2 |
suppressed. no longer used |
None
|
|
kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
|