Esempio n. 1
0
def test_add_impact_scores_to_act_existing_db(data_for_testing):
    """Test adding agg dataset to existing database"""
    Database('agg').register()
    assert 'agg' in databases
    assert len(Database('agg')) == 0

    add_impact_scores_to_act(act_code='A',
                             agg_db='agg',
                             up_db='techno_UP',
                             selected_methods=[
                                 data_for_testing['m1_name'],
                                 data_for_testing['m2_name']
                             ],
                             biosphere='biosphere',
                             overwrite=False,
                             create_ef_on_the_fly=True,
                             create_agg_database_on_fly=False)

    assert 'agg' in databases
    assert len(Database('agg')) == 1
    assert ('agg', 'A') in Database('agg')
    act = get_activity(('agg', 'A'))
    act_bio_exc = {exc.input.key: exc['amount'] for exc in act.biosphere()}
    assert len(act_bio_exc) == 2

    lca = LCA({('techno_UP', 'A'): 1}, method=data_for_testing['m1_name'])
    lca.lci()
    lca.lcia()
    assert lca.score == act_bio_exc[(
        'biosphere', Method(data_for_testing['m1_name']).get_abbreviation())]
    lca.switch_method(method=data_for_testing['m2_name'])
    lca.lcia()
    assert lca.score == act_bio_exc[(
        'biosphere', Method(data_for_testing['m2_name']).get_abbreviation())]
Esempio n. 2
0
def test_aggregated_LCIA_single_method_augment_on_fly(data_for_testing):
    projects.set_current(data_for_testing['project'])
    assert "techno_UP" in databases
    assert "biosphere" in databases
    assert "techno_agg_LCIA" not in databases
    assert data_for_testing['m1_name'] in methods

    DatabaseAggregator(up_db_name="techno_UP",
                       agg_db_name="techno_agg_LCIA",
                       database_type='LCIA',
                       method_list=[data_for_testing['m1_name']],
                       biosphere='biosphere',
                       overwrite=False).generate()

    assert "techno_agg_LCIA" in databases
    assert len(Database("techno_agg_LCIA")) == len(Database("techno_UP"))

    lca_unit_process = LCA({("techno_UP", "A"): 1},
                           method=data_for_testing['m1_name'])
    lca_unit_process.lci()
    lca_unit_process.lcia()

    lca_LCIA = LCA({("techno_agg_LCIA", "A"): 1},
                   method=data_for_testing['m1_name'])
    lca_LCIA.lci()
    lca_LCIA.lcia()
    assert lca_unit_process.score == lca_LCIA.score
def test_add_unit_score_exchange_and_cf(data_for_testing):
    """ Augment methods and biosphere database for unit scores"""
    # Make sure project received with expected initial data (possibly delete
    # since this does not test the function, but rather the testing itself)
    projects.set_current(data_for_testing['project'])
    assert "biosphere" in databases
    method_name = data_for_testing['m1_name']
    assert method_name in methods

    assert len(Database('biosphere')) == 2
    loaded_biosphere_before = Database('biosphere').load()
    method = Method(method_name)
    loaded_method_before = method.load()
    assert len(loaded_method_before) == 2
    ef_code = method.get_abbreviation()
    assert ('biosphere', ef_code) not in loaded_biosphere_before

    # Augment method and biosphere database
    add_unit_score_exchange_and_cf(method=method_name, biosphere='biosphere')
    assert len(Database('biosphere')) == 3
    loaded_biosphere_after = Database('biosphere').load()
    assert ('biosphere', ef_code) in loaded_biosphere_after
    new_ef = get_activity(('biosphere', ef_code))
    assert new_ef['name'] == 'Unit impact for {}'.format(method_name)

    method = Method(method_name)
    loaded_method_after = method.load()
    assert len(loaded_method_after) == 3
    assert (('biosphere', ef_code), 1) in loaded_method_after
