コード例 #1
0
def interpolate_topomsh(lon_pts, lat_pts):

    topo = readmsh('topo.msh')
    xpos = np.deg2rad(topo['COORD1'])
    ypos = np.deg2rad(topo['COORD2'])
    zlev = np.reshape(topo['VALUE'], (len(ypos), len(xpos)))

    Y, X = np.meshgrid(ypos, xpos)

    bathy = interpolate.LinearNDInterpolator(
        np.vstack((X.ravel(), Y.ravel())).T, zlev.ravel())
    bathymetry = bathy(np.vstack((lon_pts, lat_pts)).T)

    return bathymetry
コード例 #2
0
    else:
        output_name = options.output

    if options.msh:
        on_sphere = options.spherical
    else:
        # These will always be planar meshes for non-JIGSAW inputs
        on_sphere = False

    grid = NetCDFFile(output_name, 'w', format='NETCDF3_CLASSIC')

    # Get dimensions

    if options.msh:
        # Get nCells
        msh = readmsh(options.msh)
        nCells = msh['POINT'].shape[0]

        ## Get vertexDegree and nVertices
        vertexDegree = 3  # always triangles with JIGSAW output
        nVertices = msh['TRIA3'].shape[0]
    else:
        # Get nCells
        cell_info = open(options.node, 'r')
        nCells = -1  # There is one header line
        for block in iter(lambda: cell_info.readline(), ""):
            if block.startswith("#"):
                continue  # skip comment lines
            nCells = nCells + 1
        cell_info.close()
コード例 #3
0
#!/usr/bin/env python
# Simple script to inject bathymetry onto a mesh
# Phillip Wolfram, 01/19/2018

import matplotlib.pyplot as plt
from open_msh import readmsh
import numpy as np
from scipy import interpolate
import netCDF4 as nc4
dtor = np.pi/180.0
rtod = 180.0/np.pi

if __name__ == "__main__":
    import sys

    topo = readmsh('/Users/pwolfram/Documents/GridGen/MultiscaleMeshGen/jigsaw-geo-matlab/jigsaw/geo/topo.msh')
    xpos = topo['COORD1']*dtor
    ypos = topo['COORD2']*dtor
    zlev = np.reshape(topo['VALUE'], (len(ypos), len(xpos)))

    Y, X = np.meshgrid(ypos, xpos)

    ds = nc4.Dataset(sys.argv[1],'r+')
    ds.createVariable('bathymetry','f8',('nCells'))
    ds.createVariable('cullCell','i',('nCells'))
    bathy = interpolate.LinearNDInterpolator(np.vstack((X.ravel(), Y.ravel())).T, zlev.ravel())
    ds.variables['bathymetry'][:] = bathy(np.vstack((np.mod(ds.variables['lonCell'][:] + np.pi, 2*np.pi)-np.pi,
                                          ds.variables['latCell'][:])).T)
    ds.variables['cullCell'][:] = ds.variables['bathymetry'][:] > 20.0

    ds.close()
コード例 #4
0
# Phillip Wolfram, 01/19/2018

import matplotlib.pyplot as plt
from open_msh import readmsh
import numpy as np
from scipy import interpolate
import netCDF4 as nc4

dtor = np.pi / 180.0
rtod = 180.0 / np.pi

if __name__ == "__main__":
    import sys

    topo = readmsh(
        '/home/gyy/MPAS-Tools-master/mesh_tools/jigsaw-geo-matlab-master/jigsaw/geo/topo.msh'
    )
    xpos = topo['COORD1'] * dtor
    ypos = topo['COORD2'] * dtor
    zlev = np.reshape(topo['VALUE'], (len(ypos), len(xpos)))

    Y, X = np.meshgrid(ypos, xpos)

    ds = nc4.Dataset(sys.argv[1], 'r+')
    ds.createVariable('bathymetry', 'f8', ('nCells'))
    ds.createVariable('cullCell', 'i', ('nCells'))
    bathy = interpolate.LinearNDInterpolator(
        np.vstack((X.ravel(), Y.ravel())).T, zlev.ravel())
    ds.variables['bathymetry'][:] = bathy(
        np.vstack(
            (np.mod(ds.variables['lonCell'][:] + np.pi, 2 * np.pi) - np.pi,