QuantityRefs

antelope.refs.quantity_ref module

Quantity Reference

A couple things really bother me about this spec:

1- the routine for doing LCIA (antelope_core.implementations.quantity.do_lcia()) seems like it should be generic, but it depends on the LciaResult implementation, which is irretrievably part of the core and NOT part of the spec.

1a- That means the interface currently lacks a specification for LCIA Results, which seems important

2- The signatures for these methods are delicate:

quantity_ref.cf(flow, context=?, locale=?) –> float quantity_ref.quantity_relation(flowable, ref_quantity, context=?, locale=?) –> QuantityConversion quantity_ref.characterize(flowable, ref_quantity, value, context=?, locale=?) –> CF

exception antelope.refs.quantity_ref.RefQuantityRequired

Bases: Exception

exception antelope.refs.quantity_ref.ConversionError

Bases: Exception

antelope.refs.quantity_ref.convert(quantity, from_unit=None, to=None)

Perform unit conversion within a quantity, using a ‘UnitConversion’ table stored in the object properties. For instance, if the quantity name was ‘mass’ and the reference unit was ‘kg’, then quantity.convert(‘lb’) would[should] return 0.4536… quantity.convert(‘lb’, to=’ton’) should return 0.0005

This function requires that the quantity have a ‘UnitConversion’ property that works as a dict, with the unit names being keys. The format of the dict is that all entries should equal the same amount as each other. For instance, if the quantity was mass, then the following would be equivalent:

quantity[‘UnitConversion’] = { ‘kg’: 1, ‘lb’: 2.204622, ‘ton’: 0.0011023, ‘t’: 0.001 } quantity[‘UnitConversion’] = { ‘kg’: 907.2, ‘lb’: 2000.0, ‘ton’: 1, ‘t’: 0.9072 }

If the quantity’s reference unit is missing from the dict, it is set to 1, but it is not strictly required that the reference unit equals 1 in the dict.

If the quantity is missing a unit conversion property, raises NoUnitConversionTable. If the quantity does have such a table but one of the specified units is missing from it, raises KeyError

Parameters:
  • quantity – something with a __getitem__ and a unit() function

  • from_unit – unit to convert from (default is the reference unit)

  • to – unit to convert to (default is the reference unit)

Returns:

a float indicating how many to_units there are in one from_unit

class antelope.refs.quantity_ref.QuantityRef(external_ref, query, reference_entity=None, masquerade=None, **kwargs)

Bases: EntityRef

Quantities can lookup:

property unit
property name
serialize(**kwargs)
Parameters:

kwargs – ‘domesticate’ has no effect- refs can’t be domesticated

Returns:

property is_lcia_method
convert(from_unit=None, to=None)
quantity_terms()

This is a little kludgey– but requires agreement on what terms are considered synonymous. :return:

has_lcia_engine()
property is_local
is_canonical(other)
flowables(**kwargs)
factors(**kwargs)
cf(flow, ref_quantity=None, **kwargs)
characterize(flowable, ref_quantity, value, **kwargs)

Enter a characterization factor for the current object (query quantity) w.r.t. the specified reference quantity. The characterization value should report the amount of the query quantity (quantity being characterized) that equals a unit of the reference quantity (used to measure the flow). The following is correct, for mass in kg and volume in m3:

>>> mass.characterize('water', 'volume', 1000.0)
"I {characterize} the [mass] of [water] in a unit [volume] to be 1000.0".

The thing being measured is mass. The flow’s reference quantity is volume. a unit reference quantity of water is characterized as 1000.0 kg.

The following is NOT correct, but it may SEEM more semantically natural:

>>> mass.characterize('water', 'volume', 0.001)
"I {characterize} the unit [mass] of [water] to have a [volume] of 0.001"

The unit of the flow is measured in terms of the query quantity. But we don’t yet know the size of a unit of the query quantity because that is what is in fact being characterized.

To see this borne out, imagine using characterize() in its most natural way, for LCIA:

>>> gwp.characterize('methane', 'mass', 25)
"I characterize the GWP of methane in a unit mass to be 25" <<--- CORRECT
{I characterize the unit GWP of methane to have a mass of 0.04} <<--- plainly wrong

REALLY, the MOST natural way to characterize is to use FlowRef.characterize():

>>> m = q.get('methane')
>>> m.unit
'kg'
>>> m.characterize(gwp, 25, context='to air')

generations may determine whether this was a terrible mistake.

Parameters:
  • flowable

  • ref_quantity

  • value

  • kwargs

Returns:

get_factors(flows, **kwargs)
do_lcia(inventory, **kwargs)
quantity_relation(flowable, ref_quantity=None, context=None, locale='GLO', **kwargs)
norm(**kwargs)