Skip to content

Commit

Permalink
merge post_integration to validation
Browse files Browse the repository at this point in the history
  • Loading branch information
b4pm-devops committed Jul 24, 2024
2 parents 0c6d9cb + fa2afc0 commit c22b9eb
Show file tree
Hide file tree
Showing 112 changed files with 327 additions and 259 deletions.
34 changes: 16 additions & 18 deletions energy_models/core/ccus/ccus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from energy_models.core.stream_type.base_stream import BaseStream
from energy_models.core.stream_type.carbon_models.carbon import Carbon
from energy_models.core.stream_type.carbon_models.carbon_capture import CarbonCapture
from energy_models.core.stream_type.carbon_models.carbon_dioxyde import CO2
from energy_models.glossaryenergy import GlossaryEnergy


Expand All @@ -42,7 +41,6 @@ class CCUS(BaseStream):
CO2_list = [f'{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})',
f'{CarbonCapture.flue_gas_name} ({GlossaryEnergy.mass_unit})',
f'{GlossaryEnergy.carbon_storage} ({GlossaryEnergy.mass_unit})',
f'{CO2.name} ({GlossaryEnergy.mass_unit})',
f'{Carbon.name} ({GlossaryEnergy.mass_unit})']
ccs_list = [GlossaryEnergy.carbon_capture, GlossaryEnergy.carbon_storage]

Expand Down Expand Up @@ -85,7 +83,7 @@ def configure_parameters(self, inputs_dict):
BaseStream.configure_parameters(self, inputs_dict)

self.co2_for_food = pd.DataFrame(
{GlossaryEnergy.Years: self.production[GlossaryEnergy.Years], f'{CO2.name} for food (Mt)': 0.0})
{GlossaryEnergy.Years: self.production[GlossaryEnergy.Years], f'{GlossaryEnergy.carbon_capture} for food (Mt)': 0.0})
self.CCS_price = pd.DataFrame(
{GlossaryEnergy.Years: np.arange(inputs_dict[GlossaryEnergy.YearStart],
inputs_dict[GlossaryEnergy.YearEnd] + 1)})
Expand Down Expand Up @@ -193,7 +191,7 @@ def compute_CO2_emissions(self):
self.co2_emissions_needed_by_energy_mix[
f'{GlossaryEnergy.carbon_capture} needed by energy mix (Gt)'] * 1e3 - \
self.co2_for_food[
f'{CO2.name} for food (Mt)']
f'{GlossaryEnergy.carbon_capture} for food (Mt)']

'''
Solid Carbon to be stored to limit the carbon solid storage
Expand Down Expand Up @@ -349,37 +347,37 @@ def compute_grad_CO2_emissions(self, co2_emissions):
i.e. for machinery or tractors
'''
energy_producing_co2 = co2_production[[
col for col in co2_production if col.endswith(f'{CO2.name} ({GlossaryEnergy.mass_unit})')]]
col for col in co2_production if col.endswith(f'{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})')]]
energy_producing_co2_list = [key.replace(
f' {CO2.name} ({GlossaryEnergy.mass_unit})', '') for key in energy_producing_co2]
f' {GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})', '') for key in energy_producing_co2]
if len(energy_producing_co2_list) != 0:
for energy1 in energy_producing_co2_list:
dtot_CO2_emissions[
f'{CO2.name} from energy mix (Mt) vs {energy1}#{CO2.name} ({GlossaryEnergy.mass_unit})#prod'] = np.ones(len_years)
f'{GlossaryEnergy.carbon_capture} from energy mix (Mt) vs {energy1}#{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})#prod'] = np.ones(len_years)

# self.total_co2_emissions[f'{CO2.name} from energy mix (Mt)'] = energy_producing_co2.sum(
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'] = energy_producing_co2.sum(
# axis=1).values
# else:
# self.total_co2_emissions[
# f'{CO2.name} from energy mix (Mt)'] = 0.0
# f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'] = 0.0

