Skip to content

Commit 92520fa

Browse files
Avoid attempting to make plots which have an incomplete specification (NOAA-EMC#50)
Avoid attempting to make any plots which have an incomplete specification in the top-level yaml plot file. This is in response to problems Andrew found in testing. Absent these changes such incomplete specifications cause a catastrophic failure of all remaining plots. With these changes incomplete specifications are skipped over and an identifying warning message is produced. Closes NOAA-EMC#49
1 parent 5bad163 commit 92520fa

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

ush/plotObsMon.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
from re import sub
1010
import yaml
1111
from om_data import OM_data
12+
import datetime as dt
1213

1314
from wxflow import parse_j2yaml, save_as_yaml
1415
from wxflow import add_to_datetime, to_timedelta, to_datetime
1516
from eva.eva_driver import eva
1617
from eva.utilities.logger import Logger
18+
from datetime import timedelta
19+
20+
# --------------------------------------------------------------------------------------------
1721

1822

1923
def genYaml(input_yaml, output_yaml, config):
@@ -181,7 +185,6 @@ def loadConfig(satname, instrument, obstype, plot, cycle_tm, cycle_interval,
181185
for plot in inst.get('plot_list'):
182186
config = loadConfig(satname, instrument, obstype, plot, cycle_tm,
183187
cycle_interval, data_location, model, chan_dict)
184-
185188
plot_template = f"{config['PLOT_TEMPLATE']}.yaml"
186189
plot_yaml = f"{config['SENSOR']}_{config['SAT']}_{plot_template}"
187190

@@ -195,11 +198,17 @@ def loadConfig(satname, instrument, obstype, plot, cycle_tm, cycle_interval,
195198
os.chdir(plot_dir)
196199

197200
config['DATA'] = plot_dir
198-
genYaml(plot_template, plot_yaml, config)
201+
try:
202+
genYaml(plot_template, plot_yaml, config)
203+
204+
plotData = OM_data(data_location, config, plot_yaml, logger)
205+
eva(plot_yaml)
206+
os.remove(plot_yaml)
199207

200-
plotData = OM_data(data_location, config, plot_yaml, logger)
201-
eva(plot_yaml)
202-
os.remove(plot_yaml)
208+
except Exception as e:
209+
logger.info(f'Warning: unable to run genYaml() with plot_yaml file ' +
210+
f'{plot_yaml} error: {e}')
211+
continue
203212

204213
if 'minimization' in mon_dict.keys():
205214
satname = None

ush/splitPlotYaml.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,61 @@ def removeKey(d, keys):
2929
return r
3030

3131

32+
def check_plotlist(type, logger, plotlist, sat=None, instr=None, obstype=None):
33+
"""
34+
Parse plotlist for missing required elements.
35+
36+
Parameters:
37+
type (str): type of plot
38+
logger (Logger): logger for output warnings
39+
plotlist (list): list of requested plot specifications
40+
sat (str): satellite name (default None)
41+
instr (str); instrument name (default None)
42+
obstype (str): observation type namea (default None)
43+
44+
Return:
45+
True if no required elements are missing from plotlist, else False
46+
"""
47+
48+
sat_reqs = {'rad': ['plot', 'times', 'channels', 'component', 'run'],
49+
'ozn': ['plot', 'times', 'levels', 'component', 'run']}
50+
min_reqs = ['plot', 'times', 'run']
51+
obs_reqs = ['plot', 'times', 'datatypes', 'run']
52+
53+
rtn_val = True
54+
missing = []
55+
match type:
56+
case 'sat':
57+
if 'rad' in plotlist.get('plot'):
58+
reqs = sat_reqs.get('rad')
59+
else:
60+
reqs = sat_reqs.get('ozn')
61+
62+
for val in reqs:
63+
if val not in plotlist:
64+
missing.append(val)
65+
plot_info = (f" {instr} {sat} {plotlist.get('plot')}")
66+
67+
case 'min':
68+
for val in min_reqs:
69+
if val not in plotlist:
70+
missing.append(val)
71+
plot_info = (f" {plotlist.get('plot')}")
72+
73+
case 'obs':
74+
for val in obs_reqs:
75+
if val not in plotlist:
76+
missing.append(val)
77+
plot_info = (f" {obstype}, {plotlist.get('plot')}")
78+
79+
if len(missing) > 0:
80+
logger.info(f'WARNING: YAML for plot {plot_info} is missing {missing}')
81+
logger.info(f'WARNING: Requested plot will be SKIPPED.')
82+
rtn_val = False
83+
84+
return (rtn_val)
85+
86+
3287
if __name__ == "__main__":
3388
"""
3489
splitPlotYaml
@@ -79,6 +134,9 @@ def removeKey(d, keys):
79134
for inst in sat.get('instruments'):
80135
iname = inst.get('name')
81136
plist = inst.get('plot_list')
137+
for pl in inst.get('plot_list'):
138+
if not check_plotlist('sat', logger, pl, sat=satname, instr=iname):
139+
continue
82140

83141
# --------------------------------------------------------------------
84142
# For instruments with a large number of channels split the plot_list
@@ -114,12 +172,26 @@ def removeKey(d, keys):
114172
if 'minimization' in mon_dict.keys():
115173
md = removeKey(mon_dict, ['satellites', 'observations'])
116174
fname = f'OM_PLOT_minimization.yaml'
175+
mm = md.get('minimization')
176+
177+
for pl in mm[0]['plot_list']:
178+
if not check_plotlist('min', logger, pl):
179+
mm[0]['plot_list'].remove(pl)
180+
117181
file = open(fname, "w")
118182
yaml.dump(md, file)
119183
file.close()
120184

121185
if 'observations' in mon_dict.keys():
122186
od = removeKey(mon_dict, ['satellites', 'minimization'])
187+
obs = od.get('observations')
188+
189+
for ob in obs:
190+
obstype = ob.get('obstype')
191+
for pl in ob.get('plot_list'):
192+
if not check_plotlist('obs', logger, pl, obstype=obstype):
193+
ob.get('plot_list').remove(pl)
194+
123195
fname = f'OM_PLOT_observations.yaml'
124196
file = open(fname, "w")
125197
yaml.dump(od, file)

0 commit comments

Comments
 (0)