Previous: Diagnostic Functions: Formulas and Jython Next: Jython Methods Table of contents Frames User guide
Unidata IDV Workshop for version 6.3 > Advanced Topics > Diagnostic Functions: Formulas and Jython

4.2.0 Basics of IDV Formulas

Formulas in the IDV are one-line mathematical expressions to derive new values from data available.

The IDV comes with some Formulas. Here is an example of using one.

  1. Using an IDV System Formula
    • Load in the ETA 1998-06-29 00:00 data source. Show popup
    • Load in the ETA 1998-06-29 12:00 data source, so we have two output times from the Eta model, 12 hours apart.
    • In the Field Selector, select Formulas in the Data Sources panel. Click on the Miscellaneous tag in the Fields panel
    • Right-click on Simple difference a-b, then click on Edit Formula in the popup menu. The Formula Editor appears. (For more see Formula Editor).
    • Click Cancel in the Formula Editor.
  2. Requesting the Formula to be Computed and Displayed
    • In the Displays panel expand the Plan Views tab and click on Contour Plan View, then click on Create Display.
    • A Field Selector window appears that allows you to select which actual parameters from a data source or sources you want to use for each variable in the formula. You can select parameters from more than one data source for use in this single formula.
    • In the Field Selector window:
      For the "a" operand choose:
      Eta 1998-06-29 12:00 -> 2D Grid -> mean sea level pressure (Eta model reduction)

      For the "b" operand choose:
      Eta 1998-06-29 00:00 -> 2D Grid -> mean sea level pressure (Eta model reduction)

    • Click on OK.
    • Grids of twelve hour MSL pressure difference values are computed using the formula, and the result shown in the main view window.
    • Look at the contours and see if the values are reasonable. (What are the units?).

    You can make your own formulas. Your formulas are saved so you can build a library of your own derived quantities, using data you have.

  3. Creating a new formula for wind speed from u and v wind components
    • Remove all displays.
    • From the main menu, click on Edit->Formulas->Create Formula. The Formula Editor window appears.
    • Enter the Name windspeed (one word - no space).
    • Enter the mathematical formula definition in the Formula entry field. The formula is
        sqrt(u**2 + v**2)
    • Open the Advanced panel.
    • Enter the Description wind speed from u and v.
    • For Group enter Workshop.
    • In the Displays section, click the Use selected radio button, then click the All off button.
    • Expand the Plan Views category and check the Contour Plan View option. Also, expand the 3D Surface category and check the Isosurface option.
    • Click on Add Formula.
    • A new item wind speed from u and v should appear in the Field Selector window's Fields panel, under Workshop.
  4. Sub-setting times in the data source
    • To save computation time, set the 12:00 Z Eta data source to use the first three times, with the Field Selector window. (see Selecting Times).
  5. Requesting the new Formula to be Computed and Displayed
    • Click the wind speed from u and v item in the Fields panel under the Workshop group.
    • In the Displays panel click on Contour Plan View, then click on Create Display.
    • In the Field Selector window:
      For the "u" operand choose:
      Eta 1998-06-29 12:00 -> 3D Grid -> u component of wind

      For the "v" operand choose:
      Eta 1998-06-29 12:00 -> 3D Grid -> v component of wind

    • Click on OK.
    • Grids of wind speed are computed using the formula, and the display is made. All three data times selected for the data source are used.
    • Look at the contours and see if the speed values are reasonable. Go on to the next step to examine the wind speed in more detail.
  6. Compare to the IDV's derived wind speed
    • Use the Levels selector to change the wind display level to 250 hPa.
    • From the Eta 1998-06-29 12:00 choose the parameter 3D Grid -> Derived -> Windspeed (from Gridrelative_u and Gridrelative_v)

      Make a Contour Plan View of this wind speed automatically derived by the IDV.

    • Change its level to 250 hPa.
    • Toggle between the two displays to check for differences.
  7. Extra - Calculate a difference between the system derived wind speed and the wind speed from your local formula using the simple difference formula. What would you expect the result to be? Answer Show popup
Notes on formulas

The Description is listed in the Field Selector's Fields panel. If you leave the Description field empty, the name of the formula will be used as the description.

Group is a way of categorizing your formulas and is optional. If the Group does not already exist, it is added when you save the new formula. If the Group already exists, the new formula will appear under that group's tab in the Field Selector's Fields panel. If you leave the Group empty, the formula appears in the list directly.

The variable names in the formula definition, such as dpt, are dummy names, and in principle can be anything, such as "a" or "var2". It is best to use variable names that suggest the parameter data they represent so that later in the parameter selection step you remember what the variables should represent. Use names like Temp500m, RelHum_surf, absvort, sst_jan, or whatever makes sense to you. If you use a variable names like V1 and V2, then later when the formula requests which real parameter name goes with which dummy variable name you may be puzzled.

Once you have defined a formula, it is saved and will appear in future runs of your IDV. It is saved in your personal copy of the derived.xml file, which usually is in the file ~/.unidata/idv/DefaultIdv/derived.xml on UNIX systems.

Holding the mouse pointer stationary over the formula name in the Field Selector's Fields panel will cause a tooltip box to appear showing the formula name and the mathematical formula.

Formulas are preserved by the IDV. Next time you start the IDV you will see formulas you created before. You can build up a library of your own formulas.

To remove a formula, click on Remove formula in the Field Selector's formula pull down menu. This does not remove a display of calculations made with a formula, it removes the formula itself from the Field Selector window. Usually you leave formulas in place until you are sure you will not use them again.

 


Previous: Diagnostic Functions: Formulas and Jython Next: Jython Methods Table of contents Frames User guide
Unidata IDV Workshop for version 6.3 > Advanced Topics > Diagnostic Functions: Formulas and Jython