From d2853fddae6427e396d6bbf49c32c00b75347e5c Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Wed, 15 Nov 2023 16:52:07 +0000 Subject: [PATCH 1/3] Adding logic to allow plotting "all" for thresholds and levels --- ush/metviewer/plot_vx_metviewer.py | 42 +++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ush/metviewer/plot_vx_metviewer.py b/ush/metviewer/plot_vx_metviewer.py index 6fa5b773f2..432a3dcf09 100755 --- a/ush/metviewer/plot_vx_metviewer.py +++ b/ush/metviewer/plot_vx_metviewer.py @@ -6,6 +6,7 @@ import argparse import yaml import re +import copy import logging from textwrap import dedent @@ -101,9 +102,11 @@ def get_static_info(static_info_config_fp): levels_to_levels_in_db = static_data['levels_to_levels_in_db'] all_valid_levels = list(levels_to_levels_in_db.keys()) + all_valid_levels.append("all") threshs_to_threshs_in_db = static_data['threshs_to_threshs_in_db'] all_valid_threshs = list(threshs_to_threshs_in_db.keys()) + all_valid_threshs.append("all") # Define local dictionaries containing static values that depend on the # forecast variable. @@ -477,6 +480,16 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): cla.incl_ens_means = incl_ens_means valid_levels_or_accums = valid_levels_by_fcst_var[cla.fcst_var] + if cla.level_or_accum == "all": + output_xmls = [] + for level_or_accum in valid_levels_or_accums: + #make a deep copy so we don't override original command-line arguments + clanew = copy.deepcopy(cla) + clanew.level_or_accum = level_or_accum + print(f"calling generate_metviewer_xml with {clanew.level_or_accum=}") + _,output_xml = generate_metviewer_xml(clanew, static_info, mv_database_info) + output_xmls.extend(output_xml) + return(mv_machine_config_dict['mv_batch'],output_xmls) if cla.level_or_accum not in valid_levels_or_accums: err_msg = dedent(f""" The specified level or accumulation is not compatible with the specified @@ -561,6 +574,16 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): elif (stat_need_thresh[cla.vx_stat]): valid_thresholds = valid_threshs_by_fcst_var[cla.fcst_var] + if cla.threshold == "all": + output_xmls = [] + for threshold in valid_threshs_by_fcst_var[cla.fcst_var]: + #make a deep copy so we don't override original command-line arguments + clanew = copy.deepcopy(cla) + clanew.threshold = threshold + print(f"calling generate_metviewer_xml with {clanew.threshold=}") + _,output_xml = generate_metviewer_xml(clanew, static_info, mv_database_info) + output_xmls.extend(output_xml) + return(mv_machine_config_dict['mv_batch'],output_xmls) if cla.threshold not in valid_thresholds: err_msg = dedent(f""" The specified threshold is not compatible with the specified forecast @@ -792,7 +815,9 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): set_template(args_list) os.remove(tmp_fn) - return(mv_machine_config_dict['mv_batch'], output_xml_fp) + # Return output_xml_fp as a list so we can extend it arbitrarily with recursion + # for the "all" option for various arguments + return(mv_machine_config_dict['mv_batch'], [output_xml_fp]) def run_mv_batch(mv_batch, output_xml_fp): @@ -899,15 +924,18 @@ def plot_vx_metviewer(argv): # Generate a MetViewer xml. logging.info(dedent(f""" - Generating a MetViewer xml ... + Generating MetViewer xml(s) ... """)) mv_batch, output_xml_fp = generate_metviewer_xml(cla, static_info, mv_database_info) - # Run MetViewer on the xml to create a verification plot. - logging.info(dedent(f""" - Running MetViewer on xml file: {output_xml_fp} - """)) - run_mv_batch(mv_batch, output_xml_fp) + # Run MetViewer on the xml(s) to create verification plot(s). + # If output_xml_fp is a string, we only have one plot to make. If a list, we have multiple + + for output_xml in output_xml_fp: + logging.info(dedent(f""" + Running MetViewer on xml file: {output_xml} + """)) + run_mv_batch(mv_batch, output_xml) # # ----------------------------------------------------------------------- # From bf8bd827634fa8c19624c23828af6e0823a41e21 Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Wed, 15 Nov 2023 17:04:44 +0000 Subject: [PATCH 2/3] Convert print statements with calls to "logging.debug" --- ush/metviewer/plot_vx_metviewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ush/metviewer/plot_vx_metviewer.py b/ush/metviewer/plot_vx_metviewer.py index 432a3dcf09..31da33686b 100755 --- a/ush/metviewer/plot_vx_metviewer.py +++ b/ush/metviewer/plot_vx_metviewer.py @@ -486,7 +486,7 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): #make a deep copy so we don't override original command-line arguments clanew = copy.deepcopy(cla) clanew.level_or_accum = level_or_accum - print(f"calling generate_metviewer_xml with {clanew.level_or_accum=}") + logging.debug(f"calling generate_metviewer_xml with {clanew.level_or_accum=}") _,output_xml = generate_metviewer_xml(clanew, static_info, mv_database_info) output_xmls.extend(output_xml) return(mv_machine_config_dict['mv_batch'],output_xmls) @@ -580,7 +580,7 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): #make a deep copy so we don't override original command-line arguments clanew = copy.deepcopy(cla) clanew.threshold = threshold - print(f"calling generate_metviewer_xml with {clanew.threshold=}") + logging.debug(f"calling generate_metviewer_xml with {clanew.threshold=}") _,output_xml = generate_metviewer_xml(clanew, static_info, mv_database_info) output_xmls.extend(output_xml) return(mv_machine_config_dict['mv_batch'],output_xmls) From ccadd9bb84a71c7dca3b7a62cd21d31e73031877 Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Wed, 15 Nov 2023 17:33:30 +0000 Subject: [PATCH 3/3] Update doc string, remove out-dated comment --- ush/metviewer/plot_vx_metviewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ush/metviewer/plot_vx_metviewer.py b/ush/metviewer/plot_vx_metviewer.py index 31da33686b..4faf29b11e 100755 --- a/ush/metviewer/plot_vx_metviewer.py +++ b/ush/metviewer/plot_vx_metviewer.py @@ -325,7 +325,8 @@ def generate_metviewer_xml(cla, static_info, mv_database_info): argv: Command-line arguments Returns: - None + string: Path to MetViewer batch plotting script + list: List of strings indicating paths to XMLs for MetViewer batch plotting """ static_info_config_fp = static_info['static_info_config_fp'] @@ -929,7 +930,6 @@ def plot_vx_metviewer(argv): mv_batch, output_xml_fp = generate_metviewer_xml(cla, static_info, mv_database_info) # Run MetViewer on the xml(s) to create verification plot(s). - # If output_xml_fp is a string, we only have one plot to make. If a list, we have multiple for output_xml in output_xml_fp: logging.info(dedent(f"""