Bias Plot on Zonal Mean Wind and Temperature: UserScript, Series-Analysis

model_applications/ s2s_stratosphere/ UserScript_fcstGFS_obsERA_StratosphereBias.py

Scientific Objective

This use case calls functions in METcalcpy to create zonal and meridonial means on U and T. It then runs Series-Analysis on the output zonal means and creates a contour plot of bias in latitude and pressure level.

Datasets

GFS 24 hour forecasts: GFS_2018_02_24h.nc ERA: ERA_2018_02.nc

METplus Components

This use case runs the UserScript wrapper tool to run a user provided script, in this case, zonal_mean_driver.py, runs Series-Analysis to compute the bias, and then runs another UserScript, bias_plot_driver.py, to create the bias plots.

METplus Workflow

This use case does not loop but plots the entire time period of data

UserScript: Computes zonal and meridional means Series-Analysis: Computes the bias on zonal mean wind and temperature UserScript: Creates bias plots

METplus Configuration

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_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias.conf

[config]

# Documentation for this use case can be found at
# https://metplus.readthedocs.io/en/latest/generated/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias.html

# For additional information, please see the METplus Users Guide.
# https://metplus.readthedocs.io/en/latest/Users_Guide

###
# Processes to run
# https://metplus.readthedocs.io/en/latest/Users_Guide/systemconfiguration.html#process-list
###
PROCESS_LIST = UserScript(obs_means), UserScript(fcst_means), SeriesAnalysis(sa_ut), UserScript(bias_plot)


###
# Time Info
# LOOP_BY options are INIT, VALID, RETRO, and REALTIME
# If set to INIT or RETRO:
#   INIT_TIME_FMT, INIT_BEG, INIT_END, and INIT_INCREMENT must also be set
# If set to VALID or REALTIME:
#   VALID_TIME_FMT, VALID_BEG, VALID_END, and VALID_INCREMENT must also be set
# LEAD_SEQ is the list of forecast leads to process
# https://metplus.readthedocs.io/en/latest/Users_Guide/systemconfiguration.html#timing-control
###

LOOP_BY = VALID

VALID_TIME_FMT = %Y%m%d
VALID_BEG = 20180201
VALID_END = 20180228
VALID_INCREMENT = 30d
LEAD_SEQ = 24

USER_SCRIPT_RUNTIME_FREQ = RUN_ONCE

LOOP_ORDER = processes


###
# User Environment Variables
###
[user_env_vars]
OBS_INPUT_FILE_NAME = {INPUT_BASE}/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/ERA_2018_02.nc
FCST_INPUT_FILE_NAME = {INPUT_BASE}/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/GFS_2018_02_024h.nc

OUTPUT_DIR = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias

PLOT_U_INPUT_FILE = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/SeriesAnalysis/zonal_mean_U_stats_2018_02.nc
PLOT_U_BIAS_VAR = series_cnt_ME
PLOT_U_OBAR_VAR = series_cnt_OBAR
PLOT_U_LEVELS = 0,10,20,30,40,50,60,70,80,90,100
PLOT_U_TITLE = GFS vs ERA 24h Forecast Zonal Mean Wind Bias (ME) 02/2018
PLOT_U_OUTPUT_DIR = {OUTPUT_DIR}/plots
PLOT_U_OUTPUT_FILE = GFS_ERA_ME_2018_02_zonal_mean_U.png

PLOT_T_INPUT_FILE = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/SeriesAnalysis/zonal_mean_T_stats_2018_02.nc
PLOT_T_BIAS_VAR = series_cnt_ME
PLOT_T_OBAR_VAR = series_cnt_OBAR
PLOT_T_LEVELS = 200,210,220,230,240,250,260,270,280,290,300
PLOT_T_TITLE = GFS vs ERA 24h Forecast Zonal Mean Temperature Bias (ME) 02/2018
PLOT_T_OUTPUT_DIR = {OUTPUT_DIR}/plots
PLOT_T_OUTPUT_FILE = GFS_ERA_ME_2018_02_zonal_mean_T.png


###
# Zonal Mean UserScript Settings
# https://metplus.readthedocs.io/en/latest/Users_Guide/wrappers.html#userscript
###
[obs_means]
USER_SCRIPT_COMMAND = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/zonal_mean_driver.py obs time


[fcst_means]
USER_SCRIPT_COMMAND = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/zonal_mean_driver.py fcst time


###
# Series Analysis Settings
###
[sa_ut]
SERIES_ANALYSIS_RUNTIME_FREQ = RUN_ONCE

FCST_SERIES_ANALYSIS_INPUT_DIR = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/FCST
FCST_SERIES_ANALYSIS_INPUT_TEMPLATE = FCST_zonal_mean_U_T_{valid?fmt=%Y%m}*_{valid?fmt=%H%M%S}.nc
FCST_SERIES_ANALYSIS_INPUT_DATATYPE = PYTHON_NUMPY

