当前位置: 首页>>代码示例>>Python>>正文


Python test_examples.two_triangles函数代码示例

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


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


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