# Presentation: 218808

## Smart Tools and Procedures

- Tracy Hansen

- Sept. 24-27, 2002

## Overview

- Part 1
- What are Smart Tools?
- Executing Smart Tools
- Creating Smart Tools
- Part 2
- Creating Smart Tools (cont)
- SmartScript Library Methods
- Part 3
- Procedures
- Utilities

- Smart Tools and Procedures

- Sept. 24-27, 2002

## What are Smart Tools?

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Executing Smart Tools

- Make Weather Element Editable
- Set up Selection Time Range
- Set up Edit Area
- Execute Tool from Edit Action Dialog or Spatial Editor MB3 Popup Menu

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools

- From Edit Action Dialog MB3 Popup:
- Info...
- Cut, Copy, Paste
- Modify... or View...
- New...
- Rename...
- Delete...

- Smart Tools and Procedures

- Sept. 24-27, 2002

- ToolType = "numeric"
- from Numeric import *

- Creating Smart Tools

- WeatherElementEdited = "T"

- import SmartScript
- class Tool (SmartScript.SmartScript):
-      def __init__(self, dbss):
-           SmartScript.SmartScript__init__(self,dbss)

- def execute(self, T):

- T = T + 5
- return T

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools  Tool Arguments

- Weather Elements
-  T, Wx, variableElement, MaxT_SFC_BOU_Eta
- Topography
- Topo
- MaxGrid, MinGrid, SumGrid
- T_MaxGrid, Td_SumGrid
- GridTimeRange
- GridInfo,  GridHistory
- Wx_GridInfo, T_GridHistory

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools Conditionals

-   WeatherElementEdited = "HeatIndex"
-   def execute(self, HeatIndex, T):
-        HeatIndex = where(less(T,70), T,
-                                        where(less(T,85), HeatIndex + 10,
-                                        HeatIndex))
-        return HeatIndex

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart ToolsVariable Lists

- Allow for run-time user input

- VariableList = [
-            ("Edit Coverage or Uncertainty" , "Coverage", "radio",
-                     ["Coverage","Uncertainty"]),
-             ("Thunder Y/N" , "Y", "radio", ["Y","N"]),
-         ]

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools Variable Lists

- numeric, alphaNumeric
- radio, check
- scale
- model, D2D_model
- label

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart ToolsVariable Lists

- varDict argument to access user input

- def execute(self, varDict):

- coverageOrUncertainty = varDict["Edit Coverage or Uncertainty"]

- thunder = varDict["Thunder Y/N"]

- if coverageOrUncertainty == "Coverage":
-                 # assign coverage terms
-         else:
-                 # assign uncertainty terms
-         if thunder == "Y":
-                 # assign thunder

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryGrid Access

**getGrids**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryModel

- # Fcst or Official
- self.getGrids(“Fcst”, “T”, “SFC”, GridTimeRange)

- self.getGrids(“BOU__Eta_Oct0112”, “T”, “SFC”,
-                       GridTimeRange)

- self.getGrids(“BOU__Eta”, “T”, “SFC”, GridTimeRange)

- self.getGrids(“BOU_D2D_ETA”, “t”, “MB750”,
-                        GridTimeRange)

- # siteID_type_model_modeltime

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryModel

- # Using Site ID for portability

- def execute(self, GridTimeRange, varDict):
-      siteID = self.getSiteID()

-     model = self.siteID + “__Eta”

- self.getGrids(model, “T”, “SFC”,GridTimeRange)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryModel

- # Using VariableList
- VariableList = [("Model:", "", "D2D_model")]

- def execute(self, GridTimeRange, varDict):
-      D2Dmodel = varDict["Model:"]

-     self.getGrids(D2Dmodel, “T”, “SFC”,GridTimeRange)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library Numeric Soundings

- Geopotential height Cube:
-                  gh_c

- Temperature Cube:
-         t_c

- Pressure
- Levels

- MB700
- MB750
- MB800
- MB850
- MB900
- MB950

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryNumeric Sounding

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library Numeric Soundings

- VariableList = [("Model:", "", "D2D_model")]

- def execute(self, GridTimeRange, Topo, varDict):

