• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python test_examples.two_triangles函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyugrid.test_examples.two_triangles函数的典型用法代码示例。如果您正苦于以下问题:Python two_triangles函数的具体用法?Python two_triangles怎么用?Python two_triangles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了two_triangles函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_with_just_nodes_and_depths

def test_with_just_nodes_and_depths():

    filename = '2_triangles_depth.nc'
    grid = two_triangles()
    del grid.faces
    del grid.edges

    depth_array = [1.0, 2.0, 3.0, 4.0]

    depth = DataSet('depth',
                    'node',
                    [1.0, 2.0, 3.0, 4.0],
                    {'units':'m',
                     'positive':'down',
                     'standard_name' : "sea_floor_depth_below_geoid",
                     })

    grid.add_data(depth)

    with chdir('files'):
        grid.save_as_netcdf(filename)

        # read it back in and check it out
        grid2 = UGrid.from_ncfile(filename, load_data=True)

    assert grid2.faces is None
    assert grid2.edges is None
    assert np.array_equal( grid2.nodes, grid.nodes )

    assert np.array_equal( grid2.data['depth'].data, depth_array )     
    assert grid2.data['depth'].attributes == depth.attributes     
开发者ID:bjlittle,项目名称:pyugrid,代码行数:31,代码来源:test_write_read.py


示例2: test_add_boundary_data

def test_add_boundary_data():

    grid = two_triangles()

    print(grid.boundaries)

    # add the boundary definitions:
    grid.boundaries = [(0,1),
                       (0,2),
                       (1,3),
                       (2,3),
                      ]
    # create a UVar object for boundary conditions:
    bnds = UVar('bounds', location='boundary', data=[0, 1, 0, 0, 1])
    bnds.attributes["long_name"] = "model boundary conditions"

    # wrong size for data
    with pytest.raises(ValueError):
        grid.add_data(bnds)
    # correct data
    bnds.data = [0, 1, 0, 0]
    grid.add_data(bnds)

    assert grid.data['bounds'].name == 'bounds'
    assert np.array_equal( grid.data['bounds'].data, [0, 1, 0, 0] )
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:25,代码来源:test_add_data.py


示例3: test_write_with_depths

def test_write_with_depths():
    '''
    tests writing a netcdf file with depth data
    '''

    fname = 'temp.nc'

    grid = two_triangles()
    grid.mesh_name='mesh1'

    # create a dataset object for the depths:
    depths = DataSet('depth', location='node', data=[1.0, 2.0, 3.0, 4.0])
    depths.attributes['units'] = 'm'
    depths.attributes["standard_name"] = "sea_floor_depth_below_geoid"
    depths.attributes["positive"] = "down"

    grid.add_data(depths)

    grid.save_as_netcdf(fname)

    with netCDF4.Dataset(fname) as ds:

        assert nc_has_variable(ds, 'mesh1')
        assert nc_has_variable(ds, 'depth')

        assert nc_var_has_attr_vals(ds, 'depth', {"coordinates" : "mesh1_node_lon mesh1_node_lat",
                                                  "location" : "node",
                                                  "mesh": "mesh1"})
开发者ID:bjlittle,项目名称:pyugrid,代码行数:28,代码来源:test_save_as_netcdf.py


示例4: test_write_with_edge_data

def test_write_with_edge_data():
    '''
    tests writing a netcdf file with data on the edges (fluxes, maybe?)
    '''
    fname = 'temp.nc'

    grid = two_triangles()
    grid.mesh_name = 'mesh2'

    # create a dataset object for fluxes:
    flux = DataSet('flux', location='edge', data=[0.0, 0.0, 4.1, 0.0, 5.1, ])
    flux.attributes['units'] = 'm^3/s'
    flux.attributes["long_name"] = "volume flux between cells"
    flux.attributes["standard_name"] = "ocean_volume_transport_across_line"

    grid.add_data(flux)
    #add coordinates for edges
    grid.build_edge_coordinates()

    grid.save_as_netcdf(fname)

    with netCDF4.Dataset(fname) as ds:

        assert nc_has_variable(ds, 'mesh2')
        assert nc_has_variable(ds, 'flux')

        assert nc_var_has_attr_vals(ds, 'flux', {
                                              "coordinates" : "mesh2_edge_lon mesh2_edge_lat",
                                              "location" : "edge",
                                              'units' : 'm^3/s',
                                              "mesh": "mesh2",
                                              })
        assert np.array_equal( ds.variables['mesh2_edge_lon'], grid.edge_coordinates[:,0] )
        assert np.array_equal( ds.variables['mesh2_edge_lat'], grid.edge_coordinates[:,1] )
