78
Sept. 24-27, 200 2 Smart Tools and Procedure s 1 Smart Tools and Smart Tools and Procedures Procedures Tracy Hansen

Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Embed Size (px)

Citation preview

Page 1: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 1

Smart Tools and ProceduresSmart Tools and ProceduresTracy Hansen

Page 2: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 2

OverviewOverview Part 1Part 1

What are Smart Tools?What are Smart Tools? Executing Smart ToolsExecuting Smart Tools Creating Smart ToolsCreating Smart Tools

Part 2Part 2 Creating Smart Tools (cont)Creating Smart Tools (cont) SmartScript Library MethodsSmartScript Library Methods

Part 3Part 3 ProceduresProcedures UtilitiesUtilities

Page 3: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 3

What are Smart Tools?What are Smart Tools?

Meteorological AlgorithmsMeteorological AlgorithmsNumerical PythonNumerical Python

Smart ToolSmart Tool

Numerical ModelsNumerical ModelsObservationsObservationsTopographyTopography

Forecast GridsForecast Grids"On-the-fly" Elements"On-the-fly" Elements

ModifyModifyUser InputUser Input

Page 4: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 4

Executing Smart ToolsExecuting Smart Tools

Make Weather Element EditableMake Weather Element EditableSet up Selection Time RangeSet up Selection Time RangeSet up Edit AreaSet up Edit AreaExecute Tool from Edit Action Dialog or Execute Tool from Edit Action Dialog or

Spatial Editor MB3 Popup MenuSpatial Editor MB3 Popup Menu

Page 5: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 5

Creating Smart ToolsCreating Smart ToolsFrom Edit Action Dialog MB3 Popup:From Edit Action Dialog MB3 Popup:Info... Info... Cut, Copy, PasteCut, Copy, PasteModify... or View...Modify... or View...New...New...Rename...Rename...Delete...Delete...

Page 6: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 6

ToolType = "numeric"ToolType = "numeric"from Numeric import *from Numeric import *

CreatingCreating Smart ToolsSmart Tools

WeatherElementEdited = "T"WeatherElementEdited = "T"

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

def execute(self, T):def execute(self, T):

T = T + 5T = T + 5return Treturn T

Page 7: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 7

Creating Smart Tools Creating Smart Tools

Tool ArgumentsTool ArgumentsWeather Elements Weather Elements

T, Wx, variableElement, MaxT_SFC_BOU_EtaT, Wx, variableElement, MaxT_SFC_BOU_EtaTopographyTopography

TopoTopoMaxGrid, MinGrid, SumGridMaxGrid, MinGrid, SumGrid

T_MaxGrid, Td_SumGridT_MaxGrid, Td_SumGridGridTimeRangeGridTimeRangeGridInfo, GridHistoryGridInfo, GridHistory

Wx_GridInfo, T_GridHistoryWx_GridInfo, T_GridHistory

Page 8: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 8

Creating Smart ToolsCreating Smart Tools ConditionalsConditionals

WeatherElementEdited = "HeatIndex"WeatherElementEdited = "HeatIndex"

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

return HeatIndexreturn HeatIndex

Page 9: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 9

Creating Smart ToolsCreating Smart Tools

Variable ListsVariable ListsAllow for run-time user inputAllow for run-time user input

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

Page 10: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 10

Creating Smart Tools Creating Smart Tools

Variable ListsVariable Lists

numeric, alphaNumericnumeric, alphaNumericradio, checkradio, checkscalescalemodel, D2D_modelmodel, D2D_modellabellabel

Page 11: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 11

Creating Smart ToolsCreating Smart Tools

Variable ListsVariable ListsvarDictvarDict argument to access user input argument to access user input

def execute(self, varDict):

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

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

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

Page 12: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 12

SmartScript LibrarySmartScript Library

Page 13: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 13

SmartScript LibrarySmartScript Library

Grid AccessGrid AccessgetGridsgetGrids

self.getGridsself.getGrids

Model = “Fcst”Model = “Fcst”

Element = “T”Element = “T”TimeRangeTimeRange

Level = “SFC”Level = “SFC”

Numeric Grid for “T”Numeric Grid for “T”

Mode = “TimeWtAverage”Mode = “TimeWtAverage”

