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 Aug 29, 2024
2 parents 0904e52 + 84867ec commit 20af047
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 49 deletions.
10 changes: 10 additions & 0 deletions climateeconomics/core/core_emissions/ghg_emissions_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, param):
"""
Constructor
"""
self.emissions_after_2050_df = None
self.energy_emission_households_df = None
self.residential_energy_consumption = None
self.dict_sector_sections_energy_emissions = {}
Expand Down Expand Up @@ -361,6 +362,8 @@ def compute(self, inputs_dict):
self.compute_total_gwp()
self.compute_gwp_per_sector()
self.compute_CO2_emissions_objective()
self.compute_net_zero_2050_constraint_df()


# compute emission households
self.compute_energy_emission_households()
Expand Down Expand Up @@ -439,3 +442,10 @@ def compute_energy_emission_households(self):
GlossaryCore.TotalEmissions: energy_emission_households
})

def compute_net_zero_2050_constraint_df(self):

self.emissions_after_2050_df = self.ghg_emissions_df.loc[self.years_range >= 2050][
[GlossaryCore.Years, GlossaryCore.insertGHGTotalEmissions.format(GlossaryCore.CO2)]]

def d_2050_carbon_negative_constraint(self, d_total_co2_emissions):
return d_total_co2_emissions[self.years_range >= 2050]
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ClimateEcoDiscipline(SoSWrapp):
}

YEAR_START_DESC_IN = {'type': 'int', 'default': GlossaryCore.YearStartDefault,
'unit': 'year', 'visibility': 'Shared', 'namespace': 'ns_public', 'range': [1950,2040]}
'unit': 'year', 'visibility': 'Shared', 'namespace': 'ns_public', 'range': [1950, 2080]}
TIMESTEP_DESC_IN = {'type': 'int', 'default': 1, 'unit': 'year per period',
'visibility': 'Shared', 'namespace': 'ns_public', 'user_level': 2}
ALPHA_DESC_IN = {'type': 'float', 'range': [0., 1.], 'default': 0.5, 'visibility': 'Shared', 'namespace': GlossaryCore.NS_WITNESS,
Expand Down
2 changes: 2 additions & 0 deletions climateeconomics/glossarycore.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class GlossaryCore:
ConstraintLowerBoundUsableCapital = "Lower bound usable capital constraint"
ConstraintUpperBoundUsableCapital = "upper_bound_usable_capital_constraint"
ConstraintEnergyNonUseCapital = "constraint_non_use_capital_energy"
ConstraintCarbonNegative2050 = "constraint_carbon_negative_2050"
CleanEnergySimpleTechno = "CleanEnergySimpleTechno"
clean_energy = "clean_energy"
ConsumptionObjective = "consumption_objective"
Expand Down Expand Up @@ -165,6 +166,7 @@ class GlossaryCore:
TechnoConsumptionWithoutRatioValue = "techno_consumption_woratio"
ConstructionDelay = "construction_delay"
LifetimeName = "lifetime"
IsTechnoMainstream = "is_mainstream"
InitialPlantsAgeDistribFactor = "initial_plants_age_distrib_factor"

# namespaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from climateeconomics.core.tools.ClimateEconomicsStudyManager import (
ClimateEconomicsStudyManager,
)
from climateeconomics.glossarycore import GlossaryCore
from climateeconomics.sos_processes.iam.witness.witness_coarse_dev_ms_story_telling.usecase_witness_ms_mda import (
Study as uc_ms_mda,
)
Expand All @@ -39,11 +40,12 @@

class Study(ClimateEconomicsStudyManager):

def __init__(self, filename=__file__, bspline=False, run_usecase=False, execution_engine=None):
def __init__(self, year_start=GlossaryCore.YearStartDefault,filename=__file__, bspline=False, run_usecase=False, execution_engine=None):
super().__init__(filename, run_usecase=run_usecase, execution_engine=execution_engine)
self.bspline = bspline
self.data_dir = join(dirname(__file__), 'data')
self.test_post_procs = False
self.year_start = year_start

self.scatter_scenario = 'optimization scenarios'

Expand All @@ -62,7 +64,7 @@ def setup_usecase(self, study_folder_path=None):
}

