Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed Nov 27, 2024
1 parent e8e82be commit 35042d0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
# since the action is run on a branch in detached head state.
# This is the equivalent of running "pre-commit run --all-files" locally.
# If you commit with the `--no-verify` flag, this check may fail.
# TODO: this doesn't seem to run when I run `git commit` locally. I always have to run `pre-commit run --all-files` manually.
- name: Install and Run Pre-commit
uses: pre-commit/[email protected]

Expand Down
24 changes: 12 additions & 12 deletions zppy_interfaces/global_time_series/coupled_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import xcdat

from zppy_interfaces.global_time_series.coupled_global_plotting import make_plot_pdfs
from zppy_interfaces.global_time_series.coupled_global_utils import Metric, Variable
from zppy_interfaces.global_time_series.coupled_global_utils import (
INCLUSIONS_DIR,
Metric,
Variable,
)
from zppy_interfaces.global_time_series.coupled_global_viewer import (
create_viewer,
create_viewer_index,
Expand Down Expand Up @@ -66,13 +70,9 @@ def land_csv_row_to_var(csv_row: List[str]) -> Variable:
def construct_land_variables(requested_vars: List[str]) -> List[Variable]:
var_list: List[Variable] = []
header = True
# If this file is being run stand-alone, then
# it will search the directory above the git directory
# TODO: how do we make sure the csv is actually accessible????
# The current directory is where we ran the code from, which is not necessarily where the csv is.
csv_path = (
"/home/ac.forsyth2/ez/zppy-interfaces/zppy_interfaces/global_time_series/"
)
csv_path = INCLUSIONS_DIR
with open(f"{csv_path}/zppy_land_fields.csv", newline="") as csv_file:
logger.debug("Reading zppy_land_fields.csv")
var_reader = csv.reader(csv_file)
Expand Down Expand Up @@ -221,13 +221,13 @@ def globalAnnualHelper(
var, "year"
)
data_array = annual_average_dataset_for_var.data_vars[var]
import pprint

pprint.pprint(
f"annual_average_dataset_for_var attributes={annual_average_dataset_for_var.attrs}"
)
pprint.pprint(f"data_array attributes={data_array.attrs}")
# import pprint
# pprint.pprint(
# f"annual_average_dataset_for_var attributes={annual_average_dataset_for_var.attrs}"
# )
# pprint.pprint(f"data_array attributes={data_array.attrs}")
# data_array *= area*landfrac
# TODO: Determine how to get area and landfrac
else:
# This shouldn't be possible
raise ValueError(f"Invalid Enum option for metric={metric}")
Expand Down
5 changes: 5 additions & 0 deletions zppy_interfaces/global_time_series/coupled_global_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from enum import Enum

# TODO: how to determine this automatically?
INCLUSIONS_DIR = (
"/home/ac.forsyth2/ez/zppy-interfaces/zppy_interfaces/global_time_series/"
)


class Metric(Enum):
AVERAGE = 1
Expand Down
15 changes: 7 additions & 8 deletions zppy_interfaces/global_time_series/coupled_global_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

from bs4 import BeautifulSoup

from zppy_interfaces.global_time_series.coupled_global_utils import Variable
from zppy_interfaces.global_time_series.coupled_global_utils import (
INCLUSIONS_DIR,
Variable,
)
from zppy_interfaces.global_time_series.utils import Parameters
from zppy_interfaces.multi_utils.logger import _setup_custom_logger
from zppy_interfaces.multi_utils.viewer import OutputViewer
Expand Down Expand Up @@ -69,7 +72,6 @@ def create_viewer(parameters: Parameters, vars: List[Variable], component: str)
return url


# TODO: looks like we need to modify this (and have a index_template.html to use) to include all component viewers on the index
# Copied from E3SM Diags and modified
def create_viewer_index(
root_dir: str, title_and_url_list: List[Tuple[str, str]]
Expand All @@ -93,13 +95,10 @@ def insert_data_in_row(row_obj, name: str, url: str):
td.append(a)
row_obj.append(td)

# import sys
# logger.debug(f"sys.prefix: {sys.prefix}, ls sys.prefix: {os.listdir(sys.prefix)}")
# TODO: figure out install_path
import sys

logger.debug(f"sys.prefix: {sys.prefix}, ls sys.prefix: {os.listdir(sys.prefix)}")
install_path: str = (
"/home/ac.forsyth2/ez/zppy-interfaces/zppy_interfaces/global_time_series/"
)
install_path: str = INCLUSIONS_DIR
path: str = os.path.join(install_path, "index_template.html")
output: str = os.path.join(root_dir, "index.html")

Expand Down
5 changes: 3 additions & 2 deletions zppy_interfaces/multi_utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
logging.getLogger().addHandler(console_handler)


# TODO: Why are logging messages printing 3x?
# Following the example of https://github.com/xCDAT/xcdat/blob/27396e510185fddfe04921427ce2d67618a93709/xcdat/_logger.py#L20
def _setup_custom_logger(name, propagate=True) -> logging.Logger:
"""Sets up a custom logger.
Expand All @@ -27,7 +29,7 @@ def _setup_custom_logger(name, propagate=True) -> logging.Logger:
name : str
Name of the file where this function is called.
propagate : bool, optional
Whether to propagate logger messages or not, by default False
Whether to propagate logger messages or not, by default True
Returns
-------
Expand Down Expand Up @@ -63,6 +65,5 @@ def _setup_custom_logger(name, propagate=True) -> logging.Logger:
"""
logger = logging.getLogger(name)
logger.propagate = propagate
logger.setLevel(logging.DEBUG)

return logger

0 comments on commit 35042d0

Please sign in to comment.