Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1808 poe temp use case #1839

Merged
merged 5 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/parm/use_case_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
"index_list": "8",
"run": false
},
{
"category": "medium_range",
"index_list": "9",
"run": false
},
{
"category": "precipitation",
"index_list": "0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
GridStat: Use binary observation field to verify percentile forecast
====================================================================

model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf

"""
##############################################################################
# Scientific Objective
# --------------------
# Evaluation of a Probability of Exceedence (POE) field presents several difficulties. Some of these include a fitting verification statistic to report on,
# choosing a meaningful percentile field, and more. This use case was the culmination of attempting to verify a POE field for extreme temperature (defined
# as the 85th percentile) in METplus. In order to provide a streamlined process that didn't require vast reworkings of the MET tools, the observation
# field was converted to binary: 0s indicating a non-85th percentile temperature was observed, and a 1 indicating the opposite.
# Those observations are compared to the chosen forecast percentile and the HSS_EC becomes the main statistical focus, as the new hss_ec_value feature
# allowed the use case to more closely replicate in-house verificaiton that already existed.
# A final note that because the POE forecast file is a non-standard netCDF, Python Embedding was used to extract the desired field

##############################################################################
# Datasets
# ---------------------
#
# | **Forecast:** 85th percentile of Temperature maximum, from GEFS
#
# | **Observations:** Climate Assessment Data Base (CADB), converted into a binary field relative to the 85th percentile
#
#
# | **Location:** All of the input data required for this use case can be found in the met_test sample data tarball. Click here to the METplus releases page and download sample data for the appropriate release: https://github.com/dtcenter/METplus/releases
# | This tarball should be unpacked into the directory that you will set the value of INPUT_BASE. See `Running METplus`_ section for more information.
#
# | **Data Source:** CPC

##############################################################################
# METplus Components
# ------------------
#
# This use case calls a Python script to extract the user-defined percentile forecast. METplus then verifies it against a binary observation field
# in GridStat and returns the requested line type outputs.

##############################################################################
# METplus Workflow
# ----------------
#
# The following boundary time is used for the entire script:
#
# | **Init Beg:** 2022-05-22
# | **Init End:** 2022-05-22
#
# There is only one time processed for the use case.
#

##############################################################################
# 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
# i.e. -c parm/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf
#

##############################################################################
# MET Configuration
# ---------------------
#
# METplus sets environment variables based on the values in the METplus configuration file. These variables are referenced in the MET configuration file. **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 not controlled by an environment variable, you can add additional environment variables to be set only within the METplus environment using the [user_env_vars] section of the METplus configuration files. See the ‘User Defined Config’ section on the ‘System Configuration’ page of the METplus User’s Guide for more information.
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/met_config/GridStatConfig_wrapped
#

##############################################################################
# Python Embedding
# ----------------
#
# This use case calls a Python script to parse the user-requested percentile from the forecast dataset.
# This is controlled in the forecast VAR1 variable setting and is provided in
# parm/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE/Tmax_fcst_embedded.py
#
# .. highlight:: python
# .. literalinclude:: ../../../../parm/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE/Tmax_fcst_embedded.py
#

##############################################################################
# Running METplus
# ---------------
#
# This use case can be run two ways:
#
# 1) Passing in GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf then a user-specific system configuration file::
#
# run_metplus.py /path/to/METplus/parm/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf /path/to/user_system.conf
#
# 2) Modifying the configurations in parm/metplus_config, then passing in GridStat_fcstGEFS_obsCADB_BinaryObsPOE::
#
# run_metplus.py /path/to/METplus/parm/use_cases/model_applications/marine_and_cryosphere/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.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
#
# Example User Configuration File::
#
# [config]
# 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.
#
# Refer to the value set for **OUTPUT_BASE** to find where the output data was generated.
# Output for the use case will be found in model_applications/POE_tmax (relative to **OUTPUT_BASE**).
# The following files should exist:
#
# * grid_stat_1920000L_20220530_000000V_ctc.txt
# * grid_stat_1920000L_20220530_000000V_cts.txt
# * grid_stat_1920000L_20220530_000000V.stat
#

##############################################################################
# Keywords
# --------
#
# .. note::
#
# * GridStatUseCase
# * PythonEmbeddingFileUseCase
# * MediumRangeAppUseCase
# * NETCDFFileUseCase
#
# Navigate to the :ref:`quick-search` page to discover other similar use cases.
#
#
#
# sphinx_gallery_thumbnail_path = '_static/medium_range-GridStat_fcstGEFS_obsCADB_BinaryObsPOE.png'

2 changes: 1 addition & 1 deletion internal/tests/use_cases/all_use_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Category: medium_range
6::model_applications/medium_range/PointStat_fcstGFS_obsGDAS_UpperAir_MultiField_PrepBufr.conf
7::TCStat_SeriesAnalysis_fcstGFS_obsGFS_FeatureRelative_SeriesByLead_PyEmbed_Multiple_Diagnostics:: model_applications/medium_range/TCStat_SeriesAnalysis_fcstGFS_obsGFS_FeatureRelative_SeriesByLead_PyEmbed_Multiple_Diagnostics.conf:: cfgrib_env,py_embed
8::MTD_SeriesAnalysis_fcstGFS_obsGFS_FeatureRelative_SeriesByLead::model_applications/medium_range/MTD_SeriesAnalysis_fcstGFS_obsGFS_FeatureRelative_SeriesByLead.conf:: netcdf4_env

9::GridStat_fcstGEFS_obsCADB_BinaryObsPOE:: model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE.conf:: netcdf4_env


Category: precipitation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[config]


PROCESS_LIST = GridStat


LOOP_BY = INIT
INIT_TIME_FMT = %Y%m%d
INIT_BEG=20220522
INIT_END=20220522
INIT_INCREMENT = 12H

LEAD_SEQ = 8d

LOOP_ORDER = times


###
# File I/O
# https://metplus.readthedocs.io/en/latest/Users_Guide/systemconfiguration.html#directory-and-filename-template-info
###

FCST_GRID_STAT_INPUT_TEMPLATE = PYTHON_NUMPY

OBS_GRID_STAT_INPUT_DIR = {INPUT_BASE}/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE
OBS_GRID_STAT_INPUT_TEMPLATE = tmax_cats_{valid?fmt=%Y%m%d}.nc

GRID_STAT_CLIMO_MEAN_INPUT_DIR =
GRID_STAT_CLIMO_MEAN_INPUT_TEMPLATE =

GRID_STAT_CLIMO_STDEV_INPUT_DIR =
GRID_STAT_CLIMO_STDEV_INPUT_TEMPLATE =

GRID_STAT_OUTPUT_DIR = {OUTPUT_BASE}/model_applications/POE_tmax
GRID_STAT_OUTPUT_TEMPLATE =


###
# Field Info
# https://metplus.readthedocs.io/en/latest/Users_Guide/systemconfiguration.html#field-info
###

MODEL = GEFS
OBTYPE = Obs

GRID_STAT_ONCE_PER_FIELD = False

FCST_IS_PROB = false
#FCST_GRID_STAT_PROB_THRESH = ==0.1

FCST_VAR1_NAME = {PARM_BASE}/use_cases/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE/Tmax_fcst_embedded.py {INPUT_BASE}/model_applications/medium_range/GridStat_fcstGEFS_obsCADB_BinaryObsPOE/gefs-00z_rfcst-cal_tmax_{init?fmt=%Y%m%d}_day8.nc:85
FCST_VAR1_THRESH = >=0.2

OBS_VAR1_NAME = tmax
OBS_VAR1_LEVELS = "(*,*)"
OBS_VAR1_THRESH = gt0.5


###
# GridStat Settings (optional)
# https://metplus.readthedocs.io/en/latest/Users_Guide/wrappers.html#gridstat
###

#LOG_GRID_STAT_VERBOSITY = 2

GRID_STAT_CONFIG_FILE = {PARM_BASE}/met_config/GridStatConfig_wrapped

#FCST_GRID_STAT_FILE_TYPE =
OBS_GRID_STAT_FILE_TYPE = NETCDF_NCCF

GRID_STAT_REGRID_TO_GRID = FCST


GRID_STAT_DESC = NA

FCST_GRID_STAT_FILE_WINDOW_BEGIN = 0
FCST_GRID_STAT_FILE_WINDOW_END = 0
OBS_GRID_STAT_FILE_WINDOW_BEGIN = 0
OBS_GRID_STAT_FILE_WINDOW_END = 0

GRID_STAT_NEIGHBORHOOD_WIDTH = 1
GRID_STAT_NEIGHBORHOOD_SHAPE = SQUARE

GRID_STAT_NEIGHBORHOOD_COV_THRESH = >=0.5

GRID_STAT_OUTPUT_PREFIX =

#GRID_STAT_OUTPUT_FLAG_FHO = NONE
GRID_STAT_OUTPUT_FLAG_CTC = BOTH
GRID_STAT_OUTPUT_FLAG_CTS = BOTH
#GRID_STAT_OUTPUT_FLAG_MCTC = NONE
#GRID_STAT_OUTPUT_FLAG_MCTS = NONE
#GRID_STAT_OUTPUT_FLAG_CNT = NONE
#GRID_STAT_OUTPUT_FLAG_SL1L2 = NONE
#GRID_STAT_OUTPUT_FLAG_SAL1L2 = NONE
#GRID_STAT_OUTPUT_FLAG_VL1L2 = NONE
#GRID_STAT_OUTPUT_FLAG_VAL1L2 = NONE
#GRID_STAT_OUTPUT_FLAG_VCNT = NONE
#GRID_STAT_OUTPUT_FLAG_PCT = NONE
#GRID_STAT_OUTPUT_FLAG_PSTD = NONE
#GRID_STAT_OUTPUT_FLAG_PJC = NONE
#GRID_STAT_OUTPUT_FLAG_PRC = NONE
#GRID_STAT_OUTPUT_FLAG_ECLV = BOTH
#GRID_STAT_OUTPUT_FLAG_NBRCTC = NONE
#GRID_STAT_OUTPUT_FLAG_NBRCTS = NONE
#GRID_STAT_OUTPUT_FLAG_NBRCNT = NONE
#GRID_STAT_OUTPUT_FLAG_GRAD = BOTH
#GRID_STAT_OUTPUT_FLAG_DMAP = NONE

GRID_STAT_NC_PAIRS_FLAG_LATLON = FALSE
GRID_STAT_NC_PAIRS_FLAG_RAW = FALSE
GRID_STAT_NC_PAIRS_FLAG_DIFF = FALSE
GRID_STAT_NC_PAIRS_FLAG_CLIMO = FALSE
#GRID_STAT_NC_PAIRS_FLAG_CLIMO_CDP = FALSE
#GRID_STAT_NC_PAIRS_FLAG_WEIGHT = FALSE
#GRID_STAT_NC_PAIRS_FLAG_NBRHD = FALSE
#GRID_STAT_NC_PAIRS_FLAG_FOURIER = FALSE
#GRID_STAT_NC_PAIRS_FLAG_GRADIENT = FALSE
#GRID_STAT_NC_PAIRS_FLAG_DISTANCE_MAP = FALSE
GRID_STAT_NC_PAIRS_FLAG_APPLY_MASK = FALSE

GRID_STAT_HSS_EC_VALUE = 0.15

#GRID_STAT_MASK_GRID =
GRID_STAT_MASK_POLY = {MET_INSTALL_DIR}/share/met/poly/CONUS.poly, {MET_INSTALL_DIR}/share/met/poly/EAST.poly, {MET_INSTALL_DIR}/share/met/poly/WEST.poly, {MET_INSTALL_DIR}/share/met/poly/NPL.poly, {MET_INSTALL_DIR}/share/met/poly/NEC.poly

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import sys
import datetime as dt
import numpy as np
from netCDF4 import Dataset


try:
#user will input name of the file, as well as a percentile they're interested in
#in future iteration, this may need to change to multiple percentiles (a la list style)
print("1")
input_file,ptile = sys.argv[1].split(':')
f = Dataset(input_file, 'r')
print("2")
v = f['poe']
val_time = f.valid_date_range[1]
val_time = dt.datetime.strptime(val_time,"%Y%m%d")
ini_time = str(input_file.split('_')[-2])
ini_time = dt.datetime.strptime(ini_time,"%Y%m%d")
print("3")
lead, rem = divmod((val_time - ini_time).total_seconds(), 3600)
ptile_ind = np.where(f['ptile'][:] == int(ptile))[0][0]
print("4")
lat = np.float64(f.variables['latitude'][:])
lon = np.float64(f.variables['longitude'][:])
#var = np.float64(v[0,ptile_ind,:,:],fill_value=-9999.)
var = np.float64(v[0,ptile_ind,:,:])
print(np.amax(var),np.amin(var))
met_data = var.copy()
except NameError:
print("Can't find input file")
sys.exit(1)

#ADDED
#for i in range(len(met_data)):
# for j in range(len(met_data[i])):
# if j <=2 or j >=358:
# print("edge of ", met_data[i,j],"at", lat[i],lon[j])
# if lat[i] >=42.0 and lat[i] <= 46.0:
# if lon[j] >= 235.0 and lon[j] <= 239.0:
# print("found",met_data[i,j]," at ",lat[i],lon[j],i,j)

attrs = {

'valid': str(val_time.strftime("%Y%m%d"))+'_000000',
'init': str(ini_time.strftime("%Y%m%d"))+'_000000',
'name': 'poe_P'+str(ptile),
'long_name': v.long_name,
'lead': str(int(lead)),
'accum': '00',
'level': 'SURFACE',
'units': 'PERCENTILES',

'grid': {
'name': 'Global 1 degree',
'type': 'LatLon',
'lat_ll': -90.0,
'lon_ll': 0.0,
'delta_lat': 1.0,
'delta_lon': 1.0,

'Nlon': f.dimensions['longitude'].size,
'Nlat': f.dimensions['latitude'].size,
}
}

#print output for user to show successful run
print("Input file: " + repr(input_file.split('/')[-1]))
print("Attributes:\t"+ repr(attrs))
f.close()