- D2Dmodel = varDict["Model:"]
- levels = ["MB900", "MB850", "MB800", "MB750",
-                      "MB700", "MB650", "MB600", "MB550”]

- gh_c, t_c = self.makeNumericSounding(
- 		 D2Dmodel, "t", levels, GridTimeRange)

- if gh_c is None:
-          self.noData()

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library  Numeric Soundings

- def execute(self, GridTimeRange, Topo, varDict):
-       ....

- Topo_M = self.convertFtToM(Topo)

- T = self._empty - 200

- for i in xrange(gh_c.shape[0]):            # Go up the atmosphere

- notSet = equal(T, -200)

- aboveGround = greater(gh_c, Topo_M)

- readyToSet = logical_and(notSet, aboveGround)

- T = where(readyToSet, t_c[i], T)

- return self.convertKtoF(T)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryConversion Methods

- convertMsecToKts
- convertKtoF,  KtoF
- convertFtoK,  FtoK
- convertFtToM
- UVtoMagDir and MagDirToUV

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Trouble-shooting Ideas

- Run from terminal window to see Python error messages.
- Use "print" statements.

- print  "Made it to this point."
- print "myVariable=",  myVariable
- print "value at 25, 25 is", T[25][25]

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Tool Repository (STR)http://isl715.nws.noaa.gov/STR/index.php3

-  Provides an easy to use interface between developers of STs and the users. Promotes sharing of STs so that others can benefit from work done and not duplicate work.
-  Register tools when downloaded to received bug notification, version updates, and comments on the ST.

-  Users can also submit bugs and comments to the developer.
-  Upload a newly developed tool along with documentation and an installation guide.  You can even post a ST idea that is in development without submitting the actual code.

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Tool Repository (STR)Downloading and Adding a Tool

- Use the “Site Interface” and choose your region and WFO ID
- Choose “Info on Tools” and go to the ST you wish to download

- Right click on the “Download Software” and use “Save Link as”.  Do the same for the Documentation and Install files if available.
- Move the ST to a location where GFE is running and open the ST with an editor such as vi or nedit.

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Tool Repository (STR)Downloading and Adding a Tool (cont.)

- 5) Make the downloaded ST part of the GFE
- Use the new ifpServerText program to save the “flat file” into the GFESuite ifpServer. The program takes care of the metadata file needed.
- _6) Use the STR to register this tool to receive e-mail notices of bugs and updates._

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Tool Repository (STR)Downloading and Adding a Tool (cont.)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Executing Smart Tools Exercise

- Convective Scenario
- Winter Scenario

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart ToolsExercises

- Tool-1
- Tool-2
- Tool-3
- SmartScript-1 : Accessing Grids Directly
- SmartScript-2 : Accessing Variable Grids Directly
- SmartScript-3 : Making and Accessing Soundings
- SmartScript-4 : Making and Accessing Soundings

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library Numeric Soundings

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryInterpolateValues

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryInterpolateValues

- SmartScript LibraryInterpolateValues

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryExtrapolate

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Vector Weather Elements

- WeatherElementEdited = "Wind"
- import SmartScript
- class Tool (SmartScript.SmartScript):
-      def __init__(self, dbss):
-           SmartScript.SmartScript__init__(self,dbss)
-     def execute(self, Wind):
-           mag = Wind[0]
-           dir = Wind[1]
-           mag = mag + 5
-           return (mag, dir)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Working with Weather

- Numeric Weather is a 2-tuple:

- wxValues -- Numeric Grid of bytes

- keys -- list of "ugly strings" where the the index of the ugly string
-               corresponds to the byte value in the wxValues grid.

- Keys = ["Sct:RW:-:<NoVis>:",
-               "Chc:T:-:<NoVis>:",
-               "Chc:SW:-:<NoVis>:"
-              ]

- Then the wxValues grid is 0 where "Sct:RW:-:<NoVis>:"
-                                            1 where "Chc:T:-:<NoVis>:"
-                                            2 where "Chc:SW:-:<NoVis>:"

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Working with Weather

- Assigning Weather values:
- getIndex -- given a list of keys, returns the
-                     associated index

- byteValue = self.getIndex("SChc:RW:-:<NoVis>:",keys)

