4.2.3 Doing More with Jython
(Courtesy of Dr. William Fingerhut, Lyndon State College, VT. For full details, see http://apollo.lsc.vsc.edu/~fingerhutb/UserWshop2004/W2004_IDV_LabF.html

A vertical cross section of temperature does not show as much structure as possible because the vertical temperature gradient is much larger than the horizontal temperature gradient. One way to solve this problem is to subtract the U. S. Standard Atmosphere from the temperature field, and create a vertical cross section of temperature anomaly.

This exercise will show how Jython can be used in the IDV for complex calculations like this.

1. Load in the `Sample RUC Data` data source.
2. Create a `Contour Vertical Cross Section` of the `3D grid->temperature` field
3. Move the cross section line in the main display to a North/South orientation by dragging the endpoints.
4. View the Jython procedure for calculating temperature anomaly
• Bring up the Jython library editor with the menu item.
• Click on the `..workshop/default.py` tab which is the Jython library loaded from the plugin. You should see:
```def tempAnom(t):
""" temperature anomaly from U.S. Standard Atmosphere """
# get pressure levels of temperature grids
p=extractPressureFromNWPGrid(t)
# calculate temperature for a constant lapse rate (6.5 C/km) atmosphere
tstd=288.15*(p/1013.25)**(287.05*.0065/9.806)
# change temperature in stratosphere to isothermal (216.65 K)
for i in range(len(p)):
if p[i] < 225.0:
tstd[i]=216.65
# change the units to K
tstd = newUnit(tstd,"tstd","K")
# calculate the temperature anomaly
tanom=t-tstd
return tanom
```

If it is not there, paste this formula into your locally editable library and click the `Save` button.

5. Create a Formula to call the tempAnom procedure
• In the Formula Editor enter the following information:
• `Name:` anomaly of temperature
• `Formula:` tempAnom(temperature)
• `Group:` Workshop
• Click the `Add Formula` button.
6. Create the Display
• Select the `Formulas` data source in the `Field Selector`.
• Choose the `anomaly of temperature` formula under the Workshop tab in the `Fields` panel.
• In the `Displays` pane select `Contour Vertical Cross Section`
• Click the `Create Display` button
• When prompted for a temperature field, select it from the sample RUC data and click the `OK` button
7. Share the cross section locations
• In the menu of each display control, check the item.
• Position the control windows and the main display so you can view all three at once.
• Move the north/south line for the temperature cross section slightly to align the two transects.
• Compare the two displays. A vertical cross section of temperature anomaly can discern:
• the vertical level of temperature anomalies,
• the horizontal location of large horizontal temperature gradients, and
• the anomaly reversal across the tropopause.
8. Try this exercise with real-time model data.