exchanges
DissipationExchange
Bases: ExchangeValue
Composition / Dissipation mechanics can be encapsulated entirely into the exchange object- the problem is reduced to a serialization / deserialization problem.
Composition / Dissipation probably conflicts with Allocation, i.e. it is not supported to add a dissipation factor to an AllocatedExchange.
This is a problem because the allocated exchange is also the secret sauce being used to implement processflow parameters- and would presumably be the same mechanism to implement dissipation parameters.
best solution would be to fold reference spec higher up in inheritance- also need an ironclad way to determine the input flow (or to not support dissipation for processes with more than one reference flow) and simply make flow_quantity not None be the key to interpret the exchange value as a dissipation rate. except that I don't want to squash the non-dissipation exchange value.
Maybe I should not be worrying about this right now.
content(ref_flow=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_flow |
a flow LcEntity |
None
|
Returns:
Type | Description |
---|---|
|
Exchange
Bases: object
An exchange is an affiliation of a process, a flow, and a direction. An exchange does not include an exchange value- though presumably a valued exchange would be a subclass.
An exchange may specify a uuid of a terminating process; tests for equality will distinguish differently-terminated flows. (ecoinvent)
lkey
property
Long key, for testing equality with exchange refs whose terminations may be tuples
Returns:
Type | Description |
---|---|
|
__init__(process, flow, direction, termination=None, comment=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
process |
|
required | |
flow |
|
required | |
direction |
|
required | |
termination |
external id of terminating process or None (note: this is uuid for ecospold2) |
None
|
|
comment |
documentary information about the exchange |
None
|
Returns:
Type | Description |
---|---|
|
is_allocated(reference)
Stub for compatibility
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference |
|
required |
Returns:
Type | Description |
---|---|
|
ExchangeValue
Bases: Exchange
An ExchangeValue is an exchange with a single value (corresponding to unallocated exchange value) plus a dict of values allocated to different reference flows.
value
property
writable
unallocated value
Returns:
Type | Description |
---|---|
|
values
property
Some Good Question here about what to use for the key part- can't go wrong with str
Returns:
Type | Description |
---|---|
|
__getitem__(item)
Implements the exchange relation-- computes the quantity of self that is exchanged for a unit of item, according to whatever allocation is specified for the exchange or process. self and item must share the same process (tested as external_ref to allow entities and references to interoperate)
If self is a reference exchange, the exchange relation will equal either 0.0 or 1.0 depending on whether item is self or a different reference. FOR NOW: Reference exchanges cannot
When an exchange is asked for its value with respect to a particular reference, lookup the allocation in the value_dict. IF there is no value_dict, then the default _value is returned AS LONG AS the process has only 0 or 1 reference exchange.
Allocated exchange values should add up to unallocated value. When using the exchange values, don't forget to normalize by the chosen reference flow's input value (i.e. utilize an inbound exchange when computing node weight or when constructing A + B matrices)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
|
required |
Returns:
Type | Description |
---|---|
|
__setitem__(key, value)
Used to set custom or "causal" allocation factors. Here the allocation should be specified as a portion of the unallocated exchange value to be allocated to the reference. The entered values will be normalized by the reference exchange's reference value when they are retrieved, to report the exchange value per unit of reference.
This approach makes consistency of causal allocation easy to check: the allocation factors should simply add up to the unallocated factor. (this does not apply in ecoinvent, where the different co-products are pre-normalized and basically co-inhabiting the same process, and the unallocated factors are not present. The normalization must still occur, though, because ecoinvent still does use the sign of reference exchanges to indicate directionality)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
a reference exchange |
required | |
value |
|
required |
Returns:
Type | Description |
---|---|
|
from_allocated(allocated, reference)
classmethod
Use to flatten an allocated process inventory into a standalone inventory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
allocated |
|
required | |
reference |
a reference exchange |
required |
Returns:
Type | Description |
---|---|
|
is_allocated(key)
Report whether the exchange is allocated with respect to a given reference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
an exchange |
required |
Returns:
Type | Description |
---|---|
|
remove_allocation(key)
Removes allocation if it exists; doesn't complain if it doesn't.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
a reference exchange. |
required |
Returns:
Type | Description |
---|---|
|
MarketExchange
Bases: Exchange
A MarketExchange is an alternative implementation of an ExchangeValue that handles the multiple-input process case, i.e. when several processes produce the same product, and the database must balance them according to some apportionment of market value or production volume.
The client code has to explicitly create a market exchange. How does it know to do that? in the case of ecospold2, it has to determine whether the process has duplicate [non-zero] flows with activityLinkIds.
In other cases, it will be foreground / linker code that does it.
Add market suppliers using dictionary notation. Use exchange values or production volumes, but do it consistently. The exchange value returned is always the individual supplier's value divided by the sum of values.