Background Interface¶
The basic interface is included in the
The Background interface is a hybrid interface that can be produced from the combination of a complete index and exchange interface for a self-contained database (terminate() and inventory() are required, and the resulting matrix must be invertible)
- The default implementation is a dumb proxy, for use when archives provide LCI information over an inventory interface.
Here the proxy just ‘masquerades’ the contents to answer background instead of inventory queries. Though it does not thrown an error, it is a conceptual violation for one data source to supply both inventory and background interfaces using the proxy implementation.
The LcBackground class, added with the antelope_lcbackground plugin, provides an engine that partially orders the datasets in an ecoinvent-style unit process database and stores the results in a static set of scipy sparse arrays, in a manner consistent with the JIE disclosure paper (augmented with the full LCIDB).
The (as yet hypothetical) antelope_brightway2 plugin can provide index, inventory, and background data for a bw2 database.
More plugins are yet imagined.
- exception antelope.interfaces.ibackground.BackgroundRequired¶
Bases:
Exception
- class antelope.interfaces.ibackground.BackgroundInterface¶
Bases:
AbstractQuery
BackgroundInterface core methods
- check_bg(reset=False, **kwargs)¶
Trivial method to force creation of background / check if it exists. Also provides a way to reset / pass keyword arguments to the background engine. :param reset: [False] whether to re-create the matrix :param kwargs: :return:
- setup_bm(query)¶
Utility hook for configuring a background from an index + exchange query :param query: :return:
- exterior_flows(direction=None, search=None, **kwargs)¶
Yield a list of ExteriorFlows or cutoff flows, which serialize to flow, direction Ultimately this will be origin, flow ref, direction, context. Context=None are cutoffs.
- Parameters:
direction
search
- Returns:
ExteriorFlows
- consumers(process, ref_flow=None, **kwargs)¶
Generate Reference Exchanges which consume the query process, i.e. columns in Af / Ad having nonzero entries in the row corresponding to the query process. :param process: :param ref_flow: :param kwargs: :return:
- emitters(flow, direction=None, context=None, **kwargs)¶
Generate Reference exchanges which include the designated exterior flow in their inventories, optionally filtering by context :param flow: :param direction: :param context: :param kwargs: :return:
- dependencies(process, ref_flow=None, **kwargs)¶
Interior exchanges for a given node
- Parameters:
process
ref_flow
- Returns:
- emissions(process, ref_flow=None, **kwargs)¶
Exterior exchanges for a given node that are terminated to elementary context
- Parameters:
process
ref_flow
- Returns:
- cutoffs(process, ref_flow=None, **kwargs)¶
Exterior Intermediate Flows- exchanges with null termination or terminated to non-elementary context
- Parameters:
process
ref_flow
- Returns:
- lci(process, ref_flow=None, **kwargs)¶
returns aggregated LCI as a list of exchanges (privacy permitting) :param process: :param ref_flow: :return:
- sys_lci(demand, **kwargs)¶
Perform LCI on an arbitrary demand vector, which should be supplied as an iterable of UnallocatedExchange models whose terminations can be found in the background database.
Terminations to foreground and background are allowed. Exterior flows are just passed through but contexts may be transformed in the process and thus should be excluded. See bg_lcia() for recommended implementation.
sys_lci(process_ref.dependencies()) + process_ref.emissions() should equal process_ref.lci() although the sum of iterables would not be straightforward to compute… the correct approach is: sys_lci(itertools.chain(process_ref.dependencies(), process_ref.emissions(), process_ref.cutoffs()))
sys_lci(process_ref.inventory()) should equal process_ref.lci() directly, up to a normalization, assuming the individual exchanges are properly terminated. :param demand: an iterable of exchanges with terminations that can be found in the background database. :param kwargs: :return:
- sys_lcia(process, query_qty, observed=None, ref_flow=None, **kwargs)¶
- Parameters:
process
query_qty
observed
ref_flow
kwargs
- Returns:
- foreground_flows(search=None, **kwargs)¶
Yield a list of Reference Exchanges that make up the foreground (e.g. rows/columns of Af). Serialization should include origin, process external ref, flow external ref, direction.
- Parameters:
search
- Returns:
ProductFlows (should be ref-ized somehow)
- background_flows(search=None, **kwargs)¶
Yield a list of Reference Exchanges that make up the background (e.g. rows/columns of Ad) Serialization should include origin, process external ref, flow external ref, direction.
- Parameters:
search
- Returns:
ProductFlows (should be ref-ized somehow)
- foreground(process, ref_flow=None, **kwargs)¶
Returns an ordered list of exchanges for the foreground matrix Af for the given process and reference flow- the first being the named process + reference flow, and every successive one having a named termination, so that the exchanges could be linked into a fragment tree.
This technically should require exchange interface as well as values :param process: :param ref_flow: :return:
- is_in_scc(process, ref_flow=None, **kwargs)¶
Returns True if the identified productflow is part of a strongly connected component (including the background) :param process: :param ref_flow: :param kwargs: :return:
- is_in_background(process, ref_flow=None, **kwargs)¶
- Parameters:
process
ref_flow
kwargs
- Returns:
- ad(process, ref_flow=None, **kwargs)¶
returns foreground-aggregated dependencies on the background as a list of exchanges :param process: :param ref_flow: :return:
- bf(process, ref_flow=None, **kwargs)¶
returns foreground-aggregated emissions as a list of exchanges :param process: :param ref_flow: :return:
- deep_lcia(process, quantity_ref, ref_flow=None, **kwargs)¶
Performs LCIA at the A-matrix level :param process: :param quantity_ref: quantity’s factors must be accessible to the background’s index query :param ref_flow: :param kwargs: :return: