Skip to content

Commit

Permalink
Added arg comments to parse_kpp_arrhenius.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwfncar committed Aug 18, 2023
1 parent 2d0b99a commit d3fe44c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
27 changes: 23 additions & 4 deletions etc/scripts/kpp_to_micm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
Description:
kpp_to_micm.py translates KPP config files to MICM JSON config files
(desginated by the suffixes .kpp, .spc, .eqn, .def)
from a single directory specified by the --kpp_dir argument.
from a single directory specified by the
--kpp_dir and --kpp_name arguments.
In the initial implementation,
the KPP sections #ATOMS (not yet used), #DEFFIX,
Expand Down Expand Up @@ -42,7 +43,7 @@
__version__ = 'v1.01'


def read_kpp_config(kpp_dir):
def read_kpp_config(kpp_dir, kpp_name):
"""
Read all KPP config files in a directory
Expand All @@ -58,7 +59,7 @@ def read_kpp_config(kpp_dir):
lines = list()

for suffix in suffixes:
files = glob(os.path.join(kpp_dir, '*' + suffix))
files = glob(os.path.join(kpp_dir, kpp_name + '*' + suffix))
logging.debug(files)
for filename in files:
with open(filename, 'r') as f:
Expand Down Expand Up @@ -130,6 +131,18 @@ def micm_species_json(lines, fixed=False, tolerance=1.0e-12):

def parse_kpp_arrhenius(kpp_str):
"""
Parse KPP Arrhenius reaction
Parameters
(str) kpp_str: Arrhenius reaction string
Returns
(dict): MICM Arrhenius reaction coefficients
Arrhenius formula from KPP
--------------------------
KPP_REAL ARR_abc( float A0, float B0, float C0 )
{
double ARR_RES;
Expand All @@ -141,6 +154,9 @@ def parse_kpp_arrhenius(kpp_str):
return (KPP_REAL)ARR_RES;
}
Arrhenius formula from MICM
---------------------------
inline double ArrheniusRateConstant::calculate(
const double& temperature, const double& pressure) const
{
Expand Down Expand Up @@ -256,6 +272,9 @@ def micm_equation_json(lines):
parser.add_argument('--kpp_dir', type=str,
default=os.path.join('..', 'configs', 'kpp'),
help='KPP input config directory')
parser.add_argument('--kpp_name', type=str,
default='small_strato',
help='KPP config name')
parser.add_argument('--micm_dir', type=str,
default=os.path.join('..', 'configs', 'micm'),
help='MICM output species config file')
Expand All @@ -275,7 +294,7 @@ def micm_equation_json(lines):
"""
Read KPP config files
"""
lines = read_kpp_config(args.kpp_dir)
lines = read_kpp_config(args.kpp_dir, args.kpp_name)

"""
Split KPP config by section
Expand Down
1 change: 1 addition & 0 deletions etc/scripts/test_kpp_to_micm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ def test_parse_kpp_arrhenius():
assert arr_dict['A'] == kpp_A
assert arr_dict['B'] == kpp_B
assert arr_dict['C'] == kpp_C

0 comments on commit d3fe44c

Please sign in to comment.