示例#1
0
 def test_write_vmesh_lsc2(self):
     fpath_vmesh_in = os.path.join(self.dir_cur,
                                   'testdata/testmesh/vgrid_lsc2_1.in')
     vmesh_in = read_vmesh(fpath_vmesh_in)
     fpath_vmesh_out = os.path.join(
         self.dir_cur, 'testdata/testmesh/vgrid_lsc2_1_testout.in')
     try:
         write_vmesh(vmesh_in, fpath_vmesh_out)
         vmesh_out = read_vmesh(fpath_vmesh_out)
         self.check_vmesh_lsc2_1(vmesh_out)
     finally:
         pass
         if os.path.exists(fpath_vmesh_out):
             os.remove(fpath_vmesh_out)
def plot_vgrid(hgrid_file, vgrid0_file, vgrid_file, eta, transectfiles):
    from lsc2 import default_num_layers, plot_mesh
    from schism_vertical_mesh import read_vmesh
    import matplotlib.pylab as plt
    import os.path as ospath

    mesh = read_mesh(hgrid_file)
    x = mesh.nodes[:, 0:2]
    vmesh0 = read_vmesh(vgrid0_file)
    vmesh1 = read_vmesh(vgrid_file)
    h0 = mesh.nodes[:, 2]
    depth = eta + h0

    zcor0 = vmesh0.build_z(mesh, eta)[:, ::-1]
    zcor1 = vmesh1.build_z(mesh, eta)[:, ::-1]
    for transectfile in transectfiles:
        base = ospath.splitext(ospath.basename(transectfile))[0]
        transect = np.loadtxt(transectfile, skiprows=1, delimiter=",")
        path = []
        transx = transect[:, 1:3]
        #zcorsub = zcor[path,:]
        xx = x[path]
        xpath = np.zeros(xx.shape[0])
        for i in range(1, len(path)):
            dist = np.linalg.norm(xx[i, :] - xx[i - 1, :])
            xpath[i] = xpath[i - 1] + dist

        fig, (ax0, ax1) = plt.subplots(2, 1,
                                       figsize=(10,
                                                8))  #,sharex=True,sharey=True)
        ax0.set_title(transectfile)
        #plot_mesh(ax0,xpath,zcor0[path,:],0,len(xpath),c="0.5",linewidth=2)
        plot_mesh(ax0, xpath, zcor0[path, :], 0, len(xpath), c="red")
        plot_mesh(ax1, xpath, zcor1[path, :], 0, len(xpath), c="blue")
        ax0.plot(xpath, -h0[path], linewidth=2, c="black")
        ax1.plot(xpath, -h0[path], linewidth=2, c="black")
        plt.savefig(ospath.join("images", base + ".png"))
        plt.show()
示例#3
0
def read_mesh(fpath_mesh, fpath_vmesh=None, **kwargs):
    """ Read a mesh data

        Returns
        -------
        SchismMesh
    """
    if fpath_mesh.endswith('.gr3'):
        reader = SchismMeshIoFactory().get_reader('gr3')
        mesh = reader.read(fpath_mesh)
        if fpath_vmesh is not None:
            vmesh = read_vmesh(fpath_vmesh)
        else:
            vmesh = None
        mesh._vmesh = vmesh
        return mesh
    elif fpath_mesh.endswith('.2dm'):
        reader = SchismMeshIoFactory().get_reader('sms')
        mesh = reader.read(fpath_mesh, **kwargs)
        return mesh
    else:
        raise ValueError("Unsupported extension")
示例#4
0
 def test_build_vertical_mesh_from_sigma_lsc2(self):
     fpath_vmesh = os.path.join(self.dir_cur,
                                'testdata/testmesh/vgrid_lsc2_1.in')
     vmesh_in = read_vmesh(fpath_vmesh)
     vmesh_new = SchismLocalVerticalMesh(vmesh_in.sigma)
     self.check_vmesh_lsc2_1(vmesh_new)
示例#5
0
 def test_read_vmesh_lsc2(self):
     fpath_vmesh = os.path.join(self.dir_cur,
                                'testdata/testmesh/vgrid_lsc2_1.in')
     vmesh = read_vmesh(fpath_vmesh)
     self.check_vmesh_lsc2_1(vmesh)