Skip to content

Commit

Permalink
Update develop-ref after dtcenter/MET#2241 (#1770)
Browse files Browse the repository at this point in the history
Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com>
Co-authored-by: Hank Fisher <fisherh@seneca.rap.ucar.edu>
Co-authored-by: Mrinal Biswas <biswas@seneca.rap.ucar.edu>
Co-authored-by: jprestop <jpresto@ucar.edu>
Co-authored-by: johnhg <johnhg@ucar.edu>
Co-authored-by: Mrinal Biswas <biswas@ucar.edu>
Co-authored-by: Julie Prestopnik <jpresto@seneca.rap.ucar.edu>
Co-authored-by: j-opatz <jopatz@ucar.edu>
Co-authored-by: Kathryn Newman <knewman@seneca.rap.ucar.edu>
Co-authored-by: j-opatz <59586397+j-opatz@users.noreply.github.com>
Co-authored-by: Lisa Goodrich <lisag@ucar.edu>
Co-authored-by: Julie Prestopnik <jpresto@ucar.edu>
Co-authored-by: Christina Kalb <kalb@mohawk.rap.ucar.edu>
Co-authored-by: Christina Kalb <kalb@ucar.edu>
Co-authored-by: Hank Fisher <fisherh@ucar.edu>
Co-authored-by: mrinalbiswas <biswas@ucar.edu>
Co-authored-by: bikegeek <3753118+bikegeek@users.noreply.github.com>
Co-authored-by: lisagoodrich <33230218+lisagoodrich@users.noreply.github.com>
Co-authored-by: Howard Soh <hsoh@seneca.rap.ucar.edu>
Co-authored-by: Molly Smith <molly.b.smith@noaa.gov>
Co-authored-by: hsoh-u <hsoh@ucar.edu>
Co-authored-by: bikegeek <minnawin@ucar.edu>
  • Loading branch information
20 people committed Aug 26, 2022
1 parent b071450 commit 5ae03a5
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 147 deletions.
3 changes: 2 additions & 1 deletion .github/labels/README.md
Expand Up @@ -31,7 +31,8 @@ Sample commands for processing all METplus repos:
```
# List of METplus repositories
REPO_LIST="metplus met metplotpy metcalcpy metdataio metviewer \
metexpress metplus-training metplus-internal";
metexpress metplus-training metplus-internal \
metbaseimage";
# Build commands to add/update common labels
for repo in ${REPO_LIST}; do
Expand Down
2 changes: 1 addition & 1 deletion .github/labels/post_patch_labels.sh
Expand Up @@ -8,7 +8,7 @@

if [[ $# -ne 4 ]]; then
echo "ERROR: `basename $0` ... must specify the GitHub username, authorization key, repository name, and label file."
echo "ERROR: repo names: metplus, met, metdataio, metcalcpy, metplotpy, metviewer, metexpress, metplus-training, metplus-internal"
echo "ERROR: repo names: metplus, met, metdataio, metcalcpy, metplotpy, metviewer, metexpress, metplus-training, metplus-internal, metbaseimage"
exit 1
else
user=$1
Expand Down
2 changes: 1 addition & 1 deletion docs/Contributors_Guide/user_support.rst
Expand Up @@ -48,7 +48,7 @@ Review the `unanswered discussions <https://github.com/dtcenter/METplus/discussi
* Otherwise, leave the discussion unanswered until the next day to allow the
user community time to respond.

* For new discussions that have 0 repsonses and were posted the previous day:
* For new discussions that have 0 responses and were posted the previous day:

* Take action. See :ref:`actions_new_discussions`.

Expand Down
9 changes: 3 additions & 6 deletions metplus/util/config_metplus.py
Expand Up @@ -251,8 +251,7 @@ def launch(config_list):

# create final conf directory if it doesn't already exist
final_conf_dir = os.path.dirname(final_conf)
if not os.path.exists(final_conf_dir):
os.makedirs(final_conf_dir)
util.mkdir_p(final_conf_dir)

# set METPLUS_BASE/PARM_BASE conf so they can be referenced in other confs
config.set('config', 'METPLUS_BASE', METPLUS_BASE)
Expand Down Expand Up @@ -372,10 +371,8 @@ def get_logger(config, sublog=None):
log_dir = config.getdir('LOG_DIR')
log_level = config.getstr('config', 'LOG_LEVEL')

# Check if the directory path for the log file exists, if
# not create it.
if not os.path.exists(log_dir):
util.mkdir_p(log_dir)
# Create the log directory if it does not exist
util.mkdir_p(log_dir)

if sublog is not None:
logger = config.log(sublog)
Expand Down
25 changes: 9 additions & 16 deletions metplus/util/met_util.py
Expand Up @@ -148,15 +148,14 @@ def run_metplus(config, process_list):
"Options are processes, times")
return 1

# write out all commands and environment variables to file
if not write_all_commands(all_commands, config):
# if process list contains any wrapper that should run commands,
# report an error if no commands were generated
if any([item[0] not in NO_COMMAND_WRAPPERS
for item in process_list]):
# if process list contains any wrapper that should run commands
if any([item[0] not in NO_COMMAND_WRAPPERS for item in process_list]):
# write out all commands and environment variables to file
if not write_all_commands(all_commands, config):
# report an error if no commands were generated
total_errors += 1

# compute total number of errors that occurred and output results
# compute total number of errors that occurred and output results
for process in processes:
if process.errors != 0:
process_name = process.__class__.__name__.replace('Wrapper', '')
Expand Down Expand Up @@ -252,9 +251,7 @@ def handle_tmp_dir(config):
# create temp dir if it doesn't exist already
# this will fail if TMP_DIR is not set correctly and
# env MET_TMP_DIR was not set
tmp_dir = config.getdir('TMP_DIR')
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
mkdir_p(config.getdir('TMP_DIR'))

def handle_env_var_config(config, env_var_name, config_name):
"""! If environment variable is set, use that value
Expand Down Expand Up @@ -1230,9 +1227,7 @@ def preprocess_file(filename, data_type, config, allow_dir=False):
return stagefile
# if it does not exist, run GempakToCF and return staged nc file
# Create staging area if it does not exist
outdir = os.path.dirname(stagefile)
if not os.path.exists(outdir):
os.makedirs(outdir, mode=0o0775)
mkdir_p(os.path.dirname(stagefile))

# only import GempakToCF if needed
from ..wrappers import GempakToCFWrapper
Expand Down Expand Up @@ -1263,9 +1258,7 @@ def preprocess_file(filename, data_type, config, allow_dir=False):
# Create staging area directory only if file has compression extension
if any([os.path.isfile(f'{filename}{ext}')
for ext in COMPRESSION_EXTENSIONS]):
outdir = os.path.dirname(outpath)
if not os.path.exists(outdir):
os.makedirs(outdir, mode=0o0775)
mkdir_p(os.path.dirname(outpath))

# uncompress gz, bz2, or zip file
if os.path.isfile(filename+".gz"):
Expand Down
3 changes: 3 additions & 0 deletions metplus/util/time_looping.py
Expand Up @@ -159,6 +159,9 @@ def _get_time_prefix(config):
valid time, or None if not enough information was found in the config
"""
loop_by = config.getstr('config', 'LOOP_BY', '').upper()
if not loop_by:
return None

if loop_by in ['INIT', 'RETRO']:
return 'INIT'

Expand Down
9 changes: 0 additions & 9 deletions metplus/wrappers/ascii2nc_wrapper.py
Expand Up @@ -228,15 +228,6 @@ def get_command(self):
out_path = self.get_output_path()
cmd += ' ' + out_path

parent_dir = os.path.dirname(out_path)
if parent_dir == '':
self.log_error('Must specify path to output file')
return None

# create full output dir if it doesn't already exist
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)

# add arguments
cmd += ''.join(self.args)

Expand Down
10 changes: 4 additions & 6 deletions metplus/wrappers/command_builder.py
Expand Up @@ -912,8 +912,7 @@ def write_list_file(self, filename, file_list, output_dir=None):

list_path = os.path.join(list_dir, filename)

if not os.path.exists(list_dir):
os.makedirs(list_dir, mode=0o0775)
util.mkdir_p(list_dir)