- byteValue = self.getIndex("Chc:RW:-:<NoVis>:",keys)

- # Special case for "NoWx"
- byteValue = self.getIndex("",keys)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Working with Weather

- def execute(self, PoP, Wx):
-     wxValues, keys = Wx

- #See examples/smartTools/Convective_SmartTool.py
- #  Creating Wx from PoP

- wxValues = \
-         where(less(PoP, 10), self.getIndex("",keys),

- where(less(PoP,20) ,
-       self.getIndex("SChc:RW:-:<NoVis>:",keys),

- self.getIndex("Chc:RW:-:<NoVis>:",keys)))

- return (wxValues, keys)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Working with Weather

- Querying Weather values:
- wxMask -- given a Wx tuple and a string expression,
-                     return 1 if there is a match

- found = self.wxMask(Wx, "Iso:")

- found = self.wxMask(Wx, ":R:")

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Working with Weather

- # See examples/smartTools/PoP_From_Wx.py
- #   Creating PoP from Wx

- def execute(self, PoP,Wx):
-           PoP = where(self.wxMask(Wx, "Iso:"), 10, PoP)
-           PoP = where(self.wxMask(Wx, "Sct:"), 20, PoP)
-           return PoP

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryEdit Area Methods

- editArea = self.getEditArea(“Boulder”)

- areaMask = self.encodeEditArea(editArea)

- T = where(areaMask, T+10, T)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Script LibraryMissing Data Mode

- Set from GFE-->Editing Modes Menu
- When there is missing data:
-     Stop -- stop execution
-     Skip -- Skips the grid and reports it
-     Create -- If possible, creates a grid via interpolation.  If in the Fcst database, the new  grid can be saved.

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library"On-the-Fly" Elements

- "On-the-fly" Elements
- ISC Discrepancies
- Creating temporary weather elements

- self.createGrid(model, element, elementType,
-                          numericGrid, timeRange)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library"On-the-Fly" Elements

- self.createGrid("Diff", "T_Diff", "Scalar",
-                          myGrid, GridTimeRange)

- WeatherElementEdited = “None”

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryISC Data

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibrarySaving Objects