Esempio n. 4
0
def test_add_impact_scores_to_act_non_existing_db(data_for_testing):
    """Test adding agg dataset to non-existing database"""
    assert 'agg' not in databases

    with pytest.raises(ValueError):
        add_impact_scores_to_act(act_code='A',
                                 agg_db='agg',
                                 up_db='techno_UP',
                                 selected_methods=[
                                     data_for_testing['m1_name'],
                                     data_for_testing['m2_name']
                                 ],
                                 biosphere='biosphere',
                                 overwrite=False,
                                 create_ef_on_the_fly=True,
                                 create_agg_database_on_fly=False)

    add_impact_scores_to_act(act_code='A',
                             agg_db='agg',
                             up_db='techno_UP',
                             selected_methods=[
                                 data_for_testing['m1_name'],
                                 data_for_testing['m2_name']
                             ],
                             biosphere='biosphere',
                             overwrite=False,
                             create_ef_on_the_fly=True,
                             create_agg_database_on_fly=True)
    assert 'agg' in databases
    assert len(Database('agg')) == 1
    assert ('agg', 'A') in Database('agg')
    act = get_activity(('agg', 'A'))
    assert len([_ for _ in act.biosphere()]) == 2
def gsa(lca,
        rsca_summary,
        rscb_summary,
        number_of_trajectories=100,
        progressBar=False):
    # Binding RSC results and uncertainties
    A_indices = np.array(np.array(rsca_summary)[:, 1:3], int).tolist()
    B_indices = np.array(np.array(rscb_summary)[:, 1:3], int).tolist()
    tech_df = DataFrame.from_records(lca.tech_params)
    bio_df = DataFrame.from_records(lca.bio_params)
    # Dirty patch for elements without min and max values FIXME
    A_indices = [
        a for a in A_indices
        if len(tech_df[(tech_df.type == 1) & (tech_df.row == a[0])
                       & (tech_df.col == a[1])]) > 0
    ]
    B_indices = [
        b for b in B_indices
        if len(bio_df[(bio_df.type == 2) & (bio_df.row == b[0])
                      & (bio_df.col == b[1])]) > 0
    ]
    rev_activity, rev_product, rev_bio = lca.reverse_dict()
    morris_problem = {
        'num_vars': len(A_indices) + len(B_indices),
        'names': [],
        'bounds': [],
        'groups': None
    }
    morris_problem['names'] += [
        'Technosphere ' +
        str(Database(rev_activity[x[0]][0]).get(rev_activity[x[0]][1])) +
        ' x ' + str(Database(rev_product[x[1]][0]).get(rev_product[x[1]][1]))
        for x in A_indices
    ]
    morris_problem['names'] += [
        'Biosphere ' + str(Database(rev_bio[x[0]][0]).get(rev_bio[x[0]][1])) +
        ' x ' +
        str(Database(rev_activity[x[1]][0]).get(rev_activity[x[1]][1]))
        for x in B_indices
    ]
    # retrieve min and max values for populating morris_problem['bounds']
    tech_df = DataFrame.from_records(lca.tech_params)
    bio_df = DataFrame.from_records(lca.bio_params)
    morris_problem['bounds'] = [
        tech_df[(tech_df.type == 1) & (tech_df.row == a_ij[0]) &
                (tech_df.col == a_ij[1])][['minimum', 'maximum']].values[0]
        for a_ij in A_indices
    ] + [
        bio_df[(bio_df.type == 2) & (bio_df.row == b_ij[0]) &
               (bio_df.col == b_ij[1])][['minimum', 'maximum']].values[0]
        for b_ij in B_indices
    ]
    gsalca = ParallelGSALCA(lca.demand, lca.method, morris_problem)
    gsalca.gsa(lca.characterization_matrix.shape[0],
               A_indices,
               B_indices,
               number_of_trajectories=100,
               progressBar=progressBar)
    return gsalca.gsa_analyse()
