Skip to content

catalog_query

Query Interface -- used to operate catalog refs

CatalogQuery

Bases: BasicInterface, IndexInterface, BackgroundInterface, ExchangeInterface, QuantityInterface

A CatalogQuery is a class that performs any supported query against a supplied catalog. Supported queries are defined in the lcatools.interfaces, which are all abstract. Implementations also subclass the abstract classes.

This reduces code duplication (all the catalog needs to do is provide interfaces) and ensures consistent signatures.

The arguments to a query should always be text strings, not entities. When in doubt, use the external_ref.

The EXCEPTION is the bg_lcia routine, which works best (auto-loads characterization factors) if the query quantity is a catalog ref.

The catalog's resolver performs fuzzy matching, meaning that a generic query (such as 'local.ecoinvent') will return both exact resources and resources with greater semantic specificity (such as 'local.ecoinvent.3.2.apos'). All queries accept the "strict=" keyword: set to True to only accept exact matches.

bg_lcia(process, query_qty=None, ref_flow=None, **kwargs)

returns an LciaResult object, aggregated as appropriate depending on the interface's privacy level. This can only be implemented at the query level because it requires access to lci()

Parameters:

Name Type Description Default
process

must have a background interface

required
query_qty

an operable quantity_ref, or catalog default may be used if omitted

None
ref_flow
None
kwargs
{}

Returns:

Type Description

cascade(origin)

Generate a new query for the specified origin. Enables the query to follow the origins of foreign objects found locally. If not found locally, the current query is used instead

Parameters:

Name Type Description Default
origin
required

Returns:

Type Description

characterize(flowable, ref_quantity, query_quantity, value, context=None, location='GLO', **kwargs)

This is an Xdb innovation: we do not need or want an implementation-specific characterize routine-- just like with make_ref, the point of the catalog query is to localize all characterizations to the LciaEngine.

We simply duplicate the characterize() code from the core QuantityImplementation

Parameters:

Name Type Description Default
flowable
required
ref_quantity
required
query_quantity
required
value
required
context
None
location
'GLO'
kwargs
{}

Returns:

Type Description

clear_seen_characterizations(quantity)

An ugly hack to deal with the absolutely terrible way we are working around our slow-ass Qdb implementation the proper solution is for qdb lookup to be local, fast and correct, so as to not require caching at all.

Parameters:

Name Type Description Default
quantity
required

Returns:

Type Description

get(eid, **kwargs)

Retrieve entity by external Id. This will take any interface and should keep trying until it finds a match. It first matches canonical entities, because that is the point of canonical entities.

Parameters:

Name Type Description Default
eid

an external Id

required

Returns:

Type Description

resolve(itype=INTERFACE_TYPES, strict=False)

Secure access to all known resources but do not answer any query

Parameters:

Name Type Description Default
itype

default: all interfaces

INTERFACE_TYPES
strict

[False]

False

Returns:

Type Description

synonyms(item, **kwargs)

Potentially controversial? include canonical as well as provincial synonyms for catalog queries??

Parameters:

Name Type Description Default
item
required
kwargs
{}

Returns:

Type Description

sys_lcia(process, query_qty, observed=None, ref_flow=None, **kwargs)

Reimplement this to detect pydantic LciaResult models and de-reference them

Parameters:

Name Type Description Default
process
required
query_qty
required
observed
None
ref_flow
None
kwargs
{}

Returns:

Type Description