From 43dcc0b4171af19dcd45c43359cceed20d91ac33 Mon Sep 17 00:00:00 2001 From: bikegeek Date: Wed, 13 Nov 2024 10:25:35 -0700 Subject: [PATCH] Moved from the incorrect directory to this directory --- .../plot_time_series.py | 55 +++++++ .../plot_time_series.yaml | 145 ++++++++++++++++++ .../reformat_tcdiag.py | 58 +++++++ .../reformat_tcdiag.yaml | 2 +- 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100755 parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.py create mode 100644 parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.yaml create mode 100755 parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.py diff --git a/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.py b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.py new file mode 100755 index 000000000..7eaf7f753 --- /dev/null +++ b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import os +from time import perf_counter +import logging +import yaml +import metcalcpy.util.read_env_vars_in_config as readconfig +import metplotpy.plots.tcmpr_plots.tcmpr as tcmpr +# from metplotpy.plots.tcmpr_plots.tcmpr import Tcmpr +from metplotpy.plots.tcmpr_plots.tcmpr_config import TcmprConfig + +def main(): + + # Determine location of the default YAML config files and then + # read defaults stored in YAML formatted file into the dictionary + if 'METPLOTPY_BASE' in os.environ: + location = os.path.join(os.environ['METPLOTPY_BASE'], 'metplotpy/plots/config') + else: + location = os.path.realpath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'config')) + + with open(os.path.join(location, "tcmpr_defaults.yaml"), 'r') as stream: + try: + defaults = yaml.load(stream, Loader=yaml.FullLoader) + except yaml.YAMLError as exc: + print(exc) + + # Read in the YAML configuration file. Environment variables in + # the configuration file are supported. + try: + input_config_file = os.getenv("TIME_SERIES_PLOT_YAML_CONFIG_NAME", "plot_time_series.yaml") + settings = readconfig.parse_config(input_config_file) + logging.info(settings) + except yaml.YAMLError as exc: + logging.error(exc) + + + # merge user defined parameters into defaults if they exist + docs = {**defaults, **settings} + + + config_obj = TcmprConfig(docs) + + try: + start = perf_counter() + + tcmpr.create_plot(config_obj) + end = perf_counter() + execution_time = end - start + logging.info(f"Finished creating time series plot, execution time: {execution_time} seconds") + except ValueError as val_er: + print(val_er) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.yaml b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.yaml new file mode 100644 index 000000000..47e9a4c11 --- /dev/null +++ b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/plot_time_series.yaml @@ -0,0 +1,145 @@ +colors: +# color-blind friendly colors: green and purple + - + - '#1AFF1A' + - '#4B0092' + +fixed_vars_vals_input: + BASIN: + - AL + LEVEL: + - TS + - EX + - HU + INIT: + - '2022-09-26 00:00:00' + + +indy_vals: + - 0 + - 6 + - 12 + - 18 + - 24 + - 30 + - 36 + - 42 + - 48 + - 54 + - 60 + - 66 + - 72 + - 78 + - 84 + - 90 + - 96 + - 102 + - 108 + - 114 + - 120 + - 126 +indy_label: + - '00' + - '06' + - '12' + - '18' + - '24' + - '30' + - '36' + - '42' + - '48' + - '54' + - '60' + - '66' + - '72' + - '78' + - '84' + - '90' + - '96' + - '102' + - '108' + - '114' + - '120' + - '126' + + +list_stat_1: + - "SHEAR_MAGNITUDE" + + +plot_disp: + - 'True' + - 'True' + + +series_order: + - 1 + - 2 + + +series_val_1: + AMODEL: + - GFSO + - SHIP + +series_ci: + - 'True' + - 'True' + +series_line_width: + - 1 + - 1 + +series_line_style: + - '-' + - '-' + +series_symbols: + - 'circle-open' + - 'circle-open' + +series_symbols_size: + - 7 + - 7 + +show_nstats: 'False' +tcst_dir: !ENV '${REFORMAT_OUTPUT_BASE}' +tcst_files: [ ] +title: 'SHIP and GFSO for Ian, 2022-09-26 init time 00, all available fcst leads' + +mar: + l: 0 #left margin + r: 0 #right margin + b: 90 #bottom margin + t: 100 #top margin + +title_offset: -2.03 +yaxis_1: 'shear magnitude (units go here)' + +plot_type_list: + - 'point' + +rp_diff: +# - '>=1' + - '>=100' +event_equal: 'True' +skill_ref: +# - HFSA + +plot_dir: !ENV '${TIME_SERIES_PLOT_OUTPUT_BASE}/time_series' +prefix: '' +subtitle: +log_level: INFO +log_filename: !ENV '${METPLUS_BASE}/tcmpr_log.out' +baseline_file: !ENV '${METPLOTPY_BASE}/metplotpy/plots/tcmpr_plots/hfip_baseline.dat' +column_info_file: !ENV '${METPLOTPY_BASE}/metplotpy/plots/tcmpr_plots/plot_tcmpr_hdr.dat' +hfip_bsln: 'no' + + +connect_points: True +is_tcdiag_linetype: True + + + + + diff --git a/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.py b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.py new file mode 100755 index 000000000..95e6d2783 --- /dev/null +++ b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + + +import os +import time +import logging + +from METdbLoad.ush.read_data_files import ReadDataFiles +from METdbLoad.ush.read_load_xml import XmlLoadFile +from METreformat.write_stat_ascii import WriteStatAscii +from metcalcpy.util import read_env_vars_in_config as readconfig + + +logger = logging.getLogger(__name__) + +def main(): + + # Read in the YAML configuration file. Environment variables in + # the configuration file are supported. + input_config_file = os.getenv("REFORMAT_YAML_CONFIG_NAME", "reformat_tcdiag.yaml") + settings = readconfig.parse_config(input_config_file) + logging.info(settings) + + + # Replacing the need for an XML specification file, pass in the XMLLoadFile and + # ReadDataFile parameters + rdf_obj: ReadDataFiles = ReadDataFiles() + xml_loadfile_obj: XmlLoadFile = XmlLoadFile(None) + + # Retrieve all the filenames in the data_dir specified in the YAML config file + load_files = xml_loadfile_obj.filenames_from_template(settings['input_data_dir'], + {}) + + flags = xml_loadfile_obj.flags + line_types = xml_loadfile_obj.line_types + beg_read_data = time.perf_counter() + rdf_obj.read_data(flags, load_files, line_types) + end_read_data = time.perf_counter() + time_to_read = end_read_data - beg_read_data + logger.info("Time to read input .stat data files using METdbLoad: {time_to_read}") + file_df = rdf_obj.tcst_data + + # Check if the output file already exists, if so, delete it to avoid + # appending output from subsequent runs into the same file. + existing_output_file = os.path.join(settings['output_dir'], settings['output_filename']) + logger.info("Checking if {existing_output_file} already exists") + if os.path.exists(existing_output_file): + logger.info("Removing existing output file {existing_output_file}") + os.remove(existing_output_file) + + # Write stat file in ASCII format + stat_lines_obj: WriteStatAscii = WriteStatAscii(settings) + # stat_lines_obj.write_stat_ascii(file_df, parms, logger) + stat_lines_obj.write_stat_ascii(file_df, settings) + + +if __name__ == "__main__": + main() diff --git a/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.yaml b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.yaml index dfb09a735..1d244e367 100644 --- a/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.yaml +++ b/parm/use_cases/model_applications/tc_and_extra_tc/UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit/reformat_tcdiag.yaml @@ -1,5 +1,5 @@ # The REFORMAT_OUTPUT_BASE and REFORMAT_INPUT_BASE are defined in the -# UserScript_TCDIAG_fcstGFSO_SHIP_obsOFCL_SingleInit.conf file +# UserScript_fcstRRFS_fcstOnly_Reformat_Aggregate_Plot.conf file # # Indicates whether the .stat file input contains aggregated statistics (i.e. output from MET stat-analysis