Brightway2:如何按名称检索特定的 activity
Brightway2: how to retrieve a specific activity by name
我是新手所以请耐心等待。
我已经初始化了一个新的 BW2 安装并添加了一个 Ecoinvent 数据库(为清楚起见修剪了一些输出):
>>> from brightway2 import bw2setup, Database, SingleOutputEcospold2Importer
>>> bw2setup()
>>> ei = SingleOutputEcospold2Importer('/path/to/datasets', 'ei3.4 cutoff')
>>> ei.apply_strategies()
>>> ei.statistics()
14889 datasets
520205 exchanges
0 unlinked exchanges
>>> ei.write_database()
到目前为止,一切顺利(特别注意加载的数据集数量)。但是现在-我该如何使用它?具体来说,我想检索具有 GLO
空间范围的名为 market for transport, freight, lorry, unspecified
的进程。但是我不知道这个 activity 的密钥,令人惊讶的是,它没有出现在搜索中
>>> Database('ei3.4 cutoff').search('market for transport, freight, lorry, unspecified')
[]
>>> Database('ei3.4 cutoff').search('market for transport')
[]
!!非常令人惊讶,没有运输市场?通过检查,我可以看到在 Ecoinvent 3.4 cutoff.
中有 139 个以短语 market for transport
开头的活动
事实上,虽然在 EI 3.4 截止时有 3,966 "market" 个进程,但我的 brightway 安装只知道大约两打:
>>> Database('ei3.4 cutoff').search('market')
['market for paris market carrot' (kilogram, GLO, None),
'paris market carrot production' (kilogram, GLO, None),
'market for acetonitrile' (kilogram, GLO, None),
'market for sulfur' (kilogram, GLO, None),
'market for whey' (kilogram, GLO, None),
'market for heptane' (kilogram, GLO, None),
'market for straw' (kilogram, GLO, None),
'market for clay' (kilogram, CH, None),
'market for pitch' (kilogram, CH, None),
'market for brass' (kilogram, CH, None),
'market for platinum' (kilogram, GLO, None),
'market for polycarbonate' (kilogram, GLO, None),
'market for pitch' (kilogram, RoW, None),
'market for tetrafluoroethylene' (kilogram, GLO, None),
'market for dimethenamide' (kilogram, GLO, None),
'market for glyphosate' (kilogram, GLO, None),
'market for styrene' (kilogram, GLO, None),
'market for ferrite' (kilogram, GLO, None),
'market for folpet' (kilogram, GLO, None),
'market for magnetite' (kilogram, GLO, None),
'market for metamitron' (kilogram, GLO, None),
'market for nylon 6-6' (kilogram, GLO, None),
'market for atrazine' (kilogram, GLO, None),
'market for magnesium' (kilogram, GLO, None),
'market for metaldehyde' (kilogram, GLO, None)]
如何找到未在搜索中显示的数据集?毫无帮助的是,文档似乎 严格地 使用 random()
检索活动(例如此处:http://nbviewer.jupyter.org/urls/bitbucket.org/cmutel/brightway2/raw/default/notebooks/Databases.ipynb),这对我回答这个问题没有帮助。
那么-两个问题-
如何找到感兴趣的 activity,market for transport, freight, lorry, unspecified [GLO]
?
根据搜索,为什么我的数据库缺少大约 3,940 个市场?
提前致谢。
因此,一种明显有效的方法是使用数据库的内置迭代器:
>>> m_t_f_l_u = next(_a for _a in Database('ei3.4 cutoff') \
if _a['name'] == 'market for transport, freight, lorry, unspecified' \
and _a['location'] == 'GLO')
这行得通。不过,它似乎效率不高,而且 运行.
需要几秒钟
- 您可以使用列表解析来实现您的搜索。应该挺有效率的。
db_bd = bw.Database('ei3.4 cutoff')
market_brandon_want = [act for act in db_bd
if 'market for transport, freight, lorry, unspecified' in act['name']
and 'GLO' in act['location']
][0]
- 那么如果你这样做:
len([act for act in db_bd if 'market' in act['name'] ])
你应该得到 4183,这似乎是一个更准确的数字。我相信您可以改进您的过滤器以更接近您的号码。
您可以遵循 2017 年在苏黎世举行的 Brightway2 seminar 中的教学 material。这对我来说真的很有帮助。
尝试在搜索字段中包含更多关键字不带逗号。
Database("ecoinvent 3.4 conseq").search('market transport freight lorry unspecified')
在我的版本中 returns:
['transport, freight, lorry, all sizes, EURO3 to generic market for
transport, freight, lorry, unspecified' (ton kilometer, RER, None),
'transport, freight, lorry, all sizes, EURO3 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
'transport, freight, lorry, all sizes, EURO4 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
'transport, freight, lorry, all sizes, EURO5 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
...
您也可以使用过滤器来查找位置:
Database("ecoinvent 3.4 conseq").search('market transport freight lorry unspecified', filter={"location" : 'GLO'})
returns:
['market for transport, freight, lorry, unspecified' (ton kilometer, GLO, None)]
如果您想自动执行搜索(例如查找一系列流程的代码),不确定这是否有效。
1) 我总是像 Laurent 一样使用列表理解。请注意,活动有一个名为 activity type 的字段。可能的值为 'market activity'、'market group'、'ordinary transforming activity'
db_bd = bw.Database('ei3.4 cutoff')
set([ds['activity type'] for ds in bd_db])
此字段有助于区分市场和普通转换活动
market_brandon_want = [act for act in db_bd
if 'freight, lorry, unspecified' in act['name']
and 'GLO' in act['location']
and act['activity type']!='ordinary transforming activity'
]
market_brandon_want
2) 搜索未找到所有市场,因为结果数量有限。您可以使用参数限制 (documentation) 更改它。
bw.Database('ei3.4 cutoff').search('market',limit=5)
我是新手所以请耐心等待。
我已经初始化了一个新的 BW2 安装并添加了一个 Ecoinvent 数据库(为清楚起见修剪了一些输出):
>>> from brightway2 import bw2setup, Database, SingleOutputEcospold2Importer
>>> bw2setup()
>>> ei = SingleOutputEcospold2Importer('/path/to/datasets', 'ei3.4 cutoff')
>>> ei.apply_strategies()
>>> ei.statistics()
14889 datasets
520205 exchanges
0 unlinked exchanges
>>> ei.write_database()
到目前为止,一切顺利(特别注意加载的数据集数量)。但是现在-我该如何使用它?具体来说,我想检索具有 GLO
空间范围的名为 market for transport, freight, lorry, unspecified
的进程。但是我不知道这个 activity 的密钥,令人惊讶的是,它没有出现在搜索中
>>> Database('ei3.4 cutoff').search('market for transport, freight, lorry, unspecified')
[]
>>> Database('ei3.4 cutoff').search('market for transport')
[]
!!非常令人惊讶,没有运输市场?通过检查,我可以看到在 Ecoinvent 3.4 cutoff.
中有 139 个以短语market for transport
开头的活动
事实上,虽然在 EI 3.4 截止时有 3,966 "market" 个进程,但我的 brightway 安装只知道大约两打:
>>> Database('ei3.4 cutoff').search('market')
['market for paris market carrot' (kilogram, GLO, None),
'paris market carrot production' (kilogram, GLO, None),
'market for acetonitrile' (kilogram, GLO, None),
'market for sulfur' (kilogram, GLO, None),
'market for whey' (kilogram, GLO, None),
'market for heptane' (kilogram, GLO, None),
'market for straw' (kilogram, GLO, None),
'market for clay' (kilogram, CH, None),
'market for pitch' (kilogram, CH, None),
'market for brass' (kilogram, CH, None),
'market for platinum' (kilogram, GLO, None),
'market for polycarbonate' (kilogram, GLO, None),
'market for pitch' (kilogram, RoW, None),
'market for tetrafluoroethylene' (kilogram, GLO, None),
'market for dimethenamide' (kilogram, GLO, None),
'market for glyphosate' (kilogram, GLO, None),
'market for styrene' (kilogram, GLO, None),
'market for ferrite' (kilogram, GLO, None),
'market for folpet' (kilogram, GLO, None),
'market for magnetite' (kilogram, GLO, None),
'market for metamitron' (kilogram, GLO, None),
'market for nylon 6-6' (kilogram, GLO, None),
'market for atrazine' (kilogram, GLO, None),
'market for magnesium' (kilogram, GLO, None),
'market for metaldehyde' (kilogram, GLO, None)]
如何找到未在搜索中显示的数据集?毫无帮助的是,文档似乎 严格地 使用 random()
检索活动(例如此处:http://nbviewer.jupyter.org/urls/bitbucket.org/cmutel/brightway2/raw/default/notebooks/Databases.ipynb),这对我回答这个问题没有帮助。
那么-两个问题-
如何找到感兴趣的 activity,
market for transport, freight, lorry, unspecified [GLO]
?根据搜索,为什么我的数据库缺少大约 3,940 个市场?
提前致谢。
因此,一种明显有效的方法是使用数据库的内置迭代器:
>>> m_t_f_l_u = next(_a for _a in Database('ei3.4 cutoff') \
if _a['name'] == 'market for transport, freight, lorry, unspecified' \
and _a['location'] == 'GLO')
这行得通。不过,它似乎效率不高,而且 运行.
需要几秒钟- 您可以使用列表解析来实现您的搜索。应该挺有效率的。
db_bd = bw.Database('ei3.4 cutoff')
market_brandon_want = [act for act in db_bd
if 'market for transport, freight, lorry, unspecified' in act['name']
and 'GLO' in act['location']
][0]
- 那么如果你这样做:
len([act for act in db_bd if 'market' in act['name'] ])
你应该得到 4183,这似乎是一个更准确的数字。我相信您可以改进您的过滤器以更接近您的号码。
您可以遵循 2017 年在苏黎世举行的 Brightway2 seminar 中的教学 material。这对我来说真的很有帮助。
尝试在搜索字段中包含更多关键字不带逗号。
Database("ecoinvent 3.4 conseq").search('market transport freight lorry unspecified')
在我的版本中 returns:
['transport, freight, lorry, all sizes, EURO3 to generic market for
transport, freight, lorry, unspecified' (ton kilometer, RER, None),
'transport, freight, lorry, all sizes, EURO3 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
'transport, freight, lorry, all sizes, EURO4 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
'transport, freight, lorry, all sizes, EURO5 to generic market for transport,
freight, lorry, unspecified' (ton kilometer, RoW, None),
...
您也可以使用过滤器来查找位置:
Database("ecoinvent 3.4 conseq").search('market transport freight lorry unspecified', filter={"location" : 'GLO'})
returns:
['market for transport, freight, lorry, unspecified' (ton kilometer, GLO, None)]
如果您想自动执行搜索(例如查找一系列流程的代码),不确定这是否有效。
1) 我总是像 Laurent 一样使用列表理解。请注意,活动有一个名为 activity type 的字段。可能的值为 'market activity'、'market group'、'ordinary transforming activity'
db_bd = bw.Database('ei3.4 cutoff')
set([ds['activity type'] for ds in bd_db])
此字段有助于区分市场和普通转换活动
market_brandon_want = [act for act in db_bd
if 'freight, lorry, unspecified' in act['name']
and 'GLO' in act['location']
and act['activity type']!='ordinary transforming activity'
]
market_brandon_want
2) 搜索未找到所有市场,因为结果数量有限。您可以使用参数限制 (documentation) 更改它。
bw.Database('ei3.4 cutoff').search('market',limit=5)