Graphics

Graphics

This tutorial uses Python to visualize the post-processed model output. If users are familiar with Python, they may modify existing examples and/or create new plot types. As a note, while this tutorial supports plotting post-processed model output after running UPP, Python is also able to directly plot the NetCDF output from WRF (with numerous examples available online). Two customization options are provided below -- one for modifying the provided Python scripts and one for adding a new output variable to plot.

Modifying the provided Python script(s)

Users may modify existing script(s) by navigating to the /scripts/common directory and modifying the existing ALL_plot_allvars.py script (or the individual Python scripts). There are innumerable permutations for modifying the graphics scripts, based on user preferences, so one example will be chosen to show the workflow for modifying the plots. In this example, we will modify the ALL_plot_allvars.py script to change the contour levels used for plotting sea-level pressure.

Since the Hurricane Sandy case exceeds the current minimum value in the specified range, we will add 4 new contour levels. First, navigate to the Python plotting scripts directory:

cd ${PROJ_DIR}/container-dtc-nwp/components/scripts/common/python
vi ALL_plot_allvars.py

Edit the ALL_plot_allvars.py script to make the desired changes to the contour levels. For this example, we will be modifying line 466 from:

clevs = [976,980,984,988,992,996,1000,1004,1008,1012,1016,1020,1024,1028,1032,1036,1040,1044,1048,1052]

To extend the plotted values starting from 960 hPa:

clevs = [960,964,968,972,976,980,984,988,992,996,1000,1004,1008,1012,1016,1020,1024,1028,1032,1036,1040,1044,1048,1052]

After the new contour levels have been added, the plots can be generated using the same run command that is used for the supplied cases. Since we are interested in the impacts on the Hurricane Sandy plots, we will use the following run command:

docker run --rm -it -e LOCAL_USER_ID=`id -u $USER` \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/common:/home/scripts/common \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/sandy_20121027:/home/scripts/case \
-v ${PROJ_DIR}/data/shapefiles:/home/data/shapefiles \
-v ${CASE_DIR}/postprd:/home/postprd -v ${CASE_DIR}/pythonprd:/home/pythonprd \
--name run-sandy-python dtcenter/python:${PROJ_VERSION} /home/scripts/common/run_python.ksh
Note: The Python-based scripts are under the /scripts/common directory, which means changes to the Python scripts will be applied to all cases that are run (i.e., not case specific).

Adding a new plot type

In addition to modifying the ALL_plot_allvars.py for the current supported variables, users may want to add new variables to plot. The Python scripts use the pygrib module to read GRIB2 files. In order to determine what variables are available in the post-processed files and their names as used by pygrib, a simple script, read_grib.py, under the /scripts/common directory, is provided to print the variable names from the post-processed files. For this example, we will plot a new variable, wind at 850 hPa. This will require us to run the read_grib.py script to determine the required variable name. In order to run read_grib.py, we are assuming the user does not have access to Python and the necessary modules, so we will use the Python container. To enter the container, execute the following command:

docker run --rm -it -e LOCAL_USER_ID=`id -u $USER` \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/common:/home/scripts/common \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/sandy_20121027:/home/scripts/case \
-v ${PROJ_DIR}/data/shapefiles:/home/data/shapefiles \
-v ${CASE_DIR}/postprd:/home/postprd -v ${CASE_DIR}/pythonprd:/home/pythonprd \
--name run-sandy-python dtcenter/python:${PROJ_VERSION} /bin/bash

Once "in" the container, navigate to the location of the read_grib.py script and open the script:

cd /home/scripts/common
vi read_grib.py

This script reads a GRIB2 file output from UPP, so this step does require that the UPP step has already been run. To execute the script:

python read_grib.py

For the standard output from the Hurricane Sandy case, here is the output from executing the script:

['Pressure reduced to MSL', 'Pressure', 'Total Cloud Cover', 'Derived radar reflectivity', 'Geopotential Height', 'Temperature', 'Potential temperature', 'Relative humidity', 'Dew point temperature', 'Specific humidity', 'U component of wind', 'V component of wind', 'Vertical velocity', 'Maximum/Composite radar reflectivity', 'Visibility', 'Cloud Ice', 'Absolute vorticity', 'MSLP (Eta model reduction)', 'unknown', 'Surface pressure', 'Orography', 'Soil Temperature', 'Volumetric soil moisture content', 'Liquid volumetric soil moisture (non-frozen)', 'Moisture availability', 'Soil Moisture', 'Water equivalent of accumulated snow depth (deprecated)', 'Snow cover', '2 metre temperature', '2 metre specific humidity', '2 metre dewpoint temperature', '2 metre relative humidity', '10 metre U wind component', '10 metre V wind component', 'Total Precipitation', 'Categorical snow', 'Categorical ice pellets', 'Categorical freezing rain', 'Categorical rain', 'Vegetation', 'Surface lifted index', 'Convective available potential energy', 'Convective inhibition', 'Precipitable water', 'Low cloud cover', 'Medium cloud cover', 'High cloud cover', 'Storm relative helicity', 'U-component storm motion', 'V-component storm motion', 'Best (4-layer) lifted index', 'Pressure of level from which parcel was lifted', 'Latitude (-90 to +90)', 'East Longitude (0 - 360)', 'Land-sea mask']

After perusing the output, you can see that the precipitable water variable is called 'Precipitable water.' To add the new variable to the ALL_plot_allvars.py script, it is easiest to open the script and copy the code for plotting a pre-existing variable (e.g., composite reflectivity) and modify the code for precipitable water:

vi ALL_plot_allvars.py

In the unmodified ALL_plot_allvars.py script, copy lines 367-368 for reading in composite reflectivity, paste right below, and change the variable to be for precipitable water, where 'Precipitable water' is variable name obtained from the output of the read_grib.py

Next, we will add a new code block for plotting precipitable water, based on copying, pasting, and modifying from the composite reflectivity block above it (lines 731-760 in the unmodified code):

Note: This is a simple example of creating a new plot from the UPP output. Python has a multiple of customization options, with changes to colorbars, color maps, etc. For further customization, please refer to online resources.

To generate the new plot type, point to the scripts in the local scripts directory, run the dtcenter/python container to create graphics in docker-space and map the images into the local pythonprd directory:

docker run --rm -it -e LOCAL_USER_ID=`id -u $USER` \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/common:/home/scripts/common \
-v ${PROJ_DIR}/container-dtc-nwp/components/scripts/sandy_20121027:/home/scripts/case \
-v ${PROJ_DIR}/data/shapefiles:/home/data/shapefiles \
-v ${CASE_DIR}/postprd:/home/postprd -v ${CASE_DIR}/pythonprd:/home/pythonprd \
--name run-sandy-python dtcenter/python:${PROJ_VERSION} /home/scripts/common/run_python.ksh

After Python has been run, the plain image output files will appear in the local pythonprd directory.

Here is an example of resulting plot of the precipitable water:

If you have further questions regarding customization, please post them to the Customization Category of DTC NWP Containers GitHub Discussions forum.
jwolff Wed, 03/20/2019 - 19:44