Page 14: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 14

SmartScript LibrarySmartScript Library

ModelModel

# # Fcst or OfficialFcst or Officialself.getGrids(“self.getGrids(“FcstFcst”, “T”, “SFC”, GridTimeRange)”, “T”, “SFC”, GridTimeRange)

self.getGrids(“self.getGrids(“BOU__Eta_Oct0112BOU__Eta_Oct0112”, “T”, “SFC”, ”, “T”, “SFC”, GridTimeRange)GridTimeRange)self.getGrids(“self.getGrids(“BOU__EtaBOU__Eta”, “T”, “SFC”, GridTimeRange)”, “T”, “SFC”, GridTimeRange)

self.getGrids(“self.getGrids(“BOU_D2D_ETABOU_D2D_ETA”, “t”, “MB750”, ”, “t”, “MB750”, GridTimeRange)GridTimeRange)

# # siteID_type_model_modeltimesiteID_type_model_modeltime

Page 15: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 15

SmartScript LibrarySmartScript Library

ModelModel

# # Using Site ID for portabilityUsing Site ID for portability

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

model = self.siteID + “__Eta” model = self.siteID + “__Eta”

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

Page 16: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 16

SmartScript LibrarySmartScript Library

ModelModel

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

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

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

Page 17: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 17

SmartScript Library SmartScript Library

Numeric SoundingsNumeric Soundings

Geopotential height Cube:Geopotential height Cube: gh_cgh_c

Temperature Cube:Temperature Cube: t_ct_cPressurePressure

LevelsLevels

MB700MB700MB750MB750MB800MB800MB850MB850MB900MB900MB950MB950

Page 18: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 18

SmartScript LibrarySmartScript Library

Numeric SoundingNumeric Sounding

self.makeNumericSoundingself.makeNumericSounding

Model = Model = “BOU_D2D_ETA”“BOU_D2D_ETA”

Element = “t”Element = “t”

Numeric Cube for “gh” and Numeric Cube for “t”Numeric Cube for “gh” and Numeric Cube for “t”

TimeRangeTimeRange

LevelsLevels

Page 19: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 19

SmartScript Library SmartScript Library

Numeric SoundingsNumeric Soundings VariableList = [("Model:", "", "D2D_model")]VariableList = [("Model:", "", "D2D_model")]

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

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

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

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

Page 20: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 20

SmartScript Library SmartScript Library

Numeric SoundingsNumeric Soundingsdef execute(self, GridTimeRange, Topo, varDict): def execute(self, GridTimeRange, Topo, varDict): ........

Topo_M = self.convertFtToM(Topo)Topo_M = self.convertFtToM(Topo)

T = self._empty - 200T = self._empty - 200

for i in xrange(gh_c.shape[0]): # Go up the atmospherefor i in xrange(gh_c.shape[0]): # Go up the atmospherenotSet = equal(T, -200)notSet = equal(T, -200)

aboveGround = greater(gh_c, Topo_M)aboveGround = greater(gh_c, Topo_M)

readyToSet = logical_and(notSet, aboveGround)readyToSet = logical_and(notSet, aboveGround)

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

return self.convertKtoF(T)return self.convertKtoF(T)

Page 21: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 21

SmartScript LibrarySmartScript Library

Conversion MethodsConversion Methods

convertMsecToKtsconvertMsecToKtsconvertKtoF, KtoFconvertKtoF, KtoFconvertFtoK, FtoKconvertFtoK, FtoKconvertFtToMconvertFtToMUVtoMagDir and MagDirToUVUVtoMagDir and MagDirToUV

Page 22: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 22

Trouble-shooting IdeasTrouble-shooting IdeasRun from terminal window to see Python Run from terminal window to see Python

error messages.error messages.Use "print" statements.Use "print" statements.

print "Made it to this point."print "Made it to this point."

print "myVariable=", myVariableprint "myVariable=", myVariable

print "value at 25, 25 is", T[25][25]print "value at 25, 25 is", T[25][25]

Page 23: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 23

Smart Tool Repository (STR)Smart Tool Repository (STR)http://isl715.nws.noaa.gov/STR/index.php3http://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.

Page 24: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 24

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

