Exemplo n.º 1
0
    def getWEInventory(self, modelName, WEName, level):
        allTimes = TimeRange.allTimes()
        gridInfo = self.getGridInfo(modelName, WEName, level, allTimes)
        trList = []
        for g in gridInfo:
            start = g.gridTime().startTime().unixTime()
            end = g.gridTime().endTime().unixTime()
            tr = TimeRange.TimeRange(AbsTime.AbsTime(start),
                                AbsTime.AbsTime(end))
            trList.append(tr)

        return trList
Exemplo n.º 2
0
    def getWEInventory(self, modelName, WEName, level, timeRange):
        weTR = TimeRange.allTimes().toJavaObj()
        gridInfo = self.getGridInfo(modelName, WEName, level, weTR)

        trList = []
        for g in gridInfo:
            start = g.gridTime().startTime().unixTime() * 1000
            end = g.gridTime().endTime().unixTime() * 1000
            tr = TimeRange.TimeRange(start,end)
            if tr.overlaps(timeRange):
                trList.append(tr)   

        return trList
Exemplo n.º 3
0
 def _getWEInventory(self, dbName, WEName, timeRange=None):
     # set up a timeRange if it is None
     if timeRange is None:
         timeRange = TimeRange.allTimes()
     parm = self.getParm(dbName, WEName, LEVEL)
     if parm is None:
         return []
     inv = parm.getGridInventory(timeRange.toJavaObj())
     if inv is None: self.statusBarMsg("inv is None","S")
     elif len(inv)==0: print self.statusBarMsg("PFC: len(inv)==0","S")
     trList = []
     for gd in inv:
         tr = TimeRange.TimeRange(gd.getGridTime())
         trList.append(tr)
     return trList
Exemplo n.º 4
0
 def _deleteGrids(self, entry):
     deleteGrids = entry.get("deleteGrids", None)
     if deleteGrids is None or deleteGrids == []:
         return
     self._lastCreateGrids = []  #clear it after deleting grids
     for gridEntry in deleteGrids:
         model, elementName, level, startHour, endHour = gridEntry
         if startHour == "all" or endHour == "all":
             timeRange = TimeRange.allTimes()
         else:
             gridsTR = TimeRange.TimeRange(self._gridsStartTime, self._gridsStartTime + 12 * 3600)
             timeRange = TimeRange.TimeRange(gridsTR.startTime() + startHour * 3600,
                             gridsTR.startTime() + endHour * 3600)
         self.deleteGrid(model, elementName, level, timeRange)
         self.saveElements([elementName], model)
         if entry.get("publishGrids", 0):
             self.publishElements([elementName], timeRange)
Exemplo n.º 5
0
    def __init__(self, procName, host, port, userName,
                 configFile, startTime, endTime, timeRange, editArea,
                 mutableModel, varDict):
        
        # import the config file
        prefs = loadConfig.loadPreferences(configFile)
        
        LogStream.logEvent("Configuration File: ", configFile)
        
        if mutableModel is None:
            mutableModel = prefs.getString('mutableModel')
        else:
            prefs.setValue('mutableModel', mutableModel)

        self.__dataMgr = DataManager.getInstance(None)                

        # Create Time Range
        if startTime is not None and endTime is not None:
            start = self.getAbsTime(startTime)
            end = self.getAbsTime(endTime)
            self.__timeRange = TimeRange.TimeRange(start, end)
        elif timeRange is not None:
            self.__timeRange = TimeRange.TimeRange(self.__dataMgr.getSelectTimeRangeManager().getRange(timeRange).toTimeRange());
        else:
            self.__timeRange = TimeRange.default()

        if editArea is not None:
            refID = ReferenceID(editArea)
            self.__editArea = \
                 self.__dataMgr.getRefManager().loadRefSet(refID)
        else:            
            self.__editArea = self.__dataMgr.getRefManager().emptyRefSet()                    

        LogStream.logVerbose("varDict=",varDict)
        
        runner = ProcedureRunner(procName)        

        errors = runner.getImportErrors()
        if len(errors) > 0:
            print "Error importing the following procedures:\n"
            for s in errors:
                print s
            sys.exit(1)
        
        runner.instantiate(procName, CLASS_NAME, **{'dbss':self.__dataMgr})        
        runner.run(self.__dataMgr, procName, CLASS_NAME, METHOD_NAME, varDict, self.__editArea, self.__timeRange)                    
Exemplo n.º 6
0
def main():
    LogStream.logEvent("ifpIMAGE Starting")
    
    DEFAULT_OUTPUT_DIR = '../products/IMAGE'

    #import siteConfig
    config = 'gfeConfig'
    userNameOption = 'SITE'
    #outDir = siteConfig.GFESUITE_PRDDIR + "/IMAGE"
    outDir = DEFAULT_OUTPUT_DIR
    tr = TimeRange.allTimes()
    startTime = tr.startTime()
    baseTime = None
    endTime = tr.endTime()
    usrTimeName = None    

    #port = int(siteConfig.GFESUITE_PORT)
    try:
        optlist, oargs = getopt.getopt(sys.argv[1:], "c:u:h:p:o:b:s:e:t:")
        for opt in optlist:
            if opt[0] == '-c':
                config = opt[1]
            elif opt[0] == '-u':
                userNameOption = opt[1]
            elif opt[0] == '-o':
                outDir = opt[1]
            elif opt[0] == '-s':
                startTime = decodeTimeString(opt[1])
            elif opt[0] == '-e':
                endTime = decodeTimeString(opt[1])
            elif opt[0] == '-t':
                usrTimeName = opt[1]
            elif opt[0] == '-b':
                baseTime = decodeTimeString(opt[1])

    except getopt.GetoptError, e:
        LogStream.logProblem(e)
        usage()
        raise SyntaxError, "Bad command line argument specified"
Exemplo n.º 7
0
 def adjustTimeRange(self, timeRange, adjustHours):
     # Return a time range adjusted by the given number of hours
     return TimeRange.TimeRange(timeRange.startTime() + adjustHours * 3600,
                                timeRange.endTime() + adjustHours * 3600)
Exemplo n.º 8
0
    def makeAreaHeader(self, argDict, areaLabel, issueTime, expireTime,
                       areaDictName, defaultEditAreas,
                       cityDescriptor ="Including the cities of",
                       areaList=None, includeCities=1, includeZoneNames=1,
                       includeIssueTime=1, includeCodes=1, includeVTECString=1,
                       hVTECString=None, accurateCities=False):
        # Make a UGC area header for the given areaLabel
        # Determine list of areas (there could be more than one if we are using a combination)

        if areaDictName is None or areaDictName == "None":
            return areaLabel + "\n"

        # If we didn't supply an areaList,
        #     Use combinations file or defaultEditAreas
        if areaList is None:
            combinations = argDict["combinations"]
            if combinations is not None:
                areaList = self.getCurrentAreaNames(argDict, areaLabel)
            else:
                for editArea, label in defaultEditAreas:
                    if label == areaLabel:
                        areaList = [editArea]

        try:
            # Remove suffixes if necessary
            if self._editAreaSuffix is not None:
                areaList = self.removeSuffixes(areaList, self._editAreaSuffix)
        except:
            pass

        # Access the UGC information for the area(s) if available
        accessor = ModuleAccessor.ModuleAccessor()
        areaDict = accessor.variable(areaDictName, "AreaDictionary")
        ugcCityList = []
        if areaDict is None:  # create a dummy header
            codeString = "STZxxx-"
            nameString = areaLabel
            cityString = ""
        else:
            codeString = ""
            nameString = ""
            cityString = ""
            areaList, ugcList = self.makeUGCList(areaDict, areaList)
            codeString = self.makeUGCString(ugcList)
            ugcNameList = []
            for areaName in areaList:
                if areaName in areaDict.keys():
                    if areaDict.has_key(areaName):
                        entry = areaDict[areaName]
                    else:
                        entry = {}
                        log.error(\
                          "AreaDictionary missing definition for [" + \
                          areaName + "].")
                    if entry.has_key('ugcName'):
                        ugcName = entry['ugcName']
                    else:
                        ugcName = areaName  #missing UGCname
                        log.error(\
                          "AreaDictionary missing ugcName definition for [" + \
                          areaName + "].")
                    if ugcName not in ugcNameList:
                        ugcNameList.append(ugcName)
                    if entry.has_key("ugcCities"):
                        cities = entry["ugcCities"]
                        for c in cities:
                            if len(c) and c not in ugcCityList:
                                ugcCityList.append(c)
                else:
                    ugcNameList.append(areaName)
                    log.error("AreaDictionary does not contain " +\
                      'ugcName definition for ', areaName)

            if self.alphabetizeHeaders() == 1:
                # Alphabetize both lists.
                ugcNameList.sort()
                ugcCityList.sort()

            # Build nameString and cityString strings:
            for ugcName in ugcNameList:
                nameString = nameString + ugcName + "-"

            cityString = self.punctuateList(ugcCityList)

        # Compute accurate city list
        if accurateCities and \
           len(ugcCityList) > 0 and argDict.has_key("hazards"):
            ugcCityList, cityString = self.makeAccurateCityList(areaList, \
                                        ugcCityList, argDict)

        # get the VTEC string from the HazardsTable
        VTECString = ""
        VTECRecords = []
        if argDict.has_key("hazards") and includeVTECString:
            hazards = argDict["hazards"]
            VTECString = hazards.getVTECString(areaList)
            #must have VTECString, in order to have hVTEC string
            if hVTECString is not None and len(VTECString) and len(hVTECString):
                VTECString = VTECString + hVTECString + "\n"

        # expiration time is dependent upon the passed in expiration time
        # and the VTEC strings. expireT is seconds since epoch
        if type(expireTime) is types.IntType or\
          type(expireTime) is types.FloatType:
            expireTime = AbsTime.AbsTime(int(expireTime))
        try:
            if self._fixedExpire == 1:
                fixed = 1
            else:
                fixed = 0
        except:
            fixed = 0
        expireT = self.getExpireTime(issueTime.unixTime(),
          expireTime.unixTime(), VTECString, fixedExpire = fixed)

        # format the expiration time
        expireTimeRange = TimeRange.TimeRange(AbsTime.AbsTime(expireT),
          AbsTime.AbsTime(expireT+1))
        expireTime = self.timeDisplay(expireTimeRange, "", "","%d%H%M", "")
        codeString = self.endline(codeString + "-" + expireTime + "-",
          linelength=self._lineLength, breakStr=["-"])

        # get this time zone
        thisTimeZone = os.environ["TZ"]
        zoneList = []
        # check to see if we have any areas outside our time zone
        for areaName in areaList:
            if areaName in areaDict.keys():
                entry = areaDict[areaName]
                if not entry.has_key("ugcTimeZone"):   #add your site tz
                    if thisTimeZone not in zoneList:
                        zoneList.append(thisTimeZone)
                    continue  # skip this entry
                timeZoneList = entry["ugcTimeZone"]
                if type(timeZoneList) == types.StringType:  # a single value
                    timeZoneList = [timeZoneList]   # make it into a list
                for timeZone in timeZoneList:
                    if timeZone not in zoneList:
                        zoneList.append(timeZone)

        # if the resulting zoneList is empty, put in our time zone
        if len(zoneList) == 0:
            zoneList.append(thisTimeZone)

        # if the resulting zoneList has our time zone in it, be sure it
        # is the first one in the list
        try:
            index = zoneList.index(thisTimeZone)
            if index != 0:
                del zoneList[index]
                zoneList.insert(0, thisTimeZone)
        except:
            pass

        # now create the time string
        issueTimeStr = ''
        timeStrs = []
        for timeZone in zoneList:
            timeStr = self.formatTimeString(
              issueTime.unixTime(), "%l%M %p %Z %a %b %e %Y", timeZone)
            timeStr = string.replace(timeStr, "  ", " ")
            timeStr = string.strip(timeStr)
            if timeStr not in timeStrs:
                timeStrs.append(timeStr)
        if len(timeStrs) == 1:
            issueTimeStr = timeStrs[0]
        else:
            issueTimeStr = timeStrs[0]
            for i in xrange(1, len(timeStrs)):
                issueTimeStr = issueTimeStr + " /" + timeStrs[i] + "/"

        try:
            if self._useRegionLabel == 1:
                if (areaLabel != ""):
                    nameString = areaLabel
        except:
            pass


        nameString = self.endline(nameString, linelength=self._lineLength,breakStr=["-"])
        if cityString != "":
            numCities = len(ugcCityList)
            if numCities == 1:
                def preserveCase(matchobj):
                    orig = matchobj.group(0)
                    repl = 'city'
                    retv = ''
                    for i in range(len(repl)):
                        c = repl[i]
                        if orig[i].isupper():
                             c = c.upper()
                        retv = retv + c
                    return retv
                cityDescriptor = re.sub("cities", preserveCase, cityDescriptor, flags=re.IGNORECASE)
            cityString = self.endline(cityDescriptor + " " + cityString,
              linelength=self._lineLength, breakStr=[", "])
        issueTimeStr = issueTimeStr + "\n\n"
        try:
            if self._includeHeader == 0:
                issueTimeStr = "\n"
                codeString = ""
                cityString = ""
        except:
            pass
        if includeCities == 0:
            cityString = ""
        if includeZoneNames == 0:
            nameString = ""
        if includeIssueTime == 0:
            issueTimeStr = ""
        if includeCodes == 0:
            codeString = ""
        if includeVTECString == 0:
            VTECString = ""
        header = codeString + VTECString + nameString + cityString  + issueTimeStr
        return header
