@@ -45,6 +45,10 @@ def ecalc_npv(pred_data, **kwargs):
4545
4646 # Economic values
4747 npv_const = dict (keys_opt ['npv_const' ])
48+ if 'wem' not in npv_const :
49+ npv_const ['wem' ] = 0
50+ if 'wel' not in npv_const :
51+ npv_const ['wel' ] = 0
4852
4953 # Collect production data
5054 Qop = []
@@ -96,6 +100,7 @@ def ecalc_npv(pred_data, **kwargs):
96100 NT = Qop [l ].shape [1 ]
97101 values = []
98102 em_values = []
103+ el_values = []
99104 for n in range (N ):
100105 with open ('ecalc_input.csv' , 'w' ) as csvfile :
101106 writer = csv .writer (csvfile , delimiter = ',' )
@@ -113,31 +118,32 @@ def ecalc_npv(pred_data, **kwargs):
113118 resource_service = resource_service ,
114119 output_frequency = Frequency .NONE ,
115120 )
116- # comps = {c.name: id_hash for (id_hash, c) in yaml_model.graph.components.items()}
117121
118122 # Compute energy, emissions
119- #model = EnergyCalculator(energy_model=yaml_model, expression_evaluator=yaml_model.variables)
120- #consumer_results = model.evaluate_energy_usage()
121- #emission_results = model.evaluate_emissions()
122123 model = EnergyCalculator (graph = yaml_model .get_graph ())
123124 consumer_results = model .evaluate_energy_usage (yaml_model .variables )
124125 emission_results = model .evaluate_emissions (yaml_model .variables , consumer_results )
125126
126127 # Extract
127- # energy = results_as_df(yaml_model, consumer_results, lambda r: r.component_result.energy_usage)
128+ energy = results_as_df (yaml_model , consumer_results , lambda r : r .component_result .energy_usage )
129+ energy_total = energy .sum (1 ).rename ("emissions_total" )
130+ energy_total .to_csv (HERE / "energy.csv" )
131+ Qel = energy_total .values * Dd # total number of MWd (energy usage in MW * number of days)
132+ el_values .append (Qel )
128133 emissions = results_as_df (yaml_model , emission_results , lambda r : r ['co2_fuel_gas' ].rate )
129134 emissions_total = emissions .sum (1 ).rename ("emissions_total" )
130135 emissions_total .to_csv (HERE / "emissions.csv" )
131136 Qem = emissions_total .values * Dd # total number of tons
132137 em_values .append (Qem )
133138
134139 value = (Qop [l ][n , :] * npv_const ['wop' ] + Qgp [l ][n , :] * npv_const ['wgp' ] - Qwp [l ][n , :] * npv_const ['wwp' ] -
135- Qwi [l ][n , :] * npv_const ['wwi' ] - Qem * npv_const ['wem' ]) / (
140+ Qwi [l ][n , :] * npv_const ['wwi' ] - Qem * npv_const ['wem' ] - Qel * npv_const [ 'wel' ] ) / (
136141 (1 + npv_const ['disc' ]) ** (T / 365 ))
137142 objective [l ].append (np .sum (value ))
138143
139- # Save emissions for later inspection
144+ # Save emissions and electrisity usage for later inspection
140145 np .savez (f'em_values_level{ l } .npz' , em_values = np .array ([em_values ]))
146+ np .savez (f'el_values_level{ l } .npz' , em_values = np .array ([el_values ]))
141147
142148 objective [l ] = np .array (objective [l ]) / npv_const .get ('obj_scaling' , 1 )
143149
0 commit comments