Esempio n. 6
0
def test_aggregated_LCIA_multiple_methods_already_augmented(data_for_testing):
    projects.set_current(data_for_testing['project'])
    assert "techno_UP" in databases
    assert "biosphere" in databases
    assert "techno_agg_LCIA" not in databases
    assert data_for_testing['m1_name'] in methods
    assert data_for_testing['m2_name'] in methods
    assert len(methods) == 2

    add_all_unit_score_exchanges_and_cfs(biosphere='biosphere')
    agg_db = DatabaseAggregator(
        up_db_name="techno_UP",
        agg_db_name="techno_agg_LCIA",
        database_type='LCIA',
        method_list=[data_for_testing['m1_name'], data_for_testing['m2_name']],
        biosphere='biosphere',
        overwrite=False).generate()

    assert "techno_agg_LCIA" in databases
    assert len(Database("techno_agg_LCIA")) == len(Database("techno_UP"))

    lca_unit_process = LCA({("techno_UP", "A"): 1},
                           method=data_for_testing['m1_name'])
    lca_unit_process.lci()
    lca_unit_process.lcia()

    lca_LCIA = LCA({("techno_agg_LCIA", "A"): 1},
                   method=data_for_testing['m1_name'])
    lca_LCIA.lci()
    lca_LCIA.lcia()
    assert lca_unit_process.score == lca_LCIA.score
    score_in_B = lca_LCIA.biosphere_matrix[lca_LCIA.biosphere_dict[(
        'biosphere', Method(data_for_testing['m1_name']).get_abbreviation())],
                                           lca_LCIA.activity_dict[(
                                               "techno_agg_LCIA", "A")]]
    assert score_in_B == lca_LCIA.score

    lca_unit_process = LCA({("techno_UP", "A"): 1},
                           method=data_for_testing['m2_name'])
    lca_unit_process.lci()
    lca_unit_process.lcia()

    lca_LCIA = LCA({("techno_agg_LCIA", "A"): 1},
                   method=data_for_testing['m2_name'])
    lca_LCIA.lci()
    lca_LCIA.lcia()
    assert lca_unit_process.score == lca_LCIA.score
    score_in_B = lca_LCIA.biosphere_matrix[lca_LCIA.biosphere_dict[(
        'biosphere', Method(data_for_testing['m2_name']).get_abbreviation())],
                                           lca_LCIA.activity_dict[(
                                               "techno_agg_LCIA", "A")]]
    assert score_in_B == lca_LCIA.score
Esempio n. 7
0
def relink_exchanges_existing_db(db: bw.Database, old: str,
                                 other: bw.Database) -> None:
    """Relink exchanges after the database has been created/written.

    This means possibly doing a lot of sqlite update calls.
    """
    if old == other.name:
        print("No point relinking to same database.")
        return
    assert db.backend == "sqlite", "Relinking only allowed for SQLITE backends"
    assert other.backend == "sqlite", "Relinking only allowed for SQLITE backends"

    duplicates, candidates = {}, {}
    altered = 0

    for ds in other:
        key = activity_hash(ds, DEFAULT_FIELDS)
        if key in candidates:
            duplicates.setdefault(key, []).append(ds)
        else:
            candidates[key] = ds.key

    with sqlite3_lci_db.transaction() as transaction:
        try:
            # Only do relinking on external biosphere/technosphere exchanges.
            for i, exc in enumerate(
                    exc for act in db for exc in act.exchanges()
                    if exc.get("type") in {"biosphere", "technosphere"}
                    and exc.input[0] == old):
                # Use the input activity to generate the hash.
                key = activity_hash(exc.input, DEFAULT_FIELDS)
                if key in duplicates:
                    raise StrategyError(
                        format_nonunique_key_error(exc.input, DEFAULT_FIELDS,
                                                   duplicates[key]))
                elif key in candidates:
                    exc["input"] = candidates[key]
                    altered += 1
                exc.save()
                if i % 10000 == 0:
                    # Commit changes every 10k exchanges.
                    transaction.commit()
        except (StrategyError, ValidityError) as e:
            print(e)
            transaction.rollback()
    # Process the database after the transaction is complete.
    #  this updates the 'depends' in metadata
    db.process()
    print(
        "Relinked database '{}', {} exchange inputs changed from '{}' to '{}'."
        .format(db.name, altered, old, other.name))
