@@ -76,6 +76,7 @@ class Simulation:
7676 "inputs_stocks" ,
7777 "limiting_inputs" ,
7878 "productive_capital_to_recover" ,
79+ "value_added" ,
7980 ]
8081
8182 __file_save_array_specs = {
@@ -91,6 +92,12 @@ class Simulation:
9192 "industries" ,
9293 np .nan ,
9394 ),
95+ "value_added" : (
96+ "float64" ,
97+ "_value_added_evolution" ,
98+ "industries" ,
99+ np .nan ,
100+ ),
94101 "final_demand" : ("float64" , "_final_demand_evolution" , "industries" , np .nan ),
95102 "intermediate_demand" : (
96103 "float64" ,
@@ -209,6 +216,7 @@ def __init__(
209216 self ._io_demand_evolution = np .array ([])
210217 self ._rebuild_demand_evolution = np .array ([])
211218 self ._overproduction_evolution = np .array ([])
219+ self ._value_added_evolution = np .array ([])
212220 self ._final_demand_unmet_evolution = np .array ([])
213221 self ._rebuild_production_evolution = np .array ([])
214222 self ._inputs_evolution = np .array ([])
@@ -508,6 +516,10 @@ def next_step(
508516 "_io_demand_evolution" in self ._vars_to_record
509517 ):
510518 self ._write_io_demand ()
519+ if ("_value_added_evolution" in self ._files_to_record ) or (
520+ "_value_added_evolution" in self ._vars_to_record
521+ ):
522+ self ._write_value_added ()
511523
512524 # 1)
513525 constraints = self .model .calc_production (self .current_temporal_unit )
@@ -912,6 +924,8 @@ def update_rebuild_demand(self):
912924 * (evnt_trck ._rebuild_id + 1 ),
913925 ] = evnt_trck .distributed_reb_dem_house_tau
914926
927+ if np .isnan (_rebuilding_demand ).any ():
928+ raise ValueError ("NaNs found when creating the rebuilding demand." )
915929 self .model .rebuild_demand = _rebuilding_demand
916930
917931 def update_productive_capital_lost (self ):
@@ -1007,6 +1021,22 @@ def production_capacity(self) -> pd.DataFrame:
10071021 copy = True ,
10081022 ).rename_axis ("step" )
10091023
1024+ @property
1025+ def value_added (self ) -> pd .DataFrame :
1026+ """Returns the evolution of the production capacity of each industry (region,sector) as a DataFrame.
1027+
1028+ Returns
1029+ -------
1030+ pd.DataFrame: A pandas DataFrame where the value is the production capacity, the columns are the industries
1031+ and the index is the step considered.
1032+
1033+ """
1034+ return pd .DataFrame (
1035+ self ._value_added_evolution ,
1036+ columns = self .model .industries ,
1037+ copy = True ,
1038+ ).rename_axis ("step" )
1039+
10101040 @property
10111041 def final_demand (self ) -> pd .DataFrame :
10121042 """Return the evolution of final demand asked of each industry as a DataFrame.
@@ -1237,6 +1267,12 @@ def _write_production_max(self) -> None:
12371267 self .model .production_cap
12381268 )
12391269
1270+ def _write_value_added (self ) -> None :
1271+ """Saves the current production capacity vector to the memmap."""
1272+ self ._value_added_evolution [self .current_temporal_unit ] = (
1273+ self .model .production - self .model .intermediate_demand_tot
1274+ )
1275+
12401276 def _write_io_demand (self ) -> None :
12411277 """Saves the current (total per industry) intermediate demand vector to the memmap."""
12421278 self ._io_demand_evolution [self .current_temporal_unit ] = (
@@ -1508,16 +1544,20 @@ def _normalize_distribution(
15081544 ret .loc [addressed_to , :] = (
15091545 dist_sq .loc [addressed_to ]
15101546 .groupby (level = 1 )
1511- .transform (lambda x : x / sum (x ))
1547+ .transform (lambda x : x / sum (x ) if sum ( x ) != 0 else 0 )
15121548 .values [:, None ]
15131549 )
1550+ if np .isnan (ret ).any (axis = None ):
1551+ raise ValueError ("The distribution contains NaNs" )
15141552 return ret
15151553 elif isinstance (dist_sq , pd .DataFrame ):
15161554 ret .loc [addressed_to , affected ] = (
15171555 dist_sq .loc [addressed_to , affected ]
15181556 .groupby (level = 1 )
1519- .transform (lambda x : x / sum (x ))
1557+ .transform (lambda x : x / sum (x ) if sum ( x ) != 0 else 0 )
15201558 )
1559+ if np .isnan (ret ).any (axis = None ):
1560+ raise ValueError ("The distribution contains NaNs" )
15211561 return ret
15221562 else :
15231563 raise ValueError ("given distribution should be a Series or a DataFrame." )
0 commit comments