self.logger.debug("Writing list of filenames...")
with open(list_path, 'w') as file_handle:
Expand Down Expand Up @@ -1008,7 +1007,7 @@ def find_and_check_output_file(self, time_info=None,
if (not os.path.exists(parent_dir) and
not self.c_dict.get('DO_NOT_RUN_EXE', False)):
self.logger.debug(f"Creating output directory: {parent_dir}")
os.makedirs(parent_dir)
util.mkdir_p(parent_dir)

if not output_exists or not skip_if_output_exists:
return True
Expand Down Expand Up @@ -1195,7 +1194,7 @@ def get_command(self):
"""
if self.app_path is None:
self.log_error('No app path specified. '
'You must use a subclass')
'You must use a subclass')
return None

cmd = '{} -v {}'.format(self.app_path, self.c_dict['VERBOSITY'])
Expand All @@ -1222,8 +1221,7 @@ def get_command(self):
self.log_error('Must specify path to output file')
return None

if not os.path.exists(parent_dir):
os.makedirs(parent_dir)
util.mkdir_p(parent_dir)

cmd += " " + out_path

Expand Down
27 changes: 0 additions & 27 deletions metplus/wrappers/compare_gridded_wrapper.py
Expand Up @@ -312,33 +312,6 @@ def process_fields(self, time_info):
# run the MET command
self.build()

def create_and_set_output_dir(self, time_info):
"""! Builds the full output dir path with valid or init time
Creates output directory if it doesn't already exist
Args:
@param time_info dictionary with time information
"""
out_dir = self.c_dict['OUTPUT_DIR']

# use output template if it is set
# if not set, do not add any extra directories to path
out_template_name = '{}_OUTPUT_TEMPLATE'.format(self.app_name.upper())
if self.config.has_option('config',
out_template_name):
template = self.config.getraw('config',
out_template_name)
# perform string substitution to get full path
extra_path = do_string_sub(template,
**time_info)
out_dir = os.path.join(out_dir, extra_path)

# create full output dir if it doesn't already exist
if not os.path.exists(out_dir):
os.makedirs(out_dir)

# set output dir for wrapper
self.outdir = out_dir

def get_command(self):
"""! Builds the command to run the MET application
@rtype string
Expand Down
2 changes: 0 additions & 2 deletions metplus/wrappers/cyclone_plotter_wrapper.py
Expand Up @@ -37,8 +37,6 @@
WRAPPER_CANNOT_RUN = True
EXCEPTION_ERR = err_msg

import produtil.setup

from ..util import met_util as util
from ..util import do_string_sub
from ..util import time_generator, add_to_time_input
Expand Down
22 changes: 6 additions & 16 deletions metplus/wrappers/gen_vx_mask_wrapper.py
Expand Up @@ -12,9 +12,7 @@

import os

from ..util import getlist
from ..util import met_util as util
from ..util import time_util
from ..util import getlist, get_lead_sequence, skip_time, ti_calculate, mkdir_p
from . import CommandBuilder
from ..util import do_string_sub

Expand Down Expand Up @@ -117,15 +115,6 @@ def get_command(self):
out_path = self.get_output_path()
cmd += ' ' + out_path

parent_dir = os.path.dirname(out_path)
if not parent_dir:
self.log_error('Must specify path to output file')
return None

# create full output dir if it doesn't already exist
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)

# add arguments
cmd += ' ' + self.args

