Skip to content

Commit

Permalink
Merge branch 'develop' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
perrotcap committed Oct 13, 2024
2 parents 54a7f40 + cc9cdcb commit 449f743
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
17 changes: 12 additions & 5 deletions energy_models/core/ccus/ccus.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def configure_parameters(self, inputs_dict):
self.ccs_list = [GlossaryEnergy.carbon_capture, GlossaryEnergy.carbon_storage]

def compute_carbon_storage_capacity(self):
total_carbon_storage_by_invest_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_storage}.{GlossaryEnergy.EnergyProductionValue}"][ GlossaryEnergy.carbon_storage].values
total_carbon_storage_by_invest_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_storage}.{GlossaryEnergy.EnergyProductionValue}"][ GlossaryEnergy.carbon_storage].values * self.inputs_dict['scaling_factor_energy_production']

self.outputs_dict['carbon_storage_capacity (Gt)'] = pd.DataFrame({
GlossaryEnergy.Years: self.years,
Expand All @@ -84,14 +84,16 @@ def compute_co2_emissions(self):
# production of CCS technos are in Mt
carbon_capture_prod_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_capture}.{GlossaryEnergy.EnergyProductionValue}"][GlossaryEnergy.carbon_capture].values
carbon_storage_prod_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_storage}.{GlossaryEnergy.EnergyProductionValue}"][GlossaryEnergy.carbon_storage].values
scaling_factor_energy_prod = self.inputs_dict['scaling_factor_energy_production']

# Outputs are in Gt (for automatic differentiation purpose : coupling output var is in Gt)
carbon_capture_to_be_stored_gt, carbon_storage_limited_by_capture_gt, carbon_storage_gt, carbon_capture_from_cc_technos_gt = compute_carbon_storage_limited_by_capture_gt(
carbon_capture_prod_mt=carbon_capture_prod_mt,
carbon_storage_prod_mt=carbon_storage_prod_mt,
carbon_capture_from_energy_mix_gt=carbon_capture_from_energy_mix_gt,
co2_emissions_needed_by_energy_mix_gt=co2_emissions_needed_by_energy_mix_gt,
co2_for_food_mt=co2_for_food_mt
co2_for_food_mt=co2_for_food_mt,
scaling_factor_energy_prod=scaling_factor_energy_prod
)

