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

Change input file formats and input paths in chilled #29

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
01de126
Add CSV versions of input archetype files
measrainsey Oct 15, 2024
46a8ac2
Update functions to read in CSVs and condense functions
measrainsey Oct 15, 2024
b8271ab
Modify input parameters of updated function
measrainsey Oct 15, 2024
d2da3ff
Update parameters of function
measrainsey Oct 15, 2024
a8b31e6
Add CSV files for `dle_coolssp` version
measrainsey Oct 15, 2024
77078c1
Add CSV input files for `test` version
measrainsey Oct 15, 2024
f083caf
Remove Excel files for `ALPS2023` version
measrainsey Oct 15, 2024
f0062ac
Remove Excel files for `dle_coolssp` version
measrainsey Oct 15, 2024
9ec16d5
Remove Excel files for `test` version
measrainsey Oct 15, 2024
7d861b6
Change `read_excel` to `read_csv`
measrainsey Oct 16, 2024
7bc8668
Fix naming in arch input of `dle_coolssp` scenario
measrainsey Oct 16, 2024
c7f3293
Add arch input data for `low` arch
measrainsey Oct 16, 2024
c041c82
Remove path setting in config
measrainsey Oct 22, 2024
884681d
Add function to set paths based on user
measrainsey Oct 22, 2024
9497a78
Update path setting in other scripts
measrainsey Oct 22, 2024
b728bf3
Add second version string to correct data path
measrainsey Oct 22, 2024
4e78f3f
Fix path name typo
measrainsey Oct 22, 2024
4595c5c
Update paths to use `get_paths()` in preprocessing
measrainsey Oct 31, 2024
96da133
Save postprocessed CHILLED data
measrainsey Oct 22, 2024
50d1cf6
Merge pull request #34 from iiasa/chilled/upd-post
measrainsey Oct 31, 2024
6e173c7
Merge pull request #32 from iiasa/chilled/upd-paths
measrainsey Oct 31, 2024
f406a31
Rename `chilled.util.util` to `chilled.util.base`
measrainsey Oct 31, 2024
b7bd7f2
Move `get_logger()` and `get_project_root()` to new `chilled.util.com…
measrainsey Oct 31, 2024
8d340e9
Change logging from FileHandler() to StreamHandler() on stdout
measrainsey Oct 31, 2024
75bca5d
Add Literal options in config
measrainsey Dec 18, 2024
94ac6d9
Fix Literal options for popfix
measrainsey Dec 18, 2024
1415f2e
Create version for ALPS2024 (copied over from ALPS2023)
measrainsey Dec 19, 2024
5fa2514
Turn on both cooling and heating in config as default
measrainsey Dec 19, 2024
19a3dd8
Replace `config.chunk_size` with `get_paths(config, chunk_size)`
measrainsey Dec 19, 2024
fd2b17f
Change path that preprocess rasters are saved to
measrainsey Dec 19, 2024
772dd43
Add input data for ALPS2024 version with only heating
measrainsey Dec 19, 2024
a4a9543
Add script to run just heating
measrainsey Dec 19, 2024
dfcff62
Bring back variables lost to linting
measrainsey Dec 19, 2024
af71628
Add script to only process ISO tables
measrainsey Dec 19, 2024
1165ba9
Add other functions back
measrainsey Dec 19, 2024
1537281
Move run_iso.py file
measrainsey Dec 19, 2024
3589696
Turn off cooling in run_iso.py
measrainsey Dec 19, 2024
92e6b83
Remove Nd filter from calculation of E_h
measrainsey Dec 19, 2024
7f72a15
Fix issue with df_cool being needed when heat == 1
measrainsey Dec 20, 2024
acd5861
Only run `process_iso_tables()` function
measrainsey Dec 20, 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
162 changes: 108 additions & 54 deletions message_ix_buildings/chilled/core/climate.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion message_ix_buildings/chilled/functions/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pyam # type: ignore
import statsmodels.formula.api as smf # type: ignore

from message_ix_buildings.chilled.util.util import get_logger
from message_ix_buildings.chilled.util.common import get_logger

log = get_logger(__name__)

Expand Down
16 changes: 13 additions & 3 deletions message_ix_buildings/chilled/postprocess/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import pandas as pd

from message_ix_buildings.chilled.util.base import get_paths
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config
from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)
cfg = Config()
cfg = Config(user="MEAS")
dle_path = get_paths(cfg, "dle_path")


def get_sturm_data(input_path, input_version_name):
Expand Down Expand Up @@ -196,6 +198,14 @@ def postprocess_electricity_demand(input_path, input_version_name):
)

# Save files

df_chilled.to_csv(
os.path.join(version_output_path, "chilled_postprocessed.csv"),
index=False,
)

log.info("Saved: " + os.path.join(version_output_path, "chilled_postprocessed.csv"))

df_sturm.to_csv(
os.path.join(version_output_path, "sturm_building_stock_inputs.csv"),
index=False,
Expand Down Expand Up @@ -254,4 +264,4 @@ def postprocess_electricity_demand(input_path, input_version_name):
)


postprocess_electricity_demand(cfg.dle_path, cfg.vstr)
postprocess_electricity_demand(dle_path, cfg.vstr2 + "_" + cfg.vstr)
19 changes: 12 additions & 7 deletions message_ix_buildings/chilled/preprocess/archetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
from functions.variable_dicts import VARS_ARCHETYPES # type: ignore
from preprocess.message_raster import create_message_raster # type: ignore

from message_ix_buildings.chilled.util.config import Config # type: ignore
from message_ix_buildings.chilled.util.util import (
from message_ix_buildings.chilled.util.base import (
get_archs,
get_logger,
get_paths,
read_arch_inputs_df,
read_arch_reg_df,
)
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config # type: ignore

log = get_logger(__name__)


def create_archetypes(config: "Config"):
out_path = os.path.join(config.project_path, "out", "version")
project_path = get_paths(config, "project_path")

out_path = os.path.join(project_path, "out", "version")
archetype_path = os.path.join(out_path, config.vstr, "rasters")

# if archetypes folder does not exist, create it
Expand All @@ -49,7 +52,7 @@ def create_archetypes(config: "Config"):
)

for arch in vers_archs:
arch_reg = read_arch_reg_df(config, arch)
arch_reg = read_arch_reg_df(config).query("arch == @arch")

# Create map of archetypes based on MESSAGE regions raster
arch_map = xr.Dataset(
Expand Down Expand Up @@ -101,7 +104,9 @@ def create_archetypes(config: "Config"):


def create_archetype_variables(config: "Config"):
out_path = os.path.join(config.project_path, "out", "version")
project_path = get_paths(config, "project_path")

out_path = os.path.join(project_path, "out", "version")
archetype_path = os.path.join(out_path, config.vstr, "rasters")

# get archs
Expand All @@ -115,7 +120,7 @@ def map_archetype_variables(args):
)

# read in input files
arch_inputs = read_arch_inputs_df(config, arch)
arch_inputs = read_arch_inputs_df(config).query("arch == @arch")

# read in relevant archetype raster
map = xr.open_dataset(
Expand Down
6 changes: 4 additions & 2 deletions message_ix_buildings/chilled/preprocess/message_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pandas as pd
import xarray as xr

from message_ix_buildings.chilled.util.base import get_paths
from message_ix_buildings.chilled.util.config import Config


Expand All @@ -35,11 +36,12 @@ def create_message_raster(config: "Config"):
ISO attributes in a dataframe

"""
input_path = os.path.join(config.dle_path)
input_path = get_paths(config, "dle_path")
message_region_file = get_paths(config, "message_region_map_file")

if config.node == "R11":
msgregions = pd.read_excel(
config.message_region_file,
message_region_file,
sheet_name="regional definition",
)

Expand Down
2 changes: 1 addition & 1 deletion message_ix_buildings/chilled/run_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
process_floor_area_maps,
process_iso_tables,
)
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config # type: ignore
from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)

Expand Down
115 changes: 115 additions & 0 deletions message_ix_buildings/chilled/run_heat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import datetime
import sys
from argparse import ArgumentParser

from rich.progress import track # type: ignore

from message_ix_buildings.chilled.core.climate import (
aggregate_urban_rural_files,
create_climate_variables_maps,
make_vdd_total_maps,
process_construction_shares,
process_country_maps,
process_final_maps,
process_floor_area_maps,
process_iso_tables,
)
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config # type: ignore

log = get_logger(__name__)


def parse_arguments(arguments):
"""

:return:
"""
parser = ArgumentParser(add_help=True)

parser.add_argument(
"-version",
"--version",
default="ALPS2023",
help="Version of inputs to run. Default: ALPS2023.",
)
parser.add_argument(
"-gcm",
"--gcm",
default="GFDL-ESM4",
help="GCM to run. Options: GFDL-ESM4, IPSL-CM6A-LR, MPI-ESM1-2-HR, MRI-ESM2-0, \
UKESM1-0-LL. Default: GFDL-ESM4.",
)
parser.add_argument(
"-rcp",
"--rcp",
default="baseline",
help="RCP to run. Options: ssp126, ssp370, ssp585, baseline. \
Default: baseline.",
)

# Parse arguments
parsed_arguments = parser.parse_known_args(args=arguments)[0]

return parsed_arguments


def print_arguments(parsed_arguments):
"""
:param parsed_arguments:

"""

# Print arguments
log.info(
"\n"
+ "---------- Parsed arguments ------------"
+ "\n"
+ "Selected version: "
+ parsed_arguments.version
+ "\n"
+ "Selected GCM: "
+ parsed_arguments.gcm
+ "\n"
+ "Selected RCP scenario: "
+ parsed_arguments.rcp
)


# create climate outputs
def create_config(parsed_arguments):
cfg = Config(
vstr=parsed_arguments.version,
gcm=parsed_arguments.gcm,
rcp=parsed_arguments.rcp,
cool=0,
heat=1,
)

return cfg


def main(args=None):
if args is None:
args = sys.argv[1:]

parsed_args = parse_arguments(arguments=args)

# Run the core functions
start = datetime.datetime.now()
print_arguments(parsed_arguments=parsed_args)
cfg = create_config(parsed_arguments=parsed_args)

for step in track([cfg], description="Running core functions..."):
(create_climate_variables_maps(step, start),)
(aggregate_urban_rural_files(step),)
(make_vdd_total_maps(step),)
(process_construction_shares(step),)
(process_floor_area_maps(step),)
(process_country_maps(step),)
(process_final_maps(step),)
(process_iso_tables(step),)


if __name__ == "__main__":
main()
104 changes: 104 additions & 0 deletions message_ix_buildings/chilled/run_iso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import datetime
import sys
from argparse import ArgumentParser

from rich.progress import track # type: ignore

from message_ix_buildings.chilled.core.climate import process_iso_tables
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config # type: ignore

log = get_logger(__name__)


def parse_arguments(arguments):
"""

:return:
"""
parser = ArgumentParser(add_help=True)

parser.add_argument(
"-version",
"--version",
default="ALPS2023",
help="Version of inputs to run. Default: ALPS2023.",
)
parser.add_argument(
"-gcm",
"--gcm",
default="GFDL-ESM4",
help="GCM to run. Options: GFDL-ESM4, IPSL-CM6A-LR, MPI-ESM1-2-HR, MRI-ESM2-0, \
UKESM1-0-LL. Default: GFDL-ESM4.",
)
parser.add_argument(
"-rcp",
"--rcp",
default="baseline",
help="RCP to run. Options: ssp126, ssp370, ssp585, baseline. \
Default: baseline.",
)

# Parse arguments
parsed_arguments = parser.parse_known_args(args=arguments)[0]

return parsed_arguments


def print_arguments(parsed_arguments):
"""
:param parsed_arguments:

"""

# Print arguments
log.info(
"\n"
+ "---------- Parsed arguments ------------"
+ "\n"
+ "Selected version: "
+ parsed_arguments.version
+ "\n"
+ "Selected GCM: "
+ parsed_arguments.gcm
+ "\n"
+ "Selected RCP scenario: "
+ parsed_arguments.rcp
)


# create climate outputs
def create_config(parsed_arguments):
cfg = Config(
vstr=parsed_arguments.version,
gcm=parsed_arguments.gcm,
rcp=parsed_arguments.rcp,
cool=0,
heat=1,
)

return cfg


def main(args=None):
if args is None:
args = sys.argv[1:]

parsed_args = parse_arguments(arguments=args)

# Run the core functions
start = datetime.datetime.now()
print_arguments(parsed_arguments=parsed_args)
cfg = create_config(parsed_arguments=parsed_args)

for step in track([cfg], description="Running core functions..."):
# (make_vdd_total_maps(step),)
# (process_construction_shares(step),)
# (process_floor_area_maps(step),)
# (process_country_maps(step),)
# (process_final_maps(step),)
(process_iso_tables(step),)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion message_ix_buildings/chilled/run_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
process_floor_area_maps,
process_iso_tables,
)
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config # type: ignore
from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion message_ix_buildings/chilled/run_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
create_archetype_variables,
create_archetypes,
)
from message_ix_buildings.chilled.util.common import get_logger
from message_ix_buildings.chilled.util.config import Config
from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)

Expand Down
Loading