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

Replace print() statements with logging #25

Merged
merged 13 commits into from
Oct 2, 2024
Merged
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ doc/_build
scratch*

# CHILLED user settings
user_settings.py
user_settings.py

# log files
*.log
371 changes: 187 additions & 184 deletions message_ix_buildings/chilled/core/climate.py

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions message_ix_buildings/chilled/functions/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import pyam # type: ignore
import statsmodels.formula.api as smf # type: ignore

from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)

# from message_ix_buildings.chilled.config import Config

# cfg = Config()
Expand Down Expand Up @@ -246,14 +250,14 @@ def fit_model(q):
os.path.join(version_output_path, "regression_results.csv"), index=False
)

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

df_cc.to_csv(
os.path.join(version_output_path, "REGIONAL_EI_PATHWAYS_cc_long.csv"),
index=False,
)

print(
log.info(
"Saved: "
+ os.path.join(version_output_path, "REGIONAL_EI_PATHWAYS_cc_long.csv")
)
Expand All @@ -263,7 +267,7 @@ def fit_model(q):
index=False,
)

print(
log.info(
"Saved: "
+ os.path.join(version_output_path, "REGIONAL_EI_PATHWAYS_nocc_long.csv")
)
14 changes: 8 additions & 6 deletions message_ix_buildings/chilled/postprocess/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import pandas as pd

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()


Expand Down Expand Up @@ -199,7 +201,7 @@ def postprocess_electricity_demand(input_path, input_version_name):
index=False,
)

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

Expand All @@ -211,7 +213,7 @@ def postprocess_electricity_demand(input_path, input_version_name):
index=False,
)

print(
log.info(
"Saved: "
+ os.path.join(
version_output_path,
Expand All @@ -227,8 +229,8 @@ def postprocess_electricity_demand(input_path, input_version_name):
index=False,
)

print(
"Saved: "
log.info(
"Saved :"
+ os.path.join(
version_output_path,
"reg_en_cool_tot_" + input_version_name + "_2024_3settemps.csv",
Expand All @@ -243,11 +245,11 @@ def postprocess_electricity_demand(input_path, input_version_name):
index=False,
)

print(
log.info(
"Saved: "
+ os.path.join(
version_output_path,
"reg_en_cool_sect_" + input_version_name + "_2024_3settemp.csv",
"reg_en_cool_sect_" + input_version_name + "_2024_3settemps.csv",
)
)

Expand Down
14 changes: 8 additions & 6 deletions message_ix_buildings/chilled/preprocess/archetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
from message_ix_buildings.chilled.util.config import Config # type: ignore
from message_ix_buildings.chilled.util.util import (
get_archs,
get_logger,
read_arch_inputs_df,
read_arch_reg_df,
)

log = get_logger(__name__)


def create_archetypes(config: "Config"):
out_path = os.path.join(config.project_path, "out", "version")
Expand All @@ -36,7 +39,8 @@ def create_archetypes(config: "Config"):
# save MESSAGE regions map
msg_file = "map_reg_MESSAGE_" + config.node + ".nc"
map_reg.to_netcdf(os.path.join(archetype_path, msg_file))
print(

log.info(
"- Saved MESSAGE and raster map data to "
+ os.path.join(
archetype_path,
Expand Down Expand Up @@ -87,7 +91,7 @@ def create_archetypes(config: "Config"):
encoding=encoding,
)

print(
log.info(
"-- Saved archetype map to "
+ os.path.join(
archetype_path,
Expand All @@ -106,7 +110,7 @@ def create_archetype_variables(config: "Config"):
def map_archetype_variables(args):
arch_setting, arch, varname = args

print(
log.info(
"Creating archetype map for: " + arch_setting + " " + arch + " " + varname
)

Expand All @@ -120,7 +124,6 @@ def map_archetype_variables(args):
)
)

# print(".....Writing to netCDF")
for urt in config.urts:
for index, row in arch_inputs.iterrows():
map[urt].values[map[urt] == row["id"]] = float(row[varname])
Expand All @@ -145,13 +148,12 @@ def map_archetype_variables(args):
encoding=encoding,
)

print(
log.info(
".......Completed writing to file: "
+ os.path.join(archetype_path, filename)
)

# create archetype variables maps

func_inputs = product([config.arch_setting], vers_archs, VARS_ARCHETYPES)

list(map(map_archetype_variables, func_inputs))
34 changes: 23 additions & 11 deletions message_ix_buildings/chilled/run_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
process_iso_tables,
)
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__)


def parse_arguments(arguments):
Expand Down Expand Up @@ -52,10 +55,19 @@ def print_arguments(parsed_arguments):
"""

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


def create_config(parsed_arguments):
Expand All @@ -78,25 +90,25 @@ def main(args=None):
print_arguments(parsed_arguments=parsed_args)
cfg = create_config(parsed_arguments=parsed_args)

print("RUNNING aggregate_urban_rural_files()........")
log.info("RUNNING aggregate_urban_rural_files()........")
aggregate_urban_rural_files(cfg)

print("RUNNING make_vdd_total_maps()........")
log.info("RUNNING make_vdd_total_maps()........")
make_vdd_total_maps(cfg)

print("RUNNING process_construction_shares()........")
log.info("RUNNING process_construction_shares()........")
process_construction_shares(cfg)

print("RUNNING process_floor_area_maps()........")
log.info("RUNNING process_floor_area_maps()........")
process_floor_area_maps(cfg)

print("RUNNING process_country_maps()........")
log.info("RUNNING process_country_maps()........")
process_country_maps(cfg)

print("RUNNING process_final_maps()........")
log.info("RUNNING process_final_maps()........")
process_final_maps(cfg)

print("RUNNING process_iso_tables()........")
log.info("RUNNING process_iso_tables()........")
process_iso_tables(cfg)


Expand Down
26 changes: 20 additions & 6 deletions message_ix_buildings/chilled/run_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
process_iso_tables,
)
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__)


def parse_arguments(arguments):
Expand All @@ -34,13 +37,15 @@ def parse_arguments(arguments):
"-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.",
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.",
help="RCP to run. Options: ssp126, ssp370, ssp585, baseline. \
Default: baseline.",
)

# Parse arguments
Expand All @@ -56,10 +61,19 @@ def print_arguments(parsed_arguments):
"""

# Print arguments
print("---------- Parsed arguments ------------")
print("Selected version: " + parsed_arguments.version)
print("Selected GCM: " + parsed_arguments.gcm)
print("Selected RCP scenario: " + parsed_arguments.rcp)
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
Expand Down
18 changes: 14 additions & 4 deletions message_ix_buildings/chilled/run_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
create_archetypes,
)
from message_ix_buildings.chilled.util.config import Config
from message_ix_buildings.chilled.util.util import get_logger

log = get_logger(__name__)


def parse_arguments(arguments):
Expand Down Expand Up @@ -35,8 +38,13 @@ def print_arguments(parsed_arguments):
"""

# Print arguments
print("---------- Parsed arguments ------------")
print("Selected version: " + parsed_arguments.version)
log.info(
"\n"
+ "---------- Parsed arguments ------------"
+ "\n"
+ "Selected version: "
+ parsed_arguments.version
)


# create climate outputs
Expand All @@ -57,10 +65,12 @@ def main(args=None):
# Run the main function
print_arguments(parsed_arguments=parsed_args)
cfg = create_config(parsed_arguments=parsed_args)

create_archetypes(cfg)
print("Archetypes created successfully.")
log.info("Archetypes created successfully.")

create_archetype_variables(cfg)
print("Archetype variables created successfully.")
log.info("Archetype variables created successfully.")


if __name__ == "__main__":
Expand Down
Loading