Skip to content

Commit

Permalink
merge validation to main
Browse files Browse the repository at this point in the history
  • Loading branch information
b4pm-devops committed Sep 4, 2024
2 parents 556be3d + e87cf99 commit 16e32f0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,7 @@ class EnergyGHGEmissionsDiscipline(SoSWrapp):
GlossaryEnergy.EnergyProductionDetailedValue: {'type': 'dataframe', 'unit': 'TWh',
'visibility': SoSWrapp.SHARED_VISIBILITY,
'namespace': 'ns_energy',
'dataframe_descriptor': {
GlossaryEnergy.Years: ('float', None, True),
f'production {GlossaryEnergy.methane} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.hydrogen}.{GlossaryEnergy.gaseous_hydrogen} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.biogas} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.syngas} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.liquid_fuel} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.ethanol} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.hydrotreated_oil_fuel} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.solid_fuel} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.biomass_dry} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.electricity} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.biodiesel} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.hydrogen}.{GlossaryEnergy.liquid_hydrogen} ({GlossaryEnergy.energy_unit})': (
'float', None, True),
f'production {GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})': (
'float', None, True),
f'production {GlossaryEnergy.carbon_storage} ({GlossaryEnergy.mass_unit})': (
'float', None, True),
'Total production': ('float', None, True),
'Total production (uncut)': ('float', None, True),
},
"dynamic_dataframe_columns": True,
},
'co2_emissions_ccus_Gt': {'type': 'dataframe', 'unit': 'Gt',
'visibility': ClimateEcoDiscipline.SHARED_VISIBILITY,
Expand Down
4 changes: 2 additions & 2 deletions energy_models/core/energy_mix/energy_mix_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def run(self):
[(1. - alpha) * self.energy_model.production[GlossaryEnergy.TotalProductionValue][0] * delta_years
/ self.energy_model.production[GlossaryEnergy.TotalProductionValue].sum(), ])


if EnergyMix.PRODUCTION in self.energy_model.stream_prices:
self.energy_model.stream_prices.drop(
columns=[EnergyMix.PRODUCTION], inplace=True)
Expand Down Expand Up @@ -781,7 +781,7 @@ def compute_sos_jacobian(self):
(GlossaryEnergy.EnergyProductionDetailedValue,
f'production {energy} ({stream_class_dict[energy].unit})'),
(f'{ns_energy}.{GlossaryEnergy.EnergyProductionValue}', energy),
np.identity(len(years)) * scaling_factor_energy_production)
np.identity(len(years)) * scaling_factor_energy_production * 0.)
# ---- Loop on energy again to differentiate production and consumption ----#
for energy_input in energy_list:
ns_energy_input = self.get_ns_energy(energy_input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def compute_dnon_usecapital_dfluegas(self, dcapex_dfluegas, dprod_dfluegas):
(len(self.years), 1)))

dnon_usecapital_dfluegas = dtechnocapital_dfluegas * (
1.0 - self.applied_ratio['applied_ratio'].values).reshape((len(self.years), 1))
1.0 - self.applied_ratio['applied_ratio'].values * self.utilisation_ratio/ 100.).reshape((len(self.years), 1))

# we do not divide by / self.scaling_factor_invest_level because invest
# and non_use_capital are in G$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit
inputs_dict[GlossaryEnergy.InvestLevelValue][GlossaryEnergy.Years] <=
inputs_dict[GlossaryEnergy.YearEnd]][GlossaryEnergy.InvestValue].values,
inputs_dict['techno_infos_dict'], inputs_dict['fg_ratio_effect'])