for scenario_name, studyClass in self.scenario_dict.items():
scenarioUseCase = studyClass(execution_engine=self.execution_engine)
scenarioUseCase = studyClass(execution_engine=self.execution_engine, year_start=self.year_start)
scenarioUseCase.study_name = f'{self.study_name}.{self.scatter_scenario}.{scenario_name}'
scenarioData = scenarioUseCase.setup_usecase()
scenarioDatadict = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
limitations under the License.
'''
import pandas as pd

from climateeconomics.glossarycore import GlossaryCore
from climateeconomics.sos_processes.iam.witness.witness_coarse_dev_ms_optim_ku_process.usecase_ms_ku import (
Study as Study2020,
Expand All @@ -22,15 +24,20 @@
class Study(Study2020):

def __init__(self, run_usecase=False, execution_engine=None):
super().__init__(filename=__file__, run_usecase=run_usecase, execution_engine=execution_engine)
super().__init__(year_start=2023, filename=__file__, run_usecase=run_usecase, execution_engine=execution_engine)
self.test_post_procs = True

def setup_usecase(self, study_folder_path=None):
values_dict = super().setup_usecase(study_folder_path)
values_dict.update(
{f"{self.study_name}.{self.scatter_scenario}.{scenario_name}.{GlossaryCore.YearStart}": 2023 for
scenario_name
in self.scenario_dict.keys()})
year_start_varnames = list(filter(lambda x: f".{GlossaryCore.YearStart}" in x, values_dict.keys()))
values_dict.update({varname: 2023 for varname in year_start_varnames})

values_dict_2023 = {}
for key,value in values_dict.items():
if isinstance(value, pd.DataFrame) and GlossaryCore.Years in value.columns:
new_value = value.loc[value[GlossaryCore.Years] >= 2023]
values_dict_2023[key] = new_value
values_dict.update(values_dict_2023)

return values_dict

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
See the License for the specific language governing permissions and
limitations under the License.
'''

import pandas as pd
from sostrades_optimization_plugins.models.func_manager.func_manager import (
FunctionManager,
)
from sostrades_optimization_plugins.models.func_manager.func_manager_disc import (
FunctionManagerDisc,
)
Expand Down Expand Up @@ -59,6 +62,22 @@ def setup_usecase(self, study_folder_path=None):
for dict_data in witness_uc_data:
values_dict.update(dict_data)

function_df_key = list(filter(lambda x: 'function_df' in x, values_dict.keys()))[0]
function_df = values_dict[function_df_key]
func_df = pd.DataFrame({
'variable': [GlossaryCore.ConstraintCarbonNegative2050,],
'parent': [
'constraint_carbon_negative_2050'
],
'ftype': FunctionManager.INEQ_CONSTRAINT,
'weight': 1.,
FunctionManager.AGGR: FunctionManager.INEQ_NEGATIVE_WHEN_SATIFIED_AND_SQUARE_IT,
'namespace': [GlossaryCore.NS_FUNCTIONS]
})
function_df = pd.concat([function_df, func_df])

values_dict[function_df_key] = function_df

# design space WITNESS

# optimization functions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class GHGemissionsDiscipline(ClimateEcoDiscipline):
GlossaryCore.EnergyCarbonIntensityDfValue: GlossaryCore.EnergyCarbonIntensityDf,
GlossaryCore.EconomicsEmissionDfValue: GlossaryCore.EmissionDf,
GlossaryCore.ResidentialEmissionsDfValue: GlossaryCore.ResidentialEmissionsDf,
GlossaryCore.AllSectionsEmissionsDfValue: GlossaryCore.AllSectionsEmissionsDf
GlossaryCore.AllSectionsEmissionsDfValue: GlossaryCore.AllSectionsEmissionsDf,
GlossaryCore.ConstraintCarbonNegative2050: {'type': 'dataframe', 'unit': '-', 'visibility': ClimateEcoDiscipline.SHARED_VISIBILITY, 'namespace': GlossaryCore.NS_FUNCTIONS}
}

def setup_sos_disciplines(self):
Expand Down Expand Up @@ -189,7 +190,8 @@ def run(self):
GlossaryCore.TotalEnergyEmissions: self.emissions_model.total_energy_co2eq_emissions,
GlossaryCore.EnergyCarbonIntensityDfValue: self.emissions_model.carbon_intensity_of_energy_mix,
GlossaryCore.EconomicsEmissionDfValue: self.emissions_model.total_economics_emisssions[GlossaryCore.EmissionDf['dataframe_descriptor'].keys()],
GlossaryCore.ResidentialEmissionsDfValue: self.emissions_model.energy_emission_households_df
GlossaryCore.ResidentialEmissionsDfValue: self.emissions_model.energy_emission_households_df,
GlossaryCore.ConstraintCarbonNegative2050: self.emissions_model.emissions_after_2050_df
}

