481 lines
15 KiB
HTML
481 lines
15 KiB
HTML
<html>
|
|
<title>Smart Script Class - Utilities</title>
|
|
<body>
|
|
|
|
<h1><a name="Util"></a>Utilities</h1>
|
|
<br>
|
|
<a href="#findDatabase">findDatabase</a>
|
|
<br>
|
|
<a href="#getDatabase">getDatabase</a>
|
|
<br>
|
|
<a href="#getTimeRange">getTimeRange</a>
|
|
<br>
|
|
<a href="#createTimeRange">createTimeRange</a>
|
|
<br>
|
|
<a href="#getSamplePoints">getSamplePoints</a>
|
|
<br>
|
|
<a href="#dayTime">dayTime</a>
|
|
<br>
|
|
<a href="#determineTimeShift">determineTimeShift</a>
|
|
<br>
|
|
<a href="#getEditArea">getEditArea</a>
|
|
<br>
|
|
<a href="#saveEditArea">saveEditArea</a>
|
|
<br>
|
|
<a href="#setActiveEditArea">setActiveEditArea</a>
|
|
<br>
|
|
<a href="#clearActiveEditArea">clearActiveEditArea</a>
|
|
<br>
|
|
<a href="#setActiveElement">setActiveElement</a>
|
|
<br>
|
|
<a href="#getActiveElement">getActiveElement</a>
|
|
<br>
|
|
<a href="#getGridCellSwath">getGridCellSwath</a>
|
|
<br>
|
|
<a href="#getLatLon">getLatLon</a>
|
|
<br>
|
|
<a href="#getLatLonGrids">getLatLonGrids</a>
|
|
<br>
|
|
<a href="#getGridCell">getGridCell</a>
|
|
<br>
|
|
<a href="#getGrid2DBit">getGrid2DBit</a>
|
|
<br>
|
|
<a href="#getGridTimes">getGridTimes</a>
|
|
<br>
|
|
<a href="#getExprName">getExprName</a>
|
|
<br>
|
|
<a href="#getModelName">getModelName</a>
|
|
<br>
|
|
<a href="#getD2Dmodel">getD2Dmodel</a>
|
|
<br>
|
|
<a href="#getParm">getParm</a>
|
|
<br>
|
|
<a href="#getParmByExpr">getParmByExpr</a>
|
|
<br>
|
|
<a href="#cacheElements">cacheElements</a>
|
|
<br>
|
|
<a href="#unCacheElements">unCacheElements</a>
|
|
<br>
|
|
<a href="#loadWEGroup">loadWEGroup</a>
|
|
<br>
|
|
<a href="#unloadWE">unloadWE</a>
|
|
<br>
|
|
<a href="#saveElements">saveElements</a>
|
|
<br>
|
|
<a href="#publishElements">publishElements</a>
|
|
<br>
|
|
<a href="#combineMode_">combineMode</a>
|
|
<br>
|
|
<a href="#setCombineMode">setCombineMode</a>
|
|
<br>
|
|
<a href="#getVectorEditMode">getVectorEditMode</a>
|
|
<br>
|
|
<a href="#setVectorEditMode">setVectorEditMode</a>
|
|
<br>
|
|
<a href="#getConfigItem">getConfigItem</a>
|
|
<br>
|
|
<a href="#esat">esat</a>
|
|
<!-- Leave this comment for formatting purposes -->
|
|
<hr width="100%">
|
|
|
|
|
|
<h2>
|
|
<a name="findDatabase"></a>findDatabase</h2>
|
|
def findDatabase(self, databaseName, version=0):
|
|
<br>
|
|
# Return a database id.
|
|
<br>
|
|
# databaseName can have the appended
|
|
type. E.g. "NAM" or "D2D_NAM"
|
|
<br>
|
|
# version is 0 (most recent), -1
|
|
(previous),
|
|
-2, etc.
|
|
<br>
|
|
# E.g.
|
|
<br>
|
|
# databaseID =
|
|
self.findDatabase("NAM",0)
|
|
<br>
|
|
# returns most recent NAM model
|
|
<h2><a name="getDatabase"></a>getDatabase</h2>
|
|
def getDatabase(self, databaseString):
|
|
<br>
|
|
# Return a database id.
|
|
<br>
|
|
# databaseString is the result of a
|
|
VariableList entry of type
|
|
<br>
|
|
# "model" or "D2D_model"
|
|
<h2><a name="getTimeRange"></a>getTimeRange</h2>
|
|
def getTimeRange(self, timeRangeName):
|
|
<br>
|
|
# Returns TimeRange given
|
|
a time range name
|
|
<br>
|
|
# as defined in the GFE
|
|
<br>
|
|
# E.g.
|
|
<br>
|
|
# timeRange = self.getTimeRange("Today")
|
|
<h2><a name="createTimeRange"></a>createTimeRange</h2>
|
|
def createTimeRange(self, startHour, endHour, mode="LT", dbID=None):
|
|
<br>
|
|
# Returns TimeRange given
|
|
by:
|
|
<br>
|
|
# startHour, endHour
|
|
<br>
|
|
# (range is startHour up to and not
|
|
including endHour)
|
|
<br>
|
|
# startHour and endHour are relative
|
|
to midnight of the
|
|
<br>
|
|
# current day either in Local or Zulu
|
|
time (see below)
|
|
<br>
|
|
# mode can be:
|
|
<br>
|
|
# "LT" : the startHour and endHour are
|
|
relative to local time
|
|
<br>
|
|
# "Zulu": relative to Zulu time,
|
|
<br>
|
|
# "Database": relative to a database
|
|
(e.g. model time.
|
|
<br>
|
|
# In this case, the databaseID for the
|
|
model must
|
|
<br>
|
|
# be supplied (see findDatabase)
|
|
<br>
|
|
#
|
|
<br>
|
|
# E.g.
|
|
<br>
|
|
# timeRange =
|
|
self.createTimeRange(0,121,"Zulu")
|
|
<br>
|
|
# databaseID = self.findDatabase("NAM")
|
|
<br>
|
|
# timeRange =
|
|
self.createTimeRange(120,241,"Database",databaseID)
|
|
<h2><a name="getSamplePoints"></a>getSamplePoints</h2>
|
|
def getSamplePoints(self, sampleSetName=None):
|
|
<br>
|
|
# Return a list of x,y tuples
|
|
representing
|
|
sample points
|
|
<br>
|
|
# sampleSet is the name of a saved
|
|
sample
|
|
set
|
|
<br>
|
|
# if sampleSet is None, the sample
|
|
points
|
|
will be
|
|
<br>
|
|
# those currently displayed on the GFE
|
|
|
|
|
|
<h2><a name="dayTime"></a>dayTime</h2>
|
|
def dayTime(self, timeRange, startHour=6, endHour=18):
|
|
<br>
|
|
# Return 1 if start of timeRange is
|
|
between the
|
|
<br>
|
|
# startHour and endHour, Return 0
|
|
otherwise.
|
|
<br>
|
|
# Assume timeRange is GMT and convert
|
|
to local time.
|
|
<h2><a name="determineTimeShift"></a>determineTimeShift</h2>
|
|
def determineTimeShift(self):
|
|
<br>
|
|
# Returns the difference: Local time
|
|
- GMT in seconds
|
|
<h2><a name="getEditArea"></a>getEditArea</h2>
|
|
def getEditArea(self, editAreaName):
|
|
<br>
|
|
# Returns a ReferenceData object
|
|
given an edit area name
|
|
<br>
|
|
# as defined in the GFE
|
|
<h2><a name="saveEditArea"></a>saveEditArea</h2>
|
|
def saveEditArea(self, editAreaName, refData):
|
|
<br>
|
|
# Saves the ReferenceData object
|
|
with the given name
|
|
<h2><a name="setActiveEditArea"></a>setActiveEditArea</h2>
|
|
def setActiveEditArea(self, area):
|
|
<br>
|
|
# Set the ReferenceData area to
|
|
be the active one in the GFE
|
|
<br>
|
|
# Note: This will not take effect until
|
|
AFTER the smart tool or
|
|
<br>
|
|
# procedure is finished executing.
|
|
<h2><a name="clearActiveEditArea"></a>clearActiveEditArea</h2>
|
|
def clearActiveEditArea(self):
|
|
<br>
|
|
# Clear the active edit area in the
|
|
GFE
|
|
<h2><a name="setActiveElement"></a>setActiveElement</h2>
|
|
def setActiveElement(self, model, element, level, timeRange,
|
|
colorTable=None,
|
|
minMax=None, fitToData=0):
|
|
<br>
|
|
# Set the given element to the active
|
|
one in the GFE
|
|
<br>
|
|
# A colorTable name may be given.
|
|
<br>
|
|
# A min/max range for the colorTable
|
|
may be given.
|
|
<br>
|
|
# If fitToData = 1, the color table
|
|
is fit to the data
|
|
<br>
|
|
#
|
|
<br>
|
|
# Example:
|
|
<br>
|
|
# self.setActiveElement("ISCDisc",
|
|
WEname+"Disc",
|
|
"SFC", GridTimeRange,
|
|
<br>
|
|
# colorTable="Discrepancy",
|
|
minMax=(-20,+20),
|
|
<br>
|
|
# fitToData=1)
|
|
<br>
|
|
#
|
|
<h2><a name="getActiveElement"></a>getActiveElement</h2>
|
|
def getActiveElement(self):
|
|
<br>
|
|
# Return the parm for the current active
|
|
element
|
|
<h2><a name="getGridCellSwath"></a>getGridCellSwath</h2>
|
|
def getGridCellSwath(self, editArea, cells):
|
|
<br>
|
|
# Returns a ReferenceData swath
|
|
of the given
|
|
<br>
|
|
# number of cells around the given an
|
|
edit area.
|
|
<br>
|
|
# The edit area must not be a query.
|
|
<h2><a name="getLatLon"></a>getLatLon</h2>
|
|
def getLatLon(self, x, y):
|
|
<br>
|
|
# Get the latitude/longitude values
|
|
for the given grid point<br>
|
|
coords = Coordinate(float(x), float(y))<br>
|
|
cc2D = self.getGridLoc().latLonCenter(coords)<br>
|
|
return cc2D.y, cc2D.x
|
|
|
|
|
|
<h2><a name="getLatLonGrids"></a>getLatLonGrids</h2>
|
|
def getLatLonGrids(self):
|
|
<br>
|
|
# Get the latitude/longitude grids<br>
|
|
gridLoc = self.getGridLoc()<br>
|
|
latLonGrid = gridLoc.getLatLonGrid().__numpy__[0];<br>
|
|
latLonGrid = numpy.reshape(latLonGrid, (2,gridLoc.getNy().intValue(),<br>
|
|
gridLoc.getNx().intValue()), order='F')<br>
|
|
return latLonGrid[1], latLonGrid[0]
|
|
|
|
<h2><a name="getGridCell"></a>getGridCell</h2>
|
|
def getGridCell(self, lat, lon):
|
|
<br>
|
|
# Get the corresponding x,y values for
|
|
the given lat/lon
|
|
<br>
|
|
# Return None, None if the lat/lon is
|
|
outside the grid domain
|
|
<h2><a name="getGrid2DBit"></a>getGrid2DBit</h2>
|
|
def getGrid2DBit(self, editArea):
|
|
<br>
|
|
# Returns a Grid of on/off values
|
|
indicating
|
|
whether
|
|
<br>
|
|
# or not the grid point is in the given
|
|
edit area.
|
|
<br>
|
|
# This could be used as follows in a
|
|
Smart Tool:
|
|
<br>
|
|
# def preProcessGrid(self):
|
|
<br>
|
|
# editArea = self.getEditArea("Area1")
|
|
<br>
|
|
# self.__area1Bits =
|
|
self.getGrid2DBit(editArea)
|
|
<br>
|
|
# editArea = self.getEditArea("Area2")
|
|
<br>
|
|
# self.__area2Bits =
|
|
self.getGrid2DBit(editArea)
|
|
<br>
|
|
#
|
|
<br>
|
|
# def execute(self, x, y):
|
|
<br>
|
|
# if self.__area1Bits.get(x,y) == 1:
|
|
<br>
|
|
# <process a="" point="" in=""
|
|
area1="">
|
|
<br>
|
|
# elif self.__area2Bits.get(x,y) ==
|
|
1:
|
|
<br>
|
|
# <process a="" point="" in=""
|
|
area2="">
|
|
<br>
|
|
# </process></process>
|
|
<h2><a name="getGridTimes"></a>getGridTimes</h2>
|
|
def getGridTimes(self, model, element, level, startTime, hours):
|
|
<br>
|
|
# Return the timeRange and gridTimes
|
|
for the number of hours
|
|
<br>
|
|
# FOLLOWING the given startTime
|
|
<h2><a name="getExprName"></a>getExprName</h2>
|
|
def getExprName(self, model, element, level="SFC", mostRecent=0):
|
|
<br>
|
|
# Return an expressionName for the
|
|
element
|
|
<br>
|
|
# This method is complicated because
|
|
it is handling all the
|
|
<br>
|
|
# variations for the "model" argument.
|
|
For a description
|
|
<br>
|
|
# of the variations, see the "getValue"
|
|
documentation above.
|
|
<h2><a name="getModelName"></a>getModelName</h2>
|
|
def getModelName(self, databaseString):
|
|
<br>
|
|
# Return the model name.
|
|
<br>
|
|
# databaseString is the result of a
|
|
VariableList entry of type
|
|
<br>
|
|
# "model" or "D2D_model"
|
|
<h2><a name="getD2Dmodel"></a>getD2Dmodel</h2>
|
|
def getD2Dmodel(self, model):
|
|
<br>
|
|
# Given a GFE Surface model, return
|
|
the corresponding D2D model
|
|
<h2><a name="getParm"></a>getParm</h2>
|
|
def getParm(self, model, element, level, timeRange=None, mostRecent=0):
|
|
<br>
|
|
# Returns the parm object for the given
|
|
model, element, and level
|
|
|
|
<h2><a name="getParmByExpr"></a>getParmByExpr</h2>
|
|
def getParmByExpr(self, exprName):
|
|
<br>
|
|
# Returns the parm object for the given expression
|
|
<h2><a name="cacheElements"></a>cacheElements</h2>
|
|
def cacheElements(self, elementNames):
|
|
<br>
|
|
# This routine is deprecated - caching is controlled by the system.
|
|
<h2><a name="unCacheElements"></a>unCacheElements</h2>
|
|
def unCacheElements(self, elementNames):
|
|
<br>
|
|
# This routine is deprecated<br>
|
|
# Users may still call this method<br>
|
|
# to delete temporary parms in the parm manager.
|
|
<h2><a name="loadWEGroup"></a>loadWEGroup</h2>
|
|
def loadWEGroup(self, groupName):
|
|
<br>
|
|
# Load the given weather element group
|
|
into the GFE
|
|
<h2><a name="unloadWE"></a>unloadWE</h2>
|
|
def unloadWE(self, model, element, level, mostRecent=0):
|
|
<br>
|
|
# Unload the given weather element from GFE
|
|
<h2><a name="saveElements"></a>saveElements</h2>
|
|
def saveElements(self, elementList):
|
|
<br>
|
|
# Save the given Fcst elements to the
|
|
server
|
|
<br>
|
|
# Example:
|
|
<br>
|
|
# self.saveElements(["T","Td"])
|
|
<h2><a name="publishElements"></a>publishElements</h2>
|
|
def publishElements(self, elementList, timeRange):
|
|
<br>
|
|
# Publish the given Fcst elements to
|
|
the server
|
|
<br>
|
|
# over the given time range
|
|
<br>
|
|
# Example:
|
|
<br>
|
|
# self.publishElements(["T","Td"],
|
|
timeRange)
|
|
<h2><a name="combineMode_"></a><a name="combineMode"></a>combineMode</h2>
|
|
def combineMode(self):
|
|
<br>
|
|
# returns 1 if we are in COMBINE mode
|
|
and 0 if not
|
|
<br>
|
|
|
|
<h2><a name="setCombineMode"></a>setCombineMode</h2>
|
|
def setCombineMode(self):
|
|
<br>
|
|
# call it like this
|
|
<br>
|
|
self.setCombineMode("Replace")
|
|
<p> #or
|
|
</p>
|
|
<p> self.setCombineMode("Combine")
|
|
<br>
|
|
|
|
</p>
|
|
<h2><a name="getVectorEditMode"></a>getVectorEditMode</h2>
|
|
def getVectorEditMode(self):
|
|
<br>
|
|
# Returns Vector Edit mode in
|
|
the GFE
|
|
<br>
|
|
# mode:
|
|
<br>
|
|
#
|
|
"Magnitude
|
|
Only"
|
|
<br>
|
|
# "Vector
|
|
Only"
|
|
<br>
|
|
# "Both"
|
|
<h2><a name="setVectorEditMode"></a>setVectorEditMode</h2>
|
|
def setVectorEditMode(self, mode):
|
|
<br>
|
|
# Sets the Vector Edit mode in
|
|
the GFE
|
|
<br>
|
|
# mode:
|
|
<br>
|
|
#
|
|
"Magnitude
|
|
only"
|
|
<br>
|
|
# "Vector
|
|
only"
|
|
<br>
|
|
# "Both"
|
|
<h2><a name="getConfigItem"></a>getConfigItem</h2>
|
|
def getConfigItem(elf, itemName, default=None):
|
|
<br>
|
|
# Return the configuration file value for "itemName"<br>
|
|
# If not found, return the default given
|
|
<h2><a name="esat"></a>esat</h2>
|
|
def esat(self, temp):
|