{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# UserScript: Calculate the Difficulty Index\n\nmodel_applications/medium_range/\nUserScript_fcstGEFS\n_Difficulty_Index.conf\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Scientific Objective\n\nThis use case calls the UserScript wrapper to run a user provided script that calculates \nthe difficulty index for windspeed. This use case allows for the user to change a variety \nof variables needed to run the difficulty index (i.e. threshold start and units) so that\nuser can run the script at different thresholds without needing to alter the code. This \nscript run by the use case uses METcalcpy to provide the difficulty index calculation and\nMETplotpy to provide the plotting capability. \n\nThe difficulty index was developed by the Naval Research Lab (NRL). The overall aim of the\ndifficulty index is to graphically represent the expected difficulty of a decision based on \na set of forecasts (ensemble) of, e.g., significant wave height as a function of space and \ntime. There are two basic factors that can make a decision difficult. The first factor is the \nproximity of the ensemble mean forecast to a decision threshold, e.g. 12 ft seas. If the \nensemble mean is either much lower or much higher than the threshold, the decision is easier; \nif it is closer to the threshold, the decision is harder. The second factor is the forecast \nprecision, or ensemble spread. The greater the spread around the ensemble mean, the more likely \nit is that there will be ensemble members both above and below the decision threshold, making \nthe decision harder. (A third factor that we will not address here is undiagnosed systematic \nerror, which adds uncertainty in a similar way to ensemble spread.) The challenge is combining \nthese factors into a continuous function that allows the user to assess relative risk. \n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Datasets\n\nThis use case calculates the difficulty index for windspeed using NCEP \nGEFS ensemble data. The data is composed of 30 ensemble members that \nhave been compiled and compressed into one .npz file. \n\n - Variables required to calculate the difficulty index:\n   Levels required: 10-m\n   #. v- component of wind\n   #. u- component of wind\n   #. Windspeed\n   #. Latitude\n   #. Longitude\n - Forecast dataset: NCEP GEFS 30 member Ensemble\n   - Initialization date: 20191208\n   - Initialization hours: 12 UTC\n   - Lead times: 60\n   - Format: Grib2\n   - Resolution: 0.5 degree\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## METplus Components\n\nThis use case runs the UserScript wrapper tool to run a user provided script,\nin this case, wind_difficulty_index.py.\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## METplus Workflow\n\nThis use case loops by process which means that each tool is run for all times before moving to the\nnext tool. The tool order is as follows:\n\nUserScript\n\nThis example loops by initialization time (with begin, end, and increment as specified in the \nMETplus UserScript_fcstGEFS_Difficulty_Index.conf file). \n\n1 initialization time will be run over 1 lead time:\n\n| **Init:** 20201208_12Z\n| **Forecast lead:** 60\n|\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## METplus Configuration\n\nMETplus first loads all of the configuration files found in parm/metplus_config,\nthen it loads any configuration files passed to METplus via the command line\nwith the -c option, i.e. -c parm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index.conf\n\n.. highlight:: bash\n.. literalinclude:: ../../../../parm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index.conf\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## MET Configuration\n\nThere are no MET tools used in this use case.\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python Embedding\n\nThis use case uses a Python embedding script to read input data\n\nparm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index/wind_difficulty_index.py\n\n.. highlight:: python\n.. literalinclude:: ../../../../parm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index/wind_difficulty_index.py\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Running METplus\n\nThis use case can be run two ways:\n\n1) Passing in UserScript_fcstGEFS_Difficulty_Index.conf, \nthen a user-specific system configuration file::\n\n       run_metplus.py \\\n       -c /path/to/METplus/parm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index.conf \\\n       -c /path/to/user_system.conf\n\n2) Modifying the configurations in parm/metplus_config, then passing in UserScript_fcstGEFS_Difficulty_Index.conf::\n\n       run_metplus.py \\\n       -c /path/to/METplus/parm/use_cases/model_applications/medium_range/UserScript_fcstGEFS_Difficulty_Index.conf\n\nThe 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:\n\n* **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\n* **OUTPUT_BASE** - Path where METplus output will be written. This must be in a location where you have write permissions\n* **MET_INSTALL_DIR** - Path to location where MET is installed locally\n\n and for the [exe] section, you will need to define the location of NON-MET executables.\n If the executable is in the user's path, METplus will find it from the name. \n If the executable is not in the path, specify the full path to the executable here (i.e. RM = /bin/rm)  \n The following executables are required for performing series analysis use cases:\n\nExample User Configuration File::\n\n  [dir]\n  INPUT_BASE = /path/to/sample/input/data\n  OUTPUT_BASE = /path/to/output/dir\n  MET_INSTALL_DIR = /path/to/met-X.Y\n\n  [exe]\n  RM = /path/to/rm\n  CUT = /path/to/cut\n  TR = /path/to/tr\n  NCAP2 = /path/to/ncap2\n  CONVERT = /path/to/convert\n  NCDUMP = /path/to/ncdump\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Expected Output\n\nA successful run will output the following both to the screen and to the logfile::\n\n  INFO: METplus has successfully finished running.\n\nRefer to the value set for **OUTPUT_BASE** to find where the output data was generated.\nOutput for this use case will be found in a directory relative to **OUTPUT_BASE**. There\nshould be a list of files that have the following format:\n\nwndspd_GEFS_NorthPac_5dy_30mem_difficulty_indexTHRESH_00_kn.png\n\nWhere THRESH isa number between DIFF_INDEX_SAVE_THRESH_START and \nDIFF_INDEX_SAVE_THRESH_STOP which are defined in UserScript_fcstGEFS_Difficulty_Index.conf.\n\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Keywords\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>* UserScriptUseCase\n  * MediumRangeAppUseCase\n  * NRLOrgUseCase\n\n  Navigate to the `quick-search` page to discover other similar use cases.</p></div>\n\n\n\nsphinx_gallery_thumbnail_path = '_static/medium_range-UserScript_fcstGEFS_Difficulty_Index.png'\n\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}