Expand All @@ -141,14 +130,14 @@ def run_at_time(self, input_dict):
@param input_dict dictionary containing timing information
@returns None
"""
lead_seq = util.get_lead_sequence(self.config, input_dict)
lead_seq = get_lead_sequence(self.config, input_dict)
for lead in lead_seq:
self.clear()
input_dict['lead'] = lead

time_info = time_util.ti_calculate(input_dict)
time_info = ti_calculate(input_dict)

if util.skip_time(time_info, self.c_dict.get('SKIP_TIMES', {})):
if skip_time(time_info, self.c_dict.get('SKIP_TIMES', {})):
self.logger.debug('Skipping run time')
continue

Expand Down Expand Up @@ -193,7 +182,8 @@ def run_at_time_all(self, time_info):
temp_file = os.path.join(self.config.getdir('STAGING_DIR'),
'gen_vx_mask',
f'temp_{index}.nc')
self.set_output_path(temp_file)
self.find_and_check_output_file(time_info,
output_path_template=temp_file)

# run GenVxMask
self.build()
Expand Down
13 changes: 3 additions & 10 deletions metplus/wrappers/gfdl_tracker_wrapper.py
Expand Up @@ -272,11 +272,9 @@ def run_at_time_once(self, input_dict):
self.log_error("TCVitals file not found")
return False

# create output directory if it doesn't exist
output_dir = self.c_dict.get('OUTPUT_DIR')
if not os.path.exists(output_dir):
self.logger.debug(f"Creating output directory: {output_dir}")
os.makedirs(output_dir)
# get output path
if not self.find_and_check_output_file(input_dict):
return False

# create sym link to output directory for all files (including tcvit)
all_output_files, tc_vitals_out = (
Expand Down Expand Up @@ -656,11 +654,6 @@ def rename_fort_to_output_path(self, time_info):
self.c_dict.get('OUTPUT_TEMPLATE'))
output_path = do_string_sub(output_path, **time_info)

# create parent directory of output path if it does not exist
parent_dir = os.path.dirname(output_path)
if not os.path.exists(parent_dir):
self.logger.debug(f"Creating output directory: {parent_dir}")

# copy fort.64/66 file to new file name
self.logger.debug(f"Copying {fort_file} file to: {output_path}")
try:
Expand Down
17 changes: 4 additions & 13 deletions metplus/wrappers/point2grid_wrapper.py
Expand Up @@ -12,8 +12,8 @@

import os

from ..util import met_util as util
from ..util import time_util
from ..util import get_lead_sequence
from ..util import ti_calculate
from ..util import do_string_sub
from ..util import remove_quotes
from . import CommandBuilder
Expand Down Expand Up @@ -138,15 +138,6 @@ def get_command(self):
out_path = self.get_output_path()
cmd += ' ' + out_path

parent_dir = os.path.dirname(out_path)
if parent_dir == '':
self.log_error('Must specify path to output file')
return None

# create full output dir if it doesn't already exist
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)

# add arguments
cmd += ' ' + ' '.join(self.args)

Expand All @@ -161,12 +152,12 @@ def run_at_time(self, input_dict):
Args:
@param input_dict dictionary containing timing information
"""
lead_seq = util.get_lead_sequence(self.config, input_dict)
lead_seq = get_lead_sequence(self.config, input_dict)
for lead in lead_seq:
self.clear()
input_dict['lead'] = lead

time_info = time_util.ti_calculate(input_dict)
time_info = ti_calculate(input_dict)
for custom_string in self.c_dict['CUSTOM_LOOP_LIST']:
if custom_string:
self.logger.info(f"Processing custom string: {custom_string}")
Expand Down
5 changes: 2 additions & 3 deletions metplus/wrappers/series_analysis_wrapper.py
Expand Up @@ -22,7 +22,7 @@
WRAPPER_CANNOT_RUN = True
EXCEPTION_ERR = err_msg

from ..util import getlist, get_storms
from ..util import getlist, get_storms, mkdir_p
from ..util import do_string_sub, parse_template, get_tags
from ..util import get_lead_sequence, get_lead_sequence_groups
from ..util import ti_get_hours_from_lead, ti_get_seconds_from_lead
Expand Down Expand Up @@ -1044,8 +1044,7 @@ def generate_animations(self):

animate_dir = os.path.join(self.c_dict['OUTPUT_DIR'],
'series_animate')
if not os.path.exists(animate_dir):
os.makedirs(animate_dir)
mkdir_p(animate_dir)

for group, files in self.c_dict['PNG_FILES'].items():
# write list of files to a text file
Expand Down
9 changes: 0 additions & 9 deletions metplus/wrappers/tc_gen_wrapper.py
Expand Up @@ -329,15 +329,6 @@ def get_command(self):
out_path = self.get_output_path()
cmd += ' -out ' + out_path

parent_dir = os.path.dirname(out_path)
if not parent_dir:
self.log_error('Must specify path to output file')
return None

# create full output dir if it doesn't already exist
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)

return cmd

def run_all_times(self):
Expand Down

0 comments on commit 5ae03a5

Please sign in to comment.