Exemplo n.º 1
0
def mkSDgrd(InGrd):

    Slabgrid = InGrd

    dx = Slabgrid.geodict[
        'xdim'] * 111.19  ## Define dx as the longitude increments and convert to km
    dy = Slabgrid.geodict[
        'ydim'] * 111.19  ## Define dy as the latitude increments and convert to km
    Xgrad, Ygrad = np.gradient(
        Slabgrid.griddata, dx,
        dy)  ## Define grids of the gradients in the x and y directions
    Maggrid = np.sqrt(
        (Xgrad**2) + (Ygrad**2)
    )  ## Define a grid file that is the gradient magnitude at any given node
    Dirgrid = -1 * (
        np.degrees(np.arctan2(Ygrad, Xgrad)) - 90
    )  ## Define a grid file that is the direction perpendicular to the max gradient - in degrees clockwise from N (0 - 360)
    Dirgrid[Dirgrid < 0] += 360

    Dipgrid = gmt.GMTGrid()
    Strikegrid = gmt.GMTGrid()
    Dipgrid.griddata = np.degrees(np.arctan2(Maggrid, 1))
    Strikegrid.griddata = Dirgrid
    Dipgrid.geodict = Slabgrid.geodict.copy()
    Strikegrid.geodict = Slabgrid.geodict.copy()

    return Strikegrid, Dipgrid
Exemplo n.º 2
0
def clipGrid(ingrid, mask):

    ### Input:
    # ingrid: a gmt style grid such as created by gmt.GMTgrid() or by mySurface above
    # mask: clipping mask grid from mkMask

    ### Output:
    # outgrid: same as ingrid, but clipped

    outgrid = gmt.GMTGrid()
    outgrid.griddata = np.multiply(ingrid.griddata, np.flipud(mask))
    outgrid.geodict = ingrid.geodict.copy()

    return outgrid
Exemplo n.º 3
0
def gaussGridFilt(ingrid, filterwidth):

    ### Input:
    # ingrid: a gmt style grid such as created by gmt.GMTgrid() or by mySurface above which has not been clipped using a clipping mask.  ASSUMES SQUARE GRIDS
    # filterwidth: width (in same units as grid spacing) of gaussian filter.  equivalent to 2*sigma of the gaussian

    ### Output:
    # outgrid: same as ingrid, but filtered (smoothed)

    outgrid = gmt.GMTGrid()
    outgrid.geodict = ingrid.geodict.copy()
    sigma = (filterwidth / 2) / outgrid.geodict['xdim']
    outgrid.griddata = ndimage.filters.gaussian_filter(ingrid.griddata, sigma)

    return outgrid
Exemplo n.º 4
0
def mySurface(data, node, T):

    ### Input:
    # data: (n x 3) numpy array of form x,y,z where x,y are coordinates and z is value
    # node: float to indicate node spacing *note that this code uses only square grids
    # T: tension factor (float from 0-1) where 0 = minimum curvature solution

    ### Output:
    # newgrid: gmt-style grid after NEICIO format that is a surface of input data
    # xi: numpy array with x,y coordinates for each node

    xmin, xmax = data[:, 0].min(), data[:, 0].max()
    ymin, ymax = data[:, 1].min(), data[:, 1].max()

    xall = np.arange(np.floor(xmin), np.ceil(xmax) + node / 2, node)
    yall = np.arange(np.floor(ymin), np.ceil(ymax) + node, node)

    n = len(xall)
    m = len(yall)

    xpts, ypts = np.meshgrid(xall, yall)

    xi = np.zeros((m * n, 2))
    xi[:, 0] = xpts.flatten()
    xi[:, 1] = ypts.flatten()

    np.savetxt('temp.xyz', data, fmt='%0.4f', delimiter=' ')
    rflag = "-R%s/%s/%s/%s" % (np.floor(xmin), np.ceil(xmax), np.floor(ymin),
                               np.ceil(ymax))
    iflag = "-I%s/%s" % (node, node)
    gflag = "-Gtemp.grd"
    tflag = "-T%s" % (T)

    os.system("gmt4 blockmean temp.xyz %s %s | gmt4 surface %s %s %s %s" %
              (rflag, iflag, rflag, iflag, gflag, tflag))

    newgrid = gmt.GMTGrid('temp.grd')

    os.system("rm temp.xyz")
    os.system("rm temp.grd")

    return newgrid, xi
Exemplo n.º 5
0
minnum = 20
maxnum = 200

# depth threhsolds

mindepthcut = 60
maxdepthcut = 500
###########################

### Section 2: Load input files

print "Loading input files..."

Tomo = np.loadtxt(tomofile)  ## Load tomography file into a numpy array
Tomo[:, 1][Tomo[:, 1] > 180] -= 360
Slabgrid = gmt.GMTGrid(
    slabfile)  ## Load netcdf file of slabguide into a "grid"
if Slabgrid.geodict['xmin'] > 180:
    Slabgrid.geodict['xmin'] -= 360
if Slabgrid.geodict['xmax'] > 180:
    Slabgrid.geodict['xmax'] -= 360

Slabgrid.griddata = Slabgrid.griddata * -1  ## WILL NEED TO CHANGE THIS IF INPUT IS IN NEGATIVE DEPTH

print "Building strike and dip grids..."

Strikegrid, Dipgrid = sf.mkSDgrd(
    Slabgrid)  ## Strikes follow right hand rule, dips are positive in degrees

############################

### Section 3: Create grid of slab guide info