开发者ID:bjlittle,项目名称:pyugrid,代码行数:34,代码来源:test_save_as_netcdf.py


示例5: test_set_mesh_name

def test_set_mesh_name():
    fname = 'temp.nc'
    
    grid  =  two_triangles()
    grid.mesh_name = "mesh_2"
    
    grid.save_as_netcdf(fname)

    with netCDF4.Dataset(fname) as ds:
        assert nc_has_variable(ds, 'mesh_2')

        assert nc_var_has_attr_vals(ds, 'mesh_2', {'cf_role':'mesh_topology',
                                                   'topology_dimension' : 2,
                                                   'long_name': u'Topology data of 2D unstructured mesh'
                                                   })

        assert nc_var_has_attr_vals(ds, 'mesh_2', {'cf_role':'mesh_topology',
                                                   'topology_dimension' : 2,
                                                   'long_name': u'Topology data of 2D unstructured mesh',
                                                   'node_coordinates': 'mesh_2_node_lon mesh_2_node_lat',
                                                   })

        assert nc_has_variable(ds, 'mesh_2_node_lon')
        assert nc_has_variable(ds, 'mesh_2_node_lat')
        assert nc_has_variable(ds, 'mesh_2_face_nodes')
        assert nc_has_variable(ds, 'mesh_2_edge_nodes')

        assert nc_has_dimension(ds, "mesh_2_num_node")
        assert nc_has_dimension(ds, "mesh_2_num_edge")
        assert nc_has_dimension(ds, "mesh_2_num_face")
        assert nc_has_dimension(ds, "mesh_2_num_vertices")

        assert not nc_var_has_attr(ds, 'mesh_2', "face_edge_connectivity")
开发者ID:bjlittle,项目名称:pyugrid,代码行数:33,代码来源:test_save_as_netcdf.py


示例6: test_simple_write

def test_simple_write():

    grid = two_triangles()

    grid.save_as_netcdf('two_triangles.nc')

    ## be good to have an actual test here...
    assert True
开发者ID:acrosby,项目名称:pyugrid,代码行数:8,代码来源:test_save_as_netcdf.py


示例7: test_build_face_coordinates

def test_build_face_coordinates():
    grid = two_triangles()
    grid.build_face_coordinates()
    coords = grid.face_coordinates

    assert coords.shape == (2,2)
    assert np.allclose(coords, [ (1.1, 0.76666667),
                                 (2.1, 1.43333333)]) 
开发者ID:bjlittle,项目名称:pyugrid,代码行数:8,代码来源:test_grid_manipulation.py


示例8: test_add_face_data_wrong

def test_add_face_data_wrong():
    """too short an array"""

    grid = two_triangles()

    # create a UVar object for velocity:
    u_vel = UVar('u', location='face', data=[1.0])

    with pytest.raises(ValueError):
        grid.add_data(u_vel)
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:10,代码来源:test_add_data.py


示例9: test_add_node_data_wrong

def test_add_node_data_wrong():
    """too short an array"""

    grid = two_triangles()

    # create a UVar object for the depths:
    depths = UVar('depth', location='node', data=[1.0, 2.0, 3.0])

    with pytest.raises(ValueError):
        grid.add_data(depths)
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:10,代码来源:test_add_data.py


示例10: test_add_all_data

def test_add_all_data():
    '''
    you should not be able add a data dict directly
    '''
    grid = two_triangles()

    assert grid.data == {}

    with pytest.raises(AttributeError):
        grid.data = {'depth': UVar('depth', location='node', data=[1.0, 2.0, 3.0, 4.0])}
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:10,代码来源:test_add_data.py


示例11: test_build_boundaries

def test_build_boundaries():
    ugrid = two_triangles()

    ugrid.build_face_face_connectivity()
    ugrid.build_boundaries()

    boundaries = ugrid.boundaries.tolist()
    boundaries.sort() # it doesn' matter what order they are in

    assert boundaries == [[0, 1], [1, 3], [2, 0], [3, 2]]
开发者ID:bjlittle,项目名称:pyugrid,代码行数:10,代码来源:test_grid_manipulation.py


示例12: test_add_edge_data_wrong

def test_add_edge_data_wrong():
    """too long an array"""

    grid = two_triangles()

    # create a UVar object for velocity:
    # a miss-matched set
    bnds = UVar('bounds', location='edge', data=[0, 1, 0, 0, 1, 3, 3])

    with pytest.raises(ValueError):
        grid.add_data(bnds)
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:11,代码来源:test_add_data.py


示例13: test_build_face_face_connectivity