Esempio n. 8
0
def import_example_data():
    db = Database("temp-example-db")
    if db.name not in databases:
        db.register()
    db.write(db_data)
    db.process()

    method = Method(("static GWP", ))
    if method.name not in methods:
        method.register()
    method.write(static_cfs)
    method.process()

    dynamic_method = DynamicIAMethod("static GWP")
    if dynamic_method.name not in dynamic_methods:
        dynamic_method.register()
    dynamic_method.write({x[0]: x[1] for x in static_cfs})
    dynamic_method.to_worst_case_method(("static GWP", "worst case"))

    dynamic_method = DynamicIAMethod("dynamic GWP")
    if dynamic_method.name not in dynamic_methods:
        dynamic_method.register()
    dynamic_method.write(dynamic_cfs)
    dynamic_method.to_worst_case_method(("dynamic GWP", "worst case"))

    dynamic_method = DynamicIAMethod("discounted dynamic GWP")
    if dynamic_method.name not in dynamic_methods:
        dynamic_method.register()
    dynamic_method.write(dynamic_discounted_cfs)
    dynamic_method.to_worst_case_method(
        ("discounted dynamic GWP", "worst case"))
Esempio n. 9
0
def initialize_market_model(db_name, activity_id, *args, steps=100):
    try:
        act = next(a for a in Database(db_name)
                   if a.get('activity').startswith(activity_id))
    except StopIteration:
        raise ValueError('Activity not found: %s' % activity_id)
    return Bw2McaMarketWeight(act, *args, steps=steps)
Esempio n. 10
0
def test_aggregated_LCI(data_for_testing):
    projects.set_current(data_for_testing['project'])
    assert "techno_UP" in databases
    assert "biosphere" in databases
    assert "techno_agg_LCI" not in databases
    assert data_for_testing['m1_name'] in methods

    agg_db = DatabaseAggregator(up_db_name="techno_UP",
                                agg_db_name="techno_agg_LCI",
                                database_type='LCI',
                                method_list=[data_for_testing['m1_name']],
                                biosphere='biosphere',
                                overwrite=False).generate()

    assert "techno_agg_LCI" in databases
    assert len(Database("techno_agg_LCI")) == len(Database("techno_UP"))

    lca_unit_process = LCA({("techno_UP", "A"): 1},
                           method=data_for_testing['m1_name'])
    lca_unit_process.lci()
    lca_unit_process.lcia()

    lca_LCI = LCA({("techno_agg_LCI", "A"): 1},
                  method=data_for_testing['m1_name'])
    lca_LCI.lci()
    lca_LCI.lcia()

    for act, col in lca_LCI.activity_dict.items():
        row = lca_LCI.product_dict[act]
        # Make sure production is 1
        assert lca_LCI.technosphere_matrix[row, col] == 1.0
        # Make sure other elements of the technosphere matrix are 0
        #assert lca_LCI.technosphere_matrix.sum(axis=0)[col]==1
    for ef, ef_row in lca_unit_process.biosphere_dict.items():
        up_lci = lca_unit_process.inventory.sum(axis=1)[ef_row]
        LCI_lci = lca_LCI.biosphere_matrix[lca_LCI.biosphere_dict[ef],
                                           lca_LCI.activity_dict[(
                                               "techno_agg_LCI", "A")]]
        assert up_lci == LCI_lci
    assert lca_unit_process.score == lca_LCI.score
Esempio n. 11
0
def test_add_unit_score_exchange_and_cf_act_exists(data_for_testing):
    projects.set_current(data_for_testing['project'])
    method_name = data_for_testing['m1_name']
    assert len(Database('biosphere')) == 2
    loaded_biosphere_before = Database('biosphere').load()
    method1_name = data_for_testing['m1_name']
    method1 = Method(method1_name)
    loaded_method1_before = method1.load()
    assert len(loaded_method1_before) == 2
    ef1_code = method1.get_abbreviation()
    assert ('biosphere', ef1_code) not in loaded_biosphere_before
    # Manually add ef to biosphere
    biosphere_data = Database('biosphere').load()
    biosphere_data[("biosphere", Method(method_name).get_abbreviation())] = {
        'name': 'Unit impact for {}'.format(method_name),
        'type': 'unit exchange',
        'unit': Method(method_name).metadata['unit']
    }
    Database('biosphere').write(biosphere_data)
    assert len(Database('biosphere')) == 3
    # run function, should not change the length of biosphere, but should add
    # cf to method
    add_unit_score_exchange_and_cf(method_name, biosphere='biosphere')
    loaded_method1_after = method1.load()
    assert len(loaded_method1_after) == 3
    assert len(Database('biosphere')) == 3