Exemplo n.º 9
0
    def execute(self):

        oldTopoGrid = self.getTopo().copy()
        oldTopoGrid[greater(oldTopoGrid, 200.0)] = 200.0
        oldTopoGrid[less(oldTopoGrid, 0.0)] = 0.0
        avgTopoGrid = self.getAvgTopoGrid()
        avgTopoGridNew = self.getAvgTopoGridNew()
        maxTopoGrid = self.getMaxTopoGrid()
        maxTopoGridNew = self.getMaxTopoGridNew()
        minTopoGrid = self.getMinTopoGrid()
        minTopoGridNew = self.getMinTopoGridNew()

        thisHour = int(time.time() / 3600) * 3600
        start = AbsTime.AbsTime(thisHour)
        end = AbsTime.AbsTime(thisHour + 3600)
        tr = TimeRange.TimeRange(start, end)

        self.createGrid("Fcst",
                        "OLDTopo",
                        "SCALAR",
                        oldTopoGrid,
                        tr,
                        minAllowedValue=0.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoAvg",
                        "SCALAR",
                        avgTopoGrid,
                        tr,
                        minAllowedValue=0.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoAvgNew",
                        "SCALAR",
                        avgTopoGridNew,
                        tr,
                        minAllowedValue=-50.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoMax",
                        "SCALAR",
                        maxTopoGrid,
                        tr,
                        minAllowedValue=-50.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoMaxNew",
                        "SCALAR",
                        maxTopoGridNew,
                        tr,
                        minAllowedValue=-50.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoMin",
                        "SCALAR",
                        minTopoGrid,
                        tr,
                        minAllowedValue=-50.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        self.createGrid("Fcst",
                        "CRMTopoMinNew",
                        "SCALAR",
                        minTopoGridNew,
                        tr,
                        minAllowedValue=-50.0,
                        maxAllowedValue=10000.0,
                        precision=2)

        return
Exemplo n.º 10
0
 def getTimeRange(self, timeRangeName, argDict=None):
     # Return a timeRange corresponding to the named time range
     return TimeRange.TimeRange(
         argDict['dataMgr'].getSelectTimeRangeManager().getRange(
             timeRangeName).toTimeRange())
Exemplo n.º 11
0
    def getClosestWindGrid(self, modelName, timeTarget):
        t1 = AbsTime.AbsTime(0)
        t2 = AbsTime.current() + 300 * 24 * 3600  # 300 days out
        timeRange = TimeRange.TimeRange(t1, t2)
        siteID = self.getSiteID()
        if modelName == "Fcst":
            level = "SFC"
            elementName = "Wind"
        else:
            modelName = siteID + "_D2D_" + modelName
            level = "FHAG10"
            elementName = "wind"

        topo = self.getTopo()
        calmGrid = self.makeWindGrid(0.0, 0.0, topo.shape)
        gridInfo = []
        try:
            gridInfo = self.getGridInfo(modelName, elementName, level,
                                        timeRange)
        except Exceptions.EditActionError:
            print "No grids found for model/level:", modelName, level
            if string.find(modelName, "GFS") >= 0:
                modelName = siteID + "_D2D_" + "AVN"
                level = "BL030"
                try:
                    gridInfo = self.getGridInfo(modelName, elementName, level,
                                                timeRange)
                except Exceptions.EditActionError:
                    print "No grids found for model", modelName, "level:", level
                    print "Using calm grid."
                    return calmGrid

        if len(gridInfo) == 0:
            print "No grid info found for:", modelName, "at:", timeRange
            print "No grid info...Using calm grid."
            return calmGrid

        minDiff = 3600 * 24 * 365  # just a large number
        gridIndex = -1
        tr = None
        # figure out which grid is closest in time
        for i in xrange(len(gridInfo)):
            gridTime = gridInfo[i].gridTime()
            gTime = gridTime.startTime().unixTime()
            diff = abs(gTime - timeTarget)
            if diff < minDiff:
                tr = gridInfo[i].gridTime()
                minDiff = diff
                if diff == 0:
                    break

        if minDiff > 3 * 3600:
            print "Returning calm grid as background."
            return calmGrid

        grid = calmGrid
        # fetch the grid
        if modelName == "Fcst":
            if self.fcstWindGrids.has_key(tr):
                grid = self.fcstWindGrids[tr]
            else:
                # hunt down any grid that overlaps the timeTarget
                for gridTR in self.fcstWindGrids.keys():
                    if gridTR.contains(AbsTime.AbsTime(timeTarget)):
                        grid = self.fcstWindGrids[gridTR]
        else:
            grid = self.getGrids(modelName,
                                 elementName,
                                 level,
                                 tr,
                                 mode="First")
            grid = (grid[0] * 1.944, grid[1])

        return grid
Exemplo n.º 12
0
    def execute(self, timeRange, varDict):
        checkOnly = varDict["Check or Force:"] == "Check Only"

        # remove any temporary WEs we created
        weList = [
            "TLessThanMin", "TGreaterThanMax", "TdGreaterThanT",
            "MinGreaterThanMax", "MaxLessThanMin"
        ]
        for we in weList:
            parm = self.getParm(MODEL, we, LEVEL)
            if parm is not None:
                self.unloadWE(MODEL, we, LEVEL)

        self.setToolType("numeric")

        if timeRange is None or not timeRange.isValid():
            start = self._gmtime() - (2 * DAY_IN_SECS)  # two days ago
            end = self._gmtime() + (10 * DAY_IN_SECS)  # 10 days from now
            timeRange = TimeRange.TimeRange(start, end)

        # get all the grids for all elements upfront and update as we modify
        # any grids.  We need to do this because the GFE caches the original
        # version of all grids and there's no way yet to turn this off.

        minTRList = self.getWEInventory("MinT", timeRange)
        minTDict = self.getGrids(MODEL, "MinT", LEVEL, minTRList, mode="First")

        maxTRList = self.getWEInventory("MaxT", timeRange)
        maxTDict = self.getGrids(MODEL, "MaxT", LEVEL, maxTRList, mode="First")

        TTRList = self.getWEInventory("T", timeRange)
        tDict = self.getGrids(MODEL, "T", LEVEL, TTRList, mode="First")

        TdTRList = self.getWEInventory("Td", timeRange)
        tdDict = self.getGrids(MODEL, "Td", LEVEL, TdTRList, mode="First")

        # get the all locks by other users, so we can detect they are locked
        # before attempting to modify them
        minTLocks = self.getLocksByOthers("MinT")
        maxTLocks = self.getLocksByOthers("MaxT")
        tLocks = self.getLocksByOthers("T")
        tdLocks = self.getLocksByOthers("Td")

        # get the list of edit areas
        eaList = self.editAreaList()

        # get the local WFO domain and make a mask with it
        # local sites may wish to use a different maks so that a larger area
        # is operated on by the tool - for example marine sites may wish to
        # expand it to marine zones as well as land.
        # To change the area, simply use a locally-defined edit area instead
        # of self.getSiteID().  Example:  siteID = "CWAPlusMarineZones"
        #siteID = self.getSiteID() - this was set in A2 - changed to A1 below
        siteID = "ISC_Send_Area"
        if siteID in eaList:  # make sure the edit area is there
            siteEA = self.getEditArea(siteID)  # get the edit area
            siteMask = self.encodeEditArea(siteEA)  # make a mask with siteEA
            siteMask = siteMask.astype(bool8)
        else:
            topo = self.getGridShape()
            siteMask = ones(topo, bool8)
            print siteID, "edit area not found.  Using entire GFE domain."

        # Ensure that MinT <= MaxT first
        minMaxList = self.combineInventoryLists(minTRList, maxTRList)
        foundProblem = False
        for i in xrange(0, len(minMaxList) - 1):
            if minMaxList[i + 1] in minTRList:  # previous max modifies min
                maxTR = minMaxList[i]
                minTR = minMaxList[i + 1]
                # Make sure these TRs really exist in the inventory
                if maxTR not in maxTRList:
                    continue
                if minTR not in minTRList:
                    continue

                minGrid = minTDict[minTR]
                maxGrid = maxTDict[maxTR]

                mask = (minGrid > maxGrid) & siteMask
                if not sometrue(mask):  # make sure some points are set
                    continue

                foundProblem = True

                if checkOnly:
                    self.createGrid(MODEL,
                                    "MinGreaterThanMax",
                                    "SCALAR",
                                    mask.astype(float32),
                                    minTR,
                                    minAllowedValue=0.0,
                                    maxAllowedValue=1.0)
                else:  # force the change
                    if minTR in minTLocks:
                        msg = "Can't modify MinT grid at " + str(minTR) + \
                              " locked by another user."
                        self.statusBarMsg(msg, "S")
                        continue
                    # calculate and modify the MinT grid
                    minGrid[mask] = maxGrid[mask]
                    self.createGrid(MODEL, "MinT", "SCALAR", minGrid, minTR)
                    minTDict[minTR] = minGrid  # update the minT dictionary

            elif minMaxList[i + 1] in maxTRList:  # previous min modifies max
                minTR = minMaxList[i]
                maxTR = minMaxList[i + 1]
                # Make sure these TRs really exist in the inventory
                if maxTR not in maxTRList:
                    continue
                if minTR not in minTRList:
                    continue
                maxGrid = maxTDict[maxTR]
                minGrid = minTDict[minTR]

                mask = (maxGrid < minGrid) & siteMask
                if not sometrue(mask):  # make sure some points are set
                    continue

                foundProblem = True

                if checkOnly:
                    self.createGrid(MODEL,
                                    "MaxLessThanMin",
                                    "SCALAR",
                                    mask.astype(float32),
                                    maxTR,
                                    minAllowedValue=0.0,
                                    maxAllowedValue=1.0)
                else:  # force the change
                    if maxTR in maxTLocks:
                        msg = "Can't modify MaxT grid at " + str(maxTR) + \
                              " locked by another user."
                        self.statusBarMsg(msg, "S")
                        continue
                    # calculate and modify the MaxT grid
                    maxGrid[mask] = minGrid[mask]
                    self.createGrid(MODEL, "MaxT", "SCALAR", maxGrid, maxTR)
                    # update the minT dictionary with the modified minT grid
                    maxTDict[maxTR] = maxGrid

        # Now check for T < MinT
        for tr in minTRList:
            minTGrid = minTDict[tr]

            tInv = self.overlappingTRs(tr, TTRList)
            if tInv == []:  # empty list, keep going
                continue

            for tymeRng in tInv:
                # find points in the siteMask where T < MinT
                tGrid = tDict[tymeRng]
                tTooLow = (tGrid < minTGrid) & siteMask
                if not sometrue(tTooLow):
                    continue

                foundProblem = True

                if checkOnly:  # just make a grid showing the mask where T < MinT
                    self.createGrid(MODEL,
                                    "TLessThanMin",
                                    "SCALAR",
                                    tTooLow.astype(float32),
                                    tymeRng,
                                    minAllowedValue=0.0,
                                    maxAllowedValue=1.0)
                else:  # force T to the MinT value
                    if tymeRng in tLocks:
                        msg = "Can't modify T grid at " + str(tymeRng) + \
                              " locked by another user."
                        self.statusBarMsg(msg, "S")
                        continue
                    tGrid[tTooLow] = minTGrid[tTooLow]
                    self.createGrid(MODEL, "T", "SCALAR", tGrid, tymeRng)
                    tDict[tymeRng] = tGrid  # update the tDict

        # check for T > MaxT
        for tr in maxTRList:
            # get the grid first
            maxTGrid = maxTDict[tr]

            # then warp the end time so we include T grids ending at 01z
            startTime = tr.startTime()
            endTime = tr.endTime().unixTime()
            roundedTime = int((endTime + 43200) / 86400) * 86400 + 3600
            endTime = max(endTime, roundedTime)
            endTime = AbsTime.AbsTime(endTime)
            timeRange = TimeRange.TimeRange(startTime, endTime)

            # use the warpedTR to fetch the T inventory
            tInv = self.overlappingTRs(timeRange, TTRList)
            if tInv == []:  # empty list, keep going
                continue

            for tymeRng in tInv:
                # find points in the siteMask where T > MaxT
                tGrid = tDict[tymeRng]
                tTooHigh = (tGrid > maxTGrid) & siteMask
                if not sometrue(tTooHigh):  # make sure some points are set
                    continue

                foundProblem = True

                if checkOnly:  # just make a grid
                    self.createGrid(MODEL,
                                    "TGreaterThanMax",
                                    "SCALAR",
                                    tTooHigh.astype(float32),
                                    tymeRng,
                                    minAllowedValue=0.0,
                                    maxAllowedValue=1.0)
                else:  # force T to the MaxT value
                    if tymeRng in tLocks:
                        msg = "Can't modify T grid at " + str(tymeRng) + \
                              " locked by another user."
                        self.statusBarMsg(msg, "S")
                        continue
                    tGrid[tTooHigh] = maxTGrid[tTooHigh]
                    self.createGrid(MODEL, "T", "SCALAR", tGrid, tymeRng)
                    tDict[tymeRng] = tGrid  # update the tDict

        # Now check T < Td
        for tr in TTRList:

            # make sure there's a matching Td grid
            if not tr in TdTRList:
                continue

            tGrid = tDict[tr]
            tdGrid = tdDict[tr]

            # find points in the siteMask where Td > T
            TdTooHigh = (tdGrid > tGrid) & siteMask
            if not sometrue(TdTooHigh):  # make sure some points are set
                continue

            foundProblem = True

            if checkOnly:  # just make a grid
                self.createGrid(MODEL,
                                "TdGreaterThanT",
                                "SCALAR",
                                TdTooHigh.astype(float32),
                                tr,
                                minAllowedValue=0.0,
                                maxAllowedValue=1.0)
            else:  # force Td <= T
                if tr in tdLocks:
                    msg = "Can't modify Td grid at " + str(tInv[i]) + \
                          " locked by another user."
                    self.statusBarMsg(msg, "S")
                    continue
                tdGrid[TdTooHigh] = tGrid[TdTooHigh]
                self.createGrid(MODEL, "Td", "SCALAR", tdGrid, tr)
                tdDict[tr] = tdGrid  # update the tdDict

        if not foundProblem:
            msg = "CheckTandTd found no inconsistencies."
            self.statusBarMsg(msg, "R")
Exemplo n.º 13
0
    def process(self):
        import TimeRange
        # get list of edit areas that are part of the Zones/FireWx group
        from com.raytheon.viz.gfe.smarttool import TextFileUtil, GridCycler
        textID = TextFileUtil.getTextFile('Zones', 'editAreaGroups')
        zoneList = []
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            zoneList.append(line.rstrip())
        textFile.close()
        textID = TextFileUtil.getTextFile('FireWxZones', 'editAreaGroups')
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            zoneList.append(line.rstrip())              
        textFile.close()        

        refMgr = self.__dataMgr.getRefManager()
        # make the basic edit areas that are required, go sequentially through
        # the zoneList        
        requiredEA = ["west_half","east_half","east_one_third",
          "west_one_third", "east_two_thirds","west_two_thirds",
          "east_one_quarter", "west_one_quarter", "east_three_quarters",
          "west_three_quarters","SUPERIOR"]
        for x in xrange(len(requiredEA)):
            refData = refMgr.loadRefSet(ReferenceID(zoneList[x]))
            ea = ReferenceData(refData)
            ea.setId(ReferenceID(requiredEA[x]))
            refMgr.saveRefSet(ea)                
            #ea = self.__client.getEditAreaPolygons(zoneList[x])
            #self.__client.saveEditArea(requiredEA[x], ea)
            LogStream.logEvent("Saved ", zoneList[x], "under", requiredEA[x])

        # special EAs (source,destination)
        special = [("ISC_Send_Area","FireArea"), ("ISC_Send_Area", "area3")]
        for s in special:
            refData = refMgr.loadRefSet(ReferenceID(s[0]))
            ea = ReferenceData(refData)
            ea.setId(ReferenceID(s[1]))
            refMgr.saveRefSet(ea)             
            #ea = self.__client.getEditAreaPolygons(s[0])
            #self.__client.saveEditArea(s[1], ea)
            LogStream.logEvent("Saved ", s[0], "under", s[1])


        # topography simulated based edit areas
        # area3 = whole area, AboveElev, BelowElev
        LogStream.logEvent("Calculating topo-dependent edit areas...")        
        topo = self.__dataMgr.getParmManager().getParmInExpr("Topo", True)
        topogrid = GridCycler.getInstance().getCorrespondingResult(
                                topo, TimeRange.allTimes().toJavaObj(), "TimeWtAverage")
        topogrid = topogrid[0].getGridSlice().__numpy__[0]
        iscSend = ReferenceID('ISC_Send_Area') 
        #wholeGrid = self.__client.getEditArea("ISC_Send_Area")
        wholeGrid = refMgr.loadRefSet(iscSend).getGrid().__numpy__[0]
        topoAve = 0
        count = 0
        minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
        for x in range(minx, maxx):
            for y in range(miny, maxy): 
                if wholeGrid[y,x] == 1:
                    count = count + 1
                    topoAve = topoAve + topogrid[y,x]
        topoAve = topoAve / count
        aboveGrid = wholeGrid * 0
        belowGrid = wholeGrid * 0
        for x in xrange(topogrid.shape[1]):
            for y in xrange(topogrid.shape[0]):
                if wholeGrid[y,x] == 1:
                    if topogrid[y,x] > topoAve:
                        aboveGrid[y,x] = 1
                    else:
                        belowGrid[y,x] = 1
        # area1 and area2 need to be "BelowElev", but should be different
        # than area3
        desiredCount = 2000
        count = 0
        area1 = wholeGrid * 0
        area2 = wholeGrid * 0
        for x in xrange(topogrid.shape[1]):
            if count < desiredCount:
                for y in xrange(topogrid.shape[0]): 
                    if wholeGrid[y,x] == 0 and topogrid[y,x] < topoAve:
                        area1[y,x] = 1
                        belowGrid[y,x] = 1
                        count = count + 1
        count = 0
        for x in xrange(topogrid.shape[1]):
            if count < desiredCount:
                for y in xrange(topogrid.shape[0]): 
                    if wholeGrid[y,x] == 0 and topogrid[y,x] < topoAve and \
                      area1[y,x] == 0:
                        area2[y,x] = 1
                        belowGrid[y,x] = 1
                        count = count + 1
                
        # save all topography-dependent edit areas
        self.__saveEA("area1", area1)
        LogStream.logEvent("Saved area1 based on area2, area3, and topo <", 
          topoAve)
        self.__saveEA("area2", area2)
        LogStream.logEvent("Saved area2 based on area1, area3, and topo <", 
          topoAve)
        self.__saveEA("AboveElev", aboveGrid)
        LogStream.logEvent("Saved AboveElev based on area3 > ", topoAve)
        self.__saveEA("BelowElev", belowGrid)
        LogStream.logEvent("Saved BelowElev based on area3 <= ", topoAve)
        self.__saveEA("Ridges", aboveGrid)
        LogStream.logEvent("Saved Ridges based on area3 > ", topoAve)
        self.__saveEA("Valleys", belowGrid)
        LogStream.logEvent("Saved Valleys based on area3 < ", topoAve)
        self.__saveEA("Inland", aboveGrid)
        LogStream.logEvent("Saved Ridges based on area3 > ", topoAve)
        self.__saveEA("Coastal", belowGrid)
        LogStream.logEvent("Saved Valleys based on area3 < ", topoAve)


        #city areas, which are a small part of other edit areas
        cityBased = [("area1",["city1","city2"]), ("area2", ["city3"]),
          ("area3",["city4", "area3_pt"])]
        for baseArea,cityAreas in cityBased:
            #wholeGrid = self.__client.getEditArea(baseArea)
            wholeGrid = refMgr.loadRefSet(ReferenceID(baseArea)).getGrid().__numpy__[0]
            minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
            cNumber = 0 
            print minx, maxx, miny, maxy, wholeGrid.shape
            for x in range(minx, maxx):
                for y in range(miny, maxy): 
                    if wholeGrid[y,x] == 1:
                        if cNumber >= len(cityAreas):
                            break
                        cityGrid = numpy.logical_and(wholeGrid, 0)
                        cityGrid[y,x] = 1
                        self.__saveEA(cityAreas[cNumber], cityGrid.astype('int8'))
                        LogStream.logEvent("Saved ", cityAreas[cNumber], 
                          "based on:", baseArea)
                        cNumber = cNumber + 1

        # special for ISC areas for CCF database source test
        #txt = self.__eagdb["ISC"]
        #iscList = cPickle.loads(txt)
        textID = TextFileUtil.getTextFile('ISC', 'editAreaGroups')
        iscList = []
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            iscList.append(line.rstrip())
        textFile.close()
        count = 0
        while count < 6:
            for i in iscList:
                if i == "ISC_Send_Area" or i == "ISC_Tool_Area":
                    continue                
                wholeGrid = refMgr.loadRefSet(ReferenceID(i)).getGrid().__numpy__[0]                
                minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
                if minx == -1:
                    continue
                ok = 1
                print minx, maxx, miny, maxy, wholeGrid.shape
                for x in range(minx, maxx):
                    if ok:
                        for y in range(miny, maxy):
                            if wholeGrid[y,x] == 1:
                                ptGrid = numpy.logical_and(wholeGrid, 0)
                                ptGrid[y,x] = 1
                                name = "isc" + `count`
                                self.__saveEA(name, ptGrid.astype('int8'))
                                requiredEA.append(name)
                                LogStream.logEvent("Saved ", name, 
                                  "based on ", i)
                                ok = 0
                                break
                    else:
                        break
                            
                count = count + 1
                if count > 6:
                    break
 
        

        # store an edit area group with all of the generated edit areas                
        requiredEA.append("FireArea")
        requiredEA.append("AboveElev")
        requiredEA.append("BelowElev")
        requiredEA.append("Valleys")
        requiredEA.append("Ridges")
        requiredEA.append("Inland")
        requiredEA.append("Coastal")
        requiredEA.append("city1")
        requiredEA.append("city2")
        requiredEA.append("city3")
        requiredEA.append("city4")
        requiredEA.append("area3")
        requiredEA.append("area2")
        requiredEA.append("area1")
        
        refMgr.saveGroup("GFETest", JUtil.pylistToJavaStringList(requiredEA))
        
        time.sleep(.5)
Exemplo n.º 14
0
    def execute(self, varDict, editArea):

        mutableID = self.mutableID()

        # List of elements
        # See if we should copy from ISC. If so, do the copy and exit
        smoothThreatGrid = varDict["Grid Smoothing?"]
        makeOption = varDict["Make grids from \nPHISH, ISC, or Manually?"]
        topodb = "NED"
        #topodb = varDict["Topographic Database?"]

        stormSurgeEditArea = self.getEditArea("StormSurgeWW_EditArea")
        ssea = self.encodeEditArea(stormSurgeEditArea)

        Topo = self.getAvgTopoGrid(topodb)

        confidenceStr = varDict["Forecast Confidence?"]

        # extract the percent value from this string
        pctPos = confidenceStr.find("%")
        pctStr = confidenceStr[pctPos - 2:pctPos]

        threatWEName = "StormSurgeThreat"

        #print "pctStr is: ", pctStr

        if makeOption == "PHISH":

            # Now get the psurge
            surgePctGrid = self.getExceedanceHeight(pctStr, "FHAG0")
            surgePctGridNAVD = self.getExceedanceHeight(pctStr, "SFC")

            if surgePctGrid is None or surgePctGridNAVD is None:
                return

            #print "retrieved my grids"
#
# The following lines are the gridded vdatum corrections.
#
            msltonavd = self.getMSLtoNAVD()
            msltomllw = self.getMSLtoMLLW()
            msltomhhw = self.getMSLtoMHHW()
            navdtomllw = self.getNAVDtoMLLW()
            navdtomhhw = self.getNAVDtoMHHW()

            # Apply 3x3 smooth within the surge zone
            # for values greater than 1 as to not underplay areas adjacent to zero value pixels.
            # If you apply a smoother, for consistency among storm surge plus tide and derived
            # grids, it must be done here.

            if smoothThreatGrid is "Yes":
                surgePctGrid = np.where(np.greater(surgePctGrid, 0.0),
                                        self.smoothGrid(surgePctGrid, 3),
                                        surgePctGrid)
                surgePctGridNAVD = np.where(
                    np.greater(surgePctGridNAVD, -10.0),
                    self.smoothGrid(surgePctGridNAVD, 3), surgePctGridNAVD)

            mask1 = np.logical_and(np.greater(msltonavd, -80.0),
                                   np.greater(surgePctGridNAVD, -80.0))
            surgePctGridMSL = np.where(mask1, surgePctGridNAVD - msltonavd,
                                       np.float32(-80.0))  # MSL Grid
            surgePctGridMLLW = np.where(np.greater(navdtomllw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
                                        surgePctGridNAVD + navdtomllw, np.float32(-80.0)) # MLLW Grid
            surgePctGridMHHW = np.where(np.greater(navdtomhhw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
                                        surgePctGridNAVD + navdtomhhw, np.float32(-80.0)) # MHHW Grid
            surgeDiffMLLWMHHW = np.where(np.greater(surgePctGridMLLW,-80.0) & np.greater(surgePctGridMHHW, -80.0), \
                                         surgePctGridMLLW-surgePctGridMHHW, np.float32(-80.0)) # Diff Grid Between MLLW and MHHW

            self.makePhishGrid(pctStr, "FHAG0", smoothThreatGrid, mutableID)

        elif makeOption == "ISC":

            elementList = [
                "InundationMax", "InundationTiming", "SurgeHtPlusTideMSL",
                "SurgeHtPlusTideMLLW", "SurgeHtPlusTideNAVD",
                "SurgeHtPlusTideMHHW"
            ]
            surgePctGrid, surgePctGridMSL, surgePctGridMLLW, surgePctGridMHHW, surgePctGridNAVD = self.copyISCGridstoFcst(
                elementList, mutableID)
            if surgePctGrid is None or surgePctGridMSL is None or surgePctGridMLLW is None or \
               surgePctGridMHHW is None or surgePctGridNAVD is None:
                return

        elif makeOption == "Manually Replace" or makeOption == "Manually Add":

            inundationHeight = float(varDict["Inundation Height:"])
            inunStartHour = float(varDict["Start Hour for Inundation Timing"])
            inunEndHour = float(varDict["End Hour for Inundation Timing"])

            selectedMask = self.encodeEditArea(editArea)
            if not selectedMask.any():
                self.statusBarMsg(
                    "Please define an area over which to assign the inundation values.",
                    "S")
                return

            modifyMask = selectedMask & ssea
            if not modifyMask.any():
                self.statusBarMsg(
                    "Please define an area that intersects the StormSurgeEditArea to assign the inundation values.",
                    "S")
                return  # Calculate the intersection of the SSEditArea and selected editAre

            if inunStartHour >= inunEndHour:
                self.statusBarMsg(
                    "Please define the end hour after the start hour.", "S")
                return

            surgePctGrid = self.empty()

            # Fetch the old grids if we're adding
            if varDict[
                    "Make grids from \nPHISH, ISC, or Manually?"] == "Manually Add":
                imTRList = self.getWEInventory(mutableID, "InundationMax",
                                               "SFC")
                print "InnundationTFList:", imTRList
                if len(imTRList) > 0:
                    print "got pctSurgegrid"
                    imTR = imTRList[0]
                    surgePctGrid = self.getGrids(mutableID, "InundationMax",
                                                 "SFC", imTR)

            surgePctGrid[modifyMask] = inundationHeight

            # Make the timing grids
            baseTime = self.baseGuidanceTime()
            #            trList = self.makeTimingTRs(baseTime)
            trList, timingGrids = self.getTimingGrids()
            #             print "TRLIST IS: ", trList

            for i in range(len(trList)):
                # only modify grid in the specified time range
                start = trList[i].startTime().unixTime()
                end = trList[i].endTime().unixTime()

                if (start - baseTime) / 3600 >= inunStartHour and (
                        end - baseTime) / 3600 <= inunEndHour:
                    timingGrids[i] = surgePctGrid  # populate only where needed

            timeRange = TimeRange.allTimes()
            self.deleteCmd(
                ["InundationTiming"], timeRange
            )  #self.createGrid(mutableID, "InundationTiming", "SCALAR", timingGrids[i], trList[i])
            for i in range(len(trList)):
                self.createGrid(mutableID, "InundationTiming", "SCALAR",
                                timingGrids[i], trList[i])

        #threatWEName = "StormSurgeThreat"

        threatKeys = self.getDiscreteKeys(threatWEName)

        # Define a mapping between UI names and key names
        # keyMap = {"Very Low" :"Very Low",
        keyMap = {
            "Elevated": "Elevated",
            "Moderate": "Mod",
            "High": "High",
            "Extreme": "Extreme",
        }

        threshDict = {}  # a dict to store thresholds from the UI

        for key in keyMap.keys():

            if keyMap[key] == "Extreme":
                threshDict[keyMap[key]] = 9
            elif keyMap[key] == "High":
                threshDict[keyMap[key]] = 6
            elif keyMap[key] == "Mod":
                threshDict[keyMap[key]] = 3
            elif keyMap[key] == "Elevated":
                threshDict[keyMap[key]] = 1

            #print "threshDict[keyMap[key]]: ", keyMap[key], threshDict[keyMap[key]]

        # make a timeRange - 6 hours long
        elementList = [
            "StormSurgeThreat", "InundationMax", "SurgeHtPlusTideMSL",
            "SurgeHtPlusTideMLLW", "SurgeHtPlusTideNAVD", "SurgeHtPlusTideMHHW"
        ]

        # make a new timeRange that will be used to create new grids
        timeRange = self.makeNewTimeRange(6)

        # Remove old guidance grids and replace them with the new grids
        # Delete the old grids first
        cTime = int(self._gmtime().unixTime() / 3600) * 3600
        startTime = AbsTime.AbsTime(cTime - 48 * 3600)
        endTime = startTime + 240 * 3600
        deleteTimeRange = TimeRange.TimeRange(startTime, endTime)

        for elem in elementList:
            self.deleteCmd([elem], deleteTimeRange)

        if makeOption != "Manually Replace" and makeOption != "Manually Add":
            self.createGrid(mutableID,
                            "SurgeHtPlusTideMSL",
                            "SCALAR",
                            surgePctGridMSL,
                            timeRange,
                            precision=2)
            self.createGrid(mutableID,
                            "SurgeHtPlusTideMLLW",
                            "SCALAR",
                            surgePctGridMLLW,
                            timeRange,
                            precision=2)
            self.createGrid(mutableID,
                            "SurgeHtPlusTideNAVD",
                            "SCALAR",
                            surgePctGridNAVD,
                            timeRange,
                            precision=2)
            self.createGrid(mutableID,
                            "SurgeHtPlusTideMHHW",
                            "SCALAR",
                            surgePctGridMHHW,
                            timeRange,
                            precision=2)

        # Make the grid. Start with the existing grid if we have one otherwise zeros
        coastalThreat = self.empty(np.int8)

        self.createGrid(mutableID,
                        "InundationMax",
                        "SCALAR",
                        surgePctGrid,
                        timeRange,
                        precision=2)

        # Yet another list to define the order in which we set grid values
        # This order must be ranked lowest to highest
        #keyList = ["Very Low", "Elevated", "Mod", "High", "Extreme"]
        keyList = ["Elevated", "Mod", "High", "Extreme"]

        # Set the grid values based on the surgePctGrid grid and thresholds
        for key in keyList:
            #print "THRESHOLD FOR KEY IS: ", key, threshDict[key]
            thresh = threshDict[key]
            keyIndex = self.getIndex(key, threatKeys)
            coastalMask = ssea & np.greater_equal(surgePctGrid, thresh)
            coastalThreat[coastalMask] = keyIndex

#       create the CoastalThreat Grid
        self.createGrid(mutableID,
                        threatWEName,
                        "DISCRETE", (coastalThreat, threatKeys),
                        timeRange,
                        discreteKeys=threatKeys,
                        discreteOverlap=0,
                        discreteAuxDataLength=2,
                        defaultColorTable="Hazards")

        return
Exemplo n.º 15
0
    def execute(self, timeRange):
        mutableID = self.mutableID()
        newTerrainDbId = self.findDatabase("EditTopo_NewTerrain")
        if mutableID != newTerrainDbId:
            DisplayMessageDialog.openError(
                "Invalid Mutable Database",
                "You must be using the NewTerrain GFE configuration to run this procedure.\n"
                "Please restart CAVE and select the NewTerrain GFE configuration."
            )
            return

        newTopo = self.getGrids(newTerrainDbId,
                                "NewTopo",
                                "SFC",
                                timeRange,
                                mode="First")

        baseTerrainDbId = self.findDatabase("EditTopo_BaseTerrain")
        gmted = self.getGrids(baseTerrainDbId,
                              "GMTED",
                              "SFC",
                              timeRange,
                              mode="First")
        gtopo = self.getGrids(baseTerrainDbId,
                              "GTOPO",
                              "SFC",
                              timeRange,
                              mode="First")

        topoDbId = self.findDatabase("EditTopo_Topo")
        topo = self.getGrids(topoDbId, "Topo", "SFC", timeRange, mode="First")

        self.unloadWEs(newTerrainDbId, [("newTopoMinusTopo", "SFC"),
                                        ("GMTEDminusGTOPO", "SFC"),
                                        ("newEdits", "SFC"),
                                        ("currentEdits", "SFC")])

        delta = newTopo - topo
        maxVal = numpy.nanmax(delta)
        minVal = numpy.nanmin(delta)
        maxDelta = max(1.0, abs(maxVal), abs(minVal))
        self.createGrid(newTerrainDbId,
                        "newTopoMinusTopo",
                        "SCALAR",
                        delta,
                        TimeRange.allTimes(),
                        "NewTopo - Topo", (0, 60, 60),
                        1,
                        -maxDelta,
                        maxDelta,
                        "ft",
                        defaultColorTable="GFE/Delta")

        delta = gmted - gtopo
        maxVal = numpy.nanmax(delta)
        minVal = numpy.nanmin(delta)
        maxDelta = max(1.0, abs(maxVal), abs(minVal))
        self.createGrid(newTerrainDbId,
                        "GMTEDminusGTOPO",
                        "SCALAR",
                        delta,
                        TimeRange.allTimes(),
                        "GMTED - GTOPO", (0, 60, 60),
                        1,
                        -maxDelta,
                        maxDelta,
                        "ft",
                        defaultColorTable="GFE/Delta")

        delta = newTopo - gmted
        maxVal = numpy.nanmax(delta)
        minVal = numpy.nanmin(delta)
        maxDelta = max(1.0, abs(maxVal), abs(minVal))
        self.createGrid(newTerrainDbId,
                        "newEdits",
                        "SCALAR",
                        delta,
                        TimeRange.allTimes(),
                        "NewTopo - GMTED", (0, 60, 60),
                        1,
                        -maxDelta,
                        maxDelta,
                        "ft",
                        defaultColorTable="GFE/Delta")

        delta = topo - gtopo
        maxVal = numpy.nanmax(delta)
        minVal = numpy.nanmin(delta)
        maxDelta = max(1.0, abs(maxVal), abs(minVal))
        self.createGrid(newTerrainDbId,
                        "currentEdits",
                        "SCALAR",
                        delta,
                        TimeRange.allTimes(),
                        "Topo - GTOPO", (0, 60, 60),
                        1,
                        -maxDelta,
                        maxDelta,
                        "ft",
                        defaultColorTable="GFE/Delta")
Exemplo n.º 16
0
    def makePhishGrid(self, pctStr, level, smoothThreatGrid, mutableID):

        siteID = self.getSiteID()
        dbName = siteID + "_D2D_TPCSurgeProb"

        weName = "Surge" + pctStr + "Pctincr"
        #print "Attempting to retrieve: ", weName, level
        # get the StormSurgeProb inventory
        surgeTRList = self.getWEInventory(dbName, weName, level)
        if len(surgeTRList) == 0:
            self.statusBarMsg("No PHISH grid found.", "U")
            return

        # Make timeRanges for all 13 grids. Start with the beginning of the first Phish grid
        baseTime = int(surgeTRList[0].startTime().unixTime() /
                       (6 * 3600)) * (6 * 3600)  #snap to 6 hour period
        trList = self.makeTimingTRs(baseTime)

        n = 1
        for tr in trList:
            start = tr.startTime().unixTime() - 6 * 3600
            if n == 1:
                starttimeghls = tr.startTime().unixTime() - 48 * 3600
                trdelete = TimeRange.TimeRange(
                    AbsTime.AbsTime(starttimeghls - 100 * 3600),
                    AbsTime.AbsTime(starttimeghls + 100 * 3600))
                self.deleteCmd(['InundationTiming'], trdelete)
                n = n + 1
            end = tr.startTime().unixTime()
            tr6 = TimeRange.TimeRange(AbsTime.AbsTime(start),
                                      AbsTime.AbsTime(end))

            surgeTR = TimeRange.TimeRange(
                tr.startTime(),
                AbsTime.AbsTime(tr.startTime().unixTime() + 3600))
            if surgeTR in surgeTRList:
                phishGrid = self.getGrids(dbName, weName, level, surgeTR)
            else:
                phishGrid = np.zeros(self.getGridShape(), 'f')

#
# For consistency we need to add smoothing here too as we do in execute.
#
            if phishGrid is None:
                self.statusBarMsg("No PHISH grid available for:" + repr(tr),
                                  "S")
                continue

            if smoothThreatGrid is "Yes":
                phishGrid = np.where(np.greater(phishGrid, 0.0),
                                     self.smoothGrid(phishGrid, 3), phishGrid)

            grid = np.where(
                phishGrid > -100, phishGrid * 3.28,
                np.float32(-80.0))  # Convert units from meters to feet
            self.createGrid(mutableID,
                            "InundationTiming",
                            "SCALAR",
                            grid,
                            tr6,
                            precision=1)

        return
Exemplo n.º 17
0
    def copyISCGridstoFcst(self, elementList, mutableID):

        # Initialize all the grids we plan to return

        surgePctGrid = None
        surgePctGridMSL = None
        surgePctGridMLLW = None
        surgePctGridMHHW = None
        surgePctGridNAVD = None

        baseTime = self.baseGuidanceTime()

        for weName in elementList:
            iscWeName = weName + "nc"
            # get the inventory for the ISC grids
            try:
                trList = self.getWEInventory("ISC", iscWeName, "SFC")
            except:
                self.statusBarMsg(
                    "No grids found in ISC database for " + iscWeName, "S")
                return None, None, None, None, None

            if len(trList) == 0:
                self.statusBarMsg(
                    "No grids found in ISC database for " + iscWeName, "S")
                return None, None, None, None, None

            # Make sure that the ISC grids are current
            if baseTime > trList[0].startTime().unixTime():
                #if trList[0].startTime().unixTime() != baseTime:
                self.statusBarMsg(
                    "ISC grids for element " + weName +
                    " are not current. Aborting.", "S")
                return None, None, None, None, None

        # If we made it this far, delete the existing grids so there's no confusion
            if weName == "InundationTiming":
                timeRange = TimeRange.allTimes()
                self.deleteCmd(["InundationTiming"], timeRange)

            # Fetch the ISC grid and create the same grid in the Fcst database
            for tr in trList:
                grid = self.getGrids("ISC", iscWeName, "SFC", tr)
                if iscWeName == "InundationTimingnc":
                    self.createGrid(mutableID,
                                    weName,
                                    "SCALAR",
                                    grid,
                                    tr,
                                    precision=2)
                elif iscWeName == "InundationMaxnc":
                    surgePctGrid = grid
                elif iscWeName == "SurgeHtPlusTideMSLnc":
                    surgePctGridMSL = grid
                elif iscWeName == "SurgeHtPlusTideMLLWnc":
                    surgePctGridMLLW = grid
                elif iscWeName == "SurgeHtPlusTideMHHWnc":
                    surgePctGridMHHW = grid
                elif iscWeName == "SurgeHtPlusTideNAVDnc":
                    surgePctGridNAVD = grid

        return surgePctGrid, surgePctGridMSL, surgePctGridMLLW, surgePctGridMHHW, surgePctGridNAVD
Exemplo n.º 18
0
    def getWeekday_descriptor(self,
                              timeRange,
                              holidays=0,
                              shiftToLocal=0,
                              labelType="Worded",
                              today=0,
                              tomorrow=0,
                              holidayModule="Holidays",
                              nextDay24HourLabel=0,
                              splitDay24HourLabel=0):
        # Return a weekday text string
        # Arguments:
        #  timeRange
        #  holidays : if 1, the holiday file will be consulted
        #  shiftToLocal : if 1, will shift the given time range to local time
        #  labelType : See Labels dictionary below for types
        #  today : if 1, Today, Tonight,
        #    will be returned instead of corresponding weekday name
        #  tomorrow: if 1, Tomorrow, Tomorrow Night
        #    will be returned instead of corresponding weekday name
        #  holidayModule: file containing holiday dates
        #  nextDay24HourLabel: if 1, a 24-hour time period starting
        #    after 1600, will be labeled as the next day.
        #    This is to accommodate 24 extended periods that go from
        #    6pm-6pm.
        #  splitDay24HourLabel: if 0, a 24-hour period will be labeled with
        #    simply the weekday name (e.g. Saturday)
        #    instead of including the day and night periods
        #    (e.g. Saturday and Saturday night)
        #
        # If the time range is for today AND is less than 12 hours,
        # we must accurately describe the period.
        # At some point, this may need to be coordinated with TextRules
        # timePeriod descriptors.

        currentLocalTime, shift = self.determineTimeShift()
        if shiftToLocal == 1:
            timeRange = TimeRange.TimeRange(timeRange.startTime() + shift,
                                            timeRange.endTime() + shift)
        labels = self.Labels()[labelType]
        pre = labels["PrePunctuation"]
        post = labels["PostPunctuation"]
        todayFlag = currentLocalTime.day == timeRange.startTime().day
        try:
            if self._productIssuance == "Next Day":
                todayFlag = currentLocalTime.day + 1 == timeRange.startTime(
                ).day
        except:
            pass
        startHour = timeRange.startTime().hour
        dayNight = self.getPeriod(timeRange)
        durationHours = timeRange.duration() / 3600
        if nextDay24HourLabel:
            nextDay24Hour = durationHours >= 24 and timeRange.startTime(
            ).hour > 16
        else:
            nextDay24Hour = 0
        splitDay24Hour = splitDay24HourLabel and durationHours == 24
        # Do not say "Night" if:
        #    startHour is between midnight self.DAY (e.g. 6 am)
        nightTimeFlag = durationHours <= 12 and dayNight == self.NIGHTTIME() \
                            and startHour > self.DAY()

        # Check for holiday
        if not splitDay24Hour and not todayFlag and holidays == 1 and \
           (dayNight == self.DAYTIME() or dayNight == self.DAYNIGHT()):

            if nextDay24Hour == 1:
                label = Holidays.getHolidayLabel(timeRange.endTime())
            else:
                label = Holidays.getHolidayLabel(timeRange.startTime())

            if label != "":
                if labelType == "CapitalWithPeriod":
                    label = label.upper()

                return pre + label + post

        # Check for today or tonight
        if today == 1:
            if todayFlag:
                if dayNight == self.DAYNIGHT():
                    # Key off of end time
                    keyRange = TimeRange.TimeRange(timeRange.endTime() - 3600,
                                                   timeRange.endTime())
                    dayNight = self.getPeriod(keyRange)
                #if durationHours == 1:
                #    label =  labels["Now"]
                if durationHours < 12 and durationHours > 1:
                    if dayNight == self.DAYTIME():
                        label = labels["Rest of Today"]
                    else:
                        label = labels["Rest of Tonight"]
                elif dayNight == self.NIGHTTIME():
                    label = labels["Tonight"]
                else:
                    label = labels["Today"]
                return pre + label + post

        # Check for tomorrow or tomorrow night
        if tomorrow == 1:
            startTime = timeRange.startTime() - 24 * 3600
            if startTime.day == currentLocalTime.day:
                if durationHours == 1:
                    label = timeRange.startTime().string() + ": "
                elif nightTimeFlag:
                    label = labels["Tomorrow"] + " " + labels["Night"]
                else:
                    label = labels["Tomorrow"]
                try:
                    if self._productIssuance == "Next Day":
                        label = "Tonight"
                except:
                    pass
                return pre + label + post

        # Week day
        weekdayName = labels["Weekday"][timeRange.startTime().weekday()]
        if durationHours == 1:
            label = self.timeDisplay(timeRange, "Zulu", "", "", "%I %p")
            if label[0] == "0":
                label = label[1:]
            label = label + " " + weekdayName
        # Check for Night and Evening
        elif nightTimeFlag:
            if durationHours <= 6:
                label = weekdayName + " " + labels["Evening"]
            else:
                label = weekdayName + " " + labels["Night"]
        elif nextDay24Hour == 1:
            # If we have a 24 hour time period starting late in the day,
            # use the next day as the label.
            label = labels["Weekday"][timeRange.endTime().weekday()]
        elif splitDay24Hour:
            # See if we are starting with a night or day period
            weekNight = weekdayName + " " + labels["Night"]
            if weekdayName[-1].isupper():
                connector = " AND "
            else:
                connector = " and "

            if startHour < self.NIGHT():
                # Monday and Monday Night OR
                # Labor Day and Monday Night
                weekDayHoliday = self.getHolidayLabel(timeRange.startTime(),
                                                      holidays)
                if weekDayHoliday != "":
                    weekdayName = weekDayHoliday
                label = weekdayName + connector + weekNight
            else:
                # Sunday Night and Monday OR
                # Sunday Night and Labor Day
                nextWeekdayName = self.getHolidayLabel(timeRange.endTime(),
                                                       holidays)
                if nextWeekdayName == "":
                    nextWeekdayName = labels["Weekday"][
                        timeRange.endTime().weekday()]
                label = weekNight + connector + nextWeekdayName
        else:
            label = weekdayName
        # Check for Evening

        return pre + label + post
Exemplo n.º 19
0
    def execute(self):
        start = int(self._gmtime().unixTime() / 3600) * 3600
        end = start + 48 * 3600
        propTR = self.GM_makeTimeRange(start, end)

        # Make sure we have a ProposedSS before we begin
        propTRList = self.GM_getWEInventory(self._ssWeName,
                                            dbase=self._ssDbName,
                                            timeRange=propTR)

        if len(propTRList) == 0:
            self.statusBarMsg("No ProposedSS Fcst grid found. Tool aborting.",
                              "S")
            return

        # Make the cwa mask
        siteID = self.getSiteID()
        cwaMask = self.encodeEditArea(siteID)

        # Check each site for any conflicts and return the list of conflicting sites
        if self.checkForAnyConflicts(cwaMask):
            self.statusBarMsg(
                "Hazard ETN conflicts between " + siteID +
                " and ProposedSS from NHC ISC database.", "U")
            return

        # If there were not any wfo hazards found, make empty grid(s) based on the ProposedSS timeRange
        hazTRList = self.GM_getWEInventory("Hazards")
        if len(hazTRList) == 0:

            # Make empty hazard grids with same timeRanges as ProposedSS
            for tr in propTRList:
                self.makeEmptyHazardGrid(tr)

        # Make new Hazards grids at the beginning and/or end, if needed
        else:
            if propTR.startTime() < hazTRList[0].startTime(
            ):  # add a new Hazard grid at the beginning
                newTR = TimeRange.TimeRange(propTR.startTime(),
                                            hazTRList[0].startTime())
                self.makeEmptyHazardGrid(newTR)

            # Check and make one at the end, if needed
            if hazTRList[-1].endTime() < propTR.endTime():
                newTR = TimeRange.TimeRange(hazTRList[-1].endTime(),
                                            propTR.endTime())
                self.makeEmptyHazardGrid(newTR)

            # Finally split the Hazards grid at the propTR
            self.splitCmd(["Hazards"], propTR)

        # Refetch the hazards inventory, since it may have changed
        hazTRList = self.GM_getWEInventory("Hazards")

        # Get the ProposedSS grid
        propGrid, propKeys = self.getGrids(self._ssDbName, self._ssWeName,
                                           "SFC", propTRList[-1])

        # First remove all SS hazards from the Hazard grid
        ssKeys = ["SS.A", "SS.W"]

        # Remove all Hazards matching any SS key
        self.removeHazards(ssKeys)

        # Now add ProposedSS keys back into the hazard grids
        for hazTR in hazTRList:

            # Only add Proposed hazards where the Hazards overlap
            if not hazTR.overlaps(propTR):
                continue

            for propKey in propKeys:
                propIndex = self.getIndex(propKey, propKeys)
                mask = propGrid == propIndex
                self._hazUtils._addHazard("Hazards",
                                          hazTR,
                                          propKey,
                                          mask,
                                          combine=1)
Exemplo n.º 20
0
    def plotWCL(self, productName):
        #extract the data fro the dictionary
        watchType = self.__inventoryDict[productName]['watchType']
        expTime = self.__inventoryDict[productName]['expTime']
        issueTime = self.__inventoryDict[productName]['issueTime']
        finalUGCList = self.__inventoryDict[productName]['finalUGCList']

        currentTime = time.time()
        startTime = None
        endTime = None

        # Select WCL to plot
        wclVersion = productName

        # This section reads the active table and decodes current watches
        activeTable = self.vtecActiveTable()

        # Remove unwanted data
        cleanTable = []
        for each in activeTable:
            if not each.has_key('pil'):
                continue
            if not each['pil'] == 'WCN':
                continue
            if not each.has_key('endTime'):
                continue
            if each['endTime'] <= currentTime:
                continue
            if not each.has_key('act'):
                continue

            if each['act'] not in ['CAN', 'EXP']:
                cleanTable.append(each)
                if startTime is None:
                    startTime = each['startTime']
                elif startTime > each['startTime']:
                    startTime = each['startTime']
                if endTime is None:
                    endTime = each['endTime']
                elif endTime > each['endTime']:
                    endTime = each['endTime']

        # Adjust start/end times based on issueTime, expTime
        if endTime is None or expTime > endTime:
            endTime = expTime
        if startTime is None or issueTime < startTime:
            startTime = issueTime

        # Round to hour
        startTime = int(startTime / 3600) * 3600

        # Change keys for this procedure
        for each in cleanTable:
            if each['phensig'] == 'SV.A':
                each['phensig'] = 'sv.a'
            else:
                each['phensig'] = 'to.a'

        # Create a master list of all IDs
        watchUGCs = []
        for each in cleanTable:
            if each['id'] not in watchUGCs:
                watchUGCs.append(each['id'])
        for each in finalUGCList:
            if each not in watchUGCs:
                watchUGCs.append(each)

        # Next, loop over the master ID list to determine the final key to
        # plot.
        finalKeys = []
        for each in watchUGCs:
            actualKey = ''
            for eachRecord in cleanTable:
                if eachRecord['id'] == each:
                    actualKey = eachRecord['phensig']
            if each in finalUGCList:
                if actualKey != '':
                    if actualKey == 'sv.a':
                        if watchType == 'SV.A':
                            actualKey = 'sv->SV'
                        else:
                            actualKey = 'sv->TO'
                    else:
                        if watchType == 'SV.A':
                            actualKey = 'to->SV'
                        else:
                            actualKey = 'to->TO'
                else:
                    actualKey = watchType
            finalKeys.append((each, actualKey))

        # Get the ending day/time to create a timeRange. Don't have to bother
        # with day groups, as watches are always < 24 hrs.
        #ensure sanity
        if abs(time.time() - startTime) > 43200:
            startTime = int(time.time() / 3600) * 3600
        if abs(time.time() - endTime) > 43200:
            endTime = int(time.time() / 3600) * 3600 + (43200)
        timeRange = TimeRange.TimeRange(AbsTime.AbsTime(startTime),
                                        AbsTime.AbsTime(endTime))

        # Create a dummy grid of zeros
        grid = self.empty(int8)

        # Define the allowed keys
        keys = [
            '<None>', 'SV.A', 'TO.A', 'sv.a', 'to.a', 'to->SV', 'sv->SV',
            'to->TO', 'sv->TO'
        ]

        # Loop over the finalKeys list and plot
        eaList = self.editAreaList()

        for each in finalKeys:
            watchIndex = self.getIndex(each[1], keys)

            # Set each edit area found in the WCL to the mask value
            mask = self.empty(bool)
            if each[0] in eaList:
                zoneArea = self.getEditArea(each[0])
                zoneMask = self.encodeEditArea(zoneArea)
                mask[zoneMask] = True
            grid[mask] = watchIndex

        #remove any existing grid
        parms = self.loadedParms()
        for weName, level, dbID in parms:
            if weName == "ProposedWatches" and level == "SFC" and \
              dbID.modelName() == "WCL":
                # found parm, delete any grids
                self._deleteWCLGrids()
                break

        self.createGrid("WCL", "ProposedWatches", "DISCRETE", (grid, keys), \
          timeRange, discreteKeys=keys, discreteOverlap=0, \
          discreteAuxDataLength=0)
        self.setActiveElement("WCL", "ProposedWatches", "SFC", timeRange, \
          colorTable='GFE/WCLHazards')

        return
Exemplo n.º 21
0
 def _deleteWCLGrids(self):
     tr = TimeRange.allTimes()
     gridInfo = self.getGridInfo("WCL", "ProposedWatches", "SFC", tr)
     trList = []
     for g in gridInfo:
         self.deleteGrid("WCL", "ProposedWatches", "SFC", g.gridTime())
Exemplo n.º 22
0
    def execute(self, editArea, varDict):

        cwas = varDict["WFOs"]
        if cwas == bogusWFO:
            self.statusBarMsg("Please select a valid WFO.", "U")
            return

        # Make a time range to find the initial storm surge hazards
        # Truncate to top of last hour
        start = int(self._gmtime().unixTime() / 3600) * 3600
        end = start + 48 * 3600  # 2 days later
        timeRange48Hour = self.GM_makeTimeRange(start, end)

        # Fetch the proposed grid and the WFO ISC grid
        ssTRs = self.GM_getWEInventory("ProposedSS", "Fcst")
        if len(ssTRs) > 0:
            propSSGrid = self.getGrids("Fcst", "ProposedSS", "SFC", ssTRs[-1])
        else:
            self.statusBarMsg("No PropsedSS grids found.", "U")
            return

        # Fetch InitialSS grid
        ssTRs = self.GM_getWEInventory("InitialSS", "Fcst")
        if len(ssTRs) > 0:
            initSSGrid = self.getGrids("Fcst", "InitialSS", "SFC", ssTRs[-1])
        else:
            self.statusBarMsg("No InitialSS grids found.", "U")
            return

        # Replaced above with this code to fetch a combined Hazards grid
        wfoSSGrid = self.fetchProposedWFOGrid(cwas)

        # Calculate the overlap of selected WFO's ISC areas and selected area
        selectedMask = self.encodeEditArea(editArea)

        # If no points selected, select all points
        if not selectedMask.any():
            selectedMask = self.newGrid(True, np.bool)

        #  Make an empty mask grid, so we can use it to add up all the WFO areas
        cwaMask = self.newGrid(False, np.bool)

        #  Process all the selected CWAs
        for cwa in cwas:

            #  Get the ISC edit area mask for this office
            mask = self.encodeEditArea("ISC_" + cwa.upper())
            cwaMask = cwaMask | mask

            # Check for conflicts with just this CWA
            if self.anyHazardConflicts(initSSGrid, wfoSSGrid, mask):
                self.statusBarMsg(
                    "WFO " + cwa + " conflicts with the InitialSS grid." + \
                    " Check for discrepancy in either event code or ETN in " + \
                    "incoming WFO ISC grids.", "S")
                return

        # Use the intersection of the CWA areas and the selected area
        selectedMask = selectedMask & cwaMask

        # Further reduce the area to just the StormSurge editArea
        ssMask = self.encodeEditArea("StormSurgeWW_EditArea")
        selectedMask = selectedMask & ssMask

        # Now check for conflicts with each WFO and the InitialSS grid.
        wfoKeys = wfoSSGrid[1]
        noneWfoIndex = self.getIndex("<None>", wfoKeys)

        # Finally merge the WFO ISC grids into the ProposedSS grid
        wfoGrid, wfoKeys = wfoSSGrid
        ssGrid, ssKeys = propSSGrid
        ssGrid = ssGrid.copy()  # make a copy so we don't affect the original
        ssKeys = list(ssKeys)  # make a copy

        #  Process all the WFO proposed hazards
        for wfoIndex, wfoKey in enumerate(wfoKeys):

            #  Identify where this WFO hazard intersects the selected area
            mask = (wfoGrid == wfoIndex) & selectedMask

            #  Get the index of this hazard key within the NHC hazards
            ssIndex = self.getIndex(wfoKey, ssKeys)

            #  Convert the WFO key index to an NHC key index
            ssGrid[mask] = ssIndex

        #  Put the merged ProposedSS back together
        proposedGrid = (ssGrid, ssKeys)

        #  Delete any existing collaboration difference grids
        self.unloadWE("Fcst", "CollabDiffSS", "SFC")

        #  Delete all versions of this weather element
        self.deleteCmd(["ProposedSS"], TimeRange.allTimes())

        #  Create the grid, so we can see it
        self.createGrid("Fcst", "ProposedSS", "DISCRETE", proposedGrid,
                        timeRange48Hour)

        #  Calculate the new difference grid for this time range
        self.calcDiffGrid(initSSGrid, proposedGrid, "CollabDiffSS",
                          timeRange48Hour)
Exemplo n.º 23
0
    def copyISCGridstoFcst(self, elementList, mutableID):

        # Initialize all the grids we plan to return

        surgePctGrid = None
        surgePctGridMSL = None
        surgePctGridMLLW = None
        surgePctGridMHHW = None
        surgePctGridNAVD = None

        baseTime = self.baseGuidanceTime()

        # Remove all the grids first before replacing them later

        self.deleteCmd(elementList, TimeRange.allTimes())

        # Ensure we're not fetching older ISC grids to avoid the ISC purge bug by
        # fetching ISC grids within a specific window.
        allTimes = TimeRange.allTimes()
        iscStart = AbsTime.AbsTime(baseTime -
                                   (10 * 3600))  # 10 hours before the baseTime
        iscEnd = allTimes.endTime()  # Latest time possible
        ISCTRWindow = TimeRange.TimeRange(iscStart, iscEnd)

        # Amended To distinguish when inundation grids are available but not datum ones.
        for weName in elementList:
            #print "Processing ISC ", weName
            GridsCheck = True
            iscWeName = weName + "nc"
            # get the inventory for the ISC grids

            try:
                trList = self.GM_getWEInventory(iscWeName, "ISC", "SFC",
                                                ISCTRWindow)
            except:
                GridsCheck = False

            if len(trList) == 0:
                GridsCheck = False

            if (weName == "InundationMax"
                    or weName == "InundationTiming") and not GridsCheck:
                self.statusBarMsg(
                    "No inundation grids found in ISC database for " +
                    iscWeName + ". Stopping. Revert Forecast db.", "S")
                return None, None, None, None, None

            if not GridsCheck:
                self.statusBarMsg(
                    "No datum grids in ISC database for " + iscWeName +
                    ". Proceeding without it.", "S")

            # Make sure that the ISC grids are current
            if GridsCheck:
                if baseTime > trList[0].startTime().unixTime():
                    if weName == "InundationMax" or weName == "InundationTiming":
                        self.statusBarMsg(
                            "ISC grids for inundation element " + iscWeName +
                            " are not current. They correspond to a previous cycle. Aborting. Revert Forecast db.",
                            "S")
                        return None, None, None, None, None
                    else:
                        self.statusBarMsg(
                            "ISC grids for datum element " + iscWeName +
                            " are not current. They correspond to a previous cycle. Proceeding without it.",
                            "S")
                        GridsCheck = False

            for tr in trList:
                grid = self.getGrids("ISC", iscWeName, "SFC", tr)
                if iscWeName == "InundationMaxnc" or iscWeName == "InundationTimingnc":
                    grid.clip(0.0, 100.0, grid)
                else:
                    grid.clip(-30.0, 100.0, grid)

                if iscWeName == "InundationTimingnc":
                    self.createGrid(mutableID,
                                    weName,
                                    "SCALAR",
                                    grid,
                                    tr,
                                    precision=2)
                elif iscWeName == "InundationMaxnc":
                    surgePctGrid = grid
                    self.createGrid(mutableID,
                                    weName,
                                    "SCALAR",
                                    grid,
                                    tr,
                                    precision=2)
                elif iscWeName == "SurgeHtPlusTideMSLnc" and GridsCheck:
                    surgePctGridMSL = grid
                elif iscWeName == "SurgeHtPlusTideMLLWnc" and GridsCheck:
                    surgePctGridMLLW = grid
                elif iscWeName == "SurgeHtPlusTideMHHWnc" and GridsCheck:
                    surgePctGridMHHW = grid
                elif iscWeName == "SurgeHtPlusTideNAVDnc" and GridsCheck:
                    surgePctGridNAVD = grid

        return surgePctGrid, surgePctGridMSL, surgePctGridMLLW, surgePctGridMHHW, surgePctGridNAVD
Exemplo n.º 24
0
    def execute(self, editArea, timeRange, varDict):

        gulfStreamSites = [
            'KEY', 'MFL', 'MLB', 'JAX', 'CHS', 'ILM', 'MHX', 'AKQ', 'PHI',
            'OKX', 'BOX', 'GYX', 'CAR'
        ]
        tafbSites = [
            'BRO', 'CRP', 'HGX', 'LCH', 'LIX', 'MOB', 'TAE', 'TBW', 'MFL',
            'KEY', 'MLB', 'JAX', 'CHS', 'ILM'
        ]
        buttonList, timeList = self.getButtonNames()
        GFEDomainname = self.getSiteID()
        print "GFEDomain is: ", GFEDomainname
        cron = True

        if varDict is None:  # This means the tool is being run interactively, so make the GUI.

            variableList = [
                ("How Long Do You Want To Run NWPS:", 144, "scale", [12,
                                                                     144], 3),
                ("**NOTE: NCEP WCOSS Runs Always Go Out 144 Hours Regardless of Your Choice Here",
                 "", "label"),
                ("Model Start Time:", buttonList[4], "radio", buttonList),
                ("Local, NCEP, or Both:", "NCEP", "radio",
                 ["Local", "NCEP", "Both"]),
                ("Waterlevels:", "ESTOFS", "radio", ["ESTOFS", "PSURGE",
                                                     "No"]),
                ("If PSURGE\n% Exceedance Hgt:", "10", "radio",
                 ["10", "20", "30", "40", "50"]),
            ]

            if GFEDomainname in gulfStreamSites:
                variableList.append(
                    ("RTOFS Currents:", "Yes", "radio", ["Yes", "No"]))
            else:
                variableList.append(
                    ("RTOFS Currents:", "No", "radio", ["Yes", "No"]))

            nest = "Yes"

            if GFEDomainname in tafbSites:
                variableList.append(
                    ("Boundary Conditions:", "WAVEWATCH", "radio",
                     ["WAVEWATCH", "TAFB-NWPS", "HURWave", "No"]))
            else:
                variableList.append(("Boundary Conditions:", "WAVEWATCH",
                                     "radio", ["WAVEWATCH", "HURWave", "No"]))
            varDict = {}
            processVarList = ProcessVariableList.ProcessVariableList(
                "Run_NWPS", variableList, varDict, None)
            status = processVarList.status()
            if status != "OK":
                return

            fcst_length = processVarList.varDict(
            )["How Long Do You Want To Run NWPS:"]
            fcstlength = str(fcst_length)
            wind = "ForecastWindGrids"
            modelstarttime = processVarList.varDict()["Model Start Time:"]
            wheretorun = processVarList.varDict()["Local, NCEP, or Both:"]
            model = "SWAN"
            web = "Yes"
            plot = "Yes"
            wna = processVarList.varDict()["Boundary Conditions:"]
            gstream = processVarList.varDict()["RTOFS Currents:"]
            tstep = "600"
            hotstart = "True"
            waterlevels = processVarList.varDict()["Waterlevels:"]
            excd = processVarList.varDict()["If PSURGE\n% Exceedance Hgt:"]
            cron = False
            # label it WAVEWATCH in the GUI, but continue to call it WNAWave for WCOSS.
            if wna == "WAVEWATCH":
                wna = "WNAWave"
            # end interactive GUI portion

        else:

            # This part of if else statement assumes procedure is being run from command
            #line with variable list passed on using the -V option to runProcedure. This
            #allows to run procedure from a cron. Example default for runProcedure would be:
            # All variables shown below passed with -V option are required for procedure to run properly.
            # /awips2/GFESuite/bin/runProcedure -n Run_NWPS -c gfeConfig
            # -V '{"fcstlength":"102","wind":"ForecastWindGrids","wheretorun":"NCEP","model":"SWAN","web":"Yes","plot":"Yes","wna":"WNAWave","nest":"Yes","gstream":"Yes","tstep":"600","hotstart":"True","waterlevels":"ESTOFS","excd":"10"}'
            # If running from a cron, you do not need to create a SITE level override of this baseline procedure if your input variables
            # are different because you pass that on from the command line.

            modelstarttime = buttonList[4]
            fcstlength = varDict['fcstlength']
            wind = varDict['wind']
            wheretorun = varDict['wheretorun']
            model = varDict['model']
            web = varDict['web']
            plot = varDict['plot']
            wna = varDict['wna']
            nest = varDict['nest']
            gstream = varDict['gstream']
            tstep = varDict['tstep']
            hotstart = varDict['hotstart']
            waterlevels = varDict['waterlevels']
            excd = varDict['excd']

        modelTR = self.getModelTimeRange("Fcst", "Wind")
        startHour = modelTR[1]
        endHour = modelTR[2]
        timeRange = modelTR[0]

        if (modelstarttime == buttonList[0]):
            starttime = timeList[0]
        elif (modelstarttime == buttonList[1]):
            starttime = timeList[1]
        elif (modelstarttime == buttonList[2]):
            starttime = timeList[2]
        elif (modelstarttime == buttonList[3]):
            starttime = timeList[3]
        elif (modelstarttime == buttonList[4]):
            starttime = timeList[4]
        elif (modelstarttime == buttonList[5]):
            starttime = timeList[5]
        elif (modelstarttime == buttonList[6]):
            starttime = timeList[6]
        else:
            starttime = startHour  # Model start Hour if all others empty

        if (startHour > starttime):
            starttime = startHour

        timeRange1 = TimeRange.TimeRange(
            AbsTime.AbsTime(starttime - 7 * 24 * 3600),
            AbsTime.AbsTime(starttime + 8 * 24 * 3600))
        timeRange2 = TimeRange.TimeRange(
            AbsTime.AbsTime(starttime),
            AbsTime.AbsTime(starttime + 8 * 24 * 3600))

        self.deleteCmd(['NWPSwind'], timeRange1)
        databaseID = self.findDatabase("Fcst")
        self.copyToCmd([('Wind', 'NWPSwind')], databaseID, timeRange2)
        self.fragmentCmd(['NWPSwind'], timeRange2)
        self.saveElements(["NWPSwind"])

        trList = self.getWEInventory("NWPSwind")
        if len(trList) < 144:
            self.statusBarMsg(
                "Not enough Wind grids. You need at least 144 hours.", "S")
            return

        inp_args = fcstlength + ":" + wna + ":" + nest + ":" + gstream + ":" + wind + ":" + web + ":" + plot + ":" + tstep + ":" + hotstart + ":" + waterlevels + ":" + model + ":" + excd + ":" + wheretorun

        try:
            os.stat('/tmp/nwps/' + GFEDomainname)
        except:
            os.makedirs('/tmp/nwps/' + GFEDomainname)
        os.chmod('/tmp/nwps/' + GFEDomainname, 0o775)

        with open('/tmp/nwps/' + GFEDomainname + '/inp_args', 'w') as f:
            f.write(inp_args)
        os.chmod('/tmp/nwps/' + GFEDomainname + '/inp_args', 0o666)

        os.system('mkdir -p /awips2/GFESuite/nwps/' + GFEDomainname + '_var')
        os.system('chmod 775 /awips2/GFESuite/nwps/' + GFEDomainname + '_var')
        os.system('cp -rpq /tmp/nwps/' + GFEDomainname +
                  '/inp_args /awips2/GFESuite/nwps/' + GFEDomainname + '_var/')
        if cron:
            os.system(
                '/awips2/GFESuite/nwps/bin/runManualNWPS_OutsideAWIPS.sh ' +
                GFEDomainname)
        else:
            os.system(
                '/awips2/GFESuite/nwps/bin/runManualNWPS_OutsideAWIPS.sh ' +
                GFEDomainname + ' &')
        shutil.rmtree('/tmp/nwps/' + GFEDomainname)
Exemplo n.º 25
0
    def execute(self, timeRange):
        mutableID = self.mutableID()
        topoDbId = self.findDatabase("EditTopo_Topo")
        if mutableID != topoDbId:
            DisplayMessageDialog.openError(
                "Invalid Mutable Database",
                "You must be using the EditTopo GFE configuration to run this procedure.\n"
                "Please restart CAVE and select the EditTopo GFE configuration."
            )
            return

        # check for existence of NewTopo grid
        newTerrainDbId = self.findDatabase("EditTopo_NewTerrain")
        newTopoParm = self.getParm(newTerrainDbId, "NewTopo", "SFC")
        inventory = newTopoParm.getGridInventory()
        if len(inventory) == 0:
            DisplayMessage.openError(
                "No NewTopo grid exists!",
                "You must initialize and edit the NewTopo grid as desired.\n"
                "You should run this procedure only when your edits are final."
            )
            return

        doIt = DisplayMessageDialog.openQuestion(
            "WARNING!",
            "You are about to replace your GFE Topo data with the NewTopo data.\n"
            "You should only do this after you have completed all edits and have\n"
            "resolved any border differences with your neighboring sites.\n\n"
            "Do you wish to continue?")

        if not doIt:
            return

        baseTerrainDbId = self.findDatabase("EditTopo_BaseTerrain")
        prevTopoParm = self.getParm(baseTerrainDbId, "PrevTopo", "SFC")
        inventory = prevTopoParm.getGridInventory()
        doIt = True
        if len(inventory) > 0:
            doIt = DisplayMessageDialog.openQuestion(
                "WARNING PrevTopo exists!",
                "It appears that you have previously run CopyFromNewTopo and a\n"
                "backup copy of your original GFE Topo grid already exists.\n\n"
                "Do you want to overwrite the backup copy with your current GFE Topo grid?"
            )
        if doIt:
            # Save the current Topo grid to PrevTopo
            topo = self.getGrids(topoDbId,
                                 "Topo",
                                 "SFC",
                                 timeRange,
                                 mode="First")
            prevTopoParm.setMutable(True)
            self.createGrid(baseTerrainDbId, "PrevTopo", "SCALAR", topo,
                            TimeRange.allTimes())
            prevTopoParm.saveParameter(True)
            prevTopoParm.setMutable(False)

        # Copy the NewTopo data to Topo
        newTopo = self.getGrids(newTerrainDbId,
                                "NewTopo",
                                "SFC",
                                timeRange,
                                mode="First")

        topoParm = self.getParm(topoDbId, "Topo", "SFC")
        self.createGrid(topoDbId, "Topo", "SCALAR", newTopo,
                        TimeRange.allTimes())
        topoParm.saveParameter(True)

        DisplayMessageDialog.openInformation(
            "Topo Successfully Updated!",
            "To revert to the previous version, run the RevertTopo procedure.")
Exemplo n.º 26
0
 def _deleteWCLGrids(self):
     tr = TimeRange.allTimes()
     gridInfo = self.getGridInfo("WCL", "ProposedWatches", "SFC", tr)
     trList = []
     for g in gridInfo:
         self.deleteGrid("WCL", "ProposedWatches", "SFC", g.gridTime())
Exemplo n.º 27
0
    def execute(self):
        
        #see if the Hazards WE is loaded in the GFE, if not abort the tool
        if not self._hazUtils._hazardsLoaded():
            self.statusBarMsg("Hazards Weather Element must be loaded in "+\
              "the GFE before running MergeProposedSS.", "S")
            self.cancel()

        #ensure there are no temp grids loaded, refuse to run
        if self._hazUtils._tempWELoaded():
            self.statusBarMsg("There are temporary hazard grids loaded. " + \
                "Please merge all hazards grids before running MergeProposedSS.", "S")
            self.cancel()

        #ensure grid is not locked by another user
        if self.lockedByOther('Hazards', 'SFC'):
            self.statusBarMsg("There are conflicting locks (red locks - owned by others) on Hazards.  " + \
                "Please resolve these before running MergeProposedSS", "S")
            self.cancel()

        start = int(self._gmtime().unixTime() / 3600) * 3600
        end= start + 48 * 3600
        propTR = self.GM_makeTimeRange(start, end)

        # Make sure we have a ProposedSS before we begin
        propTRList = self.GM_getWEInventory(self._ssWeName, dbase = self._ssDbName, timeRange=propTR)

        if len(propTRList) == 0:
            self.statusBarMsg("No ProposedSS Fcst grid found. Tool aborting.", "S")
            return

        # set propTR to span the full inventory of ProposedSS grids
        propTR = self.GM_makeTimeRange(propTRList[0].startTime().unixTime(), propTRList[-1].endTime().unixTime())

        # Make the cwa mask
        siteID = self.getSiteID()
        cwaMask = self.encodeEditArea(siteID)

        # Check each site for any conflicts and return the list of conflicting sites
        if self.checkForAnyConflicts(cwaMask):
            self.statusBarMsg("Hazard ETN conflicts between " + siteID + " and ProposedSS from NHC ISC database.", "U")
            return

        # First remove all SS hazards from the Hazard grid
        ssKeys = ["SS.A", "SS.W"]
        self.removeHazards(ssKeys)

        # If there were not any wfo hazards found, make empty grid(s) based on the ProposedSS timeRange
        hazTRList = self.GM_getWEInventory("Hazards")
        if len(hazTRList) == 0:

            # Make empty hazard grids with same timeRanges as ProposedSS
            for tr in propTRList:
                self.makeEmptyHazardGrid(tr)

        # Make new Hazards grids at the beginning and/or end, if needed
        else:
            if propTR.startTime() < hazTRList[0].startTime(): # add a new Hazard grid at the beginning
                newTR = TimeRange.TimeRange(propTR.startTime(), hazTRList[0].startTime())
                self.makeEmptyHazardGrid(newTR)

            # Check and make one at the end, if needed
            if hazTRList[-1].endTime() < propTR.endTime():
                 newTR = TimeRange.TimeRange(hazTRList[-1].endTime(), propTR.endTime())
                 self.makeEmptyHazardGrid(newTR)

            # Finally split the Hazards grid at the propTR
            self.splitCmd(["Hazards"], propTR)

        # Refetch the hazards inventory, since it may have changed
        hazTRList = self.GM_getWEInventory("Hazards")

        # Get the ProposedSS grid
        propGrid, propKeys = self.getGrids(self._ssDbName, self._ssWeName, "SFC", propTRList[-1])

        # Now add ProposedSS keys back into the hazard grids
        for hazTR in hazTRList:

            # Only add Proposed hazards where the Hazards overlap
            if not hazTR.overlaps(propTR):
                continue

            for propKey in propKeys:
                if propKey != "<None>":
                    propIndex = self.getIndex(propKey, propKeys)
                    mask = propGrid == propIndex
                    self._hazUtils._addHazard("Hazards", hazTR, propKey, mask, combine=1)
Exemplo n.º 28
0
def runFormatter(databaseID,
                 site,
                 forecastList,
                 cmdLineVarDict,
                 vtecMode,
                 username,
                 dataMgr,
                 serverFile=None,
                 editAreas=[],
                 timeRanges=[],
                 timePeriod=None,
                 drtTime=None,
                 vtecActiveTable='active',
                 testMode=0,
                 experimentalMode=0,
                 serverOutputFile=None,
                 startTime=None,
                 endTime=None,
                 language=None,
                 outputFile=None,
                 appendFile=None):

    if cmdLineVarDict:
        exec "cmdLineVarDict = " + cmdLineVarDict
    else:
        cmdLineVarDict = {}

    # Set default Forecast Type
    if len(forecastList) == 0:
        usage()
        logger.error("ForecastList [-t] is empty or missing")
        return

    # Can't have both T and E modes
    if testMode and experimentalMode:
        usage()
        logger.error("Can't have both -T and -E switches")
        return

    if drtTime is not None:
        import offsetTime
        offsetTime.setDrtOffset(drtTime)

    # Create Time Range
    useRawTR = 0
    if startTime is not None and endTime is not None:
        start = getAbsTime(startTime)
        end = getAbsTime(endTime)
        timeRange = TimeRange.TimeRange(start, end)
        # Set so this time range will override all others
        useRawTR = 1
    else:
        timeRange = None

    # Handle the VTEC modes
    if vtecMode is not None and vtecMode not in ['X', 'O', 'T', 'E']:
        usage()
        logger.error("-v vtecMode must be ['X', 'O', 'T', 'E']")
        sys.exit(1)

    #force VTEC mode to "T" if in TEST mode and another vtecCode is specified
    if testMode and vtecMode is not None:
        vtecMode = "T"

    #force VTEC mode to "E" if in EXPERIMENTAL mode and another vtecCode
    #is specified
    elif experimentalMode and vtecMode is not None:
        vtecMode = "E"

    #force into TEST mode, if vtec code is 'T'
    if vtecMode == "T":
        testMode = 1
        experimentalMode = 0
    elif vtecMode == "E":
        experimentalMode = 1
        testMode = 0

    # Create an ifpClient
    ifpClient = PyFPClient(VizApp.getWsId(), site)

    global GridLoc
    GridLoc = ifpClient.getDBGridLocation()
    #importer = TextIFPImporter(ifpClient)
    #importer.install()
    import Utility

    import ForecastNarrative
    import ForecastTable

    import Analysis

    site = str(ifpClient.getSiteID()[0])

    # Create dictionary of arguments
    argDict = {
        #"host" : host,
        #"port" : port,
        "databaseID": databaseID,
        "site": site,
        "cmdLineVarDict": cmdLineVarDict,
        "serverFile": serverFile,
        "editAreas": editAreas,
        "timeRanges": timeRanges,
        "timeRange": timeRange,
        "timePeriod": timePeriod,
        "useRawTR": useRawTR,
        "vtecMode": vtecMode,
        "vtecActiveTable": vtecActiveTable,
        "testMode": testMode,
        "experimentalMode": experimentalMode,
        "serverOutputFile": serverOutputFile,
    }
    # Handle command line switches for variables that can be
    # set elsewhere i.e. in the command line varDict OR the
    # product definition section.
    # If there was a command line switch for these items,
    # make an entry in argDict. Otherwise, do not.
    for item in ["language", "outputFile", "appendFile"]:
        exec "if " + item + " is not None: argDict['" + item + "'] = " + item

    logger.info("Arguments: " + str(argDict))

    argDict["ifpClient"] = ifpClient
    argDict["utility"] = Utility.Utility(None, None, ifpClient)
    #argDict["AFPS"] = AFPS
    #argDict["AFPSSup"] = AFPSSup
    argDict["Analysis"] = Analysis
    argDict["ForecastNarrative"] = ForecastNarrative
    argDict["ForecastTable"] = ForecastTable

    # get product creation time to the minute - almost all fmtrs use this
    argDict['creationTime'] = int(time.time() / 60) * 60.0

    # Set the Site Time Zone
    tz = str(ifpClient.getSiteTimeZone())
    os.environ['TZ'] = tz
    time.tzset()

    # Create the formatter
    formatter = TextFormatter.TextFormatter(dataMgr, ifpClient)

    # For each Forecast Type,
    #   Create generate forecast
    forecasts = ""  # returned value
    outForecasts = ""  # written to output files
    for forecastType in forecastList:
        forecast = formatter.getForecast(forecastType, argDict)
        forecasts += forecast

        # Convert data written to files to upper case if required
        if argDict["mixedCaseEnabled"]:
            outForecasts += forecast
        else:
            outForecasts += forecast.upper()

    logger.info("Text:\n" + str(forecasts))

    try:
        outputFile = argDict["outputFile"]
        success = writeToFile(outForecasts, outputFile, "w")
        if success == 0:
            print "Couldn't open output file", outputFile
            logger.error("Couldn't open output file: ", outputFile)
            sys.exit(1)
    except:
        pass

    try:
        outputFile = argDict["serverOutputFile"]
        success = writeToFile(outForecasts, outputFile, "w")
        if success == 0:
            print "Couldn't open output file", outputFile
            logger.error("Couldn't open output file: ", outputFile)
            sys.exit(1)
    except:
        pass

    try:
        appendFile = argDict["appendFile"]
        success = writeToFile(outForecasts, appendFile, "a")
        if success == 0:
            print "Couldn't open append file", appendFile
            logger.error("Couldn't write to append file: ", appendFile)
        sys.exit(1)
    except:
        pass

    try:
        serverFile = argDict["serverFile"]
        writeToSite = (username == "SITE")
        success = writeToServerFile(outForecasts, serverFile, writeToSite)
        if success == 0:
            print "Couldn't open server output file", serverFile
            logger.error("Couldn't open server output file: ", serverFile)
            sys.exit(1)
    except:
        pass

    del outForecasts

    # Remove any lat/lon areas created temporarily
    #global LatLonIds
    #argDict["ifpClient"].deleteReferenceData(LatLonIds)

    # Somebody is holding onto an ifpClient and thus the C++
    # object is not being destroyed.  This causes the network
    # connection to stay open.  Below is a kludge to force
    # the destruction of the C++ object.
    #del ifpClient.this

    # This also means that you may not import any new modules after this
    # point!!!!!!!!!!!!!!!
    return forecasts
Exemplo n.º 29
0
    def execute(self, varDict, timeRange):
        self.setToolType("numeric")
        self.toolTimeRange = timeRange

        # define the default eye diameter for bulletins where they are missing
        self.dialogEyeDiameter = 0.0

        Topo = self.getTopo()

        ##        interval = int(varDict["Time Interval\n(hours):"])

        tcDuration = self.getTimeConstraintDuration("Wind")
        tcHours = int(tcDuration / 3600)  # durations are expressed in seconds
        # set the time interpolation interval to the duration
        interval = tcHours
        # get the product ID
        ##        productList1 = varDict["Product to\ndecode:"]
        ##        productList2 = varDict["Product to\n decode:"]
        ##        productList1 = productList1 + productList2  # concatenate
        ##        if len(productList1) != 1:
        ##            self.statusBarMsg("Please select one TCM bulletin only.", "S")
        ##            return None

        ##        productID = productList1[0]

        # special code for GUM since they do things just a little differently
        siteID = self.getSiteID()
        if siteID == "GUM":
            productID = "GTW" + productID

        bgModelName = varDict["Background\nModel:"]
        # If we're using the Fcst, grab all of the grids now
        if bgModelName == "Fcst":
            inv = self.getWEInventory("Fcst", "Wind", "SFC")
            for tr in inv:
                self.fcstWindGrids[tr] = self.getGrids("Fcst",
                                                       "Wind",
                                                       "SFC",
                                                       tr,
                                                       mode="First")

        pieSlices = int(varDict["Number of\n Pie Slices:"])

        self.lessOverLand = int(varDict["Decrease Wind over Land by (%):"])
        self.elevation = Topo

        ##        # Use this method to fetch a text product from a file
        ##        fileName = "Your path and file name goes here"
        ##        textProduct = self.getTextProductFromFile(fileName)
        ##        productID = string.split(fileName, "/")[-1]

        # Use this method to fetch a product from the text database
        productID = varDict["ProductID:"]
        textProduct = self.getTextProductFromDB(productID)
        if len(textProduct) < 5:
            print productID, "could not be retrieved from text database."
            return None

        decoder = TCMDecoder()
        decoder.decodeTCMProduct(textProduct, self.dialogEyeDiameter)
        fcstList = decoder.getFcstList()
        print "Decoded:", len(fcstList), " forecasts."

        # Attempt to get the alternate info from a file or the textDB
        altFileName = decoder.getAltInfoFilename()

        altFileName = "/home/eagle6/lefebvre/TPC/" + altFileName

        # get additional info if available
        altProduct = self.getTextProductFromDB(altFileName)

        ##        ## use this version to fetch from a file
        ##        altProduct = self.getTextProductFromFile(altFileName)

        rmw, outsideRad = (0, 0)  # initialize
        if len(altProduct) < 5:
            print altProduct, "alternate info file could not be retrieved from text database."
        else:
            rmw, outsideRad = self.decodeDepressionInfo(altProduct)

        # Set the baseDecodedTime - validTime of first entry - 3 hours
        if len(fcstList) > 0:
            self.baseDecodedTime = fcstList[0]['validTime'] - 3 * 3600

##        # See if the decoded fcst is close to the current time.  This is needed
##        # so the tool will work on archived data sets
        selectionTROnly = 0
        ##        if abs(time.time() - self.baseDecodedTime) > 2 * 24 * 3600:  # older than 2 days
        ##            testMode = 1
        # restrict grids to the selected time period if option is selected.
        restrictAnswer = varDict["Make Grids over\nSelected Time Only:"]
        if restrictAnswer == "Yes":
            selectionTROnly = 1

        # push this info in the fcsts
        fcstList = self.injectDepressionInfo(fcstList, rmw, outsideRad)

        # interpolate the wind forecasts we got from the decoder
        print "Interpolating wind forecasts:"
        selectedStartTime = self.toolTimeRange.startTime().unixTime()
        selectedEndTime = self.toolTimeRange.endTime().unixTime()
        interpFcstList = []
        for i in xrange(len(fcstList) - 1):

            newFcstList = self.interpolateWindFcst(fcstList[i],
                                                   fcstList[i + 1], interval)
            # if we've processed the last time segment, append the last forecast
            if i == len(fcstList) - 2:
                newFcstList.append(fcstList[-1])

            # Make sure the fcst is within the selected time range
            for f in newFcstList:
                if (selectionTROnly and (f['validTime'] >= selectedStartTime and \
                                 f['validTime'] < selectedEndTime)) or not selectionTROnly:
                    interpFcstList.append(f)

        if len(fcstList) == 1:
            interpFcstList = fcstList

        if len(interpFcstList) == 0:
            self.statusBarMsg(
                "No cyclone forecasts found within the Selected TimeRange",
                "S")
        else:
            print "Generating", len(interpFcstList), "wind grids"

        # get the lat, lon grids
        latGrid, lonGrid = self.getLatLonGrids()

        # make a grid for each interpolate forecast
        gridCount = 0
        for f in interpFcstList:
            windGrid = self.makeRankine(f, latGrid, lonGrid, pieSlices)

            validTime = int(f['validTime'] / 3600) * 3600
            bgGrid = self.getClosestWindGrid(bgModelName, validTime)

            if bgGrid is None:
                print "Using calm background grid."
                bgGrid = self.makeWindGrid(0.0, 0.0, latGrid.shape)

            grid = self.blendGrids(windGrid, bgGrid)

            start = AbsTime.AbsTime(int(validTime))
            timeRange = TimeRange.TimeRange(start, start + interval * 3600)

            name = "Wind"
            self.createGrid("Fcst",
                            name,
                            "VECTOR",
                            grid,
                            timeRange,
                            precision=1,
                            minAllowedValue=0.0,
                            maxAllowedValue=200.0)

            gridCount += 1
            print "GenerateCyclone tool:", productID, "- Generated",gridCount, \
                  "out of", len(interpFcstList), "grids"

        return None
Exemplo n.º 30
0
    def process(self):
        import TimeRange
        # get list of edit areas that are part of the Zones/FireWx group
        from com.raytheon.viz.gfe.smarttool import TextFileUtil, GridCycler
        textID = TextFileUtil.getTextFile('Zones', 'editAreaGroups')
        zoneList = []
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            zoneList.append(line.rstrip())
        textFile.close()
        textID = TextFileUtil.getTextFile('FireWxZones', 'editAreaGroups')
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            zoneList.append(line.rstrip())
        textFile.close()

        refMgr = self.__dataMgr.getRefManager()
        # make the basic edit areas that are required, go sequentially through
        # the zoneList
        requiredEA = [
            "west_half", "east_half", "east_one_third", "west_one_third",
            "east_two_thirds", "west_two_thirds", "east_one_quarter",
            "west_one_quarter", "east_three_quarters", "west_three_quarters",
            "Superior"
        ]
        for x in xrange(len(requiredEA)):
            refData = refMgr.loadRefSet(ReferenceID(zoneList[x]))
            ea = ReferenceData(refData)
            ea.setId(ReferenceID(requiredEA[x]))
            refMgr.saveRefSet(ea)
            #ea = self.__client.getEditAreaPolygons(zoneList[x])
            #self.__client.saveEditArea(requiredEA[x], ea)
            LogStream.logEvent("Saved ", zoneList[x], "under", requiredEA[x])

        # special EAs (source,destination)
        special = [("ISC_Send_Area", "FireArea"), ("ISC_Send_Area", "area3")]
        for s in special:
            refData = refMgr.loadRefSet(ReferenceID(s[0]))
            ea = ReferenceData(refData)
            ea.setId(ReferenceID(s[1]))
            refMgr.saveRefSet(ea)
            #ea = self.__client.getEditAreaPolygons(s[0])
            #self.__client.saveEditArea(s[1], ea)
            LogStream.logEvent("Saved ", s[0], "under", s[1])

        # topography simulated based edit areas
        # area3 = whole area, AboveElev, BelowElev
        LogStream.logEvent("Calculating topo-dependent edit areas...")
        topo = self.__dataMgr.getParmManager().getParmInExpr("Topo", True)
        topogrid = GridCycler.getInstance().getCorrespondingResult(
            topo,
            TimeRange.allTimes().toJavaObj(), "TimeWtAverage")
        topogrid = topogrid[0].getGridSlice().getNDArray()
        iscSend = ReferenceID('ISC_Send_Area')
        #wholeGrid = self.__client.getEditArea("ISC_Send_Area")
        wholeGrid = refMgr.loadRefSet(iscSend).getGrid().getNDArray()
        topoAve = 0
        count = 0
        minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
        for x in range(minx, maxx):
            for y in range(miny, maxy):
                if wholeGrid[y, x] == 1:
                    count = count + 1
                    topoAve = topoAve + topogrid[y, x]
        topoAve = topoAve / count
        aboveGrid = wholeGrid * 0
        belowGrid = wholeGrid * 0
        for x in xrange(topogrid.shape[1]):
            for y in xrange(topogrid.shape[0]):
                if wholeGrid[y, x] == 1:
                    if topogrid[y, x] > topoAve:
                        aboveGrid[y, x] = 1
                    else:
                        belowGrid[y, x] = 1
        # area1 and area2 need to be "BelowElev", but should be different
        # than area3
        desiredCount = 2000
        count = 0
        area1 = wholeGrid * 0
        area2 = wholeGrid * 0
        for x in xrange(topogrid.shape[1]):
            if count < desiredCount:
                for y in xrange(topogrid.shape[0]):
                    if wholeGrid[y, x] == 0 and topogrid[y, x] < topoAve:
                        area1[y, x] = 1
                        belowGrid[y, x] = 1
                        count = count + 1
        count = 0
        for x in xrange(topogrid.shape[1]):
            if count < desiredCount:
                for y in xrange(topogrid.shape[0]):
                    if wholeGrid[y,x] == 0 and topogrid[y,x] < topoAve and \
                      area1[y,x] == 0:
                        area2[y, x] = 1
                        belowGrid[y, x] = 1
                        count = count + 1

        # save all topography-dependent edit areas
        self.__saveEA("area1", area1)
        LogStream.logEvent("Saved area1 based on area2, area3, and topo <",
                           topoAve)
        self.__saveEA("area2", area2)
        LogStream.logEvent("Saved area2 based on area1, area3, and topo <",
                           topoAve)
        self.__saveEA("AboveElev", aboveGrid)
        LogStream.logEvent("Saved AboveElev based on area3 > ", topoAve)
        self.__saveEA("BelowElev", belowGrid)
        LogStream.logEvent("Saved BelowElev based on area3 <= ", topoAve)
        self.__saveEA("Ridges", aboveGrid)
        LogStream.logEvent("Saved Ridges based on area3 > ", topoAve)
        self.__saveEA("Valleys", belowGrid)
        LogStream.logEvent("Saved Valleys based on area3 < ", topoAve)
        self.__saveEA("Inland", aboveGrid)
        LogStream.logEvent("Saved Ridges based on area3 > ", topoAve)
        self.__saveEA("Coastal", belowGrid)
        LogStream.logEvent("Saved Valleys based on area3 < ", topoAve)

        #city areas, which are a small part of other edit areas
        cityBased = [("area1", ["city1", "city2"]), ("area2", ["city3"]),
                     ("area3", ["city4", "area3_pt"])]
        for baseArea, cityAreas in cityBased:
            #wholeGrid = self.__client.getEditArea(baseArea)
            wholeGrid = refMgr.loadRefSet(
                ReferenceID(baseArea)).getGrid().getNDArray()
            minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
            cNumber = 0
            print minx, maxx, miny, maxy, wholeGrid.shape
            for x in range(minx, maxx):
                for y in range(miny, maxy):
                    if wholeGrid[y, x] == 1:
                        if cNumber >= len(cityAreas):
                            break
                        cityGrid = numpy.logical_and(wholeGrid, 0)
                        cityGrid[y, x] = 1
                        self.__saveEA(cityAreas[cNumber],
                                      cityGrid.astype('int8'))
                        LogStream.logEvent("Saved ", cityAreas[cNumber],
                                           "based on:", baseArea)
                        cNumber = cNumber + 1

        # special for ISC areas for CCF database source test
        #txt = self.__eagdb["ISC"]
        #iscList = cPickle.loads(txt)
        textID = TextFileUtil.getTextFile('ISC', 'editAreaGroups')
        iscList = []
        textFile = open(textID.getFile().getPath())
        textFile.readline()
        for line in textFile:
            iscList.append(line.rstrip())
        textFile.close()
        count = 0
        while count < 6:
            for i in iscList:
                if i == "ISC_Send_Area" or i == "ISC_Tool_Area":
                    continue
                wholeGrid = refMgr.loadRefSet(
                    ReferenceID(i)).getGrid().getNDArray()
                minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid)
                if minx == -1:
                    continue
                ok = 1
                print minx, maxx, miny, maxy, wholeGrid.shape
                for x in range(minx, maxx):
                    if ok:
                        for y in range(miny, maxy):
                            if wholeGrid[y, x] == 1:
                                ptGrid = numpy.logical_and(wholeGrid, 0)
                                ptGrid[y, x] = 1
                                name = "isc" + ` count `
                                self.__saveEA(name, ptGrid.astype('int8'))
                                requiredEA.append(name)
                                LogStream.logEvent("Saved ", name, "based on ",
                                                   i)
                                ok = 0
                                break
                    else:
                        break

                count = count + 1
                if count > 6:
                    break

        # store an edit area group with all of the generated edit areas
        requiredEA.append("FireArea")
        requiredEA.append("AboveElev")
        requiredEA.append("BelowElev")
        requiredEA.append("Valleys")
        requiredEA.append("Ridges")
        requiredEA.append("Inland")
        requiredEA.append("Coastal")
        requiredEA.append("city1")
        requiredEA.append("city2")
        requiredEA.append("city3")
        requiredEA.append("city4")
        requiredEA.append("area3")
        requiredEA.append("area2")
        requiredEA.append("area1")

        refMgr.saveGroup("GFETest", JUtil.pylistToJavaStringList(requiredEA))

        time.sleep(.5)
Exemplo n.º 31
0
    def _determineTimeRanges(self, argDict):
        self.debug_print("")
        # Set up the Narrative Definition and initial Time Range
        self._issuanceInfo = self.getIssuanceInfo(self._productIssuance,
                                                  self._issuance_list(argDict))
        self._timeRange = self._issuanceInfo.timeRange()
        argDict["productTimeRange"] = self._timeRange
        self._expireTime = self._issuanceInfo.expireTime()
        self._issueTime = self._issuanceInfo.issueTime()
        self._definition["narrativeDef"] = self._issuanceInfo.narrativeDef()
        if self._periodCombining:
            self._definition["methodList"] = \
               [self.combineComponentStats, self.assembleChildWords]
        else:
            self._definition["methodList"] = [self.assembleChildWords]

        # Calculate current times
        self._ddhhmmTime = self.getCurrentTime(argDict,
                                               "%d%H%M",
                                               shiftToLocal=0,
                                               stripLeading=0)
        self._timeLabel = self.getCurrentTime(argDict,
                                              "%l%M %p %Z %a %b %e %Y",
                                              stripLeading=1)
        expireTimeRange = TimeRange.TimeRange(self._expireTime,
                                              self._expireTime + 3600)
        self._expireTimeStr = self.timeDisplay(expireTimeRange, "", "",
                                               "%d%H%M", "")

        # This section determines when to start the extended forecast
        # for the summary extended.
        (currentLocalTime, self._shift) = self.determineTimeShift()
        day = currentLocalTime.day
        month = currentLocalTime.month
        year = currentLocalTime.year
        #print "_determineTimeRanges: p1 TR=",self._issuanceInfo.period1TimeRange()
        p1_endtime = self._issuanceInfo.period1TimeRange().endTime()

        # If the first period ends at the same time as self.NIGHT(), then
        # the product starts with a daytime issuance, otherwise a nighttime
        # issuance and the extended will start 24 hrs later
        nightTime = AbsTime.absTimeYMD(year, month, day,
                                       self.NIGHT()) - self._shift
        dayTime = AbsTime.absTimeYMD(year, month, day,
                                     self.DAY()) - self._shift
        #print "_determineTimeRanges: p1, day, night=",p1_endtime,dayTime,nightTime
        # Offset is hours from self.DAY()
        if p1_endtime == nightTime:
            # Daytime run - today, tonight, day2, night2
            offset = 48
        elif p1_endtime == dayTime:
            # PM run after midnight- rest of night, today, tonight, day2, night2
            offset = 48
        else:
            # Normal pm run - tonight, day1, night1, day2, night2
            offset = 72

        # Determine "issuanceHour"
        startTime = AbsTime.absTimeYMD(year, month, day, self.DAY())
        # Convert to GMT time before making time range
        startTime = startTime - self._shift + offset * 3600
        #print "_determineTimeRanges: p1 TR=",self._issuanceInfo.period1TimeRange()
        self._extendedTimeRange = TimeRange.TimeRange(startTime,
                                                      startTime + 3600)
        #print "_determineTimeRanges: extended TR=",self._extendedTimeRange

        return None
Exemplo n.º 32
0
    def execute(self, varDict, editArea, timeRange):

        t0 = time.time()

        self._timeRange = timeRange

        mutableID = self.mutableID()

        # List of elements
        # See if we should copy from ISC. If so, do the copy and exit
        smoothThreatGrid = varDict["Grid Smoothing?"]

        makeOption = varDict[
            "Make grids from \nPHISH, PETSS, ISC, or Manually?"]
        topodb = "NED"

        ssea = self.encodeEditArea("StormSurgeWW_EditArea")

        Topo = self.getAvgTopoGrid(topodb)

        confidenceStr = varDict[
            "Forecast Confidence? - (Applies to PHISH/PETSS Only)"]

        # extract the percent value from this string
        pctPos = confidenceStr.find("%")
        pctStr = confidenceStr[pctPos - 2:pctPos]

        threatWEName = "StormSurgeThreat"

        #print "pctStr is: ", pctStr
        surgePctGrid = None
        surgePctGridMSL = None
        surgePctGridMLLW = None
        surgePctGridNHHW = None
        surgePctGridNAVD = None

        if makeOption == "PHISH" or makeOption == "PETSS":

            # Now get the psurge
            if makeOption == "PHISH":
                modelName = "TPCSurgeProb"
            else:
                modelName = "PETSS"
            surgePctGrid = self.getExceedanceHeight(modelName, pctStr, "FHAG0")
            if surgePctGrid is None:
                message = "No inundation data found for " + modelName
                self.statusBarMsg(message, "S")
                return

            phishMask = ~ssea
            surgePctGrid[phishMask] = 0.0
            surgePctGridNAVD = self.getExceedanceHeight(
                modelName, pctStr, "SFC")
            if surgePctGridNAVD is None:
                message = "No Surge plus Tide NAVD data found for " + modelName
                self.statusBarMsg(message, "S")
                return

            surgePctGridNAVD[phishMask] = -80.0
            if surgePctGrid is None or surgePctGridNAVD is None:
                return

            #
            # The following lines are the gridded vdatum corrections.
            #
            msltonavd = self.getMSLtoNAVD()
            msltomllw = self.getMSLtoMLLW()
            msltomhhw = self.getMSLtoMHHW()
            navdtomllw = self.getNAVDtoMLLW()
            navdtomhhw = self.getNAVDtoMHHW()

            # Apply 3x3 smooth within the surge zone
            # for values greater than 1 as to not underplay areas adjacent to zero value pixels.
            # If you apply a smoother, for consistency among storm surge plus tide and derived
            # grids, it must be done here.
            if smoothThreatGrid == "Yes":
                #mask = np.greater(surgePctGrid, 0.0) & ssea
                #surgePctGrid = np.where(np.greater(surgePctGrid, 0.0), self.GM_smoothGrid(surgePctGrid,3, mask), surgePctGrid)

                #                 mask = np.greater(surgePctGridNAVD, -10.0) & ssea
                #                 surgePctGridNAVD = np.where(np.greater(surgePctGridNAVD, -10.0), self.GM_smoothGrid(surgePctGridNAVD,3, mask), surgePctGridNAVD)

                mask = (surgePctGridNAVD > -10.0) & ssea
                surgePctGridNAVD = self.GM_smoothGrid(surgePctGridNAVD, 3,
                                                      mask)

#             surgePctGridMSL= np.where(mask1, surgePctGridNAVD - msltonavd, np.float32(-80.0)) # MSL Grid
            navdMask = (surgePctGridNAVD > -80.0)
            mask = (msltonavd > -80.0) & navdMask & ssea

            #  MSL Grid
            surgePctGridMSL = surgePctGridNAVD - msltonavd
            surgePctGridMSL[~mask] = -80.0

            #             surgePctGridMLLW = np.where(np.greater(navdtomllw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
            #                                         surgePctGridNAVD + navdtomllw, np.float32(-80.0)) # MLLW Grid

            #  MLLW Grid
            mask = (navdtomllw > -80.0) & navdMask
            surgePctGridMLLW = surgePctGridNAVD + navdtomllw
            surgePctGridMLLW[~mask] = -80.0

            #             surgePctGridMHHW = np.where(np.greater(navdtomhhw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
            #                                         surgePctGridNAVD + navdtomhhw, np.float32(-80.0)) # MHHW Grid
            #  MHHW Grid
            mask = (navdtomhhw > -80.0) & navdMask
            surgePctGridMHHW = surgePctGridNAVD + navdtomhhw
            surgePctGridMHHW[~mask] = -80.0

            #             surgeDiffMLLWMHHW = np.where(np.greater(surgePctGridMLLW,-80.0) & np.greater(surgePctGridMHHW, -80.0), \
            #                                          surgePctGridMLLW-surgePctGridMHHW, np.float32(-80.0)) # Diff Grid Between MLLW and MHHW

            #  Diff Grid Between MLLW and MHHW (i.e tidal range)
            mask = (surgePctGridMLLW > -80.0) & (surgePctGridMHHW > -80.0)
            surgeDiffMLLWMHHW = surgePctGridMLLW - surgePctGridMHHW
            surgeDiffMLLWMHHW[~mask] = -80.0

            #  Mask
            MHHWMask = surgePctGridMHHW <= 0.0

            #surgePctGrid[MHHWMask] = 0.0

            trList, timingGrids = self.makeInundationTiming(
                modelName, pctStr, "FHAG0", smoothThreatGrid, mutableID, ssea,
                MHHWMask)
            #surgePctGrid and InundationMax recomputed from InundationTiming sequence for consistency
            surgePctGrid = self.makeInundationMaxGrid(timingGrids, trList)

        elif makeOption == "ISC":

            elementList = [
                "InundationMax", "InundationTiming", "SurgeHtPlusTideMSL",
                "SurgeHtPlusTideMLLW", "SurgeHtPlusTideNAVD",
                "SurgeHtPlusTideMHHW"
            ]
            surgePctGrid, surgePctGridMSL, surgePctGridMLLW, surgePctGridMHHW, surgePctGridNAVD = self.copyISCGridstoFcst(
                elementList, mutableID)
            # if you look in CopyISC method if either InundationMax or InundationTiming is missing the procedure stops all together and notifies forecaster.
            if surgePctGrid is None:
                return

        elif makeOption == "Manually Replace" or makeOption == "Manually Add":

            inundationHeight = float(varDict["Inundation Height:"])
            inunStartHour = float(varDict["Start Hour for Inundation Timing"])
            inunEndHour = float(varDict["End Hour for Inundation Timing"])

            selectedMask = self.encodeEditArea(editArea)
            if not selectedMask.any():
                self.statusBarMsg(
                    "Please define an area over which to assign the inundation values.",
                    "S")
                return

            modifyMask = selectedMask & ssea
            if not modifyMask.any():
                self.statusBarMsg(
                    "Please define an area that intersects the StormSurgeEditArea to assign the inundation values.",
                    "S")
                return  # Calculate the intersection of the SSEditArea and selected editAre

            if inunStartHour >= inunEndHour:
                self.statusBarMsg(
                    "Please define the end hour after the start hour.", "S")
                return

            surgePctGrid = self.empty()

            # Fetch the old grids if we're adding
            if varDict[
                    "Make grids from \nPHISH, PETSS, ISC, or Manually?"] == "Manually Add":
                imTRList = self.GM_getWEInventory("InundationMax", mutableID,
                                                  "SFC")
                if len(imTRList) > 0:
                    imTR = imTRList[0]
                    surgePctGrid = self.getGrids(mutableID, "InundationMax",
                                                 "SFC", imTR)

            surgePctGrid[modifyMask] = inundationHeight

            # Make the timing grids
            baseTime = self.baseGuidanceTime()
            if makeOption == "Manually Replace":  # Make new grids and replace all IT grids
                trList, timingGrids = self.getTimingGrids()

                for i in range(len(trList)):
                    # only modify grids in the specified time range
                    start = trList[i].startTime().unixTime()
                    end = trList[i].endTime().unixTime()

                    if (start - baseTime) / 3600 >= inunStartHour and (
                            end - baseTime) / 3600 <= inunEndHour:
                        timingGrids[
                            i] = surgePctGrid  # populate only where needed

                timeRange = TimeRange.allTimes()
                self.deleteCmd(["InundationTiming"], timeRange)
                for i in range(len(trList)):
                    timingGrids[i].clip(0.0, 100.0, timingGrids[i])
                    self.createGrid(mutableID, "InundationTiming", "SCALAR",
                                    timingGrids[i], trList[i])

            elif makeOption == "Manually Add":  # Just replace the selected grid points over the selected time
                # Fetch the existing IT grids
                itTRList = self.GM_getWEInventory("InundationTiming",
                                                  mutableID, "SFC")
                if len(itTRList) == 0:
                    self.statusBarMsg(
                        "No InundationTiming grids found at all.", "S")
                    return
                #Fetch the grids
                itGrids = []
                trList = []
                for tr in itTRList:
                    start = tr.startTime().unixTime()
                    end = tr.endTime().unixTime()
                    #print "Checking tr:", tr
                    if (start - baseTime) / 3600 >= inunStartHour and (
                            end - baseTime) / 3600 <= inunEndHour:
                        grid = self.getGrids(mutableID, "InundationTiming",
                                             "SFC", tr)
                        itGrids.append(grid)
                        trList.append(tr)

                if len(itGrids) == 0:
                    self.statusBarMsg(
                        "No InundationTiming grids found for selected start and end hours.",
                        "S")
                    return

                # Surgically insert grid values into the InundationTiming grids over the selected hours
                for i in range(len(trList)):
                    itGrids[i][
                        modifyMask] = inundationHeight  # poke in the values

                    self.createGrid(mutableID, "InundationTiming", "SCALAR",
                                    itGrids[i], trList[i])

                timingGrids = []
                for tr in itTRList:
                    grid = self.getGrids(self.mutableID(), "InundationTiming",
                                         "SFC", tr)
                    grid[~ssea] = 0.0
                    timingGrids.append(grid)

                surgePctGrid = self.makeInundationMaxGrid(
                    timingGrids, itTRList)

        elif makeOption == "UpdateInunMax (Edit Inundation Timing Grids)":

            self.deleteAllGrids([
                "InundationMax", "SurgeHtPlusTideMSL", "SurgeHtPlusTideMLLW",
                "SurgeHtPlusTideNAVD", "SurgeHtPlusTideMHHW",
                "SurgeHtPlusTideMLLW"
            ])

            itTRList = self.GM_getWEInventory("InundationTiming", mutableID,
                                              "SFC")

            if len(itTRList) == 0:
                self.statusBarMsg(
                    "No InundationTiming grids found at all. Inundation grids required to exist when running with this option. Otherwise run with Manual Replace Option.",
                    "S")
                return

            timingGrids = []

            # Fetch all the timing grids
            for tr in itTRList:
                grid = self.getGrids(self.mutableID(), "InundationTiming",
                                     "SFC", tr)
                grid[~ssea] = 0.0
                timingGrids.append(grid)
                self.deleteGrid(mutableID, "InundationTiming", "SFC", tr)
                self.createGrid(mutableID,
                                "InundationTiming",
                                "SCALAR",
                                grid,
                                tr,
                                precision=1)

        # Finally create the surge grid which will be saved as the InundationMax

            surgePctGrid = self.makeInundationMaxGrid(timingGrids, itTRList)

            #return
            # Done with manual options

# Next line introduced on Jan 2017 SWiT. It forces points in InundationMax that are > 1 and < 1.5 to 1.5. This is because TCV rounds to
# nearest one foot for categorical HTI threat level consistency with inundation graphic. Not doing this would cause TCV to throw away zones that
# might have more than 3% coverage of inundation > 1 but less than 1.5 altogether. Changing TCV to key on anything with InundationMax >= 1 would not
# do because it would then include zones in TCV with inundation forecasts of less than 1 but >= 0.5 overdoing the threat.

        surgePctGrid[(surgePctGrid > 1.0) & (surgePctGrid < 1.5)] = 1.5

        threatKeys = self.getDiscreteKeys(threatWEName)

        # Define a mapping between UI names and key names
        # keyMap = {"Very Low" :"Very Low",
        keyMap = {
            "Elevated": "Elevated",
            "Moderate": "Mod",
            "High": "High",
            "Extreme": "Extreme",
        }

        threshDict = {}  # a dict to store thresholds from the UI

        for key in keyMap.keys():

            if keyMap[key] == "Extreme":
                threshDict[keyMap[key]] = 9
            elif keyMap[key] == "High":
                threshDict[keyMap[key]] = 6
            elif keyMap[key] == "Mod":
                threshDict[keyMap[key]] = 3
            elif keyMap[key] == "Elevated":
                threshDict[keyMap[key]] = 1

            #print "threshDict[keyMap[key]]: ", keyMap[key], threshDict[keyMap[key]]

        # make a timeRange - 6 hours long
        elementList = [
            "StormSurgeThreat", "InundationMax", "SurgeHtPlusTideMSL",
            "SurgeHtPlusTideMLLW", "SurgeHtPlusTideNAVD", "SurgeHtPlusTideMHHW"
        ]

        # make a new timeRange that will be used to create new grids
        timeRange = self.makeNewTimeRange(8)

        # Remove old guidance grids and replace them with the new grids
        # Delete the old grids first
        cTime = int(self._gmtime().unixTime() / 3600) * 3600
        startTime = AbsTime.AbsTime(cTime - 48 * 3600)
        endTime = startTime + 240 * 3600
        deleteTimeRange = TimeRange.TimeRange(startTime, endTime)

        for elem in elementList:
            self.deleteCmd([elem], deleteTimeRange)

        if makeOption != "Manually Replace" and makeOption != "Manually Add" and makeOption != "UpdateInunMax (Edit Inundation Timing Grids)":
            if surgePctGridMSL is not None:
                surgePctGridMSL.clip(-30.0, 100.0, surgePctGridMSL)
                self.createGrid(mutableID,
                                "SurgeHtPlusTideMSL",
                                "SCALAR",
                                surgePctGridMSL,
                                timeRange,
                                precision=2)
            if surgePctGridMLLW is not None:
                surgePctGridMLLW.clip(-30.0, 100.0, surgePctGridMLLW)
                self.createGrid(mutableID,
                                "SurgeHtPlusTideMLLW",
                                "SCALAR",
                                surgePctGridMLLW,
                                timeRange,
                                precision=2)
            if surgePctGridNAVD is not None:
                surgePctGridNAVD.clip(-30.0, 100.0, surgePctGridNAVD)
                self.createGrid(mutableID,
                                "SurgeHtPlusTideNAVD",
                                "SCALAR",
                                surgePctGridNAVD,
                                timeRange,
                                precision=2)
            if surgePctGridMHHW is not None:
                surgePctGridMHHW.clip(-30.0, 100.0, surgePctGridMHHW)
                self.createGrid(mutableID,
                                "SurgeHtPlusTideMHHW",
                                "SCALAR",
                                surgePctGridMHHW,
                                timeRange,
                                precision=2)

        # Make the grid. Start with the existing grid if we have one otherwise zeros
        coastalThreat = self.empty(np.int8)
        surgePctGrid.clip(0.0, 100.0, surgePctGrid)
        self.createGrid(mutableID,
                        "InundationMax",
                        "SCALAR",
                        surgePctGrid,
                        timeRange,
                        precision=2)

        # Yet another list to define the order in which we set grid values
        # This order must be ranked lowest to highest
        #keyList = ["Very Low", "Elevated", "Mod", "High", "Extreme"]
        keyList = ["Elevated", "Mod", "High", "Extreme"]

        # Set the grid values based on the surgePctGrid grid and thresholds
        for key in keyList:
            #print "THRESHOLD FOR KEY IS: ", key, threshDict[key]
            thresh = threshDict[key]
            keyIndex = self.getIndex(key, threatKeys)
            #coastalMask = ssea & np.greater_equal(surgePctGrid, thresh)
            coastalMask = ssea & np.greater(surgePctGrid, thresh)
            coastalThreat[coastalMask] = keyIndex

#       create the CoastalThreat Grid
        self.createGrid(mutableID,
                        threatWEName,
                        "DISCRETE", (coastalThreat, threatKeys),
                        timeRange,
                        discreteKeys=threatKeys,
                        discreteOverlap=0,
                        discreteAuxDataLength=2,
                        defaultColorTable="Hazards")

        t1 = time.time()
        LogStream.logEvent("Finished TCStormSurgeThreat in %f.4 ms" %
                           ((t1 - t0) * 1000))

        return
Exemplo n.º 33
0
    def _createGrids(self, entry):
        createGrids = entry.get("createGrids", None)
        if createGrids is None:
            return
        if self._createGridsRunTime == "no":
            return
        # Check to see if the last time we created grids we used the same list
        # If so, do not repeat
        if self._lastCreateGrids == createGrids:
            return
        self._lastCreateGrids = createGrids

        wxKeys = []
        hazKeys = []
        gridsTR = TimeRange.TimeRange(self._gridsStartTime,
                                      self._gridsStartTime + 12 * 3600)
        self._determineMaxMinBeginEnd(entry)
        hazardGrid = None
        createdGrids = {}
        for gridEntry in createGrids:
            if len(gridEntry) == 7:
                model, elementName, elementType, startHour, endHour, value, editAreas = gridEntry
                defValue = 0
            elif len(gridEntry) == 8:
                model, elementName, elementType, startHour, endHour, value, editAreas, defValue = gridEntry
            else:
                #print "GridEntries: ", gridEntry
                raise Exception("Improper # of Grid Entries")
            startHour = self._translateHour(startHour)
            endHour = self._translateHour(endHour)
            timeRange = TimeRange.TimeRange(
                gridsTR.startTime() + startHour * 3600,
                gridsTR.startTime() + endHour * 3600)
            #self.output("element name, type " + elementName + " " + elementType, self._outFile)
            #self.output("startHour, endHour " + `startHour` +" "+`endHour`, self._outFile)
            #self.output("   timeRange "+`timeRange`, self._outFile)
            # Get the grid we already created, if it exists
            key = (model, elementName, startHour, endHour)
            if createdGrids.has_key(key):
                grid = createdGrids[key]
            else:
                grid = self.newGrid(defValue)

            if editAreas == "all":
                mask = self.newGrid(True, bool)
            else:
                mask = self._makeMask(editAreas)
            #self.output("mask "+`size(mask)`, self._outFile)
            #self.output("grid "+`size(grid)`, self._outFile)
            #self.output("value "+`value` , self._outFile)
            if elementType == "DISCRETE":
                #self._addHazard(elementName, timeRange, value, mask)
                value = self.getIndex(value, hazKeys)
                #self.output("setting value "+value+" "+hazKeys, self._outFile)
                grid[mask] = value
                grid = grid.astype('int8')
                elementType = self.getDataType(elementName)
                self.createGrid(model, elementName, elementType,
                                (grid, hazKeys), timeRange)
            elif elementType == "WEATHER":
                if value == "NoWx":
                    value = "<NoCov>:<NoWx>:<NoInten>:<NoVis>:"
                value = self.getIndex(value, wxKeys)
                #self.output("setting value "+value+" "+wxKeys, self._outFile)
                grid[mask] = value
                grid = grid.astype('int8')
                elementType = self.getDataType(elementName)
                self.createGrid(model, elementName, elementType,
                                (grid, wxKeys), timeRange)
            elif elementType == "VECTOR":
                grid[mask] = value[0]
                dirGrid = self.empty()
                dirGrid[mask] = self.textToDir(value[1])
                elementType = self.getDataType(elementName)
                self.createGrid(model, elementName, elementType,
                                (grid, dirGrid), timeRange)
            else:
                grid[mask] = value
                elementType = self.getDataType(elementName)
                self.createGrid(model, elementName, elementType, grid,
                                timeRange)
            # Save the grid in the createdGridDict
            createdGrids[key] = grid
            self.saveElements([elementName], model)
            if entry.get("publishGrids", 0):
                self.publishElements([elementName], timeRange)
Exemplo n.º 34
0
 def GM_makeMaxTimeRange(self):
     """Gets the maximum possible time range
     Returns:
         The maximum possible Python time range.
     """
     return TimeRange.allTimes()
Exemplo n.º 35
0
 def shiftedTimeRange(self, timeRange):
     # Shift the given time range to local time.
     # It is assumed to be in GMT.
     localTime, shift = self.determineTimeShift()
     return TimeRange.TimeRange(timeRange.startTime() + shift,
                                timeRange.endTime() + shift)
Exemplo n.º 36
0
    def GM_interpolateData(self,
                           dataDict,
                           TRlist,
                           interpHours=3,
                           vector=[],
                           singleLevel=[]):
        """Produces an updated Python dictionary with interpolated data where needed
           Args:
               dict dataDict - keyed by TimeRange, data for a specific time, can be mixed (e.g. gh, t, p) 
               list TRList - list of times ranges
               integer interpHours - ????
               list vector - ????
               list singleLevel - ????
           Returns:
               dict of interpolated data ????
        """

        #-----------------------------------------------------------------------
        #  Determine the structure (i.e. how many fields are present) of the
        #  data dictionary

        try:
            numFields = len(dataDict[TRlist[0]])
        except:
            print "No data to interpolate!"
            return dataDict

        #-----------------------------------------------------------------------
        #  Cycle through each time period we already have

        for index in range(len(TRlist) - 1):

            #            print "\tindex = ", index

            #-------------------------------------------------------------------
            #  Define a list to hold the times we need to create soundings for

            makeList = []

            #-------------------------------------------------------------------
            #  Get the time range of the current and next soundings we have

            current = TRlist[index]
            next = TRlist[index + 1]
            #            print '*'*80
            #            print current, next

            #-------------------------------------------------------------------
            #  Get the starting times of each sounding time range

            currentStart = current.startTime().unixTime()
            nextStart = next.startTime().unixTime()

            #-------------------------------------------------------------------
            #  See how far apart these soundings are in time (hours)

            diffTime = nextStart - currentStart
            #            print diffTime, interpHours*3600

            #-------------------------------------------------------------------
            #  If gap between data time steps are more than what we need

            if int(diffTime) > interpHours * 3600:

                #--------------------------------------------------------------
                #  Keep track of seconds we are between data time steps

                curTime = float(interpHours * 3600)

                #---------------------------------------------------------------
                #  Make a new time range every three hours
                #                print '\t', int(currentStart + curTime), int(nextStart)

                while int(currentStart + curTime) < int(nextStart):

                    #-----------------------------------------------------------
                    #  Compute linear interpolation weight

                    weight = curTime / diffTime
                    #                    print "weight = ", weight

                    #-----------------------------------------------------------
                    #  Make a new TimeRange object for this new time step

                    newTR = TimeRange.TimeRange(
                        AbsTime.AbsTime(currentStart + curTime),
                        AbsTime.AbsTime(currentStart + curTime + 3600))

                    #-----------------------------------------------------------
                    #  Define an empty string to hold all interpolated data
                    #  which should be placed within the final data structure
                    #  for this time

                    finalData = ""

                    #===========================================================
                    #  Interpolate data for each field at this time step

                    for field in range(numFields):

                        #  Create a final data structure for interpolated data
                        exec "data%d = []" % (field)

                        #  If this field is a vector, make component data
                        #  structures
                        if field in vector:
                            exec "data%dU = []" % (field)
                            exec "data%dV = []" % (field)

                        #-------------------------------------------------------
                        #  Get data from the current and next time steps we have

                        try:
                            curData = dataDict[current][field]
                        except:
                            #  No point in continuing with this time step
                            msg = "Could not get 'current' data -> %s" % \
                                  (repr(current))
                            self.statusBarMsg(msg, "R")
                            continue  # move on

                        try:
                            nextData = dataDict[next][field]
                        except:
                            #  No point in continuing with this time step
                            msg = "Could not get 'next' data -> %s" % \
                                  (repr(next))
                            self.statusBarMsg(msg, "R")
                            continue  # move on

                        #-------------------------------------------------------
                        #  If this field is a vector, separate it into its'
                        #  u and v components

                        if field in vector:

                            (curU,
                             curV) = self.MagDirToUV(curData[0], curData[1])

                            (nextU,
                             nextV) = self.MagDirToUV(nextData[0], nextData[1])

                        #=======================================================
                        #  If this field is a single level

                        if field in singleLevel:

                            if not vector:
                                data = (curData +
                                        (nextData - curData) * weight)
                            else:
                                u = (curU + (nextU - curU) * weight)
                                v = (curV + (nextV - curV) * weight)

                            #---------------------------------------------------
                            #  Get the newly interpolated grids

                            if not vector:

                                if type(data) == types.ListType:
                                    dataGrid = data[0]
                                else:
                                    dataGrid = data

                            else:
                                if type(u) == types.ListType:
                                    uGrid = u[0]
                                else:
                                    uGrid = u

                                if type(v) == types.ListType:
                                    vGrid = v[0]
                                else:
                                    vGrid = v

                            #---------------------------------------------------
                            #  Add current level into the new data structure

                            if not vector:
                                exec "data%d = array(dataGrid)" % (field)
                            else:
                                exec "data%dU = array(uGrid)" % (field)
                                exec "data%dV = array(vGrid)" % (field)

                        #=======================================================
                        #  Otherwise, cycle through each level in the sounding

                        else:

                            for level in xrange(curData.shape[0]):

                                #-----------------------------------------------
                                #  Construct sounding values for this level

                                if not vector:
                                    data = (
                                        curData[level] +
                                        (nextData[level] - curData[level]) *
                                        weight)
                                else:
                                    u = (curU[level] +
                                         (nextU[level] - curU[level]) * weight)

                                    v = (curV[level] +
                                         (nextV[level] - curV[level]) * weight)

                                #-----------------------------------------------
                                #  Get the newly interpolated grids

                                if not vector:

                                    if type(data) == types.ListType:
                                        dataGrid = data[0]
                                    else:
                                        dataGrid = data

                                else:
                                    if type(u) == types.ListType:
                                        uGrid = u[0]
                                    else:
                                        uGrid = u

                                    if type(v) == types.ListType:
                                        vGrid = v[0]
                                    else:
                                        vGrid = v

                                #-----------------------------------------------
                                #  Add current level into the new sounding

                                if not vector:
                                    exec "data%d = data%d + [dataGrid]" % \
                                         (field, field)
                                else:
                                    exec "data%dU = data%dU + [uGrid]" % \
                                         (field, field)
                                    exec "data%dV = data%dV + [vGrid]" % \
                                         (field, field)

                            #---------------------------------------------------
                            #  Finish off the new cube for this time

                            if not vector:
                                exec "data%d = array(data%d)" % (field, field)
                            else:
                                exec "data%dU = array(data%dU)" % (field,
                                                                   field)
                                exec "data%dV = array(data%dV)" % (field,
                                                                   field)

                        #=======================================================
                        #  If this is a vector field, reconstruct vector from
                        #  the components

                        if vector:
                            exec "data%d = self.UVToMagDir(data%dU, data%dV)" %\
                                 (field, field, field)

                        #=======================================================
                        #  Add current interpolated data for this time step to
                        #  the final data structure

                        exec "finalData += 'data%d'" % (field)

                        if field < (numFields - 1):
                            finalData += ", "

                    #-----------------------------------------------------------
                    #  Add this interpolated data to data structure

                    exec "dataDict[newTR] = (%s)" % (finalData)

                    msg = "Created data for -> %s" % (repr(newTR))
                    self.statusBarMsg(msg, "R")

                    #-----------------------------------------------------------
                    #  Move on to next desired time step

                    curTime += float(interpHours) * 3600.0

        #-----------------------------------------------------------------------
        #  Return the completed data dictionary

        return dataDict
Exemplo n.º 37
0
    def getWfosAttention(self, WEname, anyChanges=None, percentThresh=3):
        #  anyChanges is a mask, where True means a change in hazards happened

        #  Make a list of WFOs NHC might communicate with
        searchWfos = set(self._surgeWfos + self._windWfos)

        #  Make sets to track WFOs with only surge hazards, those with only
        #  wind hazards, and those with both
        surgeWfos = set()
        windWfos = set()
        bothWfos = set()

        #  Make a dictionary of masks for all of these offices
        officeMasks = {}
        for wfo in searchWfos:
            try:
                officeMasks[wfo] = self.encodeEditArea("ISC_%s" %
                                                       (wfo.upper()))

                #  If we are looking for any changes to the underlying field
                if anyChanges is not None:

                    #  See if there are any changes in hazards for this WFO
                    overlay = (anyChanges & officeMasks[wfo])

                    if overlay.any():
                        msg = "Adding to surge - " + wfo + " for changes"
                        self.statusBarMsg(msg, 'R')
                        surgeWfos.add(wfo)
            except:
                msg = "No edit area found. Removing " + wfo + \
                      " from further processing."
                self.statusBarMsg(msg, 'U')

        #  Get the Hazards grid
        hazardGridList = self.getGrids(self._mutableID,
                                       WEname,
                                       "SFC",
                                       TimeRange.allTimes(),
                                       mode="List",
                                       noDataError=0)

        #         print "hazardGridList =", hazardGridList

        #  If there are no hazard grids
        if hazardGridList is None:
            hazardGridList = []

        #  Look at each WFO which needs a message
        for (hazardBytes, hazardKeys) in hazardGridList:

            #             print "Starting to examine hazards"

            #  Look at each hazard key in this grid - except the first, <None>
            for (index, key) in enumerate(hazardKeys):

                #  Ignore the <None> and <Invalid> keys
                if key in ["<None>", "<Invalid>"]:
                    continue  #  do not bother looking further

#                 print "\n\nLooking at ", index, key

#  Check this key for either storm surge (SS), or wind (HU, TR)
#  hazards
                if re.search("(SS|HU|TR).[AW]", key) is not None:

                    #                     print "found a tropical hazard"
                    hazardType = "both"  #  assume both hazards are here

                    #-----------------------------------------------------------
                    #  See if which type of hazard this is

                    #  Wind hazard, no surge hazard
                    if re.search("(HU|TR).[AW]", key) is not None and \
                       re.search("SS.[AW]", key) is None:

                        hazardType = "wind-only"

                    #  Surge hazard, no wind hazard
                    elif re.search("SS.[AW]", key) is not None and \
                         re.search("(HU|TR).[AW]", key) is None:

                        hazardType = "surge-only"

                    #  See where this hazard is on the grid
                    hazardMask = hazardBytes == index

                    #  Now determine which offices we need to notify
                    for wfo, wfoMask in officeMasks.items():

                        #  See if this office has a current hazard
                        overlay = (officeMasks[wfo] & hazardMask)

                        #  If there are any points which overlap
                        if overlay.any():

                            #                            print "Getting zones for '%s'" % (wfo)

                            #  We need to look at all the zones associated
                            #  with this WFO, get them
                            zoneList = self.findWfoZones(wfo)
                            if len(zoneList) == 0:
                                msg = "\tCould not get zones for " + wfo
                                LogStream.logProblem(msg)
                                continue

                            #  Now, process each zone
                            for zone in zoneList:

                                #                                print zone,

                                #  Get the mask for this zone
                                try:
                                    zoneMask = self.encodeEditArea(zone)
                                except errno:
                                    msg = "\tCould not get zone mask for " + wfo
                                    LogStream.logProblem(msg, LogStream.exc())
                                    continue

#                                #  If we did not get this mask - move on
#                                if zoneMask is None:
#                                    continue

#  See if there is an overlap with current
#  hazard type
                                zoneOverlap = zoneMask & hazardMask

                                #=======================================================================
                                #  This code kept in case we need to enforce the 3% area of a zone
                                #  requirement in the future. This would mimic the process of the text
                                #  formatters.
                                #  Count all the points of the masks
                                #                                 countOverlap = np.count_nonzero(zoneOverlap)
                                #                                 countMask = np.count_nonzero(zoneMask)
                                #
                                #                                 #  See if there are enough points to justify
                                #                                 #  keeping this zone in the list
                                #                                 zonePercent = (
                                #                                     float(countOverlap) / float(countMask)
                                #                                 )

                                #                                 print "overlap = %d\tmask = %d\tpercent =%.2f" % \
                                #                                       (countOverlap, countMask, zonePercent)
                                #
                                #  If the percentage is high enough
                                #                                 if int((zonePercent*100.0) + 0.5) >= percentThresh:
                                #
                                #=======================================================================

                                #  For now, notify any zone which has a
                                #  possibility for a storm surge hazard
                                if zoneOverlap.any():

                                    #  We need to notify this WFO
                                    if hazardType == "wind-only":
                                        msg = "Adding to wind - " + wfo
                                        windWfos.add(wfo)
                                    elif hazardType == "surge-only":
                                        msg = "Adding to surge - " + wfo
                                        surgeWfos.add(wfo)
                                    else:
                                        msg = "Adding to both - " + wfo
                                        bothWfos.add(wfo)

                                    self.statusBarMsg(msg, 'R')
                                    print msg

                                    #  No point in looking at further zones
                                    break

        #=======================================================================
        #  Now ensure we do not duplicate WFOs with both hazards in the
        #  individual hazard sets.  Use this code when we are no longer using
        #  the text TCV to notify WFOs of tropical wind hazards.

#         for wfo in bothWfos:
#             if wfo in windWfos:
#                 windWfos.discard(wfo)
#             if wfo in surgeWfos:
#                 surgeWfos.discard(wfo)

#=======================================================================
#  Now ensure we do not duplicate WFOs with both hazards in the
#  individual hazard sets - this is for the 2016 season

        for wfo in bothWfos:
            surgeWfos.add(wfo)

        #  Reset the sets for "both" and "wind-only" WFOs
        bothWfos = set()
        windWfos = set()

        #  Return the completed WFO notification list
        return (list(bothWfos), list(windWfos), list(surgeWfos))
Exemplo n.º 38
0
    def execute(self, editArea, timeRange, varDict):

        buttonList, timeList = self.getButtonNames()
        GFEDomainname = self.getSiteID()
        print "GFEDomain is: ", GFEDomainname
        cron = True

        if varDict is None:  # This means the tool is being run interactively, so make the GUI.

            variableList = [
                ("How Long Do You Want To Run NWPS:", 102, "scale", [12,
                                                                     102], 3),
                #("NWPS Model Winds:", "ForecastWindGrids", "radio", ["ForecastWindGrids"]),
                ("Model Start Time:", buttonList[4], "radio", buttonList),
                ("Local, NCEP, or Both:", "Both", "radio",
                 ["Local", "NCEP", "Both"]),
                ("Model Core:", "SWAN", "radio", ["SWAN", "NWW", "UNSWAN"]),
                ("Send Output to Web:", "Yes", "radio", ["Yes", "No"]),
                ("Plot Output Only (No Web):", "No", "radio", ["Yes", "No"]),
                ("Boundary Conditions:", "WNAWave", "radio",
                 ["WNAWave", "TAFB-NWPS", "HURWave", "No"]),
                ("**Boundary Conditions: OPC/TAFB-NWPS:   CHECK www.srh.noaa.gov/rtimages/nhc/wfo_boundary_conditions for up to date files for your SITE**\nNOTE: make sure there is a file time stamp online matching your selected Model Start Time",
                 "", "label"),
                ("Run Hi Res NEST:", "Yes", "radio", ["Yes", "No"]),
                ("RTOFS Currents:", "Yes", "radio", ["Yes", "No"]),
                ("Model Time Step:", "600", "radio",
                 ["1200", "900", "600", "300"]),
                ("Hotstart:", "True", "radio", ["True", "False"]),
                ("Waterlevels:", "ESTOFS", "radio", ["ESTOFS", "PSURGE",
                                                     "No"]),
                ("If PSURGE\n% Exceedance Hgt:", "10", "radio",
                 ["10", "20", "30", "40", "50"]),
            ]

            varDict = {}
            processVarList = ProcessVariableList.ProcessVariableList(
                "Run_NWPS", variableList, varDict, None)
            status = processVarList.status()
            if status != "OK":
                return

            fcst_length = processVarList.varDict(
            )["How Long Do You Want To Run NWPS:"]
            fcstlength = str(fcst_length)
            wind = "ForecastWindGrids"
            modelstarttime = processVarList.varDict()["Model Start Time:"]
            wheretorun = processVarList.varDict()["Local, NCEP, or Both:"]
            model = processVarList.varDict()["Model Core:"]
            web = processVarList.varDict()["Send Output to Web:"]
            plot = processVarList.varDict()["Plot Output Only (No Web):"]
            wna = processVarList.varDict()["Boundary Conditions:"]
            nest = processVarList.varDict()["Run Hi Res NEST:"]
            gstream = processVarList.varDict()["RTOFS Currents:"]
            tstep = processVarList.varDict()["Model Time Step:"]
            hotstart = processVarList.varDict()["Hotstart:"]
            waterlevels = processVarList.varDict()["Waterlevels:"]
            excd = processVarList.varDict()["If PSURGE\n% Exceedance Hgt:"]
            cron = False
            # end interactive GUI portion

        else:

            # This part of if else statement assumes procedure is being run from command
            #line with variable list passed on using the -V option to runProcedure. This
            #allows to run procedure from a cron. Example default for runProcedure would be:
            # All variables shown below passed with -V option are required for procedure to run properly.
            # /awips2/GFESuite/bin/runProcedure -n Run_NWPS -c gfeConfig
            # -V '{"fcstlength":"102","wind":"ForecastWindGrids","wheretorun":"NCEP","model":"SWAN","web":"Yes","plot":"Yes","wna":"WNAWave","nest":"Yes","gstream":"Yes","tstep":"600","hotstart":"True","waterlevels":"ESTOFS","excd":"10"}'
            # If running from a cron, you do not need to create a SITE level override of this baseline procedure if your input variables
            # are different because you pass that on from the command line.

            modelstarttime = buttonList[4]
            fcstlength = varDict['fcstlength']
            wind = varDict['wind']
            wheretorun = varDict['wheretorun']
            model = varDict['model']
            web = varDict['web']
            plot = varDict['plot']
            wna = varDict['wna']
            nest = varDict['nest']
            gstream = varDict['gstream']
            tstep = varDict['tstep']
            hotstart = varDict['hotstart']
            waterlevels = varDict['waterlevels']
            excd = varDict['excd']

        modelTR = self.getModelTimeRange("Fcst", "Wind")
        startHour = modelTR[1]
        endHour = modelTR[2]
        timeRange = modelTR[0]

        if (modelstarttime == buttonList[0]):
            starttime = timeList[0]
        elif (modelstarttime == buttonList[1]):
            starttime = timeList[1]
        elif (modelstarttime == buttonList[2]):
            starttime = timeList[2]
        elif (modelstarttime == buttonList[3]):
            starttime = timeList[3]
        elif (modelstarttime == buttonList[4]):
            starttime = timeList[4]
        elif (modelstarttime == buttonList[5]):
            starttime = timeList[5]
        elif (modelstarttime == buttonList[6]):
            starttime = timeList[6]
        else:
            starttime = startHour  # Model start Hour if all others empty

        if (startHour > starttime):
            starttime = startHour

        timeRange1 = TimeRange.TimeRange(
            AbsTime.AbsTime(starttime - 7 * 24 * 3600),
            AbsTime.AbsTime(starttime + 8 * 24 * 3600))
        timeRange2 = TimeRange.TimeRange(
            AbsTime.AbsTime(starttime),
            AbsTime.AbsTime(starttime + 8 * 24 * 3600))

        self.deleteCmd(['NWPSwind'], timeRange1)
        databaseID = self.findDatabase("Fcst")
        self.copyToCmd([('Wind', 'NWPSwind')], databaseID, timeRange2)
        self.fragmentCmd(['NWPSwind'], timeRange2)
        self.saveElements(["NWPSwind"])

        inp_args = fcstlength + ":" + wna + ":" + nest + ":" + gstream + ":" + wind + ":" + web + ":" + plot + ":" + tstep + ":" + hotstart + ":" + waterlevels + ":" + model + ":" + excd + ":" + wheretorun

        try:
            os.stat('/tmp/nwps/' + GFEDomainname)
        except:
            os.makedirs('/tmp/nwps/' + GFEDomainname)
        os.chmod('/tmp/nwps/' + GFEDomainname, 0o775)

        with open('/tmp/nwps/' + GFEDomainname + '/inp_args', 'w') as f:
            f.write(inp_args)
        os.chmod('/tmp/nwps/' + GFEDomainname + '/inp_args', 0o666)

        os.system('ssh -q px2f mkdir -p /awips2/GFESuite/nwps/' +
                  GFEDomainname + '_var')
        os.system('ssh -q px2f chmod 775 /awips2/GFESuite/nwps/' +
                  GFEDomainname + '_var')
        os.system('scp -rpq /tmp/nwps/' + GFEDomainname +
                  '/inp_args px2f:/awips2/GFESuite/nwps/' + GFEDomainname +
                  '_var/')
        if cron:
            os.system(
                'ssh -q px2f /awips2/GFESuite/nwps/bin/runManualNWPS_OutsideAWIPS.sh '
                + GFEDomainname)
        else:
            os.system(
                'nohup xterm -iconic -e ssh -q px2f /awips2/GFESuite/nwps/bin/runManualNWPS_OutsideAWIPS.sh '
                + GFEDomainname + ' &')
        shutil.rmtree('/tmp/nwps/' + GFEDomainname)