''' CO2 removed by energy mix
CO2 removed by energy mix technologies during the process
i.e. biomass processes as managed wood or crop energy
'''
energy_removing_co2 = co2_consumption[[
col for col in co2_consumption if col.endswith(f'{CO2.name} ({GlossaryEnergy.mass_unit})')]]
col for col in co2_consumption if col.endswith(f'{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})')]]
energy_removing_co2_list = [key.replace(
f' {CO2.name} ({GlossaryEnergy.mass_unit})', '') for key in energy_removing_co2]
f' {GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})', '') for key in energy_removing_co2]
if len(energy_removing_co2_list) != 0:
for energy1 in energy_removing_co2_list:
dtot_CO2_emissions[
f'{CO2.name} removed by energy mix (Mt) vs {energy1}#{CO2.name} ({GlossaryEnergy.mass_unit})#cons'] = np.ones(len_years)
# self.total_co2_emissions[f'{CO2.name} removed by energy mix (Mt)'] = energy_removing_co2.sum(
f'{GlossaryEnergy.carbon_capture} removed by energy mix (Mt) vs {energy1}#{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})#cons'] = np.ones(len_years)
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} removed by energy mix (Mt)'] = energy_removing_co2.sum(
# axis=1).values
# else:
# self.total_co2_emissions[
# f'{CO2.name} removed energy mix (Mt)'] = 0.0
# f'{GlossaryEnergy.carbon_capture} removed energy mix (Mt)'] = 0.0

