Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save work in progress
  • Loading branch information
EdwardSafford-NOAA committed Nov 4, 2024
1 parent 5bad163 commit 3c0e75f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ush/plotObsMon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
from re import sub
import yaml
from om_data import OM_data
import datetime as dt

from wxflow import parse_j2yaml, save_as_yaml
from wxflow import add_to_datetime, to_timedelta, to_datetime
from eva.eva_driver import eva
from eva.utilities.logger import Logger
from datetime import timedelta

# --------------------------------------------------------------------------------------------

def genYaml(input_yaml, output_yaml, config):
"""
Expand Down Expand Up @@ -179,9 +182,10 @@ def loadConfig(satname, instrument, obstype, plot, cycle_tm, cycle_interval,
instrument = inst.get('name')

for plot in inst.get('plot_list'):
logger.info(f'plot: {plot}')

config = loadConfig(satname, instrument, obstype, plot, cycle_tm,
cycle_interval, data_location, model, chan_dict)

plot_template = f"{config['PLOT_TEMPLATE']}.yaml"
plot_yaml = f"{config['SENSOR']}_{config['SAT']}_{plot_template}"

Expand All @@ -195,11 +199,17 @@ def loadConfig(satname, instrument, obstype, plot, cycle_tm, cycle_interval,
os.chdir(plot_dir)

config['DATA'] = plot_dir
genYaml(plot_template, plot_yaml, config)
try:
genYaml(plot_template, plot_yaml, config)

plotData = OM_data(data_location, config, plot_yaml, logger)
eva(plot_yaml)
# os.remove(plot_yaml)

plotData = OM_data(data_location, config, plot_yaml, logger)
eva(plot_yaml)
os.remove(plot_yaml)
except Exception as e:
logger.info(f'Warning: unable to run genYaml() with plot_yaml file {plot_yaml} ' +
f'error: {e}')
continue

if 'minimization' in mon_dict.keys():
satname = None
Expand Down
45 changes: 45 additions & 0 deletions ush/splitPlotYaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ def removeKey(d, keys):
return r


def check_plotlist(type, logger, plot_list, sat=None, instr=None):
"""
"""
logger.info(f'--> check_plotlist')
sat_reqs = {'rad': ['plot', 'times', 'channels', 'component', 'run'],
'ozn': ['plot', 'times', 'levels', 'component', 'run']}

rtn_val = True
missing = []
match type:
case 'sat':
if 'rad' in plot_list.get('plot'):
reqs = sat_reqs.get('rad')
else:
reqs = sat_reqs.get('ozn')

for val in reqs:
if val not in plot_list:
missing.append(val)
plot_str = (f" {instr} {sat} {plot_list.get('plot')}")

# case 'min':
# case 'obs':
# cast _:

if missing:
logger.info(f'WARNING: YAML for plot {plot_str} is missing {missing}')
logger.info(f'WARNING: Requested plot will be SKIPPED.')
rtn_val = False

return (rtn_val)
logger.info(f'<-- check_plotlist')


if __name__ == "__main__":
"""
splitPlotYaml
Expand Down Expand Up @@ -71,6 +105,7 @@ def removeKey(d, keys):
data = mon_dict.get('data')

if 'satellites' in mon_dict.keys():
logger.info(f' split_plot, in satellites')
sd = removeKey(mon_dict, ['minimization', 'observations'])

for sat in mon_dict.get('satellites'):
Expand All @@ -79,14 +114,19 @@ def removeKey(d, keys):
for inst in sat.get('instruments'):
iname = inst.get('name')
plist = inst.get('plot_list')
for pl in inst.get('plot_list'):
if not check_plotlist('sat', logger, pl, sat=satname, instr=iname):
continue

# --------------------------------------------------------------------
# For instruments with a large number of channels split the plot_list
#
channels = chan_dict.get(iname)
logger.info(f' channels: {channels}')
nchans = 0
if channels is not None:
nchans = len(channels.split(","))
logger.info(f' nchans: {nchans}')

if nchans > 100:
ctr = 0
Expand Down Expand Up @@ -114,6 +154,11 @@ def removeKey(d, keys):
if 'minimization' in mon_dict.keys():
md = removeKey(mon_dict, ['satellites', 'observations'])
fname = f'OM_PLOT_minimization.yaml'
mm = md.get('minimization')
logger.info(f'mm: {mm}')
for m in mm.get('plot_list'):
logger.info(f'm: {m}')

file = open(fname, "w")
yaml.dump(md, file)
file.close()
Expand Down

0 comments on commit 3c0e75f

Please sign in to comment.