Esempio n. 12
0
def test_aggregated_bd_already_exists(data_for_testing, recwarn):
    projects.set_current(data_for_testing['project'])
    assert "techno_UP" in databases
    assert "biosphere" in databases
    assert "techno_agg_LCIA" not in databases

    Database('techno_agg_LCIA').register()
    agg_db = DatabaseAggregator(
        up_db_name="techno_UP",
        agg_db_name="techno_agg_LCIA",
        database_type='LCIA',
        method_list=[data_for_testing['m1_name'], data_for_testing['m2_name']],
        biosphere='biosphere',
        overwrite=False)
    w = recwarn[-1]
    assert str(
        w.message
    ) == "A database named techno_agg_LCIA already exists, set `overwrite` to True to overwrite"
Esempio n. 13
0
def data_for_testing():
    # Make sure we are starting off with an empty project
    assert not len(Database('techno_UP'))
    assert not len(Database('techno_LCI'))
    assert not len(Database('techno_LCIA'))
    assert not len(Database('biosphere'))
    assert not len(methods)

    biosphere = Database("biosphere")
    biosphere.register()
    biosphere.write({
        ("biosphere", "1"): {
            'categories': ['things'],
            'exchanges': [],
            'name': 'an emission',
            'type': 'emission',
            'unit': 'kg'
        },
        ("biosphere", "2"): {
            'categories': ['other things'],
            'exchanges': [],
            'name': 'another emission',
            'type': 'emission',
            'unit': 'kg'
        },
    })
    assert len(Database('biosphere')) == 2

    techno_UP = Database("techno_UP")
    techno_UP.register()
    techno_UP.write({
        ("techno_UP", "A"): {
            'exchanges': [
                {
                    'amount': 1.0,
                    'input': ('techno_UP', 'A'),
                    'type': 'production'
                },
                {
                    'amount': 10,
                    'input': ('techno_UP', 'B'),
                    'type': 'technosphere'
                },
                {
                    'amount': 100,
                    'input': ('biosphere', '1'),
                    'type': 'biosphere'
                },
                {
                    'amount': 1000,
                    'input': ('biosphere', '2'),
                    'type': 'biosphere'
                },
            ],
            'name':
            'activity A',
            'unit':
            'kg',
            'location':
            'GLO',
            'reference product':
            'A',
            'production amount':
            1
        },
        ("techno_UP", "B"): {
            'exchanges': [
                {
                    'amount': 1.0,
                    'input': ('techno_UP', 'B'),
                    'type': 'production'
                },
                {
                    'amount': 25,
                    'input': ('biosphere', '1'),
                    'type': 'biosphere'
                },
                {
                    'amount': 50,
                    'input': ('biosphere', '2'),
                    'type': 'biosphere'
                },
            ],
            'name':
            'activity B',
            'unit':
            'kg',
            'location':
            'GLO',
            'reference product':
            'B',
            'production amount':
            1
        },
    })
    m1_name = ('some', 'LCIA', 'method')
    m1 = Method(m1_name)
    m1.register()
    m1.metadata['unit'] = "Some impact unit"
    m1.write([
        (("biosphere", "1"), 1),
        (("biosphere", "2"), 10),
    ])

    m2_name = ('some other', 'LCIA', 'method')
    m2 = Method(m2_name)
    m2.register()
    m2.metadata['unit'] = "Some other impact unit"
    m2.write([
        (("biosphere", "1"), 100),
        (("biosphere", "2"), 42),
    ])
    print(projects.dir)
    yield {'project': projects.current, 'm1_name': m1_name, 'm2_name': m2_name}

    rmtree(projects.dir, ignore_errors=True)
