Example #1
0
 def getCombinations(self, combinations, argDict):
     editAreas = []
     newCombinations = []
     for comboList, areaLabel in combinations:
         newComboList = []
         for editArea in comboList:
             #print("Get edit area TF: get edit area combo", editArea)
             #print("TF2: Get Edit Area set up edit areas", editArea)
             newArea = self.getEditArea(editArea, argDict)
             if comboList.index(editArea) == 0:
                 comboNumber = self.getComboNumber()
                 label = "Combo" + repr(comboNumber)
                 refId = ReferenceID(label)
                 #global GridLoc
                 #GridLoc = newArea.getGloc()
                 area = ReferenceData(newArea)
                 area.setId(refId)
                 #GridLoc, refId, newArea.getPolygons("LATLON"), "LATLON")
                 # randerso: I don't think this is necessary
                 # area.convertToAWIPS()
             newComboList.append(newArea.getId().getName())
             area = self.unionAreas(label, area, newArea)
         if argDict["fcstType"] == "table":
             # Allow user-supplied area labels to be used for simple tables
             editAreas.append((area, areaLabel))
         else:
             editAreas.append((area, label))
         newCombinations.append((newComboList, label))
     return editAreas, newCombinations
Example #2
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)
Example #3
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)