utilisation_ratio = inputs_dict[GlossaryEnergy.UtilisationRatioValue][GlossaryEnergy.UtilisationRatioValue].values
crf = self.techno_model.compute_capital_recovery_factor(inputs_dict['techno_infos_dict'])
dfactory_dfluegas = dcapex_dfluegas * \
(crf + inputs_dict['techno_infos_dict']['Opex_percentage'])
Expand Down Expand Up @@ -115,7 +115,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit
self.set_partial_derivative_for_other_types(
(GlossaryEnergy.TechnoProductionValue, f'{self.energy_name} ({self.techno_model.product_unit})'), (
GlossaryEnergy.FlueGasMean, GlossaryEnergy.FlueGasMean),
dprod_dfluegas * self.techno_model.applied_ratio['applied_ratio'].values[:,
dprod_dfluegas * (self.techno_model.applied_ratio['applied_ratio'].values * utilisation_ratio/ 100.)[:,
np.newaxis] * scaling_factor_invest_level / scaling_factor_techno_production)

production, consumption = self.get_sosdisc_outputs(
Expand All @@ -132,7 +132,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit
self.set_partial_derivative_for_other_types(
(GlossaryEnergy.TechnoConsumptionValue, column),
(GlossaryEnergy.FlueGasMean, GlossaryEnergy.FlueGasMean),
dprod_column_dfluegas * self.techno_model.applied_ratio['applied_ratio'].values[:,
dprod_column_dfluegas * (self.techno_model.applied_ratio['applied_ratio'].values * utilisation_ratio/ 100.)[:,
np.newaxis] * scaling_factor_invest_level / scaling_factor_techno_production)
self.set_partial_derivative_for_other_types(
(GlossaryEnergy.TechnoConsumptionWithoutRatioValue,
Expand Down
15 changes: 10 additions & 5 deletions energy_models/core/techno_type/techno_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,12 @@ def d_non_use_capital_d_utilisation_ratio(self):
)
return d_non_use_capital_d_utilisation_ratio

def d_non_use_capital_d_invest_level(self, d_capital_d_invest_level):
applied_ratio = self.applied_ratio['applied_ratio'].values / 100.
utilisation_ratio = self.utilisation_ratio
return np.diag(applied_ratio * utilisation_ratio / 100.) * d_capital_d_invest_level


def compute_dlanduse_dinvest(self):
"""
compute grad d_land_use / d_invest
Expand Down Expand Up @@ -1413,8 +1419,7 @@ def compute_dprod_dratio(self, prod: np.ndarray, ratio_name: str, dapplied_ratio
# Check that the ratio corresponds to something consumed
for col in self.consumption_detailed.columns:
if ratio_name in col and ratio_name != GlossaryEnergy.Years:
dprod_dratio = (np.identity(len(self.years)) * prod) * \
dapplied_ratio_dratio[ratio_name]
dprod_dratio = np.diag(prod * self.utilisation_ratio / 100) * dapplied_ratio_dratio[ratio_name]
return dprod_dratio

def compute_dnon_usecapital_dinvest(self, dcapex_dinvest, dprod_dinvest):
Expand All @@ -1430,8 +1435,8 @@ def compute_dnon_usecapital_dinvest(self, dcapex_dinvest, dprod_dinvest):
dprod_dinvest * self.cost_details[f'Capex_{self.name}'].values.reshape(
(len(self.years), 1)))

dnon_usecapital_dinvest = dtechnocapital_dinvest * (
1.0 - self.applied_ratio['applied_ratio'].values).reshape((len(self.years), 1))
dnon_usecapital_dinvest = np.diag(
1.0 - self.applied_ratio['applied_ratio'].values * self.utilisation_ratio / 100.) @ dtechnocapital_dinvest

# we do not divide by / self.scaling_factor_invest_level because invest
# and non_use_capital are in G$
Expand All @@ -1444,7 +1449,7 @@ def compute_dnon_usecapital_dratio(self, dapplied_ratio_dratio):
'''
mult_vect = self.cost_details[f'Capex_{self.name}'].values * \
self.production_woratio[f'{self.energy_name} ({self.product_unit})'].values
dnon_use_capital_dratio = -dapplied_ratio_dratio * np.diag(mult_vect)
dnon_use_capital_dratio = -dapplied_ratio_dratio * np.diag(mult_vect * self.utilisation_ratio / 100.)
return dnon_use_capital_dratio

def compute_dcapex_dinvest(self, invest_list, data_config):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def compute_sos_jacobian(self):
CCTechnoDiscipline.compute_sos_jacobian(self)

grad_dict = self.techno_model.grad_price_vs_stream_price()

carbon_emissions = self.get_sosdisc_outputs(GlossaryEnergy.CO2EmissionsValue)
self.set_partial_derivatives_techno(
grad_dict, None)
grad_dict, carbon_emissions)

self.set_partial_derivatives_flue_gas(GlossaryEnergy.clean_energy)

0 comments on commit 16e32f0

Please sign in to comment.