2017-01-04 19 views
0

私はbw2の新機能を使用しています。データベースを使用せずに手動で定義されたインベントリとLCIAメソッドを使用するだけで簡単なLCAを作成しようとしています。第11章の例の値を「ライフサイクルアセスメントの計算構造」の本から引用しました。brightway2で非常に簡単なLCIAメソッドを作成する

私は、インベントリを作成して、LCI計算を実行することができた:

t_db = Database("testdb") 

t_db.write({ 
    ("testdb", "Electricity production"):{ 
     'name':'Electricity production', 
     'unit': 'kWh', 
     'exchanges': [{ 
       'input': ('testdb', 'Fuel production'), 
       'amount': 2, 
       'unit': 'kg', 
       'type': 'technosphere' 
      },{ 
       'input': ('testdb', 'Carbon dioxide'), 
       'amount': 1, 
       'unit': 'kg', 
       'type': 'biosphere' 
      },{ 
       'input': ('testdb', 'Sulphur dioxide'), 
       'amount': 0.1, 
       'unit': 'kg', 
       'type': 'biosphere' 
      },{ 
       'input': ('testdb', 'Electricity production'), #important to write the same process name in output 
       'amount': 10, 
       'unit': 'kWh', 
       'type': 'production' 
      }] 
     }, 
    ('testdb', 'Fuel production'):{ 
     'name': 'Fuel production', 
     'unit': 'kg', 
     'exchanges':[{ 
       'input': ('testdb', 'Carbon dioxide'), 
       'amount': 10, 
       'unit': 'kg', 
       'type': 'biosphere' 
      },{ 
       'input': ('testdb', 'Sulphur dioxide'), 
       'amount': 2, 
       'unit': 'kg', 
       'type': 'biosphere' 
      },{ 
       'input': ('testdb', 'Crude oil'), 
       'amount': -50, 
       'unit': 'kg', 
       'type': 'biosphere' 
      },{ 
       'input': ('testdb', 'Fuel production'), 
       'amount': 100, 
       'unit': 'kg', 
       'type': 'production' 
      }] 
    }, 
    ('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'}, 
    ('testdb', 'Sulphur dioxide'):{'name': 'Sulphur dioxide', 'unit':'kg', 'type': 'biosphere'}, 
    ('testdb', 'Crude oil'):{'name': 'Crude oil', 'unit':'kg', 'type': 'biosphere'} 

    }) 

functional_unit = {t_db.get("Electricity production") : 1000} 
lca = LCA(functional_unit) 
lca.lci() 
print(lca.inventory) 

私は(簡単にするために1に設定されているすべてのCFSとの)仮想LCIAメソッドを作成するときしかし、問題は開始します。これは私が使用したコードですが、明らかに動作しません。重要な問題は、取引所を在庫からLCIAメソッドにリンクさせることができないように思われる。

myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0], 
     [('biosphere', 'Sulphur dioxide'), 1.0], 
     [('biosphere', 'Crude oil'), 1.0]] 

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint') 
Method(method_key).validate(myLCIAdata) #returns "TRUE" 
Method(method_key).register() 
Method(method_key).write(myLCIAdata) 
Method(method_key).load() #check everything works 
lca = LCA(functional_unit, method_key) #run LCA calculations again with method 
lca.characterized_inventory 

結果がそう<3x2 sparse matrix of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format> 空行列です。私が何を作っているのか?既存のデータベースと同じように、各交換用の一意の識別子を取得する必要がありますか?私はこのサイトのbw2チュートリアル、ドキュメンテーション、および以前の質問をチェックしましたが、答えは見つかりませんでした。前もって感謝します。

答えて

0

あなたは非常に近いです。あなたのCFの定義では、あなたは次のようにします。

最初の行を取る
myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0], 
       [('biosphere', 'Sulphur dioxide'), 1.0], 
       [('biosphere', 'Crude oil'), 1.0]] 

を、これはデータベースbiosphereに、コードCarbon dioxideと流れがあるだろうことを意味します。しかし、あなたはtestdbという名前のデータベースにすべてを入れ、biosphereデータベースを持っていない:

('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'}, 

をので、特性要因のリストに右のデータベース名を使用するか、または別の生物圏のデータベースを作成するのいずれかbiosphereと呼ばれます。その代わりに、これも

注:

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint') 
Method(method_key).validate(myLCIAdata) #returns "TRUE" 
Method(method_key).register() 
Method(method_key).write(myLCIAdata) 

あなたがこれを行う必要があります。

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint') 
my_method = Method(method_key) 
my_method.validate(myLCIAdata) 
my_method.register() 
my_method.write(myLCIAdata) 

(あなたのコードが壊れていないが、よりエレガントなことができます)。

+0

ありがとうございます。私は間違いを見て、私はLCIAメソッド定義の "生物圏"の部分に混乱していましたが、代わりにそれがデータベースを指すフローのタイプだと思いました。 'myLCIAdata = [[( 'testdb'、 'C​​arbon dioxide')、1.0] ...' lca.lcia() 'を追加して、コードを修正しました。 (エレガンスポイントを得た、提案のおかげで)。 – Bax

関連する問題