Esempio n. 14
0
def lsa(lca, threshold=0.1):
    '''
    Computes relative sensitivity coefficients (RSC) according to (Heijungs and Kleijn, 2001) and (Sakai and Yokoyama, 2002), used in (Wei et al., 2015) for performing a local sensitivity analysis.
    Returns an array of two datasets of RSC, respectively for the technosphere and the biosphere matrices, where each record contains:
     - impact indix
     - row index in the matrix
     - column index in the matrix
     - value of RSC
     - label of the row (respectively activity and biosphere)
     - label of the column (respectively product and activity)

    Only RSC above the given threshold will be keeped.

    References:
     Heijungs, R.; Kleijn, R. Numerical approaches towards life cycle interpretation five examples. Int. J. Life Cycle Assess. 2001, 6, 141−148.
     Sakai, S.; Yokoyama, K. Formulation of sensitivity analysis in life
cycle assessment using a perturbation method. Clean Technol. Environ.
Policy 2002, 4, 72−78
     W. Wei, P. Larrey Lassalle, T. Faure, N. Dumoulin, P. Roux, J.D. Mathias. How to conduct a proper sensitivity analysis in life cycle assessment: Taking into account correlations within LCI data and interactions within the LCA calculation model Environmental Science & Technology 49 (1), 2015 http://pubs.acs.org/doi/abs/10.1021/es502128k
    '''
    lca.lci()
    lca.lcia()
    m_a = lca.technosphere_matrix
    m_b = lca.biosphere_matrix
    m_q = lca.characterization_matrix
    h = lca.characterized_inventory.sum(axis=1)
    s = lca.supply_array
    m_lambda = spsolve(m_a.transpose(), m_b.transpose()).transpose()
    m_ql = m_q.dot(m_lambda)
    rev_activity, rev_product, rev_bio = lca.reverse_dict()
    m_as = m_a.multiply(s)
    rsca = [
        -m_as.multiply(1 / hk).multiply(m_ql[k, :]).tocsr()
        for k, hk in enumerate(h)
    ]
    rscb = [
        m_b.multiply(1 / hk).multiply(m_q[k, :].T).multiply(s).tocsr()
        for k, hk in enumerate(h)
    ]
    rsca_filtered = [[k, x[0], x[1], rscak[x[0], x[1]]]
                     for k, rscak in enumerate(rsca)
                     for x in np.array(rscak.nonzero()).T
                     if abs(rscak[x[0], x[1]]) > threshold]
    rsca_sorted = sorted(rsca_filtered, key=lambda x: abs(x[3]), reverse=True)
    rsca_summary = [
        x + [
            str(Database(rev_activity[x[1]][0]).get(rev_activity[x[1]][1])),
            str(Database(rev_product[x[2]][0]).get(rev_product[x[2]][1]))
        ] for x in rsca_sorted
    ]
    rscb_filtered = [[k, x[0], x[1], rscbk[x[0], x[1]]]
                     for k, rscbk in enumerate(rscb)
                     for x in np.array(rscbk.nonzero()).T
                     if abs(rscbk[x[0], x[1]]) > threshold]
    rscb_sorted = sorted(rscb_filtered, key=lambda x: abs(x[3]), reverse=True)
    rscb_summary = [
        x + [
            str(Database(rev_bio[x[1]][0]).get(rev_bio[x[1]][1])),
            str(Database(rev_activity[x[2]][0]).get(rev_activity[x[2]][1]))
        ] for x in rscb_sorted
    ]
    return [rsca_summary, rscb_summary]
Esempio n. 15
0
 def __init__(self, biosphere='biosphere3'):
     self.db = Database(biosphere)
     self.method = Method(self.name)
