277 lines
9.4 KiB
HTML
277 lines
9.4 KiB
HTML
|
<html>
|
||
|
<title>Smart Script Class - Numerics</title>
|
||
|
<body>
|
||
|
<h1><a name="Numerics"></a>Numeric Library Methods</h1>
|
||
|
<br>
|
||
|
<a href="#getTopo">getTopo</a>
|
||
|
<br>
|
||
|
<a href="#wxMask">wxMask/discreteMask</a>
|
||
|
<br>
|
||
|
<a href="#sortUglyStr">sortUglyStr</a>
|
||
|
<br>
|
||
|
<a href="#getIndex">getIndex</a>
|
||
|
<br>
|
||
|
<a href="#encodeEditArea">encodeEditArea</a>
|
||
|
<br>
|
||
|
<a href="#decodeEditArea">decodeEditArea</a>
|
||
|
<br>
|
||
|
<a href="#getindicies">getindicies</a>
|
||
|
<br>
|
||
|
<a href="#offset">offset</a>
|
||
|
<br>
|
||
|
<a href="#agradient">agradient</a>
|
||
|
<br>
|
||
|
<a href="#diff2">diff2</a>
|
||
|
<br>
|
||
|
<a href="#getGridShape">getGridShape</a>
|
||
|
<!-- Leave this comment for formatting purposes -->
|
||
|
<hr width="100%">
|
||
|
|
||
|
<h2><a name="getTopo"></a>getTopo</h2>
|
||
|
def getTopo(self):
|
||
|
<br>
|
||
|
# Return the numeric topo grid
|
||
|
<h2><a name="wxMask"></a>wxMask</h2>
|
||
|
def wxMask(self, wx, query, isreg=0):
|
||
|
<br>
|
||
|
# Returns a numeric mask i.e.
|
||
|
a grid of 0's and 1's
|
||
|
<br>
|
||
|
# where the value is 1 if the
|
||
|
given query succeeds
|
||
|
<br>
|
||
|
# Arguments:
|
||
|
<br>
|
||
|
# wx --
|
||
|
a 2-tuple:
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
wxValues : numerical grid of byte values
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
keys : list of "ugly strings" where the index of
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
the ugly string corresponds to the byte value in
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
the wxValues grid.
|
||
|
<br>
|
||
|
# query
|
||
|
-- a text string representing a query
|
||
|
<br>
|
||
|
# isreg
|
||
|
-- if 1, the query is treated as a regular expression
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
otherwise as a literal string
|
||
|
<br>
|
||
|
# Examples:
|
||
|
<br>
|
||
|
# # Here
|
||
|
we want to treat the query as a regular expression
|
||
|
<br>
|
||
|
# PoP
|
||
|
= where(self.wxMask(wxTuple, "^Chc:", 1), maximum(40, PoP), PoP)
|
||
|
<br>
|
||
|
# # Here
|
||
|
we want to treat the query as a literal
|
||
|
<br>
|
||
|
# PoP
|
||
|
= where(self.wxMask(wxTuple, ":L:") maximum(5, PoP), PoP)
|
||
|
<br>
|
||
|
#
|
||
|
<br>
|
||
|
# See the <a
|
||
|
href="SmartTools.html#SS-Ex7">Smart
|
||
|
Tool Training Guide -- Numerical Tools and Working with Weather Section</a>
|
||
|
for more information.
|
||
|
<br>
|
||
|
<h2><a name="wxMask"></a>discreteMask</h2>
|
||
|
def wxMask(self, wx, query, isreg=0):
|
||
|
<br>
|
||
|
# Returns a numeric mask i.e.
|
||
|
a grid of 0's and 1's
|
||
|
<br>
|
||
|
# where the value is 1 if the
|
||
|
given query succeeds
|
||
|
<br>
|
||
|
# Arguments:
|
||
|
<br>
|
||
|
# wx --
|
||
|
a 2-tuple:
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
values : numerical grid of byte values
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
keys : list of "ugly strings" where the index of
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
the ugly string corresponds to the byte value in
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
the discreteValues grid.
|
||
|
<br>
|
||
|
# query
|
||
|
-- a text string representing a query
|
||
|
<br>
|
||
|
# isreg
|
||
|
-- if 1, the query is treated as a regular expression
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
otherwise as a literal string
|
||
|
<br>
|
||
|
# Examples:
|
||
|
<br>
|
||
|
# # Here
|
||
|
we want to treat the query as a regular expression
|
||
|
<br>
|
||
|
# PoP
|
||
|
= where(self.wxMask(wxTuple, "BlzrdWRN", 1), maximum(40, PoP), PoP)
|
||
|
<br>
|
||
|
# # Here
|
||
|
we want to treat the query as a literal
|
||
|
<br>
|
||
|
# PoP
|
||
|
= where(self.wxMask(wxTuple, "WintStmWRN") maximum(5, PoP), PoP)
|
||
|
<br>
|
||
|
#
|
||
|
<h2><a name="sortUglyStr"></a>sortUglyStr</h2>
|
||
|
def sortUglyStr(self, uglyStr):
|
||
|
<br>
|
||
|
# Sort the subkeys of uglyStr alphabetically.<br>
|
||
|
#<br>
|
||
|
# @param uglyStr: A key with "^"s separating subkeys<br>
|
||
|
# @type uglyStr: string<br>
|
||
|
# @return: uglyStr with alpha sorted subkeys.<br>
|
||
|
# @rtype: string<br>
|
||
|
<h2><a name="getIndex"></a>getIndex</h2>
|
||
|
def getIndex(self, uglyStr, keys):
|
||
|
<br>
|
||
|
# Returns
|
||
|
the byte value that corresponds to the
|
||
|
<br>
|
||
|
# given
|
||
|
ugly string. If the ugly string is not found a new key will be added
|
||
|
<br>
|
||
|
# and
|
||
|
the index to the new entry will be returned. This method works
|
||
|
for
|
||
|
grids
|
||
|
<br>
|
||
|
# of type
|
||
|
weather and discrete.
|
||
|
<br>
|
||
|
# Arguments:
|
||
|
<br>
|
||
|
# uglyStr:
|
||
|
a string representing a weather value or a discrete value
|
||
|
<br>
|
||
|
# keys:
|
||
|
a list of ugly strings.
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
A Wx argument represents a 2-tuple:
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
wxValues : numerical grid of byte values
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
keys : list of "ugly strings" where the index of
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
the ugly string corresponds to the byte value in the wxValues grid.
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
For example, if our keys are:
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
"Sct:RW:-:<novis>:"
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
"Chc:T:-:<novis>:"
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
"Chc:SW:-:<novis>:"
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
Then, the wxValues grid will have byte values of 0 where
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
there is "Sct:RW:-:<novis>:", 1 where there is "Chc:T:-:<novis>:"
|
||
|
<br>
|
||
|
|
||
|
#
|
||
|
and 2 where there is "Chc:SW:-:<novis>:"
|
||
|
<br>
|
||
|
#
|
||
|
<br>
|
||
|
# See the <a
|
||
|
href="SmartTools.html#SS-Ex7">Smart
|
||
|
Tool Training Guide -- Numerical Tools and Working with Weather Section</a>
|
||
|
for more information. </novis></novis></novis></novis></novis></novis>
|
||
|
<h2><a name="encodeEditArea"></a>encodeEditArea</h2>
|
||
|
def encodeEditArea(self, editArea):
|
||
|
<br>
|
||
|
# Returns a numpy mask for
|
||
|
the edit area
|
||
|
<br>
|
||
|
# "editArea" can be a named area or
|
||
|
a ReferenceData object
|
||
|
<h2><a name="decodeEditArea"></a>decodeEditArea</h2>
|
||
|
def decodeEditArea(self, mask):
|
||
|
<br>
|
||
|
# Returns a ReferenceData object for the given
|
||
|
mask
|
||
|
<h2><a name="getindicies"></a>getindicies</h2>
|
||
|
def getindicies(self, o, l):
|
||
|
<h2><a name="offset"></a>offset</h2>
|
||
|
def offset(self, a, x, y):
|
||
|
<br>
|
||
|
# Gives an offset grid for array, a,
|
||
|
by x and y points
|
||
|
<h2><a name="agradient"></a>agradient</h2>
|
||
|
def agradient(self, a):
|
||
|
<br>
|
||
|
# Gives offset grids in the "forward"
|
||
|
x and "up" y directions
|
||
|
<h2><a name="diff2"></a>diff2</h2>
|
||
|
def diff2(self, x, n=1, axis=-1):
|
||
|
<br>
|
||
|
# diff2(x,n=1,axis=-1) calculates the
|
||
|
first-order, discrete
|
||
|
<br>
|
||
|
# center difference approximation to
|
||
|
the derivative along the axis
|
||
|
<br>
|
||
|
# specified. array edges are padded
|
||
|
with adjacent values.
|
||
|
|
||
|
<h2><a name="getGridShape"></a>getGridShape</h2>
|
||
|
def getGridShape(self):
|
||
|
<br>
|
||
|
# Get the grid shape from the GridLocation stored in the parm manager.<br>
|
||
|
#<br>
|
||
|
# @return: The number of data points in the X and Y directions.<br>
|
||
|
# @rtype: 2-tuple of int<br>
|