Exemplo n.º 1
0
def test_calculate_large():
   """
   @summary: Tests that calculations work for a single tile (large)
   """
   # We just need a name, not a file
   tf = NamedTemporaryFile(delete=True)
   cAryFn = tf.name
   tf.close()
   myInstance = SingleTileSerialDijkstraLCP(L_INPUT_RASTER, cAryFn, 
                              seaLevelRiseCostFn)
   myInstance.findSourceCells()
   myInstance.calculate()
   
   computedArray = np.loadtxt(cAryFn, dtype=int, comments='', skiprows=6)
   costArray = np.loadtxt(L_COST_RASTER, dtype=int, comments='', skiprows=6)
   
   # Delete temp file
   os.remove(cAryFn)
   
   assert np.array_equiv(computedArray, costArray)
Exemplo n.º 2
0
 def test_all_even(self):
    """
    @summary: This test creates a surface and runs each implementation of the
                 algorithm and checks that the results are the same
    """
    SURFACE_WIDTH = 1000
    SURFACE_HEIGHT = 1000
    STEP_SIZE = .2
    CELL_SIZE = .005
    TILE_SIZE = 1.0
    NUM_CONES = 100
    NUM_ELLIPSOIDS = 100
    MAX_HEIGHT = 50
    MAX_RADIUS = 200
    NUM_WORKERS = 1
    
    # Generate surface
    sg = SurfaceGenerator(SURFACE_HEIGHT, SURFACE_WIDTH, 0.0, 0.0, CELL_SIZE, 
                          defVal=0)
    sg.addRandom(numCones=NUM_CONES, numEllipsoids=NUM_ELLIPSOIDS, 
                 maxHeight=MAX_HEIGHT, maxRad=MAX_RADIUS)
    
    # Make sure that we have at least one source cell
    if np.min(sg.grid) > 0:
       sg.grid[0,0] = 0
    
    # Write out grid
    sg.writeGrid(self.surfaceFn)
    
    inputGrid = np.loadtxt(self.surfaceFn, dtype=int, comments='', skiprows=6)
    
    # Run Dijkstra
    serialInstance = SingleTileSerialDijkstraLCP(self.surfaceFn, 
                                                 self.serialCostFn, 
                                                 seaLevelRiseCostFn)
    serialInstance.findSourceCells()
    serialInstance.calculate()
 
    # Verify grid
    serialAry = np.loadtxt(self.serialCostFn, dtype=int, comments='', skiprows=6)
    self._verifyGrid(serialAry, inputGrid)
 
    # Run parallel Dijkstra
    parInstance = SingleTileParallelDijkstraLCP(self.surfaceFn,
                                                self.parCostFn,
                                                seaLevelRiseCostFn)
    parInstance.setMaxWorkers(16)
    parInstance.setStepSize(.20)
    parInstance.findSourceCells()
    parInstance.calculate()
    
    # Compare serial and parallel single tile
    parAry = np.loadtxt(self.parCostFn, dtype=int, comments='', skiprows=6)
    
    # Verify parallel run
    self._verifyGrid(parAry, inputGrid)
    
    #print len(np.where(serialAry != parAry))
    assert np.array_equal(serialAry, parAry)
    
    # Split surface
    splitTile(self.surfaceFn, TILE_SIZE, self.mtSurfaceDir)
    
    # Split cost surface
    splitTile(self.parCostFn, TILE_SIZE, self.mtCmpDir)
    
    # Run multi-tile
    mtInstance = MultiTileWqParallelDijkstraLCP(self.mtSurfaceDir,
                                                self.mtCostDir,
                                                self.mtOutDir,
                                                TILE_SIZE,
                                                STEP_SIZE,
                                                summaryFn=self.mtSummaryFn)
 
    # Run
    print "Starting workers"
    mtInstance.startWorkers(NUM_WORKERS)
    mtInstance.calculate()
    
    # Only on success
    print "Stopping workers"
    mtInstance.stopWorkers()
    
    # Compare output directories
    assert self._checkOutputs(self.mtCostDir, self.mtCmpDir)
Exemplo n.º 3
0
@author: CJ Grady
@status: alpha
"""
import time

from slr.singleTile.dijkstra import SingleTileSerialDijkstraLCP
# .............................................................................
if __name__ == "__main__":
   
   t1 = time.time()
   inFn = '/home/cjgrady/thesis/fl_east_gom_crm_v1.asc'
   outFn = '/home/cjgrady/thesis/serialDijkstraFL.asc'
   
   def costFn(i, x, y, z):
      c = max(i, y)
      #print i, x, y, z, c
      return c
   
   #costFn = lambda x,y,z: min(x,y)
   t1 = SingleTileSerialDijkstraLCP(inFn, outFn, costFn)
   
   t1.findSourceCells()
   
   print "t1"
   print t1.sourceCells
   
   print "Attempting to calculate"
   t1.calculate()
   
   t2 = time.time()
   print "Elapsed time:", t2-t1