Skip to content

Commit

Permalink
Merge branch 'let_GCM_specify_tracer_modules' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlevy1981 committed Mar 7, 2024
2 parents d5862c6 + c2f6188 commit 4fbe36b
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 33 deletions.
6 changes: 5 additions & 1 deletion MARBL_tools/MARBL_generate_diagnostics_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ def _parse_args(marbl_root):

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, args.grid, args.settings_file_in, args.unit_system)
DefaultSettings = MARBL_settings_class(args.default_settings_file,
args.saved_state_vars_source,
grid=args.grid,
input_file=args.settings_file_in,
unit_system=args.unit_system)
MARBL_diagnostics = MARBL_diagnostics_class(args.default_diagnostics_file, DefaultSettings, args.unit_system)

# Write the diagnostic file
Expand Down
16 changes: 15 additions & 1 deletion MARBL_tools/MARBL_generate_settings_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def _parse_args(marbl_root):
default='settings_file', choices = set(('settings_file', 'GCM')),
help="Source of initial value for saved state vars that can come from GCM or settings file")

# Command line flag to turn off the base biotic tracers
parser.add_argument('--disable-base-bio', action='store_false', dest='base_bio_on',
help='Turn off base biotic tracer module (default is on)')

# Command line flag to turn on the abiotic DIC tracers
parser.add_argument('--enable-abio-dic', action='store_true', dest='abio_dic_on',
help='Turn on abiotic DIC tracer module (default is off)')

# Command line argument to specify resolution (default is None)
parser.add_argument('-g', '--grid', action='store', dest='grid',
help='Some default values are grid-dependent')
Expand Down Expand Up @@ -115,7 +123,13 @@ def _parse_args(marbl_root):
logging.basicConfig(format='%(levelname)s (%(funcName)s): %(message)s', level=logging.DEBUG)

from MARBL_tools import MARBL_settings_class
DefaultSettings = MARBL_settings_class(args.default_settings_file, args.saved_state_vars_source, args.grid, args.settings_file_in, args.unit_system)
DefaultSettings = MARBL_settings_class(args.default_settings_file,
args.saved_state_vars_source,
args.base_bio_on,
args.abio_dic_on,
args.grid,
args.settings_file_in,
args.unit_system)

# Write the settings file
generate_settings_file(DefaultSettings, args.settings_file_out)
19 changes: 15 additions & 4 deletions MARBL_tools/MARBL_settings_file_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ class MARBL_settings_class(object):
# CONSTRUCTOR #
###############

def __init__(self, default_settings_file, saved_state_vars_source="settings_file", grid=None, input_file=None, unit_system='cgs'):
def __init__(self, default_settings_file, saved_state_vars_source="settings_file",
base_bio_on=True, abio_dic_on=False, grid=None, input_file=None,
unit_system='cgs', exclude_dict={}):
""" Class constructor: set up a dictionary of config keywords for when multiple
default values are provided, read the JSON file, and then populate
self.settings_dict and self.tracers_dict.
"""

logger = logging.getLogger(__name__)

# Check argument types
if not (type(base_bio_on) == bool and type(abio_dic_on == bool)):
raise ValueError("base_bio_on and abio_dic_on must be type bool")

# 1. List of configuration keywords to match in JSON if default_default is a dictionary
self._config_keyword = []
self._config_keyword.append(f'BASE_BIO_ON == {str(base_bio_on).upper()}')
self._config_keyword.append(f'ABIO_DIC_ON == {str(abio_dic_on).upper()}')
if grid != None:
self._config_keyword.append('GRID == "%s"' % grid)
self._config_keyword.append('SAVED_STATE_VARS_SOURCE == "%s"' % saved_state_vars_source)
Expand All @@ -38,7 +46,7 @@ def __init__(self, default_settings_file, saved_state_vars_source="settings_file
MARBL_tools.abort(1)

# 4. Read settings input file
self._input_dict = _parse_input_file(input_file)
self._input_dict = _parse_input_file(input_file, exclude_dict)

# 5. Use an ordered dictionary for keeping variable, value pairs
# Also, tracer information is in its own dictionary (initialized to None)
Expand Down Expand Up @@ -602,7 +610,7 @@ def _string_to_substring(str_in, separator):

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

def _parse_input_file(input_file):
def _parse_input_file(input_file, exclude_dict):
""" 1. Read an input file; ignore blank lines and non-quoted Fortran comments.
2. Turn lines of the form
variable = value
Expand All @@ -625,6 +633,9 @@ def _parse_input_file(input_file):
line_list = line_loc.strip().split('=')
# keys in input_dict are all lowercase to allow case-insensitive match
var_name = line_list[0].strip().lower()
if var_name in exclude_dict:
logger.error(exclude_dict[var_name])
MARBL_tools.abort(1)
value = line_list[1].strip()
val_array = _string_to_substring(value, ',')
if len(val_array) > 1:
Expand All @@ -639,7 +650,7 @@ def _parse_input_file(input_file):
except TypeError:
# If inputfile == None then the open will result in TypeError
pass
except:
except FileNotFoundError:
logger.error("input_file '%s' was not found" % input_file)
MARBL_tools.abort(1)
return input_dict
6 changes: 3 additions & 3 deletions MARBL_tools/netcdf_metadata_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def _parse_args():
ds = xr.open_dataset(args.netcdf_file)
DefaultSettings = MARBL_settings_class(args.default_settings_file,
"settings_file",
None,
args.settings_file_in,
args.unit_system
grid=None,
input_file=args.settings_file_in,
unit_system=args.unit_system
)
MARBL_diagnostics = MARBL_diagnostics_class(args.default_diagnostics_file,
DefaultSettings,
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_cesm2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -1519,15 +1519,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_cesm2.1+cocco.json
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_cesm2.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1522,15 +1522,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_latest+4p2z.json
Original file line number Diff line number Diff line change
Expand Up @@ -1617,15 +1617,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_latest+cocco.json
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
10 changes: 8 additions & 2 deletions defaults/json/settings_latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1528,15 +1528,21 @@
"abio_dic_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".false.",
"default_value": {
"ABIO_DIC_ON == TRUE": ".true.",
"default": ".false."
},
"longname": "Control whether abiotic carbon tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
},
"base_bio_on": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"default_value": {
"BASE_BIO_ON == FALSE": ".false.",
"default": ".true."
},
"longname": "Control whether the base ecosystem tracer module is active",
"subcategory": "1. tracer modules",
"units": "unitless"
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_cesm2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_cesm2.1+cocco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_cesm2.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_latest+4p2z.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_latest+cocco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down
8 changes: 6 additions & 2 deletions defaults/settings_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ tracer_modules :
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .true.
default_value :
default : .true.
BASE_BIO_ON == FALSE : .false.
_append_to_config_keywords : true
abio_dic_on :
longname : Control whether abiotic carbon tracer module is active
subcategory : 1. tracer modules
units : unitless
datatype : logical
default_value : .false.
default_value :
default : .false.
ABIO_DIC_ON == TRUE : .true.
_append_to_config_keywords : true
ciso_on :
longname : Control whether CISO tracer module is active
Expand Down

0 comments on commit 4fbe36b

Please sign in to comment.