1) Use the “Site Interface” and choose your region and WFO ID

2) Choose “Info on Tools” and go to the ST you wish to download

3) Right click on the “Download Software” and use “Save Link as”. Do the same for the Documentation and Install files if available.

4) Move the ST to a location where GFE is running and open the ST with an editor such as vi or nedit.

Page 25: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 25

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

5) Make the downloaded ST part of the GFE

a) 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.

Page 26: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 26

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

Page 27: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 27

Executing Smart Tools Executing Smart Tools ExerciseExercise

Convective ScenarioConvective ScenarioWinterWinter Scenario

Page 28: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 28

Creating Smart ToolsCreating Smart Tools

ExercisesExercisesTool-1Tool-1Tool-2Tool-2Tool-3Tool-3SmartScript-1 : Accessing Grids DirectlySmartScript-1 : Accessing Grids DirectlySmartScript-2 : Accessing Variable Grids DirectlySmartScript-2 : Accessing Variable Grids DirectlySmartScript-3 : Making and Accessing SoundingsSmartScript-3 : Making and Accessing SoundingsSmartScript-4 : Making and Accessing SoundingsSmartScript-4 : Making and Accessing Soundings

Page 29: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 29

SmartScript Library SmartScript Library

Numeric SoundingsNumeric Soundings

Geopotential height Cube:Geopotential height Cube: gh_cgh_c

Temperature Cube:Temperature Cube: t_ct_cPressurePressure

LevelsLevels

MB700MB700MB750MB750MB800MB800MB850MB850MB900MB900MB950MB950

Page 30: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 30

SmartScript LibrarySmartScript Library

InterpolateValuesInterpolateValues

self.interpolateValuesself.interpolateValues

heightheight

(height1, value1)(height1, value1)

Interpolated value at height Interpolated value at height

(height2, value2)(height2, value2)

Page 31: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 31

SmartScript LibrarySmartScript Library

InterpolateValuesInterpolateValues

self.interpolateValuesself.interpolateValues

heightheight

(height1, value1)(height1, value1)

Interpolated value at height Interpolated value at height

(height2, value2)(height2, value2)

Page 32: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 32

SmartScript LibrarySmartScript Library

ExtrapolateExtrapolate

self.extrapolateself.extrapolate

heightheight

(height1, value1)(height1, value1)

Extrapolated value at height Extrapolated value at height

(height2, value2)(height2, value2)

Page 33: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 33

Vector Weather ElementsVector Weather Elements

WeatherElementEdited = "Wind"WeatherElementEdited = "Wind"import SmartScriptimport SmartScriptclass Tool (SmartScript.SmartScript):class Tool (SmartScript.SmartScript): def __init__(self, dbss):def __init__(self, dbss): SmartScript.SmartScript__init__(self,dbss)SmartScript.SmartScript__init__(self,dbss)

def execute(self, Wind):def execute(self, Wind): mag = Wind[0]mag = Wind[0] dir = Wind[1]dir = Wind[1] mag = mag + 5mag = mag + 5 return (mag, dir)return (mag, dir)

Page 34: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 34

Working with WeatherWorking with WeatherNumeric WeatherNumeric Weather is a 2-tuple: is a 2-tuple:

wxValues -- Numeric Grid of byteswxValues -- Numeric Grid of bytes

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

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

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

Page 35: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 35

Working with WeatherWorking with Weather

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

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

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

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

Page 36: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 36

Working with WeatherWorking with Weather

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

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

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

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

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

Page 37: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 37

Working with WeatherWorking with Weather

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

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

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

Page 38: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 38

Working with WeatherWorking with Weather

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

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

Page 39: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 39

SmartScript LibrarySmartScript Library

Edit Area MethodsEdit Area Methods

editArea = self.getEditArea(“Boulder”)editArea = self.getEditArea(“Boulder”)

areaMask = self.encodeEditArea(editArea)areaMask = self.encodeEditArea(editArea)

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

Page 40: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 40

Smart Script LibrarySmart Script Library

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

Page 41: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 41

SmartScript LibrarySmartScript Library

"On-the-Fly" Elements"On-the-Fly" Elements"On-the-fly" Elements "On-the-fly" Elements

