Skip to content

Commit

Permalink
Updates following code review
Browse files Browse the repository at this point in the history
1) Cleaned up docstring for valid_diag_modes
2) Dropped valid_diag_modes from __init__.py
3) Moved imports to top of MARBL_generate_diagnostics_file.py
   -- some are inside if __name__ == "__main__" block
   -- I snuck in a sys.path.append() in the middle of the imports to get
      MARBL_tools into the path
  • Loading branch information
mnlevy1981 committed May 16, 2024
1 parent 1e4714a commit 66275b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
23 changes: 13 additions & 10 deletions MARBL_tools/MARBL_generate_diagnostics_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@
-a, --append Append to existing diagnostics file (default: False)
"""

if __name__ == "__main__":
# We need marbl_root in python path so we can import MARBL_tools from generate_settings_file()
import argparse
import os
import sys
marbl_root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
sys.path.append(marbl_root)
from MARBL_tools import MARBL_settings_class
from MARBL_tools import MARBL_diagnostics_class

import logging
from MARBL_tools.MARBL_utils import valid_diag_modes

#######################################

def generate_diagnostics_file(MARBL_diagnostics, diagnostics_file_out, diag_mode="full", append=False):
""" Produce a list of MARBL diagnostic frequencies and operators from a JSON parameter file
"""

from MARBL_tools import valid_diag_modes
import logging
logger = logging.getLogger(__name__)

if not append:
Expand Down Expand Up @@ -106,9 +117,6 @@ def _parse_args(marbl_root):
""" Parse command line arguments
"""

import argparse
from MARBL_tools import valid_diag_modes

parser = argparse.ArgumentParser(description="Generate a MARBL settings file from a JSON file",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

Expand Down Expand Up @@ -157,20 +165,15 @@ def _parse_args(marbl_root):
#######################################

if __name__ == "__main__":
# We need marbl_root in python path so we can import MARBL_tools from generate_settings_file()
import sys, os
marbl_root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
sys.path.append(marbl_root)

# Parse command-line arguments (marbl_root is used to set default for JSON file location)
args = _parse_args(marbl_root)

# Set up logging
import logging
logging.basicConfig(format='%(levelname)s (%(funcName)s): %(message)s', level=logging.DEBUG)

from MARBL_tools import MARBL_settings_class
from MARBL_tools import MARBL_diagnostics_class
DefaultSettings = MARBL_settings_class(args.default_settings_file,
args.saved_state_vars_source,
grid=args.grid,
Expand Down
6 changes: 4 additions & 2 deletions MARBL_tools/MARBL_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
################################################################################

def valid_diag_modes():
""" Return ordered list of the valid values for diag_mode.
(Ordered list => selecting diag mode includes variables)
""" Return list of the valid values for diag_mode.
Order of list => selecting specific diag mode includes all
diagnostics with lower index as well (e.g. "diag_mode = full"
will also provide diagnostics defined with minimal diag mode)
"""
return ['none', 'minimal', 'full']

Expand Down
1 change: 0 additions & 1 deletion MARBL_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .MARBL_diagnostics_file_class import MARBL_diagnostics_class
from .MARBL_utils import settings_dictionary_is_consistent
from .MARBL_utils import diagnostics_dictionary_is_consistent
from .MARBL_utils import valid_diag_modes
from .MARBL_share import abort
from .MARBL_share import LogFormatter
from .MARBL_share import sort
Expand Down

0 comments on commit 66275b1

Please sign in to comment.