Пример #1
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"))
Пример #2
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)
Пример #3
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)