Skip to content

Commit

Permalink
Handle empty track files in get_storm_ids.
Browse files Browse the repository at this point in the history
Do not open or analyze empty storm track files (.tcst files).  Instead,
return an empty list.

Also fixed typo/bug, logger was incorrectly referenced as log instead of
logger.
  • Loading branch information
Minna Win committed Dec 19, 2016
1 parent 3976450 commit 30242ba
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ush/met_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ def get_storm_ids(filter_filename, logger):
cur_filename = sys._getframe().f_code.co_filename
cur_function = sys._getframe().f_code.co_name
storm_id_list = set()
empty_list = []

# Check if the filter_filename is empty, if it
# is, then return.
if os.stat(filter_filename).st_size == 0:
return empty_list
with open(filter_filename) as fileobj:
# skip the first line as it contains the header
next(fileobj)
Expand Down Expand Up @@ -444,7 +450,7 @@ def retrieve_and_regrid(tmp_filename, cur_init, cur_storm, out_dir, logger, p):
cur_filename = sys._getframe().f_code.co_filename
cur_function = sys._getframe().f_code.co_name
gfs_dir = p.opt["GFS_DIR"]
regrid_data_plane_exe = p.opt["REGRID_DATA_PLANE"]
regrid_data_plane_exe = p.opt["REGRID_DATA_PLANE_EXE"]
wgrib2_exe = p.opt["WGRIB2"]
egrep_exe = p.opt["EGREP_EXE"]

Expand Down Expand Up @@ -968,7 +974,7 @@ def prune_empty(output_dir, p, logger):
"Empty file: " + file +
"...removing" )

log.info(msg)
logger.info(msg)
os.remove(file)


Expand Down

0 comments on commit 30242ba

Please sign in to comment.