819 lines
26 KiB
HTML
819 lines
26 KiB
HTML
|
<html>
|
||
|
<title>GFESuite Documentation - Smart Tools</title>
|
||
|
<body>
|
||
|
<h1 align=center>Smart Tools Answers to Exercises</h1>
|
||
|
<h3 class="3Heading"><a name="AnswerNum1"></a>Answer to Exercise Tool-1</h3>
|
||
|
<div class="3Heading">
|
||
|
<div class="Code">
|
||
|
<div class="3Heading">ToolType = "numeric"</div>
|
||
|
<div class="3Heading">WeatherElementEdited = "SnowAmt"</div>
|
||
|
<div class="3Heading">from numpy import *</div>
|
||
|
<div class="3Heading">import SmartScript</div>
|
||
|
<div class="3Heading">class Tool (SmartScript.SmartScript):</div>
|
||
|
<div class="3Heading"> def __init__(self, dbss):</div>
|
||
|
<div class="3Heading">
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)</div>
|
||
|
<div class="3Heading"> def execute(self, QPF):</div>
|
||
|
<div class="3Heading"> "Tool
|
||
|
to return QPF multiplied by 10"</div>
|
||
|
<div class="3Heading"> #
|
||
|
Determine
|
||
|
new value</div>
|
||
|
<div class="3Heading">
|
||
|
SnowAmt
|
||
|
= QPF * 10</div>
|
||
|
<div class="3Heading"> #
|
||
|
Return
|
||
|
the new value</div>
|
||
|
<div class="3Heading"> return
|
||
|
SnowAmt</div>
|
||
|
<h3 class="3Heading">
|
||
|
<a name="AnswerNum2"></a>Answer to Exercise Tool-2</h3>
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "SnowAmt"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, QPF, T):
|
||
|
<br>
|
||
|
"Tool to calculate SnowAmt"
|
||
|
</p>
|
||
|
<p> SnowAmt = where(less(T,
|
||
|
20),
|
||
|
QPF * 18,
|
||
|
<br>
|
||
|
|
||
|
where(less(T, 25), QPF * 14,
|
||
|
<br>
|
||
|
|
||
|
QPF * 10))
|
||
|
<br>
|
||
|
# Return the new value
|
||
|
<br>
|
||
|
return SnowAmt
|
||
|
<br>
|
||
|
|
||
|
</p>
|
||
|
<h3><a name="AnswerNum3"></a>Answer to Exercise Tool-3</h3>
|
||
|
<div class="Code">
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "SnowAmt"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>VariableList = [
|
||
|
<br>
|
||
|
("Enter elevation" , 5000,
|
||
|
"numeric"),
|
||
|
<br>
|
||
|
]
|
||
|
<br>
|
||
|
class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, QPF, T, Topo, varDict):
|
||
|
<br>
|
||
|
"Tool to calculate SnowAmt"
|
||
|
</p>
|
||
|
<p> # Set up Variables from
|
||
|
the
|
||
|
varDict
|
||
|
<br>
|
||
|
elevation = varDict["Enter
|
||
|
elevation"]
|
||
|
</p>
|
||
|
<p> SnowAmt = where(less(T,
|
||
|
20),
|
||
|
QPF * 18,
|
||
|
<br>
|
||
|
|
||
|
where(less(T, 25), QPF * 14,
|
||
|
<br>
|
||
|
|
||
|
QPF * 10))
|
||
|
<br>
|
||
|
SnowAmt = where(less(Topo,
|
||
|
elevation), 0, SnowAmt)
|
||
|
<br>
|
||
|
# Return the new value
|
||
|
<br>
|
||
|
return SnowAmt
|
||
|
<br>
|
||
|
</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="Code">
|
||
|
<div class="Code">
|
||
|
<div class="Code">
|
||
|
<h3 class="3Heading"><a name="AnswerSS1"></a>Answer to Exercise
|
||
|
SmartScript-1</h3>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="Code">
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "QPF"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, GridTimeRange, varDict):
|
||
|
<br>
|
||
|
"This tool accesses QPF
|
||
|
and tp grids directly"
|
||
|
</p>
|
||
|
<p> # Get QPF and tp
|
||
|
values
|
||
|
<br>
|
||
|
qpf = self.getGrids("Fcst",
|
||
|
"QPF", "SFC", GridTimeRange)
|
||
|
<br>
|
||
|
tp =
|
||
|
self.getGrids("BOU_D2D_NAM12",
|
||
|
"tp","SFC", GridTimeRange)
|
||
|
</p>
|
||
|
<p> qpf =
|
||
|
where(equal(qpf,0.0),
|
||
|
tp, qpf)
|
||
|
<br>
|
||
|
return qpf</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
<h3 class="3Heading">
|
||
|
<a name="AnswerSS2"></a>Answer to Exercise SmartScript-2</h3>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="Code">
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "QPF"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>VariableList = [("Model:" , "", "model")]
|
||
|
<br>
|
||
|
class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, GridTimeRange, varDict):
|
||
|
<br>
|
||
|
"This tool accesses QPF
|
||
|
and tp grids directly"
|
||
|
</p>
|
||
|
<p> model = varDict["Model:"]
|
||
|
</p>
|
||
|
<p> # Get QPF and tp
|
||
|
values
|
||
|
<br>
|
||
|
qpf = self.getGrids("Fcst",
|
||
|
"QPF", "SFC", GridTimeRange)
|
||
|
<br>
|
||
|
tp = self.getGrids(model,
|
||
|
"tp","SFC", GridTimeRange)
|
||
|
</p>
|
||
|
<p> qpf =
|
||
|
where(equal(qpf,0.0),
|
||
|
tp, qpf)
|
||
|
<br>
|
||
|
return qpf
|
||
|
<br>
|
||
|
</p>
|
||
|
<h3 class="3Heading"><a name="AnswerSS3"></a>Answer to Exercise
|
||
|
SmartScript-3</h3>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="Code">
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "T"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>VariableList = [("Model:" , "", "D2D_model")]
|
||
|
<br>
|
||
|
class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, GridTimeRange, Topo, varDict):
|
||
|
<br>
|
||
|
"This tool accesses QPF
|
||
|
and tp grids directly"
|
||
|
</p>
|
||
|
<p> model = varDict["Model:"]
|
||
|
</p>
|
||
|
<p> # Convert Topo to meters
|
||
|
<br>
|
||
|
topo_M =
|
||
|
self.convertFtToM(Topo)
|
||
|
</p>
|
||
|
<p> # Make a sounding cubes
|
||
|
for
|
||
|
T
|
||
|
<br>
|
||
|
# Height will increase in
|
||
|
the sounding and be the
|
||
|
<br>
|
||
|
# first dimension
|
||
|
<br>
|
||
|
levels =
|
||
|
["MB1000","MB950","MB900","MB850","MB800",
|
||
|
<br>
|
||
|
|
||
|
"MB750","MB700","MB650","MB600"]
|
||
|
<br>
|
||
|
gh_Cube, t_Cube =
|
||
|
self.makeNumericSounding(
|
||
|
<br>
|
||
|
|
||
|
model, "t", levels, GridTimeRange)
|
||
|
</p>
|
||
|
<p> print "Cube shapes ",
|
||
|
gh_Cube.shape,
|
||
|
t_Cube.shape
|
||
|
</p>
|
||
|
<p> # Make an initial T grid
|
||
|
with values of -200
|
||
|
<br>
|
||
|
# This is an out-of-range
|
||
|
value to help us identify values that
|
||
|
<br>
|
||
|
# have already been set.
|
||
|
<br>
|
||
|
T = (Topo * 0) - 200
|
||
|
</p>
|
||
|
<p> # Work "upward" in the
|
||
|
cubes
|
||
|
to assign T
|
||
|
<br>
|
||
|
# We will only set the value
|
||
|
once, i.e. the first time the
|
||
|
<br>
|
||
|
# gh height is greater than
|
||
|
the Topo
|
||
|
<br>
|
||
|
# For each level
|
||
|
<br>
|
||
|
for i in
|
||
|
xrange(gh_Cube.shape[0]):
|
||
|
<br>
|
||
|
|
||
|
# where ( gh > topo and T == -200),
|
||
|
<br>
|
||
|
|
||
|
# set to t_Cube value, otherwise
|
||
|
keep
|
||
|
value already set))
|
||
|
<br>
|
||
|
|
||
|
T = where(logical_and(greater(gh_Cube[i], topo_M), equal(T,-200)),
|
||
|
t_Cube[i],
|
||
|
T)
|
||
|
</p>
|
||
|
<p> # Convert from K to F
|
||
|
<br>
|
||
|
T_F = self.convertKtoF(T)
|
||
|
</p>
|
||
|
<p> return T_F
|
||
|
<br>
|
||
|
</p>
|
||
|
<h3 class="3Heading"><a name="AnswerSS4"></a>Answer to Exercise
|
||
|
SmartScript-4</h3>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="Code">
|
||
|
<div class="Code">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "T"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<br>
|
||
|
import SmartScript
|
||
|
<p>VariableList = [("Model:" , "", "D2D_model")]
|
||
|
<br>
|
||
|
class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, GridTimeRange, Topo, varDict):
|
||
|
<br>
|
||
|
"This tool accesses QPF
|
||
|
and tp grids directly"
|
||
|
</p>
|
||
|
<p> model = varDict["Model:"]
|
||
|
</p>
|
||
|
<p> # Convert Topo to meters
|
||
|
<br>
|
||
|
topo_M =
|
||
|
self.convertFtToM(Topo)
|
||
|
</p>
|
||
|
<p> # Make a sounding cubes
|
||
|
for
|
||
|
T
|
||
|
<br>
|
||
|
# Height will increase in
|
||
|
the sounding and be the
|
||
|
<br>
|
||
|
# first dimension
|
||
|
<br>
|
||
|
levels =
|
||
|
["MB1000","MB950","MB900","MB850","MB800",
|
||
|
<br>
|
||
|
|
||
|
"MB750","MB700","MB650","MB600"]
|
||
|
<br>
|
||
|
gh_Cube, t_Cube =
|
||
|
self.makeNumericSounding(
|
||
|
<br>
|
||
|
|
||
|
model, "t", levels, GridTimeRange)
|
||
|
</p>
|
||
|
<p> print "Cube shapes ",
|
||
|
gh_Cube.shape,
|
||
|
t_Cube.shape
|
||
|
</p>
|
||
|
<p> # Make an initial T grid
|
||
|
with values of -200
|
||
|
<br>
|
||
|
# This is an out-of-range
|
||
|
value to help us identify values that
|
||
|
<br>
|
||
|
# have already been set.
|
||
|
<br>
|
||
|
T = (Topo * 0) - 200
|
||
|
</p>
|
||
|
<p> # Work "upward" in the
|
||
|
cubes
|
||
|
to assign T
|
||
|
<br>
|
||
|
# We will only set the value
|
||
|
once, i.e. the first time the
|
||
|
<br>
|
||
|
# gh height is greater than
|
||
|
the Topo
|
||
|
<br>
|
||
|
# For each level
|
||
|
<br>
|
||
|
for i in
|
||
|
xrange(gh_Cube.shape[0]):
|
||
|
<br>
|
||
|
|
||
|
# where ( gh > topo and T == -200 ),
|
||
|
<br>
|
||
|
|
||
|
# set to t_Cube value, otherwise
|
||
|
keep
|
||
|
value already set))
|
||
|
<br>
|
||
|
|
||
|
notSet = equal(T, -200)
|
||
|
<br>
|
||
|
|
||
|
aboveGround = greater(gh_Cube[i], topo_M)
|
||
|
<br>
|
||
|
|
||
|
readyToSet = logical_and(notSet, aboveGround)
|
||
|
<br>
|
||
|
|
||
|
T = where(readyToSet, t_Cube[i], T)
|
||
|
</p>
|
||
|
<p> # Convert from K to F
|
||
|
<br>
|
||
|
T_F = self.convertKtoF(T)
|
||
|
</p>
|
||
|
<p> return T_F
|
||
|
<br>
|
||
|
</p>
|
||
|
<h3 class="3Heading"><a name="AnswerSS5"></a>Answer to Exercise
|
||
|
SmartScript-5</h3>
|
||
|
ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "None"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<p>ScreenList = ["T","Td"]
|
||
|
</p>
|
||
|
<p>import SmartScript
|
||
|
</p>
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, T, Td, GridTimeRange):
|
||
|
<br>
|
||
|
"Creates a temporary
|
||
|
element,
|
||
|
TempRH"
|
||
|
</p>
|
||
|
<p> # Determine new value
|
||
|
<br>
|
||
|
Tc = .556 * (T - 32.0)
|
||
|
<br>
|
||
|
Tdc = .556 * (Td - 32.0)
|
||
|
<br>
|
||
|
Vt = 6.11 * pow(10,(Tc *
|
||
|
7.5 / (Tc + 237.3)))
|
||
|
<br>
|
||
|
Vd = 6.11 * pow(10,(Tdc
|
||
|
* 7.5 / (Tdc + 237.3)))
|
||
|
<br>
|
||
|
RH = (Vd / Vt) * 100.0<br>
|
||
|
</p>
|
||
|
<p> # clip<br>
|
||
|
RH = clip(RH, 0.0, 100.0)<br>
|
||
|
</p>
|
||
|
<p> # Create Element and add
|
||
|
Grid
|
||
|
<br>
|
||
|
self.createGrid("TempModel",
|
||
|
"TempRH", "SCALAR", RH, GridTimeRange,<br>
|
||
|
descriptiveName="TempRH",<br>
|
||
|
|
||
|
timeConstraints=(0, 3600,3600), minAllowedValue = 0.0,<br>
|
||
|
maxAllowedValue
|
||
|
= 100.0, units="%")
|
||
|
<br>
|
||
|
</p>
|
||
|
<h3><a name="AnswerSS6"></a>Answer to Exercise SmartScript-6</h3>
|
||
|
ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "Wx"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<p>import SmartScript
|
||
|
</p>
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, PoP, Wx):
|
||
|
<br>
|
||
|
# Assign Wx based on PoP
|
||
|
</p>
|
||
|
<p> # Separate Wx into
|
||
|
components
|
||
|
<br>
|
||
|
wxValues = Wx[0]
|
||
|
<br>
|
||
|
keys = Wx[1]
|
||
|
</p>
|
||
|
<p> wxValues = where(
|
||
|
less(PoP,
|
||
|
20),
|
||
|
self.getIndex("<NoCov>:<NoWx>:<NoInten>:<NoVis>:",keys),
|
||
|
wxValues)
|
||
|
<br>
|
||
|
wxValues =
|
||
|
where(logical_and(
|
||
|
greater_equal(PoP, 20), less(PoP, 35)),
|
||
|
self.getIndex("Chc:R:-:<NoVis>:"
|
||
|
,keys), wxValues)
|
||
|
<br>
|
||
|
wxValues =
|
||
|
where(logical_and(
|
||
|
greater_equal(PoP, 35), less(PoP, 55)),
|
||
|
self.getIndex("Sct:RW:m:<NoVis>:"
|
||
|
,keys), wxValues)
|
||
|
<br>
|
||
|
wxValues =
|
||
|
where(greater_equal(PoP,
|
||
|
55), self.getIndex("Wide:R:+:<NoVis>:" ,keys), wxValues)
|
||
|
</p>
|
||
|
<p> return (wxValues, keys)
|
||
|
</p>
|
||
|
<h3><a name="AnswerSS7"></a>Answer to Exercise SmartScript-7</h3>
|
||
|
ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "PoP"
|
||
|
<br>
|
||
|
from numpy import *
|
||
|
<p>import SmartScript
|
||
|
</p>
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, PoP, Wx):
|
||
|
<br>
|
||
|
# Assign PoP based
|
||
|
on Wx
|
||
|
</p>
|
||
|
<p> PoP =
|
||
|
where(self.wxMask(Wx,
|
||
|
"<NoCov>:"), 0, PoP)
|
||
|
</p>
|
||
|
<p> # Here we
|
||
|
need
|
||
|
to require a regular expression to avoid confusion between "Chc" and
|
||
|
"SChc"
|
||
|
and "Sct" and "WSct"
|
||
|
<br>
|
||
|
PoP =
|
||
|
where(self.wxMask(Wx,
|
||
|
"^Chc:", 1), 25, PoP)
|
||
|
<br>
|
||
|
PoP =
|
||
|
where(self.wxMask(Wx,
|
||
|
"^Sct:", 1), 55, PoP)
|
||
|
</p>
|
||
|
<p> PoP =
|
||
|
where(self.wxMask(Wx,
|
||
|
"Wide:"), 80, PoP)
|
||
|
</p>
|
||
|
<p> return PoP
|
||
|
</p>
|
||
|
<h3 class="3Heading"><a name="AnswerProc1"></a>Answer to Exercise
|
||
|
Procedure-1</h3>
|
||
|
</div>
|
||
|
<div class="3Heading">MenuItems = ["Edit"]</div>
|
||
|
<div class="3Heading">ToolList = [</div>
|
||
|
<div class="3Heading">
|
||
|
("AdjustValue_Up", "variableElement"),</div>
|
||
|
<div class="3Heading">
|
||
|
("Smooth", "variableElement"),</div>
|
||
|
<div class="3Heading">
|
||
|
]</div>
|
||
|
<div class="3Heading">import SmartScript</div>
|
||
|
<div class="3Heading">class Procedure (SmartScript.SmartScript):</div>
|
||
|
<div class="3Heading"> def __init__(self, dbss):</div>
|
||
|
<div class="3Heading">
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)</div>
|
||
|
<div class="3Heading"> def execute(self, editArea,
|
||
|
timeRange,
|
||
|
varDict):</div>
|
||
|
<div class="3Heading"> #
|
||
|
Calls
|
||
|
each Smart Tool: T_Tool, PoP_Tool, Wind_Tool</div>
|
||
|
<div class="3Heading"> for
|
||
|
toolName,
|
||
|
elementName in ToolList:</div>
|
||
|
<div class="3Heading">
|
||
|
error = self.callSmartTool(toolName, elementName,</div>
|
||
|
<div class="3Heading">
|
||
|
editArea, timeRange, varDict)</div>
|
||
|
<div class="3Heading">
|
||
|
if error is not None:</div>
|
||
|
<div class="3Heading">
|
||
|
break</div>
|
||
|
<h3 class="3Heading">
|
||
|
<a name="AnswerProc2"></a>Answer to Exercise Procedure-2</h3>
|
||
|
<div class="3Heading">import SmartScript</div>
|
||
|
<div class="3Heading">VariableList = [("Model:" , "", "D2D_model")]</div>
|
||
|
<div class="3Heading">class Procedure (SmartScript.SmartScript):</div>
|
||
|
<div class="3Heading"> def __init__(self, dbss):</div>
|
||
|
<div class="3Heading">
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)</div>
|
||
|
<div class="3Heading"> </div>
|
||
|
<div class="3Heading"> def execute(self, editArea,
|
||
|
varDict):</div>
|
||
|
<div class="3Heading">
|
||
|
"""Copy
|
||
|
from model, create grids, run smart tool."""</div>
|
||
|
<div class="3Heading"> model
|
||
|
= varDict["Model:"]</div>
|
||
|
<div class="3Heading">
|
||
|
databaseID
|
||
|
= self.getDatabase(model)</div>
|
||
|
<div class="3Heading">
|
||
|
timeRange
|
||
|
= self.createTimeRange(0, 12, "Database", databaseID)</div>
|
||
|
<div class="3Heading">
|
||
|
elements
|
||
|
= ['T', 'Wind','Wx']</div>
|
||
|
<div class="3Heading">
|
||
|
self.copyCmd(elements,
|
||
|
databaseID, timeRange)</div>
|
||
|
<div class="3Heading">
|
||
|
self.createFromScratchCmd(['T'],
|
||
|
timeRange, repeat=3, duration=1)</div>
|
||
|
<div class="3Heading">
|
||
|
self.callSmartTool("ExSS4","T",
|
||
|
editArea, timeRange, varDict,</div>
|
||
|
<div class="3Heading">
|
||
|
missingDataMode="Create")</div>
|
||
|
<h3 class="3Heading">
|
||
|
<a name="AnswerProc3"></a>Answer to Exercise Procedure-3</h3>
|
||
|
**Running Revised Exercise Procedure-1 using runProcedure:
|
||
|
<p> ./runProcedure -n Proc1 -u hansen -c gfeConfig -a
|
||
|
CO_Boulder
|
||
|
-t Tonight
|
||
|
</p>
|
||
|
<p>**Revised Procedure-1 (does not use variableElement)
|
||
|
<br>
|
||
|
</p>
|
||
|
<div class="3Heading">MenuItems = ["Edit"]</div>
|
||
|
<div class="3Heading">ToolList = [</div>
|
||
|
<div class="3Heading">
|
||
|
("AdjustValue_Up", "T"),</div>
|
||
|
<div class="3Heading">
|
||
|
("Smooth", "T"),</div>
|
||
|
<div class="3Heading">
|
||
|
]</div>
|
||
|
<div class="3Heading">import SmartScript</div>
|
||
|
<div class="3Heading">class Procedure (SmartScript.SmartScript):</div>
|
||
|
<div class="3Heading"> def __init__(self, dbss):</div>
|
||
|
<div class="3Heading">
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)</div>
|
||
|
<div class="3Heading"> def execute(self, editArea,
|
||
|
timeRange,
|
||
|
varDict):</div>
|
||
|
<div class="3Heading"> #
|
||
|
Calls
|
||
|
each Smart Tool: T_Tool, PoP_Tool, Wind_Tool</div>
|
||
|
<div class="3Heading"> for
|
||
|
toolName,
|
||
|
elementName in ToolList:</div>
|
||
|
<div class="3Heading">
|
||
|
error = self.callSmartTool(toolName, elementName,</div>
|
||
|
<div class="3Heading">
|
||
|
editArea, timeRange, varDict)</div>
|
||
|
<div class="3Heading">
|
||
|
if error is not None:</div>
|
||
|
<div class="3Heading">
|
||
|
break</div>
|
||
|
<h3 class="3Heading">
|
||
|
<a name="AnswerUtil1"></a>Answer to Exercise Utility-1</h3>
|
||
|
<h4 class="3Heading">
|
||
|
New Utility named: Common</h4>
|
||
|
<div class="3Heading">import SmartScript
|
||
|
<p>class Common(SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss, eaMgr, mdMode=None,
|
||
|
toolType="numeric"):
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
<br>
|
||
|
self.setUp(eaMgr, mdMode,
|
||
|
toolType)
|
||
|
</p>
|
||
|
<p> # Include your utility methods here
|
||
|
<br>
|
||
|
def _convertFtToM(self, value):
|
||
|
<br>
|
||
|
return value/3.28084</p>
|
||
|
</div>
|
||
|
<h4 class="3Heading">
|
||
|
Smart Tool:</h4>
|
||
|
<div class="3Heading">ToolType = "numeric"
|
||
|
<br>
|
||
|
WeatherElementEdited = "T"
|
||
|
<br>
|
||
|
from Numeric import *
|
||
|
<p>import SmartScript
|
||
|
<br>
|
||
|
import Common
|
||
|
</p>
|
||
|
<p>VariableList = [("Model:" , "", "D2D_model")]
|
||
|
</p>
|
||
|
<p>class Tool (SmartScript.SmartScript):
|
||
|
<br>
|
||
|
def __init__(self, dbss):
|
||
|
<br>
|
||
|
self._dbss = dbss
|
||
|
<br>
|
||
|
|
||
|
SmartScript.SmartScript.__init__(self,
|
||
|
dbss)
|
||
|
</p>
|
||
|
<p> def execute(self, GridTimeRange, Topo, varDict):
|
||
|
<br>
|
||
|
"This tool accesses QPF
|
||
|
and tp grids directly"
|
||
|
<br>
|
||
|
self._common =
|
||
|
Common.Common(self._dbss,
|
||
|
self.eaMgr())
|
||
|
</p>
|
||
|
<p> # Convert Topo to meters
|
||
|
<br>
|
||
|
topo_M =
|
||
|
self._common._convertFtToM(Topo)
|
||
|
</p>
|
||
|
<p> # Make a sounding cubes
|
||
|
for
|
||
|
T
|
||
|
<br>
|
||
|
# Height will increase in
|
||
|
the sounding and be the
|
||
|
<br>
|
||
|
# first dimension
|
||
|
<br>
|
||
|
levels =
|
||
|
["MB1000","MB950","MB900","MB850","MB800",
|
||
|
<br>
|
||
|
|
||
|
"MB750","MB700","MB650","MB600"]
|
||
|
<br>
|
||
|
gh_Cube, t_Cube =
|
||
|
self.makeNumericSounding(
|
||
|
<br>
|
||
|
|
||
|
model, "t", levels, GridTimeRange)
|
||
|
</p>
|
||
|
<p> print "Cube shapes ",
|
||
|
gh_Cube.shape,
|
||
|
t_Cube.shape
|
||
|
</p>
|
||
|
<p> # Make an initial T grid
|
||
|
with values of -200
|
||
|
<br>
|
||
|
# This is an out-of-range
|
||
|
value to help us identify values that
|
||
|
<br>
|
||
|
# have already been set.
|
||
|
<br>
|
||
|
T = (Topo * 0) - 200
|
||
|
</p>
|
||
|
<p> # Work "upward" in the
|
||
|
cubes
|
||
|
to assign T
|
||
|
<br>
|
||
|
# We will only set the value
|
||
|
once, i.e. the first time the
|
||
|
<br>
|
||
|
# gh height is greater than
|
||
|
the Topo
|
||
|
<br>
|
||
|
# For each level
|
||
|
<br>
|
||
|
for i in
|
||
|
xrange(gh_Cube.shape[0]):
|
||
|
<br>
|
||
|
|
||
|
# where ( gh > topo and T == -200),
|
||
|
<br>
|
||
|
|
||
|
# set to t_Cube value, otherwise
|
||
|
keep
|
||
|
value already set))
|
||
|
<br>
|
||
|
|
||
|
T = where(logical_and(greater(gh_Cube[i], topo_M), equal(T,-200)),
|
||
|
t_Cube[i],
|
||
|
T)
|
||
|
</p>
|
||
|
<p> # Convert from K to F
|
||
|
<br>
|
||
|
T_F = self.convertKtoF(T)
|
||
|
</p>
|
||
|
<p> return T_F</p>
|
||
|
</div>
|