Title: Other GFESuite Programs
1Smart Tools and Procedures
Tracy Hansen
2Overview
- 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
3What are Smart Tools?
4Executing 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
5Creating Smart Tools
- From Edit Action Dialog MB3 Popup
- Info...
- Cut, Copy, Paste
- Modify... or View...
- New...
- Rename...
- Delete...
6Creating Smart Tools
ToolType "numeric" from Numeric import
WeatherElementEdited "T"
import SmartScript class Tool (SmartScript.SmartSc
ript) def __init__(self, dbss)
SmartScript.SmartScript__init__(self,dbss)
def execute(self, T)
T T 5 return T
7Creating 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
8Creating 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
9Creating Smart ToolsVariable Lists
- Allow for run-time user input
VariableList ("Edit Coverage or
Uncertainty" , "Coverage", "radio",
"Coverage","Uncertainty"),
("Thunder Y/N" , "Y", "radio", "Y","N"),
10Creating Smart Tools Variable Lists
- numeric, alphaNumeric
- radio, check
- scale
- model, D2D_model
- label
11Creating Smart ToolsVariable 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
12SmartScript Library
13SmartScript LibraryGrid Access
14SmartScript LibraryModel
Fcst or Official self.getGrids(Fcst, T,
SFC, GridTimeRange)
siteID_type_model_modeltime
self.getGrids(BOU__Eta_Oct0112, T, SFC,
GridTimeRange)
self.getGrids(BOU__Eta, T, SFC,
GridTimeRange)
self.getGrids(BOU_D2D_ETA, t, MB750,
GridTimeRange)
15SmartScript LibraryModel
Using Site ID for portability
def execute(self, GridTimeRange, varDict)
siteID self.getSiteID()
model self.siteID __Eta
self.getGrids(model, T, SFC,GridTimeRange)
16SmartScript LibraryModel
Using VariableList VariableList ("Model",
"", "D2D_model")
def execute(self, GridTimeRange, varDict)
D2Dmodel varDict"Model"
self.getGrids(D2Dmodel, T,
SFC,GridTimeRange)
17SmartScript Library Numeric Soundings
Temperature Cube t_c
Geopotential height Cube gh_c
Pressure Levels
MB700 MB750 MB800 MB850 MB900 MB950
18SmartScript LibraryNumeric Sounding
19SmartScript 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()
20SmartScript Library Numeric Soundings
def execute(self, GridTimeRange, Topo, varDict)
....
Topo_M self.convertFtToM(Topo)
T self._empty - 200
for i in xrange(gh_c.shape0) Go
up the atmosphere
notSet equal(T, -200)
aboveGround greater(gh_c, Topo_M)
readyToSet logical_and(notSet, aboveGround)
T where(readyToSet, t_ci, T)
return self.convertKtoF(T)
21SmartScript LibraryConversion Methods
- convertMsecToKts
- convertKtoF, KtoF
- convertFtoK, FtoK
- convertFtToM
- UVtoMagDir and MagDirToUV
22Trouble-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", T2525
23Smart 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.
24Smart 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.
25Smart 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.
26Smart Tool Repository (STR)Downloading and
Adding a Tool (cont.)
27Executing Smart Tools Exercise
- Convective Scenario
- Winter Scenario
28Creating Smart ToolsExercises
- 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
29SmartScript Library Numeric Soundings
30SmartScript LibraryInterpolateValues
31SmartScript LibraryInterpolateValues
32SmartScript LibraryExtrapolate
33Vector Weather Elements
WeatherElementEdited "Wind" import
SmartScript class Tool (SmartScript.SmartScript)
def __init__(self, dbss)
SmartScript.SmartScript__init__(self,dbss)
def execute(self, Wind) mag Wind0
dir Wind1 mag mag 5
return (mag, dir)
34Working 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 "SctRW-ltNoVisgt",
"ChcT-ltNoVisgt",
"ChcSW-ltNoVisgt"
Then the wxValues grid is 0 where
"SctRW-ltNoVisgt"
1 where "ChcT-ltNoVisgt"
2 where
"ChcSW-ltNoVisgt"
35Working with Weather
Assigning Weather values getIndex -- given a
list of keys, returns the
associated index
byteValue self.getIndex("SChcRW-ltNoVisgt",key
s)
byteValue self.getIndex("ChcRW-ltNoVisgt",keys
)
Special case for "NoWx" byteValue
self.getIndex("",keys)
36Working with Weather
See examples/smartTools/Convective_SmartTool.py
Creating Wx from PoP
def execute(self, PoP, Wx) wxValues, keys
Wx
wxValues \ where(less(PoP, 10),
self.getIndex("",keys),
where(less(PoP,20) , self.getIndex("SChcRW
-ltNoVisgt",keys),
self.getIndex("ChcRW-ltNoVisgt",keys)))
return (wxValues, keys)
37Working 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")
38Working 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
39SmartScript LibraryEdit Area Methods
editArea self.getEditArea(Boulder)
areaMask self.encodeEditArea(editArea)
T where(areaMask, T10, T)
40Smart Script LibraryMissing Data Mode
- Set from GFE--gtEditing 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.
41SmartScript Library"On-the-Fly" Elements
- "On-the-fly" Elements
- ISC Discrepancies
- Creating temporary weather elements
self.createGrid(model, element, elementType,
numericGrid, timeRange)
42SmartScript Library"On-the-Fly" Elements
WeatherElementEdited None
self.createGrid("Diff", "T_Diff", "Scalar",
myGrid, GridTimeRange)
43SmartScript LibraryISC Data
44SmartScript LibrarySaving Objects
self.saveObject(objectName, object, category
self.saveObject(MyGrid, numericGrid,
DiscrepancyValueGrids)
myGrid self.getObject(MyGrid,
DiscrepancyValueGrids)
45Smart Script LibraryError 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
46Smart ToolsScreenList
ScreenList "SCALAR","VECTOR" ScreenList
"Td","T","MaxT","MinT"
47Creating 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.SmartScr
ipt.__init__(self, dbss) def
preProcessTool(self, varDict)
self._thunder varDict"Thunder Y/N" def
execute(self, Wx) if self._thunder
"Y" assign thunder
48Creating 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.SmartScr
ipt.__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)
49SmartScript LibraryComing Soon
- A library of meteorological functions
- Gradient
- Curl
- Dot product
- Cross product
- Advection
- Others
50SmartScript LibraryExercises
- SmartScript-5 Making and Accessing Soundings
- SmartScript-6 Creating Elements "On-the-Fly"
- SmartScript-7 Working with Weather
- SmartScript-8 Working with Weather
51Procedures
52SmartScript LibraryProcedure Commands
- copyCmd
- createFromScratchCmd
- assignValueCmd
- zeroCmd
- interpolateCmd
- timeShiftCmd
- splitCmd, fragmentCmd, deleteCmd
53SmartScript LibraryProcedure Commands
54SmartScript LibraryTime 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)
55SmartScript LibraryDatabases
databaseID
Find database -- databaseName, version
databaseID self.findDatabase(Eta, 0)
databaseID self.findDatabase(D2D_ETA, -1)
56SmartScript LibraryDatabases
databaseID
Get database -- result of VariableList
VariableList ("Model", "", "D2D_model")
def execute(self, varDict) D2Dmodel
varDict"Model"
databaseID self.getDatabase(D2Dmodel)
57SmartScript LibraryProcedure Commands
58SmartScript LibraryProcedure Commands
59SmartScript LibraryProcedure Commands
60SmartScript LibraryProcedure Commands
61SmartScript LibraryProcedure Commands
62SmartScript LibraryProcedure Commands
63SmartScript LibraryProcedure Commands
64SmartScript LibraryProcedure Commands
65SmartScript LibraryProcedure Commands
66SmartScript LibraryProcedure Commands
Creating a Time Range model
varDict"Model" databaseID self.getDatabase(mod
el) timeRange_0_60 self.createTimeRange(
0, 60, "DatabaseID", databaseID)
Copy from model elements T, Wind,
Wx self.copyCmd(elements, databaseID,
timeRange_0_60)
67SmartScript LibraryProcedure Commands
Find most recent Eta model databaseID
self.findDatabase("Eta", version0)
Copy grids self.copyCmd( "T", "Td",
"Wind", databaseID, timeRange_0_60)
68SmartScript LibraryProcedure Commands
69SmartScript LibraryProcedure Commands
Create Grids self.createFromScratchCmd(
"MixHgt", timeRange_0_60, repeat6, duration1)
Get edit area toolEditArea self.getEditArea("B
oulder")
Call Smart Tool self.callSmartTool("MixHgt_Init
", "MixHgt",
toolEditArea, timeRange_0_60)
70ProcedurescallSmartTool and VariableLists
Smart Tool, "MyTool" VariableList
("Threshold", 10, "numeric")
def execute(self, varDict) threshold
varDict"Threshold"
71ProcedurescallSmartTool 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)
72SmartScript LibraryProcedure Commands
- getGridCellSwath
- saveEditArea
- setActiveElement
- cacheElements, uncacheElements
73SmartScript Library
Procedure commands
Smart Tool commands
getEditArea
createFromScratch
makeNumericSounding
extrapolate
interpolateCmd
createTimeRange
getGrids
callSmartTool
getGrids
74Background Procedures
./runProcedure
-n procedure name
-u userID
-c config file
-a edit area name
-t time range
75Background Procedures
./runProcedure -n Proc1 -u ifpUser -c
gfeConfig -a
CO_Boulder -t Tonight
76Utilities
- Allows for sharing of common methods among Smart
Tools and Procedures
77SmartScript LibraryProgress Dialog
import MyDialog def execute(self, editArea,
timeRange)
Display dialog dialog MyDialog.MyDialog(
None, Status, Loading Grids)
Do stuff
Close dialog dialog.top().destroy()
78Procedures and UtilitiesExercises
- Procedure-1
- Procedure-2
- Procedure-3
- Utility-1