ISC DiscrepanciesISC DiscrepanciesCreating temporary weather elementsCreating temporary weather elements

self.self.createGridcreateGrid(model, element, elementType,(model, element, elementType, numericGrid, timeRange)numericGrid, timeRange)

Page 42: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 42

SmartScript LibrarySmartScript Library

"On-the-Fly" Elements"On-the-Fly" Elements

self.self.createGridcreateGrid("Diff", "T_Diff", "Scalar",("Diff", "T_Diff", "Scalar", myGrid, GridTimeRange)myGrid, GridTimeRange)

WeatherElementEdited = “None”WeatherElementEdited = “None”

Page 43: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 43

SmartScript LibrarySmartScript Library

ISC DataISC Data

self.getCompositeself.getComposite

WEnameWEname GridTimeRangeGridTimeRange

Primary Grid plus corresponding ISC dataPrimary Grid plus corresponding ISC data

exactMatchexactMatch

Numeric mask indicating valid pointsNumeric mask indicating valid points

Page 44: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 44

SmartScript LibrarySmartScript Library

Saving ObjectsSaving Objects

self.saveObject(objectName, object, categoryself.saveObject(objectName, object, category

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

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

Page 45: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 45

Smart Script LibrarySmart Script Library

Error HandlingError Handling

abort -- abort with user-supplied error messageabort -- abort with user-supplied error messagenoData -- abort with a No Data errornoData -- abort with a No Data errorcancel -- abort with no error messagecancel -- abort with no error messagestatusBarMsg -- sends message to the Status BarstatusBarMsg -- sends message to the Status Bar

Page 46: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 46

Smart ToolsSmart Tools

ScreenListScreenList

ScreenList = ["SCALAR","VECTOR"]ScreenList = ["SCALAR","VECTOR"]

ScreenList = ["Td","T","MaxT","MinT"]ScreenList = ["Td","T","MaxT","MinT"]

Page 47: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 47

Creating Smart Tools Creating Smart Tools

Reserved MethodsReserved Methods

executeexecutepreProcessTool, postProcessToolpreProcessTool, postProcessTool

Actions that need to be done once per toolActions that need to be done once per toolclass Tool (SmartScript.SmartScript):class Tool (SmartScript.SmartScript): def __init__(self, dbss):def __init__(self, dbss): SmartScript.SmartScript.__init__(self, dbss)SmartScript.SmartScript.__init__(self, dbss)

def preProcessTool(self, varDict):def preProcessTool(self, varDict): self._thunder = varDict["Thunder Y/N"]self._thunder = varDict["Thunder Y/N"]

def execute(self, Wx): def execute(self, Wx): if if self._thunderself._thunder == "Y": == "Y": # assign thunder # assign thunder

Page 48: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 48

Creating Smart Tools Creating Smart Tools

Creating Your Own MethodsCreating Your Own Methods Name preceeded by underscoreName preceeded by underscore "self" used in call and in "def" argument list"self" used in call and in "def" argument list

Class Tool (SmartScript.SmartScript):Class Tool (SmartScript.SmartScript): def __init__(self, dbss):def __init__(self, dbss): SmartScript.SmartScript.__init__(self, dbss)SmartScript.SmartScript.__init__(self, dbss)

def execute(self, QPF, T): def execute(self, QPF, T): SnowRatio =SnowRatio = self._getSnowRatio(T)self._getSnowRatio(T) SnowAmt = QPF * SnowRatioSnowAmt = QPF * SnowRatio return SnowAmt return SnowAmt

def _getSnowRatio(self, T): def _getSnowRatio(self, T): return where( less(T, 20), 18, return where( less(T, 20), 18, where( less(T, 21), 14, 10) where( less(T, 21), 14, 10)

Page 49: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 49

SmartScript LibrarySmartScript Library

Coming SoonComing SoonA library of meteorological functions

Gradient Curl Dot product Cross product Advection Others

Page 50: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 50

SmartScript LibrarySmartScript Library

ExercisesExercises

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

Page 51: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 51

ProceduresProcedures

Page 52: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 52

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure Commands copyCmdcopyCmd createFromScratchCmdcreateFromScratchCmd assignValueCmdassignValueCmd zeroCmdzeroCmd interpolateCmdinterpolateCmd timeShiftCmdtimeShiftCmd splitCmd, fragmentCmd, deleteCmdsplitCmd, fragmentCmd, deleteCmd

Page 53: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 53

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandscopyCmdcopyCmd

self.copyCmdself.copyCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange

databaseIDdatabaseID

Copies Elements from database to Fcst for grids Copies Elements from database to Fcst for grids overlapping the given timeRange.overlapping the given timeRange.

Page 54: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 54

SmartScript LibrarySmartScript Library

Time RangesTime Ranges

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

# Get Selection Time Range# Get Selection Time RangetodayRange = self.todayRange = self.getTimeRangegetTimeRange(“Today”)(“Today”)

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

Page 55: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 55

SmartScript LibrarySmartScript Library

DatabasesDatabases

# Find database -- databaseName, version# Find database -- databaseName, version

databaseIDdatabaseID

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

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

Page 56: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 56

SmartScript LibrarySmartScript Library

DatabasesDatabases

# Get database -- result of VariableList# Get database -- result of VariableList

databaseIDdatabaseID

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

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

databaseID = self.getDatabase(D2Dmodel)databaseID = self.getDatabase(D2Dmodel)

Page 57: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 57

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandscreateFromScratchCmdcreateFromScratchCmd

self.createFromScratchCmdself.createFromScratchCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange repeat = 3repeat = 3

Creates Element grids every three hoursCreates Element grids every three hourswith a one-hour duration in the given time range.with a one-hour duration in the given time range.

duration = 1duration = 1

Page 58: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 58

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandsassignValueCmdassignValueCmd

self.assignValueCmdself.assignValueCmd

Element list = Element list = [“T”, “Td”][“T”, “Td”]

timeRangetimeRange

valuevalue

Assigns the given value to Element grids Assigns the given value to Element grids overlapping the given time range.overlapping the given time range.

Page 59: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 59

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandszeroCmdzeroCmd

self.zeroCmdself.zeroCmd

Element list = Element list = [“T”, “Wind”, “Wx”][“T”, “Wind”, “Wx”]

timeRangetimeRange

Assigns minimum possible value to scalar and Assigns minimum possible value to scalar and vector Element grids an “<NoWx>” to “Wx” vector Element grids an “<NoWx>” to “Wx” grids overlapping the given time range.grids overlapping the given time range.

Page 60: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 60

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandsinterpolateCmdinterpolateCmd

self.interpolateCmdself.interpolateCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange interval = 3interval = 3

Interpolates Element grids “by gaps” every three hours with a one-Interpolates Element grids “by gaps” every three hours with a one-hour duration. Command completes “synchronously” before going hour duration. Command completes “synchronously” before going on to next command in the Procedure.on to next command in the Procedure.

duration = 1duration = 1

interpState=“SYNC”interpState=“SYNC”

interpMode = “GAPS”interpMode = “GAPS”

Page 61: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 61

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandsinterpolateCmdinterpolateCmd

self.interpolateCmdself.interpolateCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange interval = 0interval = 0

Interpolates Element grids based “on edited” data to the interval and Interpolates Element grids based “on edited” data to the interval and duration of the minimum time constraints. duration of the minimum time constraints. Command executes “asynchronously.”Command executes “asynchronously.”

duration = 0duration = 0

interpState=“ASYNC”interpState=“ASYNC”

interpMode = “ON_EDITED”interpMode = “ON_EDITED”

Page 62: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 62

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandstimeShiftCmdtimeShiftCmd

self.timeShiftCmdself.timeShiftCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRangecopyOnly=1copyOnly=1

Copies Element grids overlapping the given Copies Element grids overlapping the given timeRange 24 hours in the futuretimeRange 24 hours in the future

shiftAmount=24shiftAmount=24

Page 63: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 63

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandssplitCmdsplitCmd

self.splitCmdself.splitCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange

Splits any grid that falls on the start time or end Splits any grid that falls on the start time or end time of the given time range.time of the given time range.

Page 64: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 64

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandsfrfragmentCmdagmentCmd

self.fragmentCmdself.fragmentCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange

Fragments any grids that overlap the time range.Fragments any grids that overlap the time range.

Page 65: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 65

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandsdeleteCmddeleteCmd

self.deleteCmdself.deleteCmd

Element list = Element list = [“T”, “Wind”,”Wx”][“T”, “Wind”,”Wx”]

timeRangetimeRange

Deletes any Element grids that overlap the Deletes any Element grids that overlap the given timeRange.given timeRange.

Page 66: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 66

# Creating a Time Range# Creating a Time Rangemodel = varDict["Model"]model = varDict["Model"]databaseID = self.getDatabase(model)databaseID = self.getDatabase(model)timeRange_0_60timeRange_0_60 = self.createTimeRange( = self.createTimeRange( 0, 60, "DatabaseID", databaseID)0, 60, "DatabaseID", databaseID)

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure Commands

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

Page 67: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 67

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

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure Commands

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

Page 68: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 68

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure CommandscallSmartToolcallSmartTool

self.callSmartToolself.callSmartTool

toolNametoolName

elementNameelementName varDictvarDict

Execute the given tool editing the element over editArea and Execute the given tool editing the element over editArea and timeRange. Use varDict for user-input variables. If possible, create timeRange. Use varDict for user-input variables. If possible, create missing data.missing data.

missingDataMode=“Create”missingDataMode=“Create”

timeRangetimeRange

editAreaeditArea

Page 69: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 69

# Create Grids# Create Gridsself.createFromScratchCmd(self.createFromScratchCmd( "MixHgt", "MixHgt", timeRange_0_60timeRange_0_60, repeat=6, duration=1), repeat=6, duration=1)

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure Commands

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

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

Page 70: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 70

ProceduresProcedures

callSmartTool and VariableListscallSmartTool and VariableLists

Smart Tool, "MyTool":Smart Tool, "MyTool":

VariableList = [("Threshold", 10, "numeric") ]VariableList = [("Threshold", 10, "numeric") ]

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

Page 71: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 71

ProceduresProcedures

callSmartTool and VariableListscallSmartTool and VariableListsProcedure:Procedure:VariableList = [VariableList = [ ("Model", "", "model"),("Model", "", "model"), ("Threshold", 10, "numeric")("Threshold", 10, "numeric") ] ]

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

Page 72: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 72

SmartScript LibrarySmartScript Library

Procedure CommandsProcedure Commands

getGridCellSwathgetGridCellSwath saveEditAreasaveEditArea setActiveElementsetActiveElement cacheElements, uncacheElementscacheElements, uncacheElements

Page 73: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 73

SmartScriptSmartScript Library Library

Procedure Procedure commandscommands

Smart ToolSmart Toolcommandscommands

getEditAreagetEditArea makeNumericSoundingmakeNumericSounding

getGridsgetGrids getGridsgetGrids

createFromScratchcreateFromScratch

extrapolateextrapolateinterpolateCmdinterpolateCmd

callSmartToolcallSmartTool

createTimeRangecreateTimeRange

Page 74: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 74

Background Procedures Background Procedures runProcedurerunProcedure commandcommand

-n procedure name-n procedure name

./runProcedure./runProcedure

-u userID-u userID

-c config file-c config file

[-a edit area name][-a edit area name]

[-t time range][-t time range]

Page 75: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 75

Background Procedures Background Procedures

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

Page 76: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 76

UtilitiesUtilitiesAllows for sharing of common methods among Allows for sharing of common methods among

Smart Tools and ProceduresSmart Tools and Procedures

Page 77: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 77

SmartScript LibrarySmartScript Library

Progress DialogProgress Dialogimport MyDialogimport MyDialogdef execute(self, editArea, timeRange)def execute(self, editArea, timeRange)

# # Display dialogDisplay dialogdialog = MyDialog.MyDialog(dialog = MyDialog.MyDialog( None, “Status”, “ Loading Grids”)None, “Status”, “ Loading Grids”)# # Do stuffDo stuff

# # Close dialogClose dialogdialog.top().destroy() dialog.top().destroy()

Page 78: Sept. 24-27, 2002Smart Tools and Procedures1 Tracy Hansen

Sept. 24-27, 2002 Smart Tools and Procedures 78

Procedures and UtilitiesProcedures and Utilities

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