Esempio n. 16
0
def data_for_testing():
    # Make sure we are starting off with an empty project
    assert not len(Database('test_db'))
    assert not len(Database('biosphere'))

    biosphere = Database("biosphere")
    biosphere.register()
    biosphere.write({
        ("biosphere", "Transformation, from 1"): {
            'categories': ('natural resource', 'land'),
            'exchanges': [],
            'name': 'Transformation, from 1',
            'type': 'natural resource',
            'unit': 'square meter'
        },
        ("biosphere", "Transformation, from 2"): {
            'categories': ('natural resource', 'land'),
            'exchanges': [],
            'name': 'Transformation, from 2',
            'type': 'natural resource',
            'unit': 'square meter'
        },
        ("biosphere", "Transformation, to 1"): {
            'categories': ('natural resource', 'land'),
            'exchanges': [],
            'name': 'Transformation, to 1',
            'type': 'natural resource',
            'unit': 'square meter'
        },
        ("biosphere", "Transformation, to 2"): {
            'categories': ('natural resource', 'land'),
            'exchanges': [],
            'name': 'Transformation, to 2',
            'type': 'natural resource',
            'unit': 'square meter'
        },
        ("biosphere", "Something else"): {
            'categories': ['air'],
            'exchanges': [],
            'name': 'Something else to air, in m3',
            'type': 'emission',
            'unit': 'kg'
        },
    })
    assert len(Database('biosphere')) == 5

    test_db = Database("test_db")
    test_db.register()
    test_db.write({
        ("test_db", "X"): {
            'name':
            'X',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
            ],
        },
        ("test_db", "A"): {
            'name':
            'A',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'A'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1,
                    'formula': 'some_formula'
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                    'loc': 1.0,
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1),
                    'scale': 0.1,
                },
            ],
        },
        ("test_db", "B"): {
            'name':
            'B',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'B'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1),
                    'scale': 0.1,
                },
            ],
        },
        ("test_db", "C"): {
            'name':
            'C',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'C'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 4.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(4.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'Something else, to air',
                    'unit': 'kilogram',
                    'amount': 100.0,
                    'input': ("biosphere", "Something else"),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(100.0),
                    'scale': 0.1
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1),
                    'scale': 0.1,
                },
            ],
        },
        ("test_db", "D"): {
            'name':
            'D',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'expected results': {
                'strategy': 'inverse',
                'ratio': 2,
                'balance': 20
            },
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'D'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 4.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1),
                    'scale': 0.1,
                },
            ],
        },
        ("test_db", "G"): {
            'name':
            'G',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'G'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 0,
                },
            ],
        },
        ("test_db", "H"): {
            'name':
            'H',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'expected results': {
                'strategy': 'set_static',
                'ratio': 1,
                'balance': 0
            },
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'H'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
            ],
        },
        ("test_db", "I"): {
            'name':
            'I',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'expected results': {
                'strategy': 'skip',
                'ratio': None,
                'balance': -20
            },
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'I'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
            ],
        },
        ("test_db", "J"): {
            'name':
            'J',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'J'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1.0),
                    'scale': 0.1
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 2,
                    'loc': np.log(2.0),
                    'scale': 0.1
                },
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'X'),
                    'type': 'technosphere',
                    'uncertainty type': 2,
                    'loc': np.log(1),
                    'scale': 0.1,
                },
            ],
        },
        ("test_db", "K"): {
            'name':
            'K',
            'unit':
            'kilogram',
            'location':
            'GLO',
            'reference product':
            'some product',
            'production amount':
            1,
            'activity type':
            'ordinary transforming activity',
            'expected results': {
                'strategy': 'skip',
                'ratio': None,
                'balance': 0
            },
            'exchanges': [
                {
                    'name': 'some product',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('test_db', 'K'),
                    'type': 'production',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, from 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, from 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, from 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 1',
                    'unit': 'kilogram',
                    'amount': 1.0,
                    'input': ('biosphere', 'Transformation, to 1'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
                {
                    'name': 'Transformation, to 2',
                    'unit': 'kilogram',
                    'amount': 2.0,
                    'input': ('biosphere', 'Transformation, to 2'),
                    'type': 'biosphere',
                    'uncertainty type': 0,
                },
            ],
        },
    })
    yield {'project': projects.current}

    rmtree(projects.dir, ignore_errors=True)