def test_build_face_face_connectivity():
    ugrid = two_triangles()

    ugrid.build_face_face_connectivity()

    face_face = ugrid.face_face_connectivity

    # order matters!
    print ugrid.faces
    assert np.array_equal( face_face[0], [-1, 1, -1] )
    assert np.array_equal( face_face[1], [-1, -1, 0] )
开发者ID:bjlittle,项目名称:pyugrid,代码行数:11,代码来源:test_grid_manipulation.py


示例14: test_build_edges

def test_build_edges():
    ugrid = two_triangles()
    ugrid.build_edges()
    edges = ugrid.edges

    edges.sort(axis=0)
    print edges
    assert np.array_equal(edges, [[0, 1],
                                  [0, 2],
                                  [1, 2],
                                  [1, 3],
                                  [2, 3]])
开发者ID:acrosby,项目名称:pyugrid,代码行数:12,代码来源:test_grid_manipulation.py


示例15: test_add_edge_data

def test_add_edge_data():

    grid = two_triangles()

    # create a UVar object for velocity:
    bnds = UVar('bounds', location='edge', data=[0, 1, 0, 0, 1])
    bnds.attributes["standard_name"] = "boundary type"

    grid.add_data(bnds)

    assert grid.data['bounds'].name == 'bounds'
    assert np.array_equal( grid.data['bounds'].data, [0, 1, 0, 0, 1] )
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:12,代码来源:test_add_data.py


示例16: test_build_edge_coordinates

def test_build_edge_coordinates():
    grid = two_triangles()
    grid.build_edge_coordinates()
    coords = grid.edge_coordinates
    nodes = grid.nodes
    print coords

    assert coords.shape == (5,2)
    assert np.allclose(coords, [[ 1.1,  0.1],
                                [ 2.6,  1.1],
                                [ 2.1,  2.1],
                                [ 0.6,  1.1],
                                [ 1.6,  1.1]]) 
开发者ID:bjlittle,项目名称:pyugrid,代码行数:13,代码来源:test_grid_manipulation.py


示例17: test_without_faces

def test_without_faces():
    grid = two_triangles()
    del grid.faces
    assert grid.faces is None

    with chdir('files'):
        grid.save_as_netcdf('2_triangles.nc')

        # read it back in and check it out
        grid2 = UGrid.from_ncfile('2_triangles.nc')

    assert grid2.faces is None
    assert np.array_equal(grid.faces, grid2.faces)
    assert np.array_equal(grid.edges, grid2.edges)
开发者ID:bjlittle,项目名称:pyugrid,代码行数:14,代码来源:test_write_read.py


示例18: test_add_face_data

def test_add_face_data():

    grid = two_triangles()

    # create a UVar object for velocity:
    u_vel = UVar('u', location='face', data=[1.0, 2.0])
    u_vel.attributes['units'] = 'm/s'
    u_vel.attributes["standard_name"] = "eastward_sea_water_velocity"

    grid.add_data(u_vel)

    assert grid.data['u'].name == 'u'
    assert grid.data['u'].attributes['units'] == 'm/s'
    assert np.array_equal( grid.data['u'].data, [1.0, 2.0] )
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:14,代码来源:test_add_data.py


示例19: test_add_node_data

def test_add_node_data():

    grid = two_triangles()

    # create a UVar object for the depths:
    depths = UVar('depth', location='node', data=[1.0, 2.0, 3.0, 4.0])
    depths.attributes['units'] = 'm'
    depths.attributes["standard_name"] = "sea_floor_depth"
    depths.attributes["positive"] = "down"

    grid.add_data(depths)

    assert grid.data['depth'].name == 'depth'
    assert grid.data['depth'].attributes['units'] == 'm'
    assert np.array_equal( grid.data['depth'].data, [1.0, 2.0, 3.0, 4.0] )
开发者ID:rsignell-usgs,项目名称:notebook,代码行数:15,代码来源:test_add_data.py


示例20: test_build_face_face_connectivity

def test_build_face_face_connectivity():
    ugrid = two_triangles()

    ugrid.build_face_face_connectivity()

    face_face = ugrid.face_face_connectivity

    #zeroth triangle should have two empty faces
    assert sum(face_face[0] == -1) == 2
    #zeroth triangle should have one neighbor: 1
    assert sum(face_face[0] == 1) == 1
    #first triangle should have two empty faces
    assert sum(face_face[1] == -1) == 2
    #first triangle should have one neighbor: 0
    assert sum(face_face[1] == 1) == 0
开发者ID:acrosby,项目名称:pyugrid,代码行数:15,代码来源:test_grid_manipulation.py



注:本文中的pyugrid.test_examples.two_triangles函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ugrid.UGrid类代码示例发布时间:2022-05-27
下一篇:
Python _util.ensure_unicode_string函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap