Ejemplo n.º 1
0
    def createAlgsList(self):
        # First we populate the list of algorithms with those created
        # extending GeoAlgorithm directly (those that execute GDAL
        # using the console)
        self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
                              rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(),
                              ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
                              sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
                              hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
                              ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
                              GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(),
                              # ----- OGR tools -----
                              OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
                              Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
                              Ogr2OgrBuffer(), Ogr2OgrDissolve(), Ogr2OgrOneSideBuffer(),
                              Ogr2OgrTableToPostGisList(), OgrSql(),
                              ]

        # And then we add those that are created as python scripts
        folder = self.scriptsFolder()
        if os.path.exists(folder):
            for descriptionFile in os.listdir(folder):
                if descriptionFile.endswith('py'):
                    try:
                        fullpath = os.path.join(self.scriptsFolder(),
                                                descriptionFile)
                        alg = GdalScriptAlgorithm(fullpath)
                        self.preloadedAlgs.append(alg)
                    except WrongScriptException as e:
                        ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
Ejemplo n.º 2
0
    def createAlgsList(self):
        # First we populate the list of algorithms with those created
        # extending GeoAlgorithm directly (those that execute GDAL
        # using the console)
        self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
            rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(),
            ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
            sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
            hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
            ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
            GridDataMetrics(),
            # ----- OGR tools -----
            OgrInfo(), Ogr2Ogr(), OgrSql(),
            ]

        # And then we add those that are created as python scripts
        folder = self.scriptsFolder()
        if os.path.exists(folder):
            for descriptionFile in os.listdir(folder):
                if descriptionFile.endswith('py'):
                    try:
                        fullpath = os.path.join(self.scriptsFolder(),
                                descriptionFile)
                        alg = GdalScriptAlgorithm(fullpath)
                        self.preloadedAlgs.append(alg)
                    except WrongScriptException, e:
                        ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
Ejemplo n.º 3
0
 def testBasics(self):
     SIZE = 100
     INTERCEPT = 5
     SLOPE = 3
     SD = 1.0
     tolerance = 4 * SD / np.sqrt(SIZE)
     xarray = np.array(range(SIZE), dtype=float)
     yarray = INTERCEPT + SLOPE * xarray + sp.random.normal(0, SD, SIZE)
     computed_slope = slope(xarray, yarray)
     self.assertLessEqual(abs(computed_slope[0] - SLOPE), tolerance)
Ejemplo n.º 4
0
 def testBasics(self):
   SIZE = 100
   INTERCEPT = 5
   SLOPE = 3
   SD = 1.0
   tolerance = 4*SD/np.sqrt(SIZE)
   xarray = np.array(range(SIZE), dtype=float)
   yarray = INTERCEPT + SLOPE*xarray + sp.random.normal(0, SD, SIZE)
   computed_slope = slope(xarray, yarray)
   self.assertLessEqual(abs(computed_slope[0] - SLOPE), tolerance)
Ejemplo n.º 5
0
 def createAlgsList(self):
     # First we populate the list of algorithms with those created
     # extending GeoAlgorithm directly (those that execute GDAL
     # using the console)
     self.preloadedAlgs = [
         nearblack(),
         information(),
         warp(),
         translate(),
         rgb2pct(),
         pct2rgb(),
         merge(),
         buildvrt(),
         polygonize(),
         gdaladdo(),
         ClipByExtent(),
         ClipByMask(),
         contour(),
         rasterize(),
         proximity(),
         sieve(),
         fillnodata(),
         ExtractProjection(),
         gdal2xyz(),
         hillshade(),
         slope(),
         aspect(),
         tri(),
         tpi(),
         roughness(),
         ColorRelief(),
         GridInvDist(),
         GridAverage(),
         GridNearest(),
         GridDataMetrics(),
         gdaltindex(),
         gdalcalc(),
         rasterize_over(),
         retile(),
         gdal2tiles(),
         # ----- OGR tools -----
         OgrInfo(),
         Ogr2Ogr(),
         Ogr2OgrClip(),
         Ogr2OgrClipExtent(),
         Ogr2OgrToPostGis(),
         Ogr2OgrToPostGisList(),
         Ogr2OgrPointsOnLines(),
         Ogr2OgrBuffer(),
         Ogr2OgrDissolve(),
         Ogr2OgrOneSideBuffer(),
         Ogr2OgrTableToPostGisList(),
         OgrSql(),
     ]
Ejemplo n.º 6
0
 def createAlgsList(self):
     # First we populate the list of algorithms with those created
     # extending GeoAlgorithm directly (those that execute GDAL
     # using the console)
     self.preloadedAlgs = [
         nearblack(),
         information(),
         warp(),
         translate(),
         rgb2pct(),
         pct2rgb(),
         merge(),
         buildvrt(),
         polygonize(),
         gdaladdo(),
         ClipByExtent(),
         ClipByMask(),
         contour(),
         rasterize(),
         proximity(),
         sieve(),
         fillnodata(),
         ExtractProjection(),
         gdal2xyz(),
         hillshade(),
         slope(),
         aspect(),
         tri(),
         tpi(),
         roughness(),
         ColorRelief(),
         GridInvDist(),
         GridAverage(),
         GridNearest(),
         GridDataMetrics(),
         gdaltindex(),
         gdalcalc(),
         rasterize_over(),
         retile(),
         gdal2tiles(),
         # ----- OGR tools -----
         OgrInfo(),
         Ogr2Ogr(),
         Ogr2OgrClip(),
         Ogr2OgrClipExtent(),
         Ogr2OgrToPostGis(),
         Ogr2OgrToPostGisList(),
         Ogr2OgrPointsOnLines(),
         Ogr2OgrBuffer(),
         Ogr2OgrDissolve(),
         Ogr2OgrOneSideBuffer(),
         Ogr2OgrTableToPostGisList(),
         OgrSql(),
     ]
def calcSlope(inBlock,
              inXSize,
              inYSize,
              fitPlane=False,
              zScale=1,
              winSize=3,
              minSlope=None):
    """ Calculates slope for a block of data
        Arrays are provided giving the size for each pixel.

        * inBlock - In elevation
        * inXSize - Array of pixel sizes (x)
        * inYSize - Array of pixel sizes (y)
        * fitPlane - Calculate slope by fitting a plane to elevation 
                     data using least squares fitting.
        * zScale - Scaling factor between horizontal and vertical
        * winSize - Window size to fit plane over.
    """
    # If fortran class could be imported use this
    if useFortranSlope:
        if fitPlane:
            outBlock = slope.slopeplane(inBlock[0], inXSize, inYSize, zScale,
                                        winSize)
        else:
            outBlock = slope.slope(inBlock[0], inXSize, inYSize, zScale)
        # Add third dimension (required by rios)
        outBlock = outBlock.reshape(1, outBlock.shape[0], outBlock.shape[1])
        # Cast to 32 bit float (rather than 64 bit numpy default)
        outBlock = outBlock.astype(np.float32)

    else:
        # Otherwise run through loop in python (which will be slower)
        # Setup output block
        outBlock = np.zeros_like(inBlock, dtype=np.float32)
        if fitPlane:
            # Setup matrix and vector required for least squares fitting.
            winOffset = int(winSize / 2)
            A_mat = np.zeros((winSize**2, 3))
            z_vec = np.zeros(winSize**2)

            slopePythonPlane(inBlock, outBlock, inXSize, inYSize, A_mat, z_vec,
                             zScale, winSize)
        else:
            slopePython(inBlock, outBlock, inXSize, inYSize, zScale)

    if minSlope is not None:
        # Set very low values to constant
        outBlock[0] = np.where(
            np.logical_and(outBlock[0] > 0, outBlock[0] < minSlope), minSlope,
            outBlock[0])

    return (outBlock)
Ejemplo n.º 8
0
def calcSlope(inBlock, inXSize, inYSize, fitPlane=False, zScale=1, winSize=3, minSlope=None):
    """ Calculates slope for a block of data
        Arrays are provided giving the size for each pixel.

        * inBlock - In elevation
        * inXSize - Array of pixel sizes (x)
        * inYSize - Array of pixel sizes (y)
        * fitPlane - Calculate slope by fitting a plane to elevation 
                     data using least squares fitting.
        * zScale - Scaling factor between horizontal and vertical
        * winSize - Window size to fit plane over.
    """
    # If fortran class could be imported use this
    if useFortranSlope:
        if fitPlane:
            outBlock = slope.slopeplane(inBlock[0], inXSize, inYSize, zScale, winSize)
        else:
            outBlock = slope.slope(inBlock[0], inXSize, inYSize, zScale)
        # Add third dimension (required by rios)
        outBlock = outBlock.reshape(1, outBlock.shape[0], outBlock.shape[1])
        # Cast to 32 bit float (rather than 64 bit numpy default)
        outBlock = outBlock.astype(np.float32)

    else:
        # Otherwise run through loop in python (which will be slower)
        # Setup output block
        outBlock = np.zeros_like(inBlock, dtype=np.float32)
        if fitPlane:
            # Setup matrix and vector required for least squares fitting.
            winOffset = int(winSize/2)
            A_mat = np.zeros((winSize**2,3))
            z_vec = np.zeros(winSize**2)

            slopePythonPlane(inBlock, outBlock, inXSize, inYSize, A_mat, z_vec, zScale, winSize)
        else:
            slopePython(inBlock, outBlock, inXSize, inYSize, zScale)

    if minSlope is not None:
        # Set very low values to constant
        outBlock[0] = np.where(np.logical_and(outBlock[0] > 0,outBlock[0] < minSlope),minSlope,outBlock[0])

    return(outBlock)
Ejemplo n.º 9
0
ax.append(fig.add_subplot(gs[0:8,11:21]))
ax.append(fig.add_subplot(gs[10:18,0:10]))
ax.append(fig.add_subplot(gs[10:18,11:21]))
ax.append(fig.add_subplot(gs[20:28,0:10]))
ax.append(fig.add_subplot(gs[20:28,11:21]))

for i,q in enumerate(interest):
    md=glue_runs_md('./Models/'+geompath[i]+q)
    Vx=md.results.TransientSolution[time_instance[i]].Vx
    Vy=md.results.TransientSolution[time_instance[i]].Vy
    stress=mechanicalproperties(md, Vx, Vy)

    sigma_xy=md.results.deviatoricstress.xy
    sigma_xy_a=averaging(md, sigma_xy, 0)
    H=np.squeeze(md.results.TransientSolution[time_instance[i]].Thickness)
    shear=slope(md, H*sigma_xy_a)[1]
    shear_a=averaging(md, shear, 0)*-1

    sigma_xx=md.results.deviatoricstress.xx
    sigma_xx_a=averaging(md, sigma_xx, 0)
    sigma_yy=md.results.deviatoricstress.yy
    sigma_yy_a=averaging(md, sigma_yy, 0)
    longi=slope(md, 2*H*sigma_xx_a+H*sigma_yy_a)[0]
    longi_a=averaging(md, longi, 0)*-1
    
    mask=np.zeros(len(shear_a))
    thk=(md.results.TransientSolution[time_instance[i]].Thickness>10)[:,0]
    mask_Vx=np.zeros(len(Vx))
    mask_Vy=np.zeros(len(Vy))
    mask_Vx[thk]=Vx[thk,0]
    mask_Vy[thk]=Vy[thk,0]
Ejemplo n.º 10
0
#Variables
input_, loop = 0, 1

#Main loop
while (loop == 1):
    print(
        '\n--------------------------------------------------\nAssignment 1:\nHello World:[1]   Celsius/Fahrenheit Converter:[2]\nFurlong/Meter/Kilometer Converter:[3]   Slope:[4]\nFibonacci Sequence:[5]   Change Calculator:[6]\nQuit:[7]\n--------------------------------------------------'
    )
    input_ = int(input('>>'))
    if (input_ == 1):
        print('Running Hello World:\n')
        hlwd.hello_world()
    elif (input_ == 2):
        print('Running Celsius/Fahrenheit Converter:\n')
        cov.cel_fah_con()
    elif (input_ == 3):
        print('Running Furlong/Meter/Kilometer Converter:\n')
        cov.fur_met_con()
    elif (input_ == 4):
        print('Running Slope:\n')
        sl.slope()
    elif (input_ == 5):
        print('Running Fibonacci Sequence:\n')
        fib.fib_seq()
    elif (input_ == 6):
        print('Running Change Calculator:\n')
        chg.change()
    elif (input_ == 7):
        loop = 0
    else:
        print('\nERROR: Invalid input, please try again.')
Ejemplo n.º 11
0
if s.exists() == False:
    scrg = arcpy.CreateFileGDB_management(pth, "outputs")
    scr = scrg.getOutput(0) # scratch folder
else:
    scr = os.path.join(pth, "outputs.gdb") #scr = r"in_memory" (if you want to store in memory)

# Check to see if cost dist folder exists (use code in comments if you want results in a folder instead of gdb)
c = Path(os.path.join(pth, "costdist.gdb")) # Path(os.path.join(pth, "costdist"))
if c.exists() == False:
    cstg = arcpy.CreateFileGDB_management(pth, "costdist")  # arcpy.CreateFolder_management(pth, "costdist")
    cst = cstg.getOutput(0) # cost distance folder
else:
    cst = os.path.join(pth, "costdist.gdb") # os.path.join(pth, "costdist")

# Calculate slope and replace 0 slopes with small value
slope(riv, cat, dem, scr)

# Cost distance calculation
costdist(riv, cat, os.path.join(scr, "con_slope"), cst, scr)

# Extract valley
valley(riv, wet, cst, scr, outval)

# Ending script
end = datetime.datetime.now()
print("Script ended at %s" % end)
arcpy.AddMessage ("Script ended at %s" % end)
arcpy.AddMessage ("\n")
time_elapsed = end - start
print("Time elapsed %s" % (time_elapsed))
arcpy.AddMessage ("Time elapsed %s" % time_elapsed)