Skip to content

Commit

Permalink
feature 1273 TCGen -edeck and -shape (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe committed Feb 9, 2022
1 parent 82bd30c commit a4f2f41
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 22 deletions.
20 changes: 20 additions & 0 deletions docs/Users_Guide/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4765,6 +4765,16 @@ METplus Configuration Glossary

| *Used by:* TCGen
TC_GEN_EDECK_INPUT_DIR
Directory containing the edeck data used by TCGen. This variable is optional because you can specify the full path to edeck data using :term:`TC_GEN_EDECK_INPUT_TEMPLATE`.

| *Used by:* TCGen
TC_GEN_SHAPE_INPUT_DIR
Directory containing the shape data used by TCGen. This variable is optional because you can specify the full path to shape data using :term:`TC_GEN_SHAPE_INPUT_TEMPLATE`.

| *Used by:* TCGen
TC_GEN_TRACK_INPUT_TEMPLATE
Filename template of the track data used by TCGen. See also :term:`TC_GEN_TRACK_INPUT_DIR`.

Expand All @@ -4775,6 +4785,16 @@ METplus Configuration Glossary

| *Used by:* TCGen
TC_GEN_EDECK_INPUT_TEMPLATE
Filename template of the edeck data used by TCGen. See also :term:`TC_GEN_EDECK_INPUT_DIR`.

| *Used by:* TCGen
TC_GEN_SHAPE_INPUT_TEMPLATE
Filename template of the shape data used by TCGen. See also :term:`TC_GEN_SHAPE_INPUT_DIR`.

| *Used by:* TCGen
TC_GEN_OUTPUT_DIR
Specify the output directory where files from the MET TCGen tool are written.

Expand Down
4 changes: 4 additions & 0 deletions docs/Users_Guide/wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6908,6 +6908,10 @@ METplus Configuration
| :term:`TC_GEN_TRACK_INPUT_TEMPLATE`
| :term:`TC_GEN_GENESIS_INPUT_DIR`
| :term:`TC_GEN_GENESIS_INPUT_TEMPLATE`
| :term:`TC_GEN_EDECK_INPUT_DIR`
| :term:`TC_GEN_EDECK_INPUT_TEMPLATE`
| :term:`TC_GEN_SHAPE_INPUT_DIR`
| :term:`TC_GEN_SHAPE_INPUT_TEMPLATE`
| :term:`TC_GEN_OUTPUT_DIR`
| :term:`TC_GEN_OUTPUT_TEMPLATE`
| :term:`LOG_TC_GEN_VERBOSITY`
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
33 changes: 28 additions & 5 deletions internal_tests/pytests/tc_gen/test_tc_gen_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
# expected number of 2016 files (including file_list line)
expected_genesis_count = 7
expected_track_count = expected_genesis_count
expected_edeck_count = 6
expected_shape_count = 5

config = metplus_config()

Expand All @@ -279,9 +281,13 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
'tc_gen')
track_dir = os.path.join(test_data_dir, 'track')
genesis_dir = os.path.join(test_data_dir, 'genesis')
edeck_dir = os.path.join(test_data_dir, 'edeck')
shape_dir = os.path.join(test_data_dir, 'shape')

track_template = 'track_*{init?fmt=%Y}*'
genesis_template = 'genesis_*{init?fmt=%Y}*'
edeck_template = 'edeck_*{init?fmt=%Y}*'
shape_template = 'shape_*{init?fmt=%Y}*'

# set config variables to prevent command from running and bypass check
# if input files actually exist
Expand All @@ -299,6 +305,10 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
config.set('config', 'TC_GEN_TRACK_INPUT_TEMPLATE', track_template)
config.set('config', 'TC_GEN_GENESIS_INPUT_DIR', genesis_dir)
config.set('config', 'TC_GEN_GENESIS_INPUT_TEMPLATE', genesis_template)
config.set('config', 'TC_GEN_EDECK_INPUT_DIR', edeck_dir)
config.set('config', 'TC_GEN_EDECK_INPUT_TEMPLATE', edeck_template)
config.set('config', 'TC_GEN_SHAPE_INPUT_DIR', shape_dir)
config.set('config', 'TC_GEN_SHAPE_INPUT_TEMPLATE', shape_template)
config.set('config', 'TC_GEN_OUTPUT_DIR', '{OUTPUT_BASE}/TCGen/output')
config.set('config', 'TC_GEN_OUTPUT_TEMPLATE', 'tc_gen_{init?fmt=%Y}')

Expand All @@ -319,20 +329,25 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
'file_lists')
genesis_path = os.path.join(file_list_dir,
'20160101000000_tc_gen_genesis.txt')
edeck_path = os.path.join(file_list_dir,
'20160101000000_tc_gen_edeck.txt')
shape_path = os.path.join(file_list_dir,
'20160101000000_tc_gen_shape.txt')
track_path = os.path.join(file_list_dir,
'20160101000000_tc_gen_track.txt')

# remove list files if they already exist
if os.path.exists(genesis_path):
os.remove(genesis_path)
if os.path.exists(track_path):
os.remove(track_path)
for the_path in (genesis_path, edeck_path, shape_path, track_path):
if os.path.exists(the_path):
os.remove(the_path)

out_dir = wrapper.c_dict.get('OUTPUT_DIR')

expected_cmds = [
(f"{app_path} {verbosity} "
f"-genesis {genesis_path} "
f"-edeck {edeck_path} "
f"-shape {shape_path} "
f"-track {track_path} "
f"-config {config_file} -out {out_dir}/tc_gen_2016"),
]
Expand All @@ -357,11 +372,19 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
value = match.split('=', 1)[1]
assert(env_var_values.get(env_var_key, '') == value)

