"""
GenVxMask and Point-Stat: Computing PBLH from AMDAR data using "Theta-increase" method
======================================================================================

model_applications/pbl/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed.conf

"""
##############################################################################
# .. contents::
#   :depth: 1
#   :local:
#   :backlinks: none

##############################################################################
# Scientific Objective
# --------------------
#
# The Planetary Boundary Layer Height (PBLH) arises from a complex interaction of 
# lower atmosphere and surface processes, and is therefore a useful metric to
# evaluate models. This PointStat use case computes PBLH from AMDAR aircraft data
# using the "Theta-increase" method (Nielsen-Gammon et al., 2008, J. App. Met. Clim.),
# which computes PBLH by finding the lowest altitude in an aircraft profile that 
# exceeds a specified increase in potential temperature from a base value.
# Generally this theta-increase (pt_delta) ranges from 1.0-2.5 K. The pt_delta,
# list of airports to process, and sounding are specified in the configuration
# script.
# 

##############################################################################
# Version Added
# -------------
#
# METplus version 6.0

##############################################################################
# Datasets
# --------
#
# **Forecast:** NOAA High Resolution Rapid Refresh (HRRR)
#
# **Observation:** AMDAR hourly 1-d netcdf files
#
# **Climatology:** None
#
# **Location:** All of the input data required for this use case can be 
# found in a sample data tarball. Each use case category will have 
# one or more sample data tarballs. It is only necessary to download 
# the tarball with the use case’s dataset and not the entire collection 
# of sample data. Click here to access 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 :ref:`running-metplus` section for more information.

##############################################################################
# METplus Components
# ------------------
# 
# This use case utilizes GenVxMask and the METplus PointStat tool to compare PBLH 
# from AMDAR data to model output. The python embedding script "calc_amdar_pblh.py" 
# computes PBLH and sends data MET via python embedding. The configuration file also filters 
# output through static geographic masks generated by GenVxMask.
 
##############################################################################
# METplus Workflow
# ----------------
#
# **Beginning time (INIT_BEG):** 2022070108
#
# **End time (INIT_END):** 2022070108
#
# **Increment between beginning and end times (INIT_INCREMENT):** 1H
#
# **Sequence of forecast leads to process (LEAD_SEQ):** 12
#
# GenVxMask and PointStat are called in this example. The following run times are processed:
#
# | **Valid:** 2022-07-01_20Z
# | **Forecast lead:** 12 hour
#
# GenVxMask input file is a two-row text file (met_mask_AIRPORT.txt): row 1: AIRPORT row 2: lat lon
# GenVxMask output file is a netcdf file w/ geographic radius part of the file name (met_mask_AIRPORT_100km.nc)
# Input file provided in this example: (met_mask_DENVER.txt): row 1: DENVER  row2: 39.856 -104.6764
#
# PointStat is run with Python embedding (calc_amdar_pblh.py).

##############################################################################
# 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. parm/use_cases/model_applications/pbl/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed.conf
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/use_cases/model_applications/pbl/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed.conf

##############################################################################
# MET Configuration
# -----------------
#
# METplus sets environment variables based on user settings in the METplus configuration file. 
# See :ref:`How METplus controls MET config file settings<metplus-control-met>` 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:
# :ref:`Overriding Unsupported MET config file settings<met-config-overrides>`
#
# .. dropdown:: PointStatConfig_wrapped
#
#   .. literalinclude:: ../../../../parm/met_config/PointStatConfig_wrapped

##############################################################################
# Python Embedding
# ----------------
#
# This use case uses a Python embedding script to read input data.
#
# .. dropdown:: parm/use_cases/model_applications/pbl/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed/calc_amdar_pblh.py
#
#   .. highlight:: python
#   .. literalinclude:: ../../../../parm/use_cases/model_applications/pbl/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed/calc_amdar_pblh.py
#
# For more information on the basic requirements to utilize Python Embedding in METplus, 
# please refer to the MET User’s Guide section on
# `Python embedding <https://met.readthedocs.io/en/latest/Users_Guide/appendixF.html#appendix-f-python-embedding>`_.

##############################################################################
# User Scripting
# --------------
#
# User Scripting is not used in this use case.

##############################################################################
# Running METplus
# ---------------
#
# Pass the use case configuration file to the run_metplus.py script along 
# with any user-specific system configuration files if desired::
#
#   run_metplus.py /path/to/PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed.conf /path/to/user_system.conf
#
# See :ref:`running-metplus` for more information.

##############################################################################
# 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 this use case will be found in point_stat_pblh  (relative to **OUTPUT_BASE**)
# with subdirectories for valid time (YYYYMMDD) and will contain .stat files with the following naming convention:
#
# convention: point_stat_{AIRPORT}_{SOUNDING_FLAG}_{PT_DELTA}_{LEADTIME}L_{VALIDTIME}.stat
#    example: point_stat_DENVER_ALL_1.25_120000L_20220701_200000V.stat

##############################################################################
# Keywords
# --------
#
# .. note::
#
#   * GenVxMaskToolUseCase 
#   * PointStatToolUseCase 
#   * PythonEmbeddingFileUseCase 
#   * PBLAppUseCase
#
#   Navigate to the :ref:`quick-search` page to discover other similar use cases.
#

# sphinx_gallery_thumbnail_path = '_static/pbl-PointStat_fcstHRRR_obsAMDAR_PBLH_PyEmbed.png'
