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

Reorganization and cleanup of CHILLED code #30

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions message_ix_buildings/chilled/core/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
from message_ix_buildings.chilled.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,
load_all_scenarios_data,
load_parametric_analysis_data,
)
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__)

Expand Down
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
2 changes: 1 addition & 1 deletion message_ix_buildings/chilled/postprocess/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pandas as pd

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()
Expand Down
8 changes: 5 additions & 3 deletions message_ix_buildings/chilled/preprocess/archetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
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,
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__)

Expand Down Expand Up @@ -157,3 +157,5 @@ def map_archetype_variables(args):
func_inputs = product([config.arch_setting], vers_archs, VARS_ARCHETYPES)

list(map(map_archetype_variables, func_inputs))

log.info("Completed building input maps.")
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
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
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
import logging
import os
from pathlib import Path

import pandas as pd
from util.common import get_project_root # type: ignore
from util.config import Config # type: ignore


def get_project_root() -> Path:
return Path(__file__).parent.parent.parent


def get_logger(name: str):
log = logging.getLogger(name)
log.setLevel(logging.INFO)

# configure the handler and formatter as needed
handler = logging.FileHandler(f"{name}.log", mode="w")
formatter = logging.Formatter("%(name)s %(asctime)s %(levelname)s %(message)s")

# add formatter to the handler
handler.setFormatter(formatter)

# add handler to the logger
log.addHandler(handler)

return log


def get_archs(config: "Config"):
root_path = get_project_root()
version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr)
Expand Down
24 changes: 24 additions & 0 deletions message_ix_buildings/chilled/util/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
import sys
from pathlib import Path


def get_project_root() -> Path:
return Path(__file__).parent.parent.parent


def get_logger(name: str):
log = logging.getLogger(name)
log.setLevel(logging.INFO)

# configure the handler and formatter as needed
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter("%(name)s %(asctime)s %(levelname)s %(message)s")

# add formatter to the handler
handler.setFormatter(formatter)

# add handler to the logger
log.addHandler(handler)

return log