Skip to content
Merged
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
28 changes: 27 additions & 1 deletion ProConPy/out_handler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
""" Logging Output Handler Module """

import logging
import sys
import ipywidgets as widgets

logger = logging.getLogger(__name__)


class _NameStrippingFormatter(logging.Formatter):
"""Formatter that drops the whitespace some logger names are padded with."""

def format(self, record):
name = record.name
record.name = name.strip()
try:
return super().format(record)
finally:
record.name = name


def _console_handlers():
"""INFO and below to stdout, WARNING and above to stderr, so that notebooks
(which show stderr on a red background) only flag actual warnings."""
formatter = _NameStrippingFormatter("%(levelname)s [%(name)s] %(message)s")
to_stdout = logging.StreamHandler(sys.stdout)
to_stdout.addFilter(lambda record: record.levelno < logging.WARNING)
to_stderr = logging.StreamHandler(sys.stderr)
to_stderr.setLevel(logging.WARNING)
for handler in (to_stdout, to_stderr):
handler.setFormatter(formatter)
return [to_stdout, to_stderr]


class OutHandler(logging.Handler):
"""Custom logging handler sending logs to an output widget"""

Expand All @@ -17,7 +43,7 @@ def __init__(self, *args, **kwargs):
"border": "1px solid black"
}
self.out = widgets.Output(layout=layout)
logging.basicConfig(level=logging.DEBUG, datefmt="%I:%M:%S")
logging.basicConfig(level=logging.DEBUG, handlers=_console_handlers())
self.set_verbosity(verbose=False)

def emit(self, record):
Expand Down
2 changes: 1 addition & 1 deletion external/mom6_forge
23 changes: 11 additions & 12 deletions visualCaseGen/custom_widget_types/case_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ def _run_create_newcase(self, caseroot, compset, resolution, do_exec):
+ f"--case {caseroot} "
+ f"--machine {machine} "
+ "--run-unsupported "
+ "--handle-preexisting-dirs a "
)

# append pecount if provided:
Expand Down Expand Up @@ -549,14 +550,22 @@ def _run_create_newcase(self, caseroot, compset, resolution, do_exec):

# Run the create_newcase command:
if do_exec:
runout = subprocess.run(cmd, shell=True, capture_output=True)
runout = subprocess.run(
cmd, shell=True, capture_output=True, text=True, stdin=subprocess.DEVNULL
)
with self._out:
if runout.returncode == 0:
print(f"{COMMENT}The create_newcase command was successful.{RESET}\n")
else:
print(f"{ERROR}Error creating case.{RESET}\n")
print(f"{runout.stderr}\n")
if runout.returncode != 0:
if "Aborting by user request" in runout.stderr:
raise RuntimeError(
"Error creating case: a previous case with the same name left its "
"build/run directories behind (see the message above). Remove them, "
"or choose a different case name."
)
raise RuntimeError("Error creating case.")

def _apply_all_xmlchanges(self, do_exec):
Expand All @@ -578,7 +587,6 @@ def _apply_all_xmlchanges(self, do_exec):
self._apply_lnd_grid_xmlchanges(do_exec)
self._apply_ocn_grid_xmlchanges(do_exec)
self._apply_runoff_ocn_mapping_xmlchanges(do_exec)
self._apply_wav_coupling_xmlchanges(do_exec)


def _apply_lnd_grid_xmlchanges(self, do_exec):
Expand Down Expand Up @@ -642,16 +650,6 @@ def _wav_uses_custom_ocn_grid(self):
)
return not picked_standard_wav_grid

def _apply_wav_coupling_xmlchanges(self, do_exec):
"""Use the legacy MOM6-WW3 wave coupling method when the custom ocean grid is reused as
the wave grid."""

if cvars["COMP_WAV"].value == "ww3" and self._wav_uses_custom_ocn_grid():
with self._out:
print(f"{COMMENT}Set wave coupling mode to legacy:{RESET}\n")
xmlchange("MOM6_WW3_CPL_METHOD", "legacy", do_exec, self._is_non_local(), self._out)


@staticmethod
def _calc_cores_based_on_grid( num_points, min_points_per_core = 32, max_points_per_core = 300, ideal_multiple_of_cores_used = 128):
"""Calculate the number of cores based on the grid size."""
Expand Down Expand Up @@ -946,6 +944,7 @@ def _update_component_grids_xml(
if self._wav_uses_custom_ocn_grid():
comps_sharing_ocn_grid.append("WAV")
for comp in comps_sharing_ocn_grid:
xmlchange(f"{comp}_GRID", ocn_grid, do_exec, self._is_non_local(), self._out)
xmlchange(f"{comp}_NX", cvars["OCN_NX"].value, do_exec, self._is_non_local(), self._out)
xmlchange(f"{comp}_NY", cvars["OCN_NY"].value, do_exec, self._is_non_local(), self._out)
xmlchange(f"{comp}_DOMAIN_MESH", ocn_mesh.as_posix(), do_exec, self._is_non_local(), self._out)
Expand Down
2 changes: 1 addition & 1 deletion visualCaseGen/custom_widget_types/case_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def xmlchange(var, val, do_exec=True, is_non_local=False, out=None):

out = DummyOutput() if out is None else out
with out:
print(f"{cmd}\n")
print(cmd)

if not do_exec:
return
Expand Down
Loading