Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerplant data functions #198

Merged
merged 20 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f3044f3
Removed unused packages/variables in powerplant_data
maartenbrinkerink Sep 6, 2024
9135f3d
Merge branch 'master' into powerplant_data-functions
maartenbrinkerink Sep 10, 2024
6a56c06
Merge branch 'master' into powerplant_data-functions
maartenbrinkerink Sep 10, 2024
d590bd3
First functional split of powerplant_data in functions
maartenbrinkerink Sep 12, 2024
57641f8
Updates to powerplant_data
maartenbrinkerink Sep 16, 2024
033b583
Merge branch 'master' into powerplant_data-functions
maartenbrinkerink Sep 17, 2024
4f155b1
Merge branch 'demand-refactor' into powerplant_data-functions
maartenbrinkerink Sep 17, 2024
cace89b
CP - Functional powerplant scripts standalone (untested through Snake…
maartenbrinkerink Sep 20, 2024
33b7755
Merge branch 'master' into powerplant_data-functions
maartenbrinkerink Sep 21, 2024
6268d45
Merge branch 'master' into powerplant_data-functions
maartenbrinkerink Sep 23, 2024
ce91ebf
Updates to avoid future depreciation warnings
maartenbrinkerink Sep 24, 2024
493c584
CP - Powerplant refactoring functional through Snakemake
maartenbrinkerink Sep 24, 2024
58e2241
CP: Transmission functional as standalone set of scripts, snakemake i…
maartenbrinkerink Oct 3, 2024
3f1cdbe
Merge branch 'master' into powerplant_data-functions
trevorb1 Oct 6, 2024
754705e
update file check
trevorb1 Oct 6, 2024
ea6f89a
correct residual capacity concat
trevorb1 Oct 6, 2024
a85e95b
fix udc powerplant fuels
trevorb1 Oct 7, 2024
25528c7
out of domain error fixed
trevorb1 Oct 7, 2024
c907da0
Merge pull request #206 from OSeMOSYS/file-check-patch
maartenbrinkerink Oct 8, 2024
dcf3edb
PR review updates
maartenbrinkerink Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ workflow/.DS_Store
workflow/scripts/.DS_Store

# Environment credentials
.env
.env
workflow/scripts/osemosys_global/powerplant_data_test.py
11 changes: 10 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ user_defined_capacity:
# first_year_of_expansion,
# build_rate_per_year,
# cost]
TRNINDEAINDNE: [0, 2030, "open", 2030, 10, 861]
PWRCOAINDWE01: [8, 2000, "open", 2025, 5, 1100]

user_defined_capacity_transmission:
# technology: [capacity,
# first_year,
# "fixed/open",
# first_year_of_expansion,
# build_rate_per_year,
# cost]
TRNINDEAINDNE: [5, 1975, "open", 2030, 10, 861]

nodes_to_add:
#- "AAAXX" where AAA is a 3-letter country code,
Expand Down
98 changes: 76 additions & 22 deletions workflow/rules/preprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,35 @@ demand_figures = [
# output script files

power_plant_files = [
'powerplant/CapitalCost.csv',
'powerplant/FixedCost.csv',
'powerplant/CapacityToActivityUnit.csv',
'powerplant/OperationalLife.csv',
'powerplant/TotalAnnualMaxCapacityInvestment.csv',
'powerplant/TotalAnnualMinCapacityInvestment.csv',
'FUEL.csv',
'powerplant/InputActivityRatio.csv',
'powerplant/OutputActivityRatio.csv',
'MODE_OF_OPERATION.csv',
'REGION.csv',
'powerplant/ResidualCapacity.csv',
'powerplant/TECHNOLOGY.csv',
'YEAR.csv',
'AvailabilityFactor.csv'
]

transmission_files = [
'CapitalCost.csv',
'FixedCost.csv',
'CapacityToActivityUnit.csv',
'OperationalLife.csv',
'TotalAnnualMaxCapacityInvestment.csv',
'TotalAnnualMinCapacityInvestment.csv',
'TotalTechnologyModelPeriodActivityUpperLimit.csv',
'FUEL.csv',
'InputActivityRatio.csv',
'OutputActivityRatio.csv',
'MODE_OF_OPERATION.csv',
'REGION.csv',
'ResidualCapacity.csv',
'TECHNOLOGY.csv',
'YEAR.csv',
'AvailabilityFactor.csv'
]

timeslice_files = [
Expand Down Expand Up @@ -88,42 +101,84 @@ user_capacity_files = [

check_files = os.listdir('resources/otoole/data')
generated_files = [
power_plant_files,
power_plant_files,
transmission_files,
timeslice_files,
variable_cost_files,
demand_files,
emission_files,
max_capacity_files]
for file_list in generated_files:
[check_files.remove(csv) for csv in file_list]

# rules

rule make_data_dir:
output: directory('results/data')
shell: 'mkdir -p {output}'


def powerplant_cap_custom_csv() -> str:
if config["nodes_to_add"]:
return "resources/data/custom_nodes/residual_capacity.csv"
else:
return []

rule powerplant:
message:
'Generating powerplant data...'
"Generating powerplant data..."
input:
'resources/data/PLEXOS_World_2015_Gold_V1.1.xlsx',
'resources/data/weo_2020_powerplant_costs.csv',
'resources/data/operational_life.csv',
'resources/data/naming_convention_tech.csv',
'resources/data/Costs Line expansion.xlsx',
'resources/data/weo_region_mapping.csv',
params:
trade = config['crossborderTrade'],
plexos = 'resources/data/PLEXOS_World_2015_Gold_V1.1.xlsx',
weo_costs = 'resources/data/weo_2020_powerplant_costs.csv',
weo_regions = 'resources/data/weo_region_mapping.csv',
default_op_life = 'resources/data/operational_life.csv',
naming_convention_tech = 'resources/data/naming_convention_tech.csv',
line_data = 'resources/data/Costs Line expansion.xlsx',
default_av_factors = 'resources/data/availability_factors.csv',
custom_res_cap = powerplant_cap_custom_csv()
params:
start_year = config['startYear'],
end_year = config['endYear'],
invest_techs = config['no_invest_technologies']
region_name = 'GLOBAL',
custom_nodes = config['nodes_to_add'],
user_defined_capacity = config['user_defined_capacity'],
no_investment_techs = config['no_invest_technologies'],
output_data_dir = 'results/data',
input_data_dir = 'resources/data',
powerplant_data_dir = 'results/data/powerplant',

output:
csv_files = expand('results/data/{output_file}', output_file = power_plant_files)
log:
log = 'results/logs/powerplant.log'
shell:
'python workflow/scripts/osemosys_global/powerplant_data.py 2> {log}'
script:
"../scripts/osemosys_global/powerplant/main.py"

rule transmission:
message:
"Generating transmission data..."
input:
rules.powerplant.output.csv_files,
plexos = 'resources/data/PLEXOS_World_2015_Gold_V1.1.xlsx',
default_op_life = 'resources/data/operational_life.csv',
line_data = 'resources/data/Costs Line expansion.xlsx',
params:
trade = config['crossborderTrade'],
start_year = config['startYear'],
end_year = config['endYear'],
region_name = 'GLOBAL',
custom_nodes = config['nodes_to_add'],
user_defined_capacity_transmission = config['user_defined_capacity_transmission'],
no_investment_techs = config['no_invest_technologies'],
output_data_dir = 'results/data',
input_data_dir = 'resources/data',
powerplant_data_dir = 'results/data/powerplant',
output:
csv_files = expand('results/data/{output_file}', output_file = transmission_files)
log:
log = 'results/logs/transmission.log'
script:
"../scripts/osemosys_global/transmission/main.py"

rule timeslice:
message:
Expand Down Expand Up @@ -251,6 +306,7 @@ rule file_check:
'Generating missing files...'
input:
rules.powerplant.output.csv_files,
rules.transmission.output.csv_files,
rules.timeslice.output.csv_files,
rules.variable_costs.output.csv_files,
rules.demand_projections.output.csv_files,
Expand All @@ -262,6 +318,4 @@ rule file_check:
log:
log = 'results/logs/file_check.log'
shell:
'python workflow/scripts/osemosys_global/file_check.py 2> {log}'


'python workflow/scripts/osemosys_global/file_check.py 2> {log}'
48 changes: 48 additions & 0 deletions workflow/scripts/osemosys_global/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Custom Nodes logic"""

import pandas as pd
import itertools


def _get_custom_demand_expected(
nodes: list[str], start_year: int, end_year: int
) -> pd.DataFrame:
"""Gets formatted expected custom data"""

years = range(start_year, end_year + 1)

df = pd.DataFrame(
list(itertools.product(nodes, years)), columns=["CUSTOM_NODE", "YEAR"]
)
df["REGION"] = "GLOBAL"
df["FUEL"] = "ELC" + df["CUSTOM_NODE"] + "02"

return df


def import_custom_demand_data(csv: str) -> pd.DataFrame:
"""Gets all custom demand data"""
return pd.read_csv(csv)


def get_custom_demand_data(
all_custom: pd.DataFrame, nodes: list[str], start_year: int, end_year: int
) -> pd.DataFrame:
"""Gets merged custom demand data"""

expected = _get_custom_demand_expected(nodes, start_year, end_year)

df = pd.merge(expected, all_custom, how="left", on=["CUSTOM_NODE", "YEAR"])
df = df[["REGION", "FUEL", "YEAR", "VALUE"]]

return df


def merge_default_custom_data(
default: pd.DataFrame, custom: pd.DataFrame
) -> pd.DataFrame:
assert default.columns.equals(custom.columns)
df = pd.concat([default, custom], ignore_index=True)
df["VALUE"] = df["VALUE"].round(2)
df = df.drop_duplicates(keep="first", subset=["REGION", "FUEL", "YEAR"])
return df
Loading
Loading