self.outputs_dict['co2_emissions_ccus'] = pd.DataFrame({
Expand Down Expand Up @@ -130,6 +132,7 @@ def grad_co2_emissions_ccus_Gt(self):
# production of CCS technos are in Mt
carbon_capture_prod_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_capture}.{GlossaryEnergy.EnergyProductionValue}"][GlossaryEnergy.carbon_capture].values
carbon_storage_prod_mt = self.inputs_dict[f"{GlossaryEnergy.carbon_storage}.{GlossaryEnergy.EnergyProductionValue}"][GlossaryEnergy.carbon_storage].values
scaling_factor_energy_prod = self.inputs_dict['scaling_factor_energy_production']

jac_carbon_capture_from_cc_prod, jac_carbon_capture_from_cs_prod, jac_carbon_capture_from_energy_mix, jac_co2_emissions_needed_by_energy_mix =\
compute_carbon_storage_limited_by_capture_gt_der(
Expand All @@ -138,6 +141,7 @@ def grad_co2_emissions_ccus_Gt(self):
carbon_capture_from_energy_mix_gt=carbon_capture_from_energy_mix_gt,
co2_emissions_needed_by_energy_mix_gt=co2_emissions_needed_by_energy_mix_gt,
co2_for_food_mt=co2_for_food_mt,
scaling_factor_energy_prod=scaling_factor_energy_prod
)
# input_name : (column_name, grad value)
out = {
Expand All @@ -156,6 +160,7 @@ def compute_carbon_storage_limited_by_capture_gt(
carbon_capture_from_energy_mix_gt: np.ndarray,
co2_emissions_needed_by_energy_mix_gt: np.ndarray,
co2_for_food_mt: np.ndarray,
scaling_factor_energy_prod: float
):
'''
The carbon stored by invest is limited by the carbon to stored
Expand All @@ -165,13 +170,13 @@ def compute_carbon_storage_limited_by_capture_gt(
carbon_capture_from_cc_technos_mt = carbon_capture_prod_mt

carbon_capture_to_be_stored_mt = (
carbon_capture_from_cc_technos_mt +
carbon_capture_from_cc_technos_mt * scaling_factor_energy_prod +
carbon_capture_from_energy_mix_gt * 1e3 -
0 * co2_emissions_needed_by_energy_mix_gt * 1e3 -
0 * co2_for_food_mt
)

carbon_storage_limited_by_capture_mt = np.minimum(carbon_capture_to_be_stored_mt, carbon_storage_prod_mt)
carbon_storage_limited_by_capture_mt = np.minimum(carbon_capture_to_be_stored_mt, carbon_storage_prod_mt * scaling_factor_energy_prod)
return carbon_capture_to_be_stored_mt / 1e3, carbon_storage_limited_by_capture_mt / 1e3, carbon_storage_prod_mt / 1e3, carbon_capture_from_cc_technos_mt / 1e3


Expand All @@ -181,12 +186,14 @@ def compute_carbon_storage_limited_by_capture_gt_der(
carbon_capture_from_energy_mix_gt: np.ndarray,
co2_emissions_needed_by_energy_mix_gt: np.ndarray,
co2_for_food_mt: np.ndarray,
scaling_factor_energy_prod: float,
):
args = (carbon_capture_prod_mt,
carbon_storage_prod_mt,
carbon_capture_from_energy_mix_gt,
co2_emissions_needed_by_energy_mix_gt,
co2_for_food_mt,)
co2_for_food_mt,
scaling_factor_energy_prod)

jac_carbon_capture_from_cc_prod = jacobian(lambda *args: compute_carbon_storage_limited_by_capture_gt(*args)[1], 0)
jac_carbon_capture_from_cs_prod = jacobian(lambda *args: compute_carbon_storage_limited_by_capture_gt(*args)[1], 1)
Expand Down
7 changes: 2 additions & 5 deletions energy_models/core/ccus/ccus_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ class CCUS_Discipline(SoSWrapp):
GlossaryEnergy.YearStart: ClimateEcoDiscipline.YEAR_START_DESC_IN,
GlossaryEnergy.YearEnd: {'type': 'int',
'unit': 'year', 'visibility': 'Shared', 'namespace': 'ns_public', 'range': [2000,2300]},
'alpha': {'type': 'float', 'range': [0., 1.], 'default': 0.5, 'unit': '-',
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy_study'},
'carbonstorage_limit': {'type': 'float', 'default': 12e6, 'unit': 'Mt', 'user_level': 2,},
'carbonstorage_constraint_ref': {'type': 'float', 'default': 12e6, 'unit': 'Mt', 'user_level': 2},
'co2_emissions_needed_by_energy_mix': {'type': 'dataframe', 'unit': 'Gt',
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, True),
'carbon_capture needed by energy mix (Gt)': ('float', None, True),
}, },
'scaling_factor_energy_production': {'type': 'float', 'default': 1e3, 'user_level': 2, 'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_public'},
'carbon_capture_from_energy_mix': {'type': 'dataframe', 'unit': 'Gt',
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, True),
Expand Down Expand Up @@ -303,7 +300,7 @@ def get_chart_co2_limited_storage(self):
(co2_emissions[f'{GlossaryEnergy.carbon_storage} Limited by capture (Mt)'].values / 1.0e3).tolist(),
'CO2 captured and stored', 'bar')
new_chart.add_series(serie)

new_chart.to_plotly().show()
return new_chart

def get_chart_co2_emissions_sources(self):
Expand Down
Binary file modified energy_models/tests/jacobian_pkls/jacobian_CCUS_disc.pkl
Binary file not shown.

0 comments on commit 449f743

Please sign in to comment.