Point-based
Arguments
Reserved Methods
Exercise Point-based-1 --
Creating a Tool
Exercise Point-based-2 --
Modifying a Tool
Exercise Point-based-3 --
Using VariableLists
Working With Point-based Weather
Exercise Point-based
SmartScript-1
-- Accessing Grids Directly
Exercise Point-based
SmartScript-2
-- Accessing Variable Grids Directly
Exercise Point-based
SmartScript-3
-- Making and Accessing Soundings
Answers to Point-based
Exercises
T
|
Multiply QPF by
|
---|---|
< 20
|
18
|
between 20 and 25
|
14
|
over 25
|
10
|
import string
import SmartScript
class Tool
(SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self, dbss)
def execute(self, Wx, varDict):
"Tool to calculate LAL from Wx"
if string.find(Wx, "Iso:T")>=0:
LAL = 2
elif string.find(Wx, "Sct:T")>=0:
LAL = 3
elif string.find(Wx, "Num:T")>=0:
LAL = 4
elif string.find(Wx, "Wide:T")>=0:
LAL = 5
else
LAL = 1
return LAL
if string.find(Wx, ":R:")>=0:
Note that we need to include the colons so that the test distinguishes between "R" and "RW". A similar confusion can arise when looking for Coverages such as "Sct" and "WSct" or "Chc" and "SChc". If you are looking for a particular Coverage, you may want to use the simple (and fast) WxMethod, WxParts, to separate the string into a list of parts and then test for inclusion. At the beginning of your tool, be sure to "import" the WxMethods utility as shown:
from WxMethods import *
import SmartScript
class Tool
(SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self, dbss)
def execute(self, Wx, varDict):
"Tool to calculate PoP from Wx"
parts = WxParts(Wx)
if "Def" in parts:
PoP = 100
elif "Wide" in parts:
PoP = 90
elif "Ocnl" in parts:
PoP = 80
elif "Lkly" in parts:
PoP = 70
elif "Chc" in parts:
PoP = 40
elif "SChc" in parts:
PoP = 20
elif "Iso" in parts:
PoP = 10
return PoP
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, QPF):
"Tool to return QPF
multiplied
by 10"
# Determine new value
SnowAmt = QPF * 10
# Return the new value
return SnowAmt
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, QPF, T):
"Tool to calculate SnowAmt"
if T < 20:
SnowRatio
= 18
elif T < 25:
SnowRatio
= 14
else:
SnowRatio = 10
# Determine new value
SnowAmt = QPF * SnowRatio
# Return the new value
return SnowAmt
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, QPF, T, Topo, varDict):
"Tool to calculate SnowAmt"
# Set up Variables from
the
varDict
elevation = varDict["Enter
elevation"]
if T < 20:
SnowRatio = 18
elif T < 25:
SnowRatio = 14
else:
SnowRatio = 10
# Determine new value
if Topo > elevation:
SnowAmt = SnowRatio * QPF
else:
SnowAmt = 0
# Return the new value
return
SnowAmt
VariableList = [
("Enter elevation" , 5000,
"numeric"),
]
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, x, y,
GridTimeRange):
"This
tool accesses QPF and tp grids directly"
# Get QPF and tp values
qpf = self.getValue("Fcst", "QPF", "SFC", x, y, GridTimeRange)
tp = self.getValue("BOU_D2D_NAM12", "tp","SFC", x, y, GridTimeRange)
if qpf == 0:
return tp
else:
return qpf
VariableList = [("Model:" , "", "D2D_model")]
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, x, y,
GridTimeRange,
varDict):
"This
tool accesses QPF and tp grids directly"
model = varDict["Model:"]
# Get QPF and tp values
qpf = self.getValue("Fcst", "QPF", "SFC", x, y, GridTimeRange)
tp = self.getValue(model, "tp","SFC", x, y, GridTimeRange)
if qpf == 0:
return tp
else:
return qpf
VariableList = [("Model:" , "", "D2D_model")]
class Tool (SmartScript.SmartScript):
def __init__(self, dbss):
SmartScript.SmartScript.__init__(self,
dbss)
def execute(self, Topo, x, y, GridTimeRange,
varDict):
"This tool initializes T
based on model temperature soundings"
model = varDict["Model:"]
# Make a sounding for T
at
this point
# Height will increase in
the sounding
levels =
["MB1000","MB950","MB900","MB850","MB800",
"MB750","MB700","MB650","MB600"]
topo_M =
self.convertFtToM(Topo)
T_K =
self.getSoundingValue(model,
"t", levels, x, y, GridTimeRange, topo_M)
T_F = self.convertKtoF(T_K)
# Return the new value
return T_F