# verify file count of genesis and track file list files
# verify file count of genesis, edeck, shape, and track file list files
with open(genesis_path, 'r') as file_handle:
lines = file_handle.read().splitlines()
assert(len(lines) == expected_genesis_count)

with open(edeck_path, 'r') as file_handle:
lines = file_handle.read().splitlines()
assert(len(lines) == expected_edeck_count)

with open(shape_path, 'r') as file_handle:
lines = file_handle.read().splitlines()
assert(len(lines) == expected_shape_count)

with open(track_path, 'r') as file_handle:
lines = file_handle.read().splitlines()
assert(len(lines) == expected_track_count)
Expand Down
53 changes: 36 additions & 17 deletions metplus/wrappers/tc_gen_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,39 @@ def create_c_dict(self):
self.config.getdir(f'{app_name_upper}_GENESIS_INPUT_DIR', '')
)
c_dict['GENESIS_INPUT_TEMPLATE'] = (
self.config.getraw('filename_templates',
self.config.getraw('config',
f'{app_name_upper}_GENESIS_INPUT_TEMPLATE')
)
if not c_dict['GENESIS_INPUT_TEMPLATE']:
self.log_error(f'{app_name_upper}_GENESIS_INPUT_TEMPLATE must be '
'set to run TCGen')

c_dict['EDECK_INPUT_DIR'] = (
self.config.getdir(f'{app_name_upper}_EDECK_INPUT_DIR', '')
)
c_dict['EDECK_INPUT_TEMPLATE'] = (
self.config.getraw('config',
f'{app_name_upper}_EDECK_INPUT_TEMPLATE')
)

c_dict['SHAPE_INPUT_DIR'] = (
self.config.getdir(f'{app_name_upper}_SHAPE_INPUT_DIR', '')
)
c_dict['SHAPE_INPUT_TEMPLATE'] = (
self.config.getraw('config',
f'{app_name_upper}_SHAPE_INPUT_TEMPLATE')
)

c_dict['OUTPUT_DIR'] = (
self.config.getdir(f'{app_name_upper}_OUTPUT_DIR', '')
)
c_dict['OUTPUT_TEMPLATE'] = (
self.config.getraw('filename_templates',
self.config.getraw('config',
f'{app_name_upper}_OUTPUT_TEMPLATE')
)

c_dict['TRACK_INPUT_DIR'] = (
self.config.getdir(f'{app_name_upper}_TRACK_INPUT_DIR', '')
)
c_dict['TRACK_INPUT_TEMPLATE'] = (
self.config.getraw('filename_templates',
self.config.getraw('config',
f'{app_name_upper}_TRACK_INPUT_TEMPLATE')
)
if not c_dict['TRACK_INPUT_TEMPLATE']:
Expand Down Expand Up @@ -294,8 +307,11 @@ def handle_filter(self):
def get_command(self):
cmd = f"{self.app_path} -v {self.c_dict['VERBOSITY']}"

# add genesis
cmd += ' -genesis ' + self.c_dict['GENESIS_FILE']
# add genesis, edeck, and/or shape if set
for file_type in ('genesis', 'edeck', 'shape'):
file_path = self.c_dict.get(f'{file_type.upper()}_FILE')
if file_path:
cmd += f' -{file_type} {file_path}'

# add track
cmd += ' -track ' + self.c_dict['TRACK_FILE']
Expand Down Expand Up @@ -390,18 +406,21 @@ def find_input_files(self, time_info):
self.c_dict['TRACK_FILE'] = self.write_list_file(list_filename,
track_files)

# get genesis file(s) or directory
genesis_files = self.find_data(time_info,
data_type='GENESIS',
# get genesis, edeck, and/or shape file(s) or directory
for file_type in ('genesis', 'edeck', 'shape'):
if not self.c_dict.get(f'{file_type.upper()}_INPUT_TEMPLATE'):
continue
file_list = self.find_data(time_info,
data_type=file_type.upper(),
return_list=True,
allow_dir=True)
if not file_list:
continue

if not genesis_files:
return False

list_filename = time_info['init_fmt'] + '_tc_gen_genesis.txt'
self.c_dict['GENESIS_FILE'] = self.write_list_file(list_filename,
genesis_files)
list_filename = f"{time_info['init_fmt']}_tc_gen_{file_type}.txt"
self.c_dict[f'{file_type.upper()}_FILE'] = (
self.write_list_file(list_filename, file_list)
)

# set METPLUS_LEAD_LIST to list of forecast leads used
lead_seq = util.get_lead_sequence(self.config, time_info)
Expand Down
7 changes: 7 additions & 0 deletions parm/use_cases/met_tool_wrapper/TCGen/TCGen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ TC_GEN_TRACK_INPUT_TEMPLATE = {init?fmt=%Y}/*.dat
TC_GEN_GENESIS_INPUT_DIR = {INPUT_BASE}/met_test/tc_data/genesis/suite1
TC_GEN_GENESIS_INPUT_TEMPLATE = {init?fmt=%Y}*/genesis*{init?fmt=%Y}*

#TC_GEN_EDECK_INPUT_DIR =
#TC_GEN_EDECK_INPUT_TEMPLATE =

#TC_GEN_SHAPE_INPUT_DIR =
#TC_GEN_SHAPE_INPUT_TEMPLATE =


# directory to write output files generated by tc_gen
TC_GEN_OUTPUT_DIR = {OUTPUT_BASE}/met_tool_wrapper/TCGen
TC_GEN_OUTPUT_TEMPLATE = tc_gen_{init?fmt=%Y}
Expand Down

0 comments on commit a4f2f41

Please sign in to comment.