예제 #1
0
def dem2():
    framenumber = 0
    outfile = 'depth_t0s_ft.tt2'

    (X,Y,Q)=cf.fort2griddata(framenumber,xll,yll,cellsize,ncols,nrows)
    print 'converting file to feet'
    X = X*m2ft
    Y = Y*m2ft
    Q = Q*m2ft
    gt.griddata2topofile(X,Y,Q,outfile)

    infile = 'depth_t0s_ft.tt2'
    outfile = 'depth_t0s_ft.asc'
    gt.esriheader(infile,outfile)
예제 #2
0
def fort2topotype(framenumber,
                  outfile,
                  fortdir,
                  xll,
                  yll,
                  cellsize,
                  ncols,
                  nrows,
                  m=1,
                  topotype=2):
    """
    convert data in a fort file of framenumber = XXXX, ie fort.qXXXX
    to a DEM style file of topotype=1,2 or 3, or gdal (gdal/esri header) with uniform spacing.
    m is the component of q, ie. the column in the fort.qXXXX file
    for all components of q, see fort2xyscattered or amr2single

    specifying xll, yll, cellsize, ncols, nrows will result in interpolation of AMR data

    without xll, yll, cellsize, ncols, nrows...the domain will be the same as input frame
    and coarse resolution. 
    """

    try:
        import geotools.topotools as gt
    except:
        import clawpack.geoclaw.topotools as gt

    numstring = str(10000 + framenumber)
    framenostr = numstring[1:]
    forttname = os.path.join(fortdir, 'fort.t' + framenostr)
    fortqname = os.path.join(fortdir, 'fort.q' + framenostr)

    nodata_value = -9999.0

    solutionlist = fort2list(fortqname, forttname)

    if (not xll):
        dx = solutionlist[0]['dx']
        dy = solutionlist[0]['dy']
        xll = solutionlist[0]['xlowdomain']
        yll = solutionlist[0]['ylowdomain']
        xhi = solutionlist[0]['xhidomain']
        yhi = solutionlist[0]['yhidomain']

        cellsize = min(dx, dy)
        ncols = int(np.floor((xhi - xll) / cellsize))
        nrows = int(np.floor((yhi - yll) / cellsize))

        xll = xll + 0.5 * cellsize
        yll = yll + 0.5 * cellsize
        xhi = xhi - 0.5 * cellsize
        yhi = yhi - 0.5 * cellsize

    meqn = solutionlist[0]['meqn']

    xv = np.array(xll + cellsize * np.arange(ncols))
    yv = np.array(yll + cellsize * np.arange(nrows))

    (X, Y) = np.meshgrid(xv, yv)

    Y = np.flipud(Y)

    Q = np.zeros(np.shape(X))

    if (m == 'topo'):
        for j in xrange(ncols):
            xp = X[0, j]
            for i in xrange(nrows):
                yp = Y[i, 0]
                qv = pointfromfort((xp, yp), solutionlist)
                Q[i, j] = qv[meqn - 1] - qv[0]

    elif (m == 'depth'):
        for j in xrange(ncols):
            xp = X[0, j]
            for i in xrange(nrows):
                yp = Y[i, 0]
                qv = pointfromfort((xp, yp), solutionlist)
                depth = qv[0]
                if (depth <= 1.e-3):
                    depth = nodata_value
                Q[i, j] = depth

    elif (m == 'eta'):
        for j in xrange(ncols):
            xp = X[0, j]
            for i in xrange(nrows):
                yp = Y[i, 0]
                qv = pointfromfort((xp, yp), solutionlist)
                eta = qv[meqn - 1]
                if (qv[0] <= 1.e-3):
                    eta = nodata_value
                Q[i, j] = eta

    elif (m == 'all'):
        Q = np.zeros((ncols * nrows, meqn))
        for i in xrange(nrows):
            yp = Y[i, 0]
            for j in xrange(ncols):
                xp = X[0, j]
                k = i * ncols + j
                qv = pointfromfort((xp, yp), solutionlist)
                Q[k] = qv

    else:
        for j in xrange(ncols):
            xp = X[0, j]
            for i in xrange(nrows):
                yp = Y[i, 0]
                qv = pointfromfort((xp, yp), solutionlist)
                Q[i, j] = qv[m - 1]

    if m == 'all':
        headerstring = """


                    """
        np.savetxt(outfile,
                   Q)  #,header=headerstring) save for new numpy version
    elif (topotype == 'gdal'):
        gt.griddata2topofile(X,
                             Y,
                             Q,
                             '.tmpfile',
                             nodata_value_out=nodata_value)
        infile = '.tmpfile'
        gt.esriheader(infile, outfile)
        os.system('rm .tmpfile')
    else:
        gt.griddata2topofile(X,
                             Y,
                             Q,
                             outfile,
                             topotype,
                             nodata_value_out=nodata_value)
