-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
58 lines (46 loc) · 2.07 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def replace_stuff(main_act, sub_act, repl_act, method):
# first we need the demand of the sub_act in the main act
for exc in list(main_act.exchanges()):
if exc.input.id == sub_act.id:
demand = exc['amount']
gangnam_style = 1_000_000
indices = np.array(
[
(gangnam_style, gangnam_style), # Production exchange for new main_act ( activity produces itself ) - need to have this to make matrix square
(main_act.id, gangnam_style),
(sub_act.id, gangnam_style), # subtract sub_act
] + [
(node.id, gangnam_style) for node in [repl_act] # replace with this - something about new dps replacing old ones - could also have the values being added together?
# see gh bw processing -> policies
], dtype=bwp.INDICES_DTYPE
)
data = np.array([
1,
1,
demand, # old activity
] + [
demand # new activity - same amount
]
)
flip = np.array(
[False, True, False] + [True for _ in [repl_act]] # First False because ?, True - motor is consumed, False because numbers are negative ... ?,
# WAIT I think I get it. This is the data array, where we put False for old act, and True for new act...
# ...This is probably where we would want to change things to create new market shares...?
) # could alsos set minussign if you prefer but i still wouldnt know where
# return(demand)
dp = bwp.create_datapackage()
dp.add_persistent_vector(
matrix="technosphere_matrix",
data_array=data,
indices_array=indices,
flip_array=flip,
name="New technosphere",
)
_, data_objs, _ = bd.prepare_lca_inputs({main_act: 1}, ipcc) # data_objs - still using ei
lca = bc.LCA({main_act.id: 1}, data_objs=data_objs + [dp]) # old motor + add [dp] (new motor)
lca.lci()
lca.lcia()
lcascore1 = lca.score # first version
lca.lcia({gangnam_style: 1}) # new motor
lcascore2 = lca.score # substituted sub_act w repl_act
return(lcascore1, lcascore2)