From 41500bed0bc45f6f06afe56cf11fdd68a91c0c0f Mon Sep 17 00:00:00 2001 From: bikegeek <3753118+bikegeek@users.noreply.github.com> Date: Wed, 22 Jun 2022 09:19:17 -0600 Subject: [PATCH] Feature 1650 update hovmoeller (#1666) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> --- ...UserScript_obsPrecip_obsOnly_Hovmoeller.py | 19 +++-- ...erScript_obsPrecip_obsOnly_Hovmoeller.conf | 3 +- .../hovmoeller.yaml | 15 ++-- .../hovmoeller_diagram.py | 82 +------------------ 4 files changed, 26 insertions(+), 93 deletions(-) diff --git a/docs/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.py b/docs/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.py index a72af7258e..cbc5031ddf 100644 --- a/docs/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.py +++ b/docs/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.py @@ -30,6 +30,15 @@ # This use case runs the UserScript wrapper tool to run a user provided script, # in this case, hovmoeller.py. # +# It also requires the METcalcpy and METplotpy source code to generate the plot. +# Clone the METcalcpy repository (https://github.com/dtcenter/METcalcpy) and the +# METplotpy repository (https://github.com/dtcenter/METplotpy) under the same base +# directory as the METPLUS_BASE directory so that the METplotpy, METcalcpy, and +# METplotpy directories are under the same base directory (i.e. if the METPLUS_BASE directory is +# /home/username/working/METplus, then clone the METcalcpy and METplotpy source +# code into the /home/username/working directory). +# + ############################################################################## # METplus Workflow @@ -48,7 +57,7 @@ # # METplus first loads all of the configuration files found in parm/metplus_config, # then it loads any configuration files passed to METplus via the command line -# with the -c option, i.e. -c parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf +# parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf # # .. highlight:: bash # .. literalinclude:: ../../../../parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf @@ -78,14 +87,14 @@ # then a user-specific system configuration file:: # # run_metplus.py \ -# -c /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf \ -# -c /path/to/user_system.conf +# /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf \ +# /path/to/user_system.conf # # 2) Modifying the configurations in parm/metplus_config, then passing in UserScript_obsPrecip_obsOnly_Hovmoeller.conf:: # # run_metplus.py \ -# -c /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf -# +# /path/to/METplus/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf +# # The former method is recommended. Whether you add them to a user-specific configuration file or modify the metplus_config files, the following variables must be set correctly: # # * **INPUT_BASE** - Path to directory where sample data tarballs are unpacked (See Datasets section to obtain tarballs). This is not required to run METplus, but it is required to run the examples in parm/use_cases diff --git a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf index c729d81d6d..ed4ef9111b 100644 --- a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf +++ b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller.conf @@ -19,8 +19,9 @@ LOG_FILE = "Hovmoeller_diagram.log" LOG_LEVEL = "INFO" -INPUT_FILE_NAME = {INPUT_BASE}/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/precip.erai.sfc.1p0.2x.2014-2016.nc YAML_CONFIG_NAME = {PARM_BASE}/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller.yaml +INPUT_FILE_NAME = {INPUT_BASE}/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/precip.erai.sfc.1p0.2x.2014-2016.nc + METPLOTPY_BASE = {METPLUS_BASE}/../METplotpy OUTPUT_DIR = {OUTPUT_BASE}/plots diff --git a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller.yaml b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller.yaml index a66945af73..33f9770318 100644 --- a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller.yaml +++ b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller.yaml @@ -1,11 +1,14 @@ -height: 800 -width: 1200 +plot_filename: !ENV '${OUTPUT_DIR}/erai_precip2.png' +input_data_file: !ENV '${INPUT_FILE_NAME}' +plot_height: 800 +plot_width: 1200 title: ERAI Precipitation -font_size: 20 +xy_label_font_size: 20 +title_size: 20 -xaxis_title: Longitude -yaxis_title: Time +xaxis: Longitude +yaxis: Time date_start: 2016-01-01 date_end: 2016-03-31 @@ -21,5 +24,3 @@ contour_min: 0.2 contour_max: 1.6 contour_del: 0.2 colorscale: 'BuPu' -plot_filename: -- !ENV '${OUTPUT_DIR}/erai_precip2.png' diff --git a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller_diagram.py b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller_diagram.py index fcdf72c5dc..22dd967279 100755 --- a/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller_diagram.py +++ b/parm/use_cases/model_applications/s2s/UserScript_obsPrecip_obsOnly_Hovmoeller/hovmoeller_diagram.py @@ -5,86 +5,8 @@ """ import os -import sys -import logging -import yaml -import xarray as xr # http://xarray.pydata.org/ import metplotpy.plots.hovmoeller.hovmoeller as Hovmoeller -import metcalcpy.util.read_env_vars_in_config as readconfig - - -def main(): - """ - Use existing default Hovmoeller config file found int METplotpy to - create a default plot, using data in the METplus data store - """ - - """ - Read METplus config file paramaters - """ - input_file_name = os.environ.get("INPUT_FILE_NAME","precip.erai.sfc.1p0.2x.2014-2016.nc") - plot_config_file = os.getenv("YAML_CONFIG_NAME","hovmoeller.yaml") - input_file = input_file_name - - """ - Read Hovmoeller YAML configuration file - """ - try: - config = readconfig.parse_config(plot_config_file) - logging.info(config) - except yaml.YAMLError as exc: - logging.error(exc) - - - """ - Setup logging - """ - logfile = "Hovmoeller_diagram.log" - logging_level = os.environ.get("LOG_LEVEL","logging.INFO") - logging.basicConfig(stream=logfile, level=logging_level) - - # Plot and save difficulty index figures - """ - Read dataset - """ - try: - logging.info('Opening ' + input_file) - ds = xr.open_dataset(input_file) - except IOError as exc: - logging.error('Unable to open ' + input_file) - logging.error(exc) - sys.exit(1) - logging.debug(ds) - - data = ds[config['var_name']] - logging.debug(data) - - data = data.sel(time=slice(config['date_start'], config['date_end'])) - time = ds.time.sel(time=slice(config['date_start'], config['date_end'])) - lon = ds.lon - - data = data * config['unit_conversion'] - data.attrs['units'] = config['var_units'] - - plot_filename = config['plot_filename'][0] - print("Plot name",plot_filename) - logging.info(plot_filename) - - # create output directory if it does not exist - plot_dir = os.path.dirname(plot_filename) - if not os.path.exists(plot_dir): - logging.info(f"Creating output directory: {plot_dir}") - os.makedirs(plot_dir) - - custom_param_dict = {"plot_filename": plot_filename} - plot = Hovmoeller.Hovmoeller(custom_param_dict, time, lon, data) - plot.save_to_file() - - # check if output file exists since save_to_file doesn't return - # an error code on failure - if not os.path.exists(plot_filename): - logging.error(f"Could not create output file: {plot_filename}") - sys.exit(1) if __name__ == '__main__': - main() + config_file = os.environ.get('YAML_CONFIG_NAME') + Hovmoeller.main(config_file)