@@ -131,6 +131,9 @@ def build_dynamic_biosphere_matrix(
131
131
A sparse matrix with the dimensions (bio_flows at a specific time step) x (processes).
132
132
"""
133
133
134
+ lci_dict = {}
135
+ temporal_market_lci_dict = {}
136
+
134
137
for row in self .timeline .itertuples ():
135
138
idx = row .time_mapped_producer
136
139
if from_timeline :
@@ -145,6 +148,8 @@ def build_dynamic_biosphere_matrix(
145
148
time ,
146
149
) = self .activity_time_mapping_dict .reversed ()[idx ]
147
150
151
+
152
+
148
153
if idx in self .node_id_collection_dict ["temporalized_processes" ]:
149
154
150
155
time_in_datetime = convert_date_string_to_datetime (
@@ -204,6 +209,7 @@ def build_dynamic_biosphere_matrix(
204
209
col = process_col_index ,
205
210
amount = amount ,
206
211
)
212
+
207
213
elif idx in self .node_id_collection_dict ["temporal_markets" ]:
208
214
(
209
215
(original_db , original_code ),
@@ -215,11 +221,24 @@ def build_dynamic_biosphere_matrix(
215
221
else :
216
222
demand = self .demand_from_technosphere (idx , process_col_index )
217
223
224
+
218
225
if demand :
219
- self .lca_obj .redo_lci (demand )
220
- # aggregated biosphere flows of background supply chain emissions.
221
- # Rows are bioflows.
222
- aggregated_inventory = self .lca_obj .inventory .sum (axis = 1 )
226
+ for act , amount in demand .items ():
227
+ # check if lci already calculated for this activity
228
+ if not act in lci_dict .keys ():
229
+ self .lca_obj .redo_lci ({act : 1 })
230
+ # biosphere flows by activity of background supply chain emissions.
231
+ # Rows are bioflows. Columns are activities.
232
+ # save for reuse in dict
233
+ lci_dict [act ] = self .lca_obj .inventory
234
+ # add lci of both background activities of the temporal market and save total lci
235
+ if idx not in temporal_market_lci_dict .keys ():
236
+ temporal_market_lci_dict [idx ] = lci_dict [act ] * amount
237
+ else :
238
+ temporal_market_lci_dict [idx ] += lci_dict [act ] * amount
239
+
240
+
241
+ aggregated_inventory = temporal_market_lci_dict [idx ].sum (axis = 1 )
223
242
224
243
for row_idx , amount in enumerate (aggregated_inventory .A1 ):
225
244
bioflow = self .lca_obj .dicts .biosphere .reversed [row_idx ]
@@ -254,7 +273,7 @@ def build_dynamic_biosphere_matrix(
254
273
dynamic_biomatrix = sp .coo_matrix ((self .values , (self .rows , self .cols )), shape )
255
274
self .dynamic_biomatrix = dynamic_biomatrix .tocsr ()
256
275
257
- return self .dynamic_biomatrix
276
+ return self .dynamic_biomatrix , temporal_market_lci_dict
258
277
259
278
def demand_from_timeline (self , row , original_db ):
260
279
"""
@@ -278,13 +297,9 @@ def demand_from_timeline(self, row, original_db):
278
297
"""
279
298
demand = {}
280
299
for db , amount in row .interpolation_weights .items ():
281
- [(timed_act_id , _ )] = [
282
- (act , db_name )
283
- for (act , db_name ) in self .interdatabase_activity_mapping [
284
- (row .producer , original_db )
285
- ]
286
- if db == db_name
287
- ]
300
+ timed_act_id = self .interdatabase_activity_mapping .find_match (
301
+ row .producer , db
302
+ )
288
303
demand [timed_act_id ] = amount
289
304
return demand
290
305
0 commit comments