''' Total C02 from Flue gas
sum of all production of flue gas
Expand All @@ -403,10 +401,10 @@ def compute_grad_CO2_emissions(self, co2_emissions):
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} to be stored (Mt)'] = self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit}) from CC technos'] + \
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'] - \
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} needed by energy mix (Mt)'] -\
# self.total_co2_emissions[f'{CO2.name} for food (Mt)'
# self.total_co2_emissions[f'{GlossaryEnergy.carbon_capture} for food (Mt)'

new_key = f'{GlossaryEnergy.carbon_capture} to be stored (Mt)'
dtot_CO2_emissions[f'{new_key} vs {CO2.name} for food (Mt)#carbon_capture'] = - np.ones(
dtot_CO2_emissions[f'{new_key} vs {GlossaryEnergy.carbon_capture} for food (Mt)#carbon_capture'] = - np.ones(
len_years)
dtot_CO2_emissions[f'{new_key} vs {GlossaryEnergy.carbon_capture} from energy mix (Mt)#carbon_capture'] = np.ones(
len_years)
Expand All @@ -415,7 +413,7 @@ def compute_grad_CO2_emissions(self, co2_emissions):
key_dep_tuple_list = [(f'{GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit}) from CC technos', 1.0),
(f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)', 1.0),
(f'{GlossaryEnergy.carbon_capture} needed by energy mix (Mt)', -1.0),
(f'{CO2.name} for food (Mt)', -1.0)]
(f'{GlossaryEnergy.carbon_capture} for food (Mt)', -1.0)]
dtot_CO2_emissions = update_new_gradient(
dtot_CO2_emissions, key_dep_tuple_list, new_key)

Expand All @@ -424,7 +422,7 @@ def compute_grad_CO2_emissions(self, co2_emissions):
f'{GlossaryEnergy.carbon_capture} from energy mix (Gt)'].values * 1e3 - \
self.co2_emissions_needed_by_energy_mix[
f'{GlossaryEnergy.carbon_capture} needed by energy mix (Gt)'].values * 1e3 - \
self.co2_for_food[f'{CO2.name} for food (Mt)'].values
self.co2_for_food[f'{GlossaryEnergy.carbon_capture} for food (Mt)'].values
# if the carbon to be stored is lower than zero that means that we need
# more carbon capture for energy mix than the one created by CC technos
# or upgrading biogas
Expand Down
17 changes: 8 additions & 9 deletions energy_models/core/ccus/ccus_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from energy_models.core.ccus.ccus import CCUS
from energy_models.core.energy_mix.energy_mix import EnergyMix
from energy_models.core.stream_type.carbon_models.carbon_capture import CarbonCapture
from energy_models.core.stream_type.carbon_models.carbon_dioxyde import CO2
from energy_models.glossaryenergy import GlossaryEnergy


Expand Down Expand Up @@ -142,10 +141,10 @@ def setup_sos_disciplines(self):
if year_start is not None and year_end is not None:
dynamic_inputs['co2_for_food'] = {
'type': 'dataframe', 'unit': 'Mt', 'default': pd.DataFrame(
{GlossaryEnergy.Years: np.arange(year_start, year_end + 1), f'{CO2.name} for food (Mt)': 0.0}),
{GlossaryEnergy.Years: np.arange(year_start, year_end + 1), f'{GlossaryEnergy.carbon_capture} for food (Mt)': 0.0}),
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, True),
'CO2_resource for food (Mt)': ('float', None, True), }
f'{GlossaryEnergy.carbon_capture} for food (Mt)': ('float', None, True), }
}

self.add_inputs(dynamic_inputs),
Expand Down Expand Up @@ -276,10 +275,10 @@ def compute_sos_jacobian(self):
self.set_partial_derivative_for_other_types(
('co2_emissions_ccus_Gt', co2_emission_column_upd), (f'{energy}.{GlossaryEnergy.CO2PerUse}', GlossaryEnergy.CO2PerUse),
np.identity(len(years)) * value / 1.0e3)
elif energy_prod_info.startswith(f'{CO2.name} for food (Mt)'):
elif energy_prod_info.startswith(f'{GlossaryEnergy.carbon_capture} for food (Mt)'):
self.set_partial_derivative_for_other_types(
('co2_emissions_ccus_Gt', co2_emission_column_upd),
('co2_for_food', f'{CO2.name} for food (Mt)'), np.identity(len(years)) * value / 1.0e3)
('co2_for_food', f'{GlossaryEnergy.carbon_capture} for food (Mt)'), np.identity(len(years)) * value / 1.0e3)

elif energy_prod_info.startswith(f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'):
self.set_partial_derivative_for_other_types(
Expand Down Expand Up @@ -329,9 +328,9 @@ def compute_sos_jacobian(self):
elif last_part_key == 'co2_per_use':
self.set_partial_derivative_for_other_types(
(EnergyMix.CARBON_STORAGE_CONSTRAINT,), (f'{energy}.{GlossaryEnergy.CO2PerUse}', GlossaryEnergy.CO2PerUse), value)
elif energy_prod_info.startswith(f'{CO2.name} for food (Mt)'):
elif energy_prod_info.startswith(f'{GlossaryEnergy.carbon_capture} for food (Mt)'):
self.set_partial_derivative_for_other_types(
(EnergyMix.CARBON_STORAGE_CONSTRAINT,), ('co2_for_food', f'{CO2.name} for food (Mt)'), value)
(EnergyMix.CARBON_STORAGE_CONSTRAINT,), ('co2_for_food', f'{GlossaryEnergy.carbon_capture} for food (Mt)'), value)

elif energy_prod_info.startswith(f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'):
self.set_partial_derivative_for_other_types(
Expand Down Expand Up @@ -480,7 +479,7 @@ def get_chart_co2_to_store(self):

serie = InstanciatedSeries(
x_serie_1,
(-co2_for_food[f'{CO2.name} for food (Mt)'].values / 1.0e3).tolist(), f'{CO2.name} used for food', 'bar')
(-co2_for_food[f'{GlossaryEnergy.carbon_capture} for food (Mt)'].values / 1.0e3).tolist(), f'{GlossaryEnergy.carbon_capture} used for food', 'bar')
new_chart.add_series(serie)

serie = InstanciatedSeries(
Expand Down Expand Up @@ -548,7 +547,7 @@ def get_chart_co2_emissions_sources(self):

serie = InstanciatedSeries(
x_serie_1,
(co2_emissions[f'{CO2.name} from energy mix (Mt)'].values / 1.0e3).tolist(),
(co2_emissions[f'{GlossaryEnergy.carbon_capture} from energy mix (Mt)'].values / 1.0e3).tolist(),
'CO2 from energy mix (machinery fuels)')
new_chart.add_series(serie)

Expand Down
Loading

0 comments on commit c22b9eb

Please sign in to comment.