예제 #1
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
예제 #2
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
예제 #3
0
def test_aggregated_LCIA_no_methods(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

    with pytest.raises(
            ValueError,
            match=
            'Need to pass a list of method identifiers to create an LCIA score database, none passed'
    ):
        DatabaseAggregator(up_db_name="techno_UP",
                           agg_db_name="techno_agg_LCIA",
                           database_type='LCIA',
                           method_list=[],
                           biosphere='biosphere',
                           overwrite=False)
예제 #4
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"
예제 #5
0
def test_aggregated_invalid_db_type(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

    with pytest.raises(
            ValueError,
            match=
            'other is not a valid database type, should be "LCI" or "LCIA"'):
        DatabaseAggregator(up_db_name="techno_UP",
                           agg_db_name="techno_agg_LCIA",
                           database_type='other',
                           method_list=[
                               data_for_testing['m1_name'],
                               data_for_testing['m2_name']
                           ],
                           biosphere='biosphere',
                           overwrite=False)
예제 #6
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