diff --git a/MARBL_tools/MARBL_generate_diagnostics_file.py b/MARBL_tools/MARBL_generate_diagnostics_file.py index 4b66b8a7..d9823b54 100755 --- a/MARBL_tools/MARBL_generate_diagnostics_file.py +++ b/MARBL_tools/MARBL_generate_diagnostics_file.py @@ -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 diff --git a/MARBL_tools/MARBL_generate_settings_file.py b/MARBL_tools/MARBL_generate_settings_file.py index 7c691e27..bd07c747 100755 --- a/MARBL_tools/MARBL_generate_settings_file.py +++ b/MARBL_tools/MARBL_generate_settings_file.py @@ -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') @@ -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) diff --git a/MARBL_tools/MARBL_settings_file_class.py b/MARBL_tools/MARBL_settings_file_class.py index b1bb2c99..269236d7 100644 --- a/MARBL_tools/MARBL_settings_file_class.py +++ b/MARBL_tools/MARBL_settings_file_class.py @@ -13,7 +13,9 @@ 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. @@ -21,8 +23,14 @@ def __init__(self, default_settings_file, saved_state_vars_source="settings_file 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) @@ -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) @@ -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 @@ -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: @@ -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 diff --git a/MARBL_tools/netcdf_metadata_check.py b/MARBL_tools/netcdf_metadata_check.py index 8bbdd5ce..925a8fce 100755 --- a/MARBL_tools/netcdf_metadata_check.py +++ b/MARBL_tools/netcdf_metadata_check.py @@ -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, diff --git a/defaults/json/settings_cesm2.0.json b/defaults/json/settings_cesm2.0.json index fe00827a..e2a51bf9 100644 --- a/defaults/json/settings_cesm2.0.json +++ b/defaults/json/settings_cesm2.0.json @@ -1519,7 +1519,10 @@ "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" @@ -1527,7 +1530,10 @@ "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" diff --git a/defaults/json/settings_cesm2.1+cocco.json b/defaults/json/settings_cesm2.1+cocco.json index 31e40282..d1f627e7 100644 --- a/defaults/json/settings_cesm2.1+cocco.json +++ b/defaults/json/settings_cesm2.1+cocco.json @@ -1564,7 +1564,10 @@ "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" @@ -1572,7 +1575,10 @@ "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" diff --git a/defaults/json/settings_cesm2.1.json b/defaults/json/settings_cesm2.1.json index 5bda7925..4c8cbb93 100644 --- a/defaults/json/settings_cesm2.1.json +++ b/defaults/json/settings_cesm2.1.json @@ -1522,7 +1522,10 @@ "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" @@ -1530,7 +1533,10 @@ "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" diff --git a/defaults/json/settings_latest+4p2z.json b/defaults/json/settings_latest+4p2z.json index 0d1c0888..5ff2b46f 100644 --- a/defaults/json/settings_latest+4p2z.json +++ b/defaults/json/settings_latest+4p2z.json @@ -1617,7 +1617,10 @@ "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" @@ -1625,7 +1628,10 @@ "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" diff --git a/defaults/json/settings_latest+cocco.json b/defaults/json/settings_latest+cocco.json index e3935275..67de0b33 100644 --- a/defaults/json/settings_latest+cocco.json +++ b/defaults/json/settings_latest+cocco.json @@ -1564,7 +1564,10 @@ "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" @@ -1572,7 +1575,10 @@ "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" diff --git a/defaults/json/settings_latest.json b/defaults/json/settings_latest.json index cb09cf79..36d5a57d 100644 --- a/defaults/json/settings_latest.json +++ b/defaults/json/settings_latest.json @@ -1528,7 +1528,10 @@ "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" @@ -1536,7 +1539,10 @@ "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" diff --git a/defaults/settings_cesm2.0.yaml b/defaults/settings_cesm2.0.yaml index d7c4c826..d33ac0b7 100644 --- a/defaults/settings_cesm2.0.yaml +++ b/defaults/settings_cesm2.0.yaml @@ -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 diff --git a/defaults/settings_cesm2.1+cocco.yaml b/defaults/settings_cesm2.1+cocco.yaml index ff5fb1a5..4d34a419 100644 --- a/defaults/settings_cesm2.1+cocco.yaml +++ b/defaults/settings_cesm2.1+cocco.yaml @@ -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 diff --git a/defaults/settings_cesm2.1.yaml b/defaults/settings_cesm2.1.yaml index 824271c9..1cc48809 100644 --- a/defaults/settings_cesm2.1.yaml +++ b/defaults/settings_cesm2.1.yaml @@ -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 diff --git a/defaults/settings_latest+4p2z.yaml b/defaults/settings_latest+4p2z.yaml index 875ba595..dbe103fb 100644 --- a/defaults/settings_latest+4p2z.yaml +++ b/defaults/settings_latest+4p2z.yaml @@ -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 diff --git a/defaults/settings_latest+cocco.yaml b/defaults/settings_latest+cocco.yaml index b27afe40..f1f61569 100644 --- a/defaults/settings_latest+cocco.yaml +++ b/defaults/settings_latest+cocco.yaml @@ -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 diff --git a/defaults/settings_latest.yaml b/defaults/settings_latest.yaml index 67b178b7..e30b714f 100644 --- a/defaults/settings_latest.yaml +++ b/defaults/settings_latest.yaml @@ -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