for sector in self.emissions_model.new_sector_list:
Expand Down Expand Up @@ -225,12 +227,25 @@ def compute_sos_jacobian(self):
(GlossaryCore.GHGEmissionsDfValue, GlossaryCore.insertGHGTotalEmissions.format(ghg)),
(GlossaryCore.insertGHGAgriLandEmissions.format(ghg), column),
np.identity(len(years)))
if ghg == GlossaryCore.CO2:
d_constraint_2050 = self.emissions_model.d_2050_carbon_negative_constraint(np.identity(len(years)))
self.set_partial_derivative_for_other_types(
(GlossaryCore.ConstraintCarbonNegative2050, GlossaryCore.insertGHGTotalEmissions.format(GlossaryCore.CO2)),
(GlossaryCore.insertGHGAgriLandEmissions.format(ghg), column),
d_constraint_2050)

self.set_partial_derivative_for_other_types(
(GlossaryCore.GHGEmissionsDfValue, GlossaryCore.insertGHGTotalEmissions.format(ghg)),
('GHG_total_energy_emissions', GlossaryCore.insertGHGTotalEmissions.format(ghg)),
np.identity(len(years)))

if ghg == GlossaryCore.CO2:
d_constraint_2050 = self.emissions_model.d_2050_carbon_negative_constraint(np.identity(len(years)))
self.set_partial_derivative_for_other_types(
(GlossaryCore.ConstraintCarbonNegative2050, GlossaryCore.insertGHGTotalEmissions.format(GlossaryCore.CO2)),
('GHG_total_energy_emissions', GlossaryCore.insertGHGTotalEmissions.format(ghg)),
d_constraint_2050)

self.set_partial_derivative_for_other_types(
(GlossaryCore.TotalEnergyEmissions, GlossaryCore.TotalEnergyEmissions),
('GHG_total_energy_emissions', GlossaryCore.insertGHGTotalEmissions.format(ghg)),
Expand Down Expand Up @@ -289,6 +304,10 @@ def compute_sos_jacobian(self):
(GlossaryCore.GHGEmissionsDfValue, GlossaryCore.insertGHGTotalEmissions.format(GlossaryCore.CO2)),
(f"{sector}.{GlossaryCore.SectionGdpDfValue}", section),
d_sector_section_non_energy_emissions_d_section_gdp)
self.set_partial_derivative_for_other_types(
(GlossaryCore.ConstraintCarbonNegative2050, GlossaryCore.insertGHGTotalEmissions.format(GlossaryCore.CO2)),
(f"{sector}.{GlossaryCore.SectionGdpDfValue}", section),
self.emissions_model.d_2050_carbon_negative_constraint(d_sector_section_non_energy_emissions_d_section_gdp))
self.set_partial_derivative_for_other_types(
(GlossaryCore.EconomicsEmissionDfValue, GlossaryCore.TotalEmissions),
(f"{sector}.{GlossaryCore.SectionGdpDfValue}", section),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Generation of the consumption in $ for each sector based on :
- population
- a value of reference for yearly need in each sector, in $/person. For example, GDP Agriculture 2020 / GDP 2020.

For each sector, consumption, expressed in $, is calculated as :
$$ consumption\ sector\ S = population \times Value\ of \reference \sector S $$
For each sector, consumption, expressed in $, is calculated as :
$$consumption\ sector\ S = population \times Value\ of \reference \sector S$$

## Redistribution of resources

Expand All @@ -20,11 +20,11 @@ Inputs :
Output:
- for each sector :

$$ allocated\ energy\ for\ sector\ S = Share\ energy\ sector\ S \times Total\ energy\ production\ S$$
$$allocated\ energy\ for\ sector\ S = Share\ energy\ sector\ S \times Total\ energy\ production\ S$$

- Total :

$$ Total\ allocated\ energy\ = Sum\ of\ allocated\ energy\ on\ sectors$$
$$Total\ allocated\ energy\ = Sum\ of\ allocated\ energy\ on\ sectors$$

#### Investments

Expand All @@ -34,5 +34,5 @@ Inputs :
Output:
- Total investments

$$ Total\ investments\ = Sum\ of\ investments\ on\ sectors\ $$
$$Total\ investments\ = Sum\ of\ investments\ on\ sectors\$$

Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Inputs :
Output:
- Total investments

$$ Total\ investments\ = Sum\ of\ investments\ on\ sectors\ $$
$$ Total\ investments\ = Sum\ of\ investments\ on\ sectors\$$

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ Inputs :
Output:
- Total investments

$$ Total\ investments\ = Sum\ of\ investments\ on\ sectors\ $$
$$ Total\ investments\ = Sum\ of\ investments\ on\ sectors\$$

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $$\beta_i := \sum_{\mathclap{j \in J}} \alpha_{i,j}$$
Finally [^10], death rate is impacted by average calorie intake and deviating from a parametrable reference value will have a significant impact on death rate in both ways. Death rate age range is impacted differently whether the average calorie intake rises or decreases: younger people will be more impacted by undernutrition whereas older one by overnutrition due to cardiovascular deseases [^11]. It is modelized such as:
$$DR\_i = \widetilde{DR}\_i + \overline{DR}\_i$$
with $\widetilde{DR}\_i$ death rate related to economy and temperature, $\overline{DR}\_i$ related to calorie intake.
$$\(\overline{DR}\_i = \alpha\_{i,j} \left| \frac{kcal - kcal\_{\text{ref}}}{\theta \cdot kcal\_{\text{ref}}} \right|\)$$
$$\overline{DR}_i = \alpha_{i,j} \left| \frac{\text{kcal} - \text{kcal}_{\text{ref}}}{\theta \cdot \text{kcal}_{\text{ref}}} \right|$$
with $kcal$ average food intake per capita per day, $kcal\_{ref}$ food intake recommended per capita per day, $\alpha$ relative increase in the probability of dying due to risk j for age-group i, $\theta$ fitting value.

The following table shows the relative increase in mortality $\alpha$:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ $$RF_{CH4,N2O,t} = 0.036 (\sqrt{C_{CH4}^t}-\sqrt{C_{CH4}^{1750}}) - MN(C_{CH4}^t

with $MN$ a function defined as:

$$ MN(c1,c2) =0.47 \log(1 + 2.01.10^{-5} (c_1 c_2)^{0.75} +
5.31.10^{-15} c_1 (c_1 c_2)^{1.52}) $$
$$MN(c1,c2) =0.47 \log(1 + 2.01.10^{-5} (c_1 c_2)^{0.75} +
5.31.10^{-15} c_1 (c_1 c_2)^{1.52})$$


The Myhre equation is mainly used in climate change models such as in MAGICC [^4], FUND [^5] or FAIR [^6] models.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ $$RF_{CH4,N2O,t} = 0.036 (\sqrt{C_{CH4}^t}-\sqrt{C_{CH4}^{1750}}) - MN(C_{CH4}^t

with $MN$ a function defined as :

$$ MN(c1,c2) =0.47 \log(1 + 2.01.10^{-5} (c_1 c_2)^{0.75} +
5.31.10^{-15} c_1 (c_1 c_2)^{1.52}) $$
$$MN(c1,c2) =0.47 \log(1 + 2.01.10^{-5} (c_1 c_2)^{0.75} +
5.31.10^{-15} c_1 (c_1 c_2)^{1.52})$$


The Myhre equation is mainly used in climate change models such as in MAGICC [^4], FUND [^5] or FAIR [^6] models.
Expand All @@ -53,8 +53,8 @@ The model of Etminan [^7] is an improved version of the Myhre model especially f
$$RF_{CO2,t} = \eta_{CO2,Etminan}(\ln(C_{CO2}^t) - ln(C_{CO2}^{1750}))$$

with :
$$ \eta_{CO2,Etminan} = -2.4.10^{-7} (C_{CO2}^t - C_{CO2}^{1750})^2 + 7.2.10^{-4} abs(C_{CO2}^t - C_{CO2}^{1750}) \\ -2.1.10^{-4} * n2o_{mean} + \frac{\eta}{np.log(2)} $$

$$\eta_{CO2,Etminan} = -2.4.10^{-7} (C_{CO2}^t - C_{CO2}^{1750})^2 + 7.2.10^{-4} abs(C_{CO2}^t - C_{CO2}^{1750}) \\ -2.1.10^{-4} * n2o_{mean} + \frac{\eta}{np.log(2)}$$

$$n2o_{mean}= \frac{1}{2}(C_{N2O}^t + C_{N2O}^{1750})$$

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 20af047

Please sign in to comment.