Data formats


Exchanges with temporal distributions

Both inventory dataset inputs and biosphere flows (i.e. exchanges) can be distributed in time, can occur both before and after the inventory dataset itself and be in absolute or relative time. Their distribution is specified using the Temporal Distribution object. and are stored in brightway2 using the key temporal distribution:

"exchanges": [
        "amount": 5,
        "temporal distribution": TemporalDistribution(np.array([ 0,  1,  2,  3,  4],dtype='timedelta64[Y]') ,np.array([1.0, 1.0, 1.0, 1.0, 1.0])),

See the example for a real-world implementation.

The sum of all amounts in the temporal distribution should equal the total exchange amount. This is checked automatically during the LCI solving.

Impact Assessment

Dynamic impact assessment methods

Brightway2-temporalis supports three types of characterization factors for use in dynamic LCA:

  1. Static characterization factors, i.e. those which do not change over time.
  2. Dynamic characterization factors, i.e. those whose value changes over time, but whose impact still occurs at the time of emission.
  3. Extended dynamic characterization factors, i.e. CFs whose impact is allocated over time using something like atmospheric decay rates.

Impact assessment methods must be defined as a DynamicIAMethod, not a normal LCIA Method, even if all CFs are static (see Impact Assessment methods).

The data format for dynamic IA methods is:

    ("biosphere", "flow"): number or python_function_as_string


This data format is different than the normal method data; it is a dictionary, not a list.

Static characterization factors

Static characterization factors can be defined as usual, e.g.

    ("biosphere", "n2o"): 296,
    ("biosphere", "chloroform"): 30,

Dynamic characterization factors

Dynamic characterization factors are realized with pure python functions, e.g.

def silly_random_cf(passed_datetime):
    import random
    return random.random()

def increasing_co2_importance(passed_datetime):
    """Importance of CO2 doubles every twenty years from 2010"""
    CF = 1.
    cutoff = datetime.datetime(2010, 1, 1)
    return max(1, 2 ** ((passed_datetime - cutoff).days / 365.24 / 20) * CF)

def days_since_best_movie_evar(passed_datetime):
    return (passed_datetime - datetime.datetime(2011, 6, 23)).days

However, there are some things to bear in mind with dynamic characterization functions:

  • Dynamic characterization functions must take a datetime as the single input, and return a single numeric characterization factor.
  • You will need to import whatever you need in the body of the function; don’t assume anything other than the standard library is in the current namespace.
  • These functions must be stored as unicode strings, not actual python code:
    ("my", "function"): """def some_func(datetime):
from datetime import timedelta + timedelta(100)"""

This can be a bit confusing. See the examples and the built-in climate functions for a real-world implementation.

These function strings will be executed using exec. Don’t accept dynamic characterization function code from strange men in dark alleyways.

Extended dynamic characterization factors

Extended dynamic characterization functions don’t return a single number, but rather a list of characterization factors allocated over time.

Returned CFs must be named tuples with field names dt, and amount.

def spread_over_a_week(datetime):
    """Spread impact over a week"""
    from datetime import timedelta
    import collections
    return_tuple = collections.namedtuple('return_tuple', ['dt', 'amount'])
    return [return_tuple(datetime + timedelta(days=x), 1 / 7.) for x in range(7)]

See also functions in the examples.

Aside from the return format, they are identical to normal dynamic characterization factors, and have the same restrictions.