OBS_SERIES_ANALYSIS_INPUT_DIR = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/OBS
OBS_SERIES_ANALYSIS_INPUT_TEMPLATE = OBS_zonal_mean_U_T_{valid?fmt=%Y%m}*_{valid?fmt=%H%M%S}.nc
OBS_SERIES_ANALYSIS_INPUT_DATATYPE = PYTHON_NUMPY

SERIES_ANALYSIS_CLIMO_MEAN_INPUT_DIR =
SERIES_ANALYSIS_CLIMO_MEAN_INPUT_TEMPLATE =

SERIES_ANALYSIS_CLIMO_STDEV_INPUT_DIR =
SERIES_ANALYSIS_CLIMO_STDEV_INPUT_TEMPLATE =

SERIES_ANALYSIS_OUTPUT_DIR = {OUTPUT_BASE}/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/SeriesAnalysis

SERIES_ANALYSIS_DESC =

SERIES_ANALYSIS_CAT_THRESH =

SERIES_ANALYSIS_VLD_THRESH =

SERIES_ANALYSIS_BLOCK_SIZE =

SERIES_ANALYSIS_CTS_LIST =

SERIES_ANALYSIS_REGRID_TO_GRID =
SERIES_ANALYSIS_REGRID_METHOD =
SERIES_ANALYSIS_REGRID_WIDTH =
SERIES_ANALYSIS_REGRID_VLD_THRESH =
SERIES_ANALYSIS_REGRID_SHAPE =

SERIES_ANALYSIS_RUN_ONCE_PER_STORM_ID = False

SERIES_ANALYSIS_IS_PAIRED = False

SERIES_ANALYSIS_CONFIG_FILE = {PARM_BASE}/met_config/SeriesAnalysisConfig_wrapped

SERIES_ANALYSIS_OUTPUT_STATS_CNT = TOTAL, ME, RMSE, FBAR, OBAR

MODEL = GFS

OBTYPE = ERA

SERIES_ANALYSIS_OUTPUT_TEMPLATE = zonal_mean_{fcst_level}_stats_2018_02.nc

FCST_SERIES_ANALYSIS_VAR1_NAME = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/read_met_axis_mean.py MET_PYTHON_INPUT_ARG u lat
# This level is used as a label only
FCST_SERIES_ANALYSIS_VAR1_LEVELS = U 

OBS_SERIES_ANALYSIS_VAR1_NAME = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/read_met_axis_mean.py MET_PYTHON_INPUT_ARG u lat


FCST_SERIES_ANALYSIS_VAR2_NAME = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/read_met_axis_mean.py MET_PYTHON_INPUT_ARG T lat
FCST_SERIES_ANALYSIS_VAR2_LEVELS = T

OBS_SERIES_ANALYSIS_VAR2_NAME = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/read_met_axis_mean.py MET_PYTHON_INPUT_ARG T lat


###
# UserScript Bias Plot Settings
# https://metplus.readthedocs.io/en/latest/Users_Guide/wrappers.html#userscript
###
[bias_plot]
USER_SCRIPT_COMMAND = {PARM_BASE}/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias/bias_plot_driver.py

MET Configuration

METplus sets environment variables based on user settings in the METplus configuration file. See How METplus controls MET config file settings for more details.

YOU SHOULD NOT SET ANY OF THESE ENVIRONMENT VARIABLES YOURSELF! THEY WILL BE OVERWRITTEN BY METPLUS WHEN IT CALLS THE MET TOOLS!

If there is a setting in the MET configuration file that is currently not supported by METplus you’d like to control, please refer to: Overriding Unsupported MET config file settings

SeriesAnalysisConfig_wrapped

Note

See the Series-Analysis MET Configuration section of the User’s Guide for more information on the environment variables used in the file below:

////////////////////////////////////////////////////////////////////////////////
//
// Series-Analysis configuration file.
//
// For additional information, see the MET_BASE/config/README file.
//
////////////////////////////////////////////////////////////////////////////////

//
// Output model name to be written
//
//model =
${METPLUS_MODEL}

//
// Output description to be written
//
//desc =
${METPLUS_DESC}

//
// Output observation type to be written
//
//obtype =
${METPLUS_OBTYPE}

////////////////////////////////////////////////////////////////////////////////

//
// Verification grid
// May be set separately in each "field" entry
//
//regrid = {
${METPLUS_REGRID_DICT}

////////////////////////////////////////////////////////////////////////////////

censor_thresh = [];
censor_val    = [];
//cat_thresh =
${METPLUS_CAT_THRESH}
cnt_thresh    = [ NA ];
cnt_logic     = UNION;

//
// Forecast and observation fields to be verified
//
fcst = {
   ${METPLUS_FCST_FILE_TYPE}
   ${METPLUS_FCST_CAT_THRESH}
   //field = [
   ${METPLUS_FCST_FIELD}
}
obs = {
   ${METPLUS_OBS_FILE_TYPE}
   ${METPLUS_OBS_CAT_THRESH}
   //field = [
   ${METPLUS_OBS_FIELD}
}

////////////////////////////////////////////////////////////////////////////////

//
// Climatology data
//
//climo_mean = {
${METPLUS_CLIMO_MEAN_DICT}


//climo_stdev = {
${METPLUS_CLIMO_STDEV_DICT}

//climo_cdf = {
${METPLUS_CLIMO_CDF_DICT}

////////////////////////////////////////////////////////////////////////////////

//
// Confidence interval settings
//
ci_alpha  = [ 0.05 ];

boot = {
   interval = PCTILE;
   rep_prop = 1.0;
   n_rep    = 0;
   rng      = "mt19937";
   seed     = "";
}

////////////////////////////////////////////////////////////////////////////////

//
// Verification masking regions
//
//mask = {
${METPLUS_MASK_DICT}

//
// Number of grid points to be processed concurrently.  Set smaller to use
// less memory but increase the number of passes through the data.
//
//block_size =
${METPLUS_BLOCK_SIZE}

//
// Ratio of valid matched pairs to compute statistics for a grid point
//
//vld_thresh =
${METPLUS_VLD_THRESH}

////////////////////////////////////////////////////////////////////////////////

//
// Statistical output types
//
//output_stats = {
${METPLUS_OUTPUT_STATS_DICT}

////////////////////////////////////////////////////////////////////////////////

//hss_ec_value =
${METPLUS_HSS_EC_VALUE}
rank_corr_flag = FALSE;

tmp_dir = "${MET_TMP_DIR}";

//version        = "V10.0";

////////////////////////////////////////////////////////////////////////////////

${METPLUS_MET_CONFIG_OVERRIDES}

Python Embedding

This use case uses a Python embedding script to read in the zonal mean data to Series-Analysis

import os
import sys
import numpy as np
import datetime as dt
import netCDF4 as nc4


if len(sys.argv) != 4:
    print("Must specify exactly one input file, variable name, and summary axis (lat, lon, latlon).")
    sys.exit(1)

# Read the input file as the first argument
input_file = os.path.expandvars(sys.argv[1])
var_name   = sys.argv[2]
axis       = sys.argv[3]

# Read the data
f = nc4.Dataset(input_file, 'r')
data = np.float64(f.variables[var_name][:])
met_data = np.transpose(data).copy()

if axis == "lon":
   lats   = list()
   lons   = list(np.float64(f.variables["lon"][:]))
elif axis == "lat":
   lats   = list(np.float64(f.variables["lat"][:]))
   lons   = list()

pres = list(list(np.float64(f.variables["pres"][:])))
times  = list()

lead_ma = f.variables["lead_time"][:]
lead = lead_ma.__int__()
vtime = f.variables["time"]
cur_date = nc4.num2date(vtime[:], vtime.units, vtime.calendar)
init = cur_date - dt.timedelta(hours=lead)
accum     = "00"

attrs = {
   'valid': cur_date.strftime("%Y%m%d_%H%M%S"),
   'init':   init.strftime("%Y%m%d_%H%M%S"),
   'lead':   str(int(lead)).zfill(2),
   'accum':  accum,

   'name':      var_name,
   'long_name': str(getattr(f.variables[var_name], "long_name")),
   'level':     axis + "_mean",
   'units':     str(getattr(f.variables[var_name], "units")),

   'grid': {
     'type'   : "SemiLatLon",
     'name'   : axis + "_mean",
     'lats'   : lats,
     'lons'   : lons,
     'levels' : pres,
     'times'  : times
   }
}

print("Attributes: " + repr(attrs))

Running METplus

This use case can be run two ways:

1) Passing in UserScript_fcstGFS_obsERA_StratosphereBias.conf, then a user-specific system configuration file:

run_metplus.py -c /path/to/METplus/parm/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias.conf -c /path/to/user_system.conf
  1. Modifying the configurations in parm/metplus_config, then passing in UserScript_fcstGFS_obsERA_StratosphereBias.conf:

    run_metplus.py -c /path/to/METplus/parm/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratosphereBias.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

  • OUTPUT_BASE - Path where METplus output will be written. This must be in a location where you have write permissions

  • MET_INSTALL_DIR - Path to location where MET is installed locally

and for the [exe] section, you will need to define the location of NON-MET executables. No executables are required for performing this use case.

Example User Configuration File:

[dir]
INPUT_BASE = /path/to/sample/input/data
OUTPUT_BASE = /path/to/output/dir
MET_INSTALL_DIR = /path/to/met-X.Y

Expected Output

A successful run will output the following both to the screen and to the logfile:

INFO: METplus has successfully finished running.

Keywords

Note

  • UserScriptUseCase

  • S2SAppUseCase

  • S2SStratosphereAppUseCase

  • SeriesAnalysisUseCase

  • METcalcpyUseCase

  • METplotpyUseCase

Navigate to the METplus Quick Search for Use Cases page to discover other similar use cases.

sphinx_gallery_thumbnail_path = ‘_static/s2s_stratosphere-UserScript_fcstGFS_obsERA_StratosphereBias.png’

Total running time of the script: (0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery