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