- self.saveObject(objectName, object, category

- self.saveObject(“MyGrid”, numericGrid,
-                           “DiscrepancyValueGrids”)

- myGrid = self.getObject(“MyGrid”,
-                          “DiscrepancyValueGrids”)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart Script LibraryError Handling

- abort -- abort with user-supplied error message
- noData -- abort with a No Data error
- cancel -- abort with no error message
- statusBarMsg -- sends message to the Status Bar

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Smart ToolsScreenList

- ScreenList = ["SCALAR","VECTOR"]
- ScreenList = ["Td","T","MaxT","MinT"]

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools Reserved Methods

- execute
- preProcessTool, postProcessTool
- Actions that need to be done once per tool

- class Tool (SmartScript.SmartScript):
-    def __init__(self, dbss):
-         SmartScript.SmartScript.__init__(self, dbss)
-    def preProcessTool(self, varDict):
-        self._thunder = varDict["Thunder Y/N"]
-    def execute(self, Wx):
-        if self._thunder == "Y":
-            # assign thunder

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Creating Smart Tools Creating Your Own Methods

- Name preceeded by underscore
- "self" used in call and in "def" argument list

- Class Tool (SmartScript.SmartScript):
-    def __init__(self, dbss):
-         SmartScript.SmartScript.__init__(self, dbss)
-    def execute(self, QPF, T):
-         SnowRatio = self._getSnowRatio(T)
-         SnowAmt = QPF * SnowRatio
-         return SnowAmt
-     def _getSnowRatio(self, T):
-          return where( less(T, 20), 18,
-                                 where( less(T, 21), 14, 10)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryComing Soon

- A library of meteorological functions
- Gradient
- Curl
- Dot product
- Cross product
- Advection
- Others

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryExercises

- SmartScript-5 : Making and Accessing Soundings
- SmartScript-6 : Creating Elements "On-the-Fly"
- SmartScript-7 : Working with Weather
- SmartScript-8 : Working with Weather

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Procedures

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

- copyCmd
- createFromScratchCmd
- assignValueCmd
- zeroCmd
- interpolateCmd
- timeShiftCmd
- splitCmd, fragmentCmd, deleteCmd

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**copyCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryTime Ranges

- # Active timeRange in GFE:
- def execute(self, editArea, timeRange)

- # Get Selection Time Range
- todayRange = self.getTimeRange(“Today”)

- # Create Time Range with startHour, endHour
- todayRange = self.createTimeRange(6, 18, “LT”)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryDatabases

- # Find database -- databaseName, version

-  databaseID

- databaseID = self.findDatabase(“Eta”, 0)

- databaseID = self.findDatabase(“D2D_ETA”, -1)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryDatabases

- # Get database -- result of VariableList

-  databaseID

- VariableList = [("Model:", "", "D2D_model")]

- def execute(self, varDict):
-      D2Dmodel = varDict["Model:"]

- databaseID = self.getDatabase(D2Dmodel)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**createFromScratchCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**assignValueCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**zeroCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**interpolateCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**interpolateCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**timeShiftCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**splitCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**fr****	****agmentCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**deleteCmd**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

- model = varDict["Model"]
- databaseID = self.getDatabase(model)
- timeRange_0_60 = self.createTimeRange(
-                         0, 60, "DatabaseID", databaseID)

- SmartScript LibraryProcedure Commands

- # Copy from model
- elements = [“T”, “Wind”, “Wx”]
- self.copyCmd(elements, databaseID, timeRange_0_60)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

- # Find most recent Eta model
- databaseID = self.findDatabase("Eta", version=0)

- SmartScript LibraryProcedure Commands

- # Copy grids
- self.copyCmd(
-          [ "T", "Td", "Wind"], databaseID, timeRange_0_60)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

**callSmartTool**

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

- self.createFromScratchCmd(
-           "MixHgt", timeRange_0_60, repeat=6, duration=1)

- SmartScript LibraryProcedure Commands

- # Get edit area
- toolEditArea = self.getEditArea("Boulder")

- # Call Smart Tool
- self.callSmartTool("MixHgt_Init", "MixHgt",
-                                 toolEditArea, timeRange_0_60)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## ProcedurescallSmartTool and VariableLists

- Smart Tool, "MyTool":
- VariableList = [("Threshold", 10, "numeric") ]

- def execute(self, varDict):
-          threshold = varDict["Threshold"]

- Smart Tools and Procedures

- Sept. 24-27, 2002

## ProcedurescallSmartTool and VariableLists

- Procedure:
- VariableList = [
-               ("Model", "", "model"),
-               ("Threshold", 10, "numeric") ]

-     def execute(self, varDict):
-          # This call will pass varDict which has variables for
-          # both the Procedure and the Smart Tool
-          self.callSmartTool(
-                "MyTool", "T", editArea, timeRange, varDict)

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProcedure Commands

- getGridCellSwath
- saveEditArea
- setActiveElement
- cacheElements, uncacheElements

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript Library

- Procedure
-  commands

- Smart Tool
- commands

- getEditArea

- makeNumericSounding

- getGrids

- getGrids

- createFromScratch

- extrapolate

- interpolateCmd

- callSmartTool

- createTimeRange

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Background Procedures 

- runProcedure command

- -n   procedure name

- ./runProcedure

- -u   userID

- -c   config file

- [-a   edit area name]

- [-t    time range]

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Background Procedures 

- ./runProcedure    -n Proc1   -u ifpUser  -c gfeConfig
-                             -a CO_Boulder    -t Tonight

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Utilities

- Allows for sharing of common methods among Smart Tools and Procedures

- Smart Tools and Procedures

- Sept. 24-27, 2002

## SmartScript LibraryProgress Dialog

- import MyDialog
- def execute(self, editArea, timeRange)

- # Display dialog
- dialog = MyDialog.MyDialog(
-         None, “Status”, “   Loading Grids”)

- # Do stuff

- # Close dialog
- dialog.top().destroy()

- Smart Tools and Procedures

- Sept. 24-27, 2002

## Procedures and UtilitiesExercises

- Procedure-1
- Procedure-2
- Procedure-3
- Utility-1

- Smart Tools and Procedures

- Sept. 24-27, 2002