Smart Tools Procedures

Executing Procedures
Exercise Procedure-1 -- Creating a Procedure
Exercise Procedure-2 -- Using the Smart Script Library from a Procedure
Exercise Procedure-3 -- Running Procedures in the Background

Procedures

Once we have a set of Smart Tools, it is natural to want to execute related tools together in succession and to perform other operations such as copying, creating, and interpolating grids. For this, we have Procedures. The following diagram depicts the Procedure architecture within the GFESuite software. It shows Procedures as a sequence of commands which modify the Forecast database. Like Smart Tools, these commands are written in Python, but operate at a higher level through the Smart Script Library to copy the Forecast database from models, interpolate grids, and call Smart Tools. The GFESuite software locates the procedure, sets up information to be passed to it, and invokes it. Procedures can be run from the GFE or in background mode.
 


Using procedures you can:

Executing Procedures

Procedures can be set up to appear under various menu items on the GFE Main Menu. Keep in mind that you can make a procedure that can take several minutes to complete, particularly if it includes a lot of interpolation.
  1. Try executing the QPF_SnowAmt Procedure which appears under Main Menu --> Edit and runs the QPF_SmartTool followed by the SnowAmt_SmartTool.
NOTE: Procedures can be run in background mode from the command line. For instructions, see the runProcedure documentation and Exercise Procedure-3 below.

Exercise Procedure-1 -- Creating a Procedure

For the following exercise, choose two or more tools from the Smart Tool list you would like to run in sequence. One possibility would be to run the Assign_Value tool followed by the Smooth tool.
  1. Choose Main Menu-->GFE-->Define Procedures. From the MB3 Pop-up on the Procedures folder, choose New....
  2. Enter a Name for your Procedure.
  3. Select OK. A Python Editor window will appear with the Procedure template.
  4. The MenuItems list defines the GFE menu item(s) under which the Procedure is to appear. Possible items are: Populate, Edit, Consistency, Verify, and Hazards. Set up the MenuItems list, perhaps listing "Edit" as the item under which you want your procedure to appear.
  5. Make sure the Tools you want to run in your procedure (if any) appear in the proper order in the Tool List. Specify the weather element to be modified by the tool. If you want the tool to modify the active element, whatever it may be, enter "variableElement" for the element name. This is likely to be your choice for tools like Assign_Value or Smooth.
  6. Save the Python file and run your Procedure.
Note: If any of the tools in your procedure need user-supplied variables, the system will automatically ask the user for them when your procedure is run. Procedures can be simple or extremely powerful because of the availability of the Smart Script Class library. (See the section describing this library)

Answer to Procedure Exercise 1

Exercise Procedure-2 -- Using the SmartScript Library from a Procedure

The Smart Script library contains methods for "procedure-type" commands which allow you to copy data from models, create grids from scratch and perform interpolation, as well as methods for calling Smart Tools. In this exercise, we'll create a Procedure to call some of these commands.
  • Study the SmartScript Libary commands: copyCmd, createFromScratchCmd, getDatabase, and createTimeRange.
  • Study the SmartScript Library section on "Calling Smart Tools and Procedures."
  • From the Define Procedures Dialog Procedures Window, select MB3-->New.
  • Name your Procedure and select OK.
  • Include a VariableList with a "model" field for the user to select an IFP input model.
  • Use the SmartScript Library commands: getDatabase, createTimeRange, copyCmd, createFromScratchCmd, and callSmartTool to:
    • Create a databaseID for the chosen model,
    • Create a time range based on the model (perhaps the first 12 hours),
    • Copy the grids from the model for the new time range,
    • Create 1-hour T grids every 3 hours over the new time range,
    • Run the Smart Tool from Exercise SmartScript-4 over the new time range, interpolating for missing data by setting the Missing Data Mode. Pass the varDict from the Procedure to the Smart Tool in the "callSmartTool" command so that the VariableList dialog does not appear twice. For this to work, make sure that the VariableList model field has the same name as that in the Smart Tool.
  • Run and test your Procedure to make sure it works. Note that the Procedure could take some time to execute since the Smart Tool is being called over a time range of grids. You can notice the progress of execution in the progress bar at the bottom right of the display. Also, if you are running the GFE from a terminal window with a -console argument, you will see status messages appear in the window.
  • Answer to Procedure Exercise 2

    Exercise Procedure-3 -- Running Procedures in the Background

    Procedures which are routine or take time to execute can be run in background mode. This exercise will show you how to do this.
  • Study the documentation and example for the runProcedure command.
  • Run your the procedure of Exercise Procedure-1 from the command line using the "runProcedure" command. Note you will need to specify an edit area and a time range. Also, since you will be running the Procedure outside the context of the GFE, you will have to reference specific weather elements instead of "variableElement" in your ToolList.
  • Answer to Procedure Exercise 3