Skip to content

Commit

Permalink
Merge branch 'master' into ASEAN-ClimateFinance
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbrinkerink committed Dec 20, 2024
2 parents 954490e + 8d04482 commit 641bb9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions workflow/rules/preprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ rule timeslice:
csv_files = expand('results/data/{output_file}.csv', output_file=timeslice_files),
log:
log = 'results/logs/timeslice.log'
shell:
'python workflow/scripts/osemosys_global/TS_data.py 2> {log}'
script:
"../scripts/osemosys_global/TS_data.py"

rule reserves:
message:
Expand Down
48 changes: 21 additions & 27 deletions workflow/scripts/osemosys_global/TS_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main(
node_region_dict = dict(zip(nodes, regions))

hyd_df = hyd_df.loc[hyd_df["NAME"].str.endswith("Capacity Scaler")]
hyd_df["NAME"] = hyd_df["NAME"].str.split("_").str[0]
hyd_df.loc[:,"NAME"] = hyd_df["NAME"].str.split("_").str[0]

hyd_df = pd.concat([hyd_df, hyd_df_custom])

Expand Down Expand Up @@ -132,11 +132,10 @@ def correct_datetime_formatting(time_str):
)

# Create column for weekday/weekend
demand_df["Day-of-week"] = demand_df["Datetime"].dt.dayofweek
demand_df.loc[demand_df["Day-of-week"] < 5, "Day-of-week"] = "WD"
demand_df["Day-of-week"] = demand_df["Datetime"].dt.dayofweek.astype(str)
demand_df.loc[demand_df["Day-of-week"].isin([0,1,2,3,4]), "Day-of-week"] = "WD"
demand_df.loc[demand_df["Day-of-week"] != "WD", "Day-of-week"] = "WE"


# ### Create dictionaries for 'seasons' and 'dayparts'

seasons_dict = dict(zip(list(seasons_df["month"]), list(seasons_df["season"])))
Expand All @@ -155,7 +154,7 @@ def correct_datetime_formatting(time_str):


demand_df["Season"] = demand_df["Month"]
demand_df["Season"].replace(seasons_dict, inplace=True)
demand_df["Season"] = demand_df["Season"].replace(seasons_dict)

demand_df["Hour"] = demand_df["Hour"].map(lambda x: apply_timeshift(int(x), timeshift))
for daypart in dayparts_dict:
Expand All @@ -176,7 +175,7 @@ def correct_datetime_formatting(time_str):
# ### Create column for timeslice with and without day-type


if daytpe:
if daytype:
demand_df["TIMESLICE"] = (
demand_df["Season"] + demand_df["Day-of-week"] + demand_df["Daypart"]
)
Expand Down Expand Up @@ -219,7 +218,7 @@ def correct_datetime_formatting(time_str):
value_name="demand",
)

sp_demand_df = sp_demand_df.groupby(["TIMESLICE", "node"], as_index=False).agg(sum)
sp_demand_df = sp_demand_df.groupby(["TIMESLICE", "node"], as_index=False).sum()

# Calculate SpecifiedAnnualDemand
total_demand_df = (
Expand Down Expand Up @@ -305,9 +304,6 @@ def correct_datetime_formatting(time_str):
# CapacityFactor

datetime_ts_df = demand_df[["Datetime", "TIMESLICE"]]
capfac_all_df = pd.DataFrame(
columns=["REGION", "TECHNOLOGY", "TIMESLICE", "YEAR", "VALUE"]
)

def capacity_factor(df):
df["Datetime"] = pd.to_datetime(df["Datetime"], format="%d/%m/%Y %H:%M")
Expand Down Expand Up @@ -368,10 +364,10 @@ def capacity_factor(df):

return capfac_df_final


capfacs = [capfac_all_df]
capfacs = []
for each in [hyd_df_processed, csp_df, spv_df, won_df, wof_df]:
capfacs.append(capacity_factor(each))

capfac_all_df = pd.concat(capfacs).reset_index(drop=True)

capfac_all_df.drop_duplicates(
Expand Down Expand Up @@ -451,7 +447,6 @@ def capacity_factor(df):
end_year = snakemake.params.end_year
region_name = snakemake.params.region_name
geographic_scope = snakemake.params.geographic_scope
custom_nodes = snakemake.params.custom_nodes
output_data_dir = snakemake.params.output_data_dir
input_data_dir = snakemake.params.input_data_dir
output_dir = snakemake.params.output_dir
Expand All @@ -462,18 +457,18 @@ def capacity_factor(df):
dayparts = snakemake.params.dayparts
timeshift = snakemake.params.timeshift

plexos_demand = snakemake.input.plexos_demand
plexos_csp_2015 = snakemake.input.plexos_csp_2015
plexos_spv_2015 = snakemake.input.plexos_spv_2015
plexos_hyd_2015 = snakemake.input.plexos_hyd_2015
plexos_won_2015 = snakemake.input.plexos_won_2015
plexos_wof_2015 = snakemake.input.plexos_wof_2015
custom_specified_demand_profiles = snakemake.input.custom_specified_demand_profiles
custom_csp_profiles = snakemake.input.custom_csp_profiles
custom_hyd_profiles = snakemake.input.custom_hyd_profiles
custom_spv_profiles = snakemake.input.custom_spv_profiles
custom_wof_profiles = snakemake.input.custom_wof_profiles
custom_won_profiles = snakemake.input.custom_won_profiles
plexos_demand = pd.read_csv(snakemake.input.plexos_demand)
plexos_csp_2015 = pd.read_csv(snakemake.input.plexos_csp_2015)
plexos_spv_2015 = pd.read_csv(snakemake.input.plexos_spv_2015)
plexos_hyd_2015 = pd.read_csv(snakemake.input.plexos_hyd_2015)
plexos_won_2015 = pd.read_csv(snakemake.input.plexos_won_2015)
plexos_wof_2015 = pd.read_csv(snakemake.input.plexos_wof_2015)
custom_specified_demand_profiles = pd.read_csv(snakemake.input.custom_specified_demand_profiles)
custom_csp_profiles = pd.read_csv(snakemake.input.custom_csp_profiles)
custom_hyd_profiles = pd.read_csv(snakemake.input.custom_hyd_profiles)
custom_spv_profiles = pd.read_csv(snakemake.input.custom_spv_profiles)
custom_wof_profiles = pd.read_csv(snakemake.input.custom_wof_profiles)
custom_won_profiles = pd.read_csv(snakemake.input.custom_won_profiles)

# The below else statement defines variables if the 'powerplant/main' script is to be run locally
# outside the snakemake workflow. This is relevant for testing purposes only! User inputs when running
Expand All @@ -484,13 +479,12 @@ def capacity_factor(df):
end_year = 2050
region_name = 'GLOBAL'
geographic_scope = ['BTN', 'IND']
custom_nodes = []
output_data_dir = 'results/data'
input_data_dir = 'resources/data'
output_dir = 'results'
input_dir = 'resources'
custom_nodes_dir = 'resources/data/custom_nodes'
daytpe = False
daytype = False
seasons = {'S1': [1, 2, 3, 4, 5, 6],
'S2': [7, 8, 9, 10, 11, 12]}
dayparts = {'D1': [1, 7],
Expand Down

0 comments on commit 641bb9a

Please sign in to comment.