예제 #3
0
def fort2topotype(framenumber,outfile,fortdir,xll,yll,cellsize,ncols,nrows,m=1,topotype=2):
    """
    convert data in a fort file of framenumber = XXXX, ie fort.qXXXX
    to a DEM style file of topotype=1,2 or 3, or gdal (gdal/esri header) with uniform spacing.
    m is the component of q, ie. the column in the fort.qXXXX file
    for all components of q, see fort2xyscattered or amr2single

    specifying xll, yll, cellsize, ncols, nrows will result in interpolation of AMR data

    without xll, yll, cellsize, ncols, nrows...the domain will be the same as input frame
    and coarse resolution. 
    """

    try:
        import geotools.topotools as gt
    except:
        import clawpack.geoclaw.topotools as gt

    numstring = str(10000 + framenumber)
    framenostr = numstring[1:]
    forttname = os.path.join(fortdir,'fort.t'+framenostr)
    fortqname = os.path.join(fortdir,'fort.q'+framenostr)

    nodata_value = -9999.0

    solutionlist=fort2list(fortqname,forttname)

    if (not xll):
        dx = solutionlist[0]['dx']
        dy = solutionlist[0]['dy']
        xll = solutionlist[0]['xlowdomain']
        yll = solutionlist[0]['ylowdomain']
        xhi = solutionlist[0]['xhidomain']
        yhi = solutionlist[0]['yhidomain']

        cellsize = min(dx,dy)
        ncols = int(np.floor((xhi-xll)/cellsize))
        nrows = int(np.floor((yhi-yll)/cellsize))

        xll = xll + 0.5*cellsize
        yll = yll + 0.5*cellsize
        xhi = xhi  - 0.5*cellsize
        yhi = yhi  - 0.5*cellsize

    meqn = solutionlist[0]['meqn']

    xv = np.array(xll + cellsize*np.arange(ncols))
    yv = np.array(yll + cellsize*np.arange(nrows))

    (X,Y) = np.meshgrid(xv,yv)
    
    Y = np.flipud(Y)

    Q = np.zeros(np.shape(X))

    if (m=='topo'):
        for j in xrange(ncols):
            xp = X[0,j]
            for i in xrange(nrows):
                yp = Y[i,0]
                qv = pointfromfort((xp,yp),solutionlist)
                Q[i,j] = qv[meqn-1]-qv[0]

    elif (m=='depth'):
        for j in xrange(ncols):
            xp = X[0,j]
            for i in xrange(nrows):
                yp = Y[i,0]
                qv = pointfromfort((xp,yp),solutionlist)
                depth = qv[0]
                if (depth<=1.e-3):
                    depth = nodata_value
                Q[i,j] = depth

    elif (m=='eta'):
        for j in xrange(ncols):
            xp = X[0,j]
            for i in xrange(nrows):
                yp = Y[i,0]
                qv = pointfromfort((xp,yp),solutionlist)
                eta = qv[meqn-1]
                if (qv[0]<=1.e-3):
                    eta = nodata_value
                Q[i,j] = eta

    elif (m=='all'):
        Q = np.zeros((ncols*nrows,meqn))
        for i in xrange(nrows):
            yp = Y[i,0]
            for j in xrange(ncols):
                xp = X[0,j]
                k = i*ncols + j
                qv = pointfromfort((xp,yp),solutionlist)
                Q[k]=qv

    else:
        for j in xrange(ncols):
            xp = X[0,j]
            for i in xrange(nrows):
                yp = Y[i,0]
                qv = pointfromfort((xp,yp),solutionlist)
                Q[i,j] = qv[m-1]

    if m=='all':
        headerstring="""


                    """
        np.savetxt(outfile,Q)#,header=headerstring) save for new numpy version
    elif (topotype=='gdal'):
        gt.griddata2topofile(X,Y,Q,'.tmpfile',nodata_value_out=nodata_value)
        infile = '.tmpfile'
        gt.esriheader(infile,outfile)
        os.system('rm .tmpfile')
    else:
        gt.griddata2topofile(X,Y,Q,outfile,topotype,nodata_value_out=nodata_value)