Skip to content

Commit

Permalink
Add more type hints to model/material
Browse files Browse the repository at this point in the history
  • Loading branch information
macflo8 committed Oct 14, 2024
1 parent 820160e commit 778f02a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion message_ix_models/model/material/data_ammonia_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def gen_all_NH3_fert(


def broadcast_years(
df_new: pd.DataFrame, max_lt: int, act_years, vtg_years
df_new: pd.DataFrame, max_lt: int, act_years: pd.Series, vtg_years: pd.Series
) -> pd.DataFrame:
if "year_act" in df_new.columns:
df_new = df_new.pipe(same_node).pipe(broadcast, year_act=act_years)
Expand Down
4 changes: 1 addition & 3 deletions message_ix_models/model/material/data_cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def gen_data_cement(
context.datafile = "Global_steel_cement_MESSAGE.xlsx"

# Techno-economic assumptions
# TEMP: now add cement sector as well
data_cement = read_sector_data(scenario, "cement", "Global_cement_MESSAGE.xlsx")
# Special treatment for time-dependent Parameters
data_cement_ts = read_timeseries(scenario, "cement", "Global_cement_MESSAGE.xlsx")
Expand All @@ -183,15 +182,14 @@ def gen_data_cement(
# List of data frames, to be concatenated together at end
results = defaultdict(list)

# For each technology there are differnet input and output combinations
# For each technology there are different input and output combinations
# Iterate over technologies

yv_ya = s_info.yv_ya
yv_ya = yv_ya.loc[yv_ya.year_vtg >= 1980]
# Do not parametrize GLB region the same way
nodes = nodes_ex_world(s_info.N)

# for t in s_info.set['technology']:
for t in config["technology"]["add"]:
t = t.id
params = data_cement.loc[(data_cement["technology"] == t), "parameter"].unique()
Expand Down
6 changes: 4 additions & 2 deletions message_ix_models/model/material/data_generic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict

import pandas as pd
from message_ix import make_df
from message_ix import Scenario, make_df

import message_ix_models.util
from message_ix_models import ScenarioInfo
Expand Down Expand Up @@ -40,7 +40,9 @@ def read_data_generic(scenario: Scenario) -> (pd.DataFrame, pd.DataFrame):
return data_generic, data_generic_ts


def gen_data_generic(scenario: Scenario, dry_run: bool = False) -> dict[str, pd.DataFrame]:
def gen_data_generic(
scenario: Scenario, dry_run: bool = False
) -> dict[str, pd.DataFrame]:
# Load configuration

config = read_config()["material"]["generic"]
Expand Down
22 changes: 3 additions & 19 deletions message_ix_models/model/material/data_petro.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import defaultdict
from typing import List
from typing import List, Set

import message_ix
import pandas as pd
Expand Down Expand Up @@ -166,7 +166,7 @@ def get_demand_t1_with_income_elasticity(


def gen_data_petro_ts(
data_petro_ts: pd.DataFrame, results: dict[list], tec_ts, nodes
data_petro_ts: pd.DataFrame, results: dict[list], tec_ts: Set[str], nodes: List[str]
) -> None:
for t in tec_ts:
common = dict(
Expand Down Expand Up @@ -234,7 +234,7 @@ def assign_input_outpt(
split: str,
param_name: str,
regions: pd.DataFrame,
val,
val: float | int,
t: str,
rg: str,
global_region: str,
Expand Down Expand Up @@ -480,23 +480,7 @@ def gen_data_petro_chemicals(
)
results["demand"].append(demand_hvc)

# df_e = make_df(paramname, level='final_material', commodity="ethylene", \
# value=demand_e.value, unit='t',year=demand_e.year, time='year', \
# node=demand_e.node)#.pipe(broadcast, node=nodes)
# results["demand"].append(df_e)
#
# df_p = make_df(paramname, level='final_material', commodity="propylene", \
# value=demand_p.value, unit='t',year=demand_p.year, time='year', \
# node=demand_p.node)#.pipe(broadcast, node=nodes)
# results["demand"].append(df_p)
#
# df_BTX = make_df(paramname, level='final_material', commodity="BTX", \
# value=demand_BTX.value, unit='t',year=demand_BTX.year, time='year', \
# node=demand_BTX.node)#.pipe(broadcast, node=nodes)
# results["demand"].append(df_BTX)

# Special treatment for time-varying params

tec_ts = set(data_petro_ts.technology) # set of tecs in timeseries sheet

gen_data_petro_ts(data_petro_ts, results, tec_ts, nodes)
Expand Down
2 changes: 1 addition & 1 deletion message_ix_models/model/material/data_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ def gen_te_projections(


def get_ssp_soc_eco_data(
context: "Context", model: str, measure: str, tec
context: "Context", model: str, measure: str, tec: str
) -> pd.DataFrame:
"""
Function to update scenario GDP and POP timeseries to SSP 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def steel_function(x: pd.DataFrame | float, a: float, b: float, m: float):
return a * np.exp(b / gdp_pcap) * (1 - m) ** del_t


def cement_function(x: pd.DataFrame | float, a, b):
def cement_function(x: pd.DataFrame | float, a: float, b: float):
gdp_pcap = x[0]
return a * np.exp(b / gdp_pcap)

Expand Down

0 comments on commit 778f02a

Please sign in to comment.