當前位置: 首頁>>代碼示例>>Python>>正文


Python ugrid.UGrid類代碼示例

本文整理匯總了Python中pyugrid.ugrid.UGrid的典型用法代碼示例。如果您正苦於以下問題:Python UGrid類的具體用法?Python UGrid怎麽用?Python UGrid使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UGrid類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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_two_triangles_without_edges

def test_two_triangles_without_edges():
    grid = two_triangles_with_depths()
    grid.edges = None

    grid.save_as_netcdf("2_triangles_without_edges.nc")

    # read it back in and check it out
    ug = UGrid.from_ncfile("2_triangles_without_edges.nc", load_data=True)

    assert ug.nodes.shape == (4, 2)
    assert ug.nodes.shape == grid.nodes.shape

    # not ideal to pull specific values out, but how else to test?
    assert np.array_equal(ug.nodes[0, :], (0.1, 0.1))
    assert np.array_equal(ug.nodes[-1, :], (3.1, 2.1))
    assert np.array_equal(ug.nodes, grid.nodes)

    assert ug.faces.shape == grid.faces.shape

    assert ug.edges is None

    depths = find_depths(ug)
    assert depths.data.shape == (4,)
    assert depths.data[0] == 1
    assert depths.attributes["units"] == "unknown"
開發者ID:rsignell-usgs,項目名稱:pyugrid,代碼行數:25,代碼來源:test_find_uvar.py

示例3: test_with_just_nodes_and_depths

def test_with_just_nodes_and_depths():
    expected = two_triangles()
    del expected.faces
    del expected.edges

    depth = UVar('depth',
                 'node',
                 np.array([1.0, 2.0, 3.0, 4.0]),
                 {'units': 'm',
                  'positive': 'down',
                  'standard_name': 'sea_floor_depth_below_geoid'})
    expected.add_data(depth)

    fname = '2_triangles_depth.nc'
    with chdir(test_files):
        expected.save_as_netcdf(fname)
        grid = UGrid.from_ncfile(fname, load_data=True)
        os.remove(fname)

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

    assert np.array_equal(expected.data['depth'].data, grid.data['depth'].data)
    assert expected.data['depth'].attributes == grid.data['depth'].attributes
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:25,代碼來源:test_write_read.py

示例4: ugrid

def ugrid(location, name):
    """
    Create a cube from an unstructured grid.

    Args:

    * location:
        A string whose value represents the path to a file or
        URL to an OpenDAP resource conforming to the
        Unstructured Grid Metadata Conventions for Scientific Datasets
        https://github.com/ugrid-conventions/ugrid-conventions

    * name:
        A string whose value represents a cube loading constraint of
        first the standard name if found, then the long name if found,
        then the variable name if found, before falling back to
        the value of the default which itself defaults to "unknown"

    Returns:
        An instance of :class:`iris.cube.Cube` decorated with
        an instance of :class:`pyugrid.ugrid.Ugrid`
        bound to an attribute of the cube called "mesh"

    """

    cube = iris.load_cube(location, name)
    ug = UGrid.from_ncfile(location)
    cube.mesh = ug
    cube.mesh_dimension = 1  # {0:time, 1:node}
    return cube
開發者ID:ckmo,項目名稱:iris,代碼行數:30,代碼來源:ugrid.py

示例5: test_two_triangles_without_edges

def test_two_triangles_without_edges():
    grid = two_triangles_with_depths()
    grid.edges = None

    fname = '2_triangles_without_edges.nc'
    with chdir(test_files):
        grid.save_as_netcdf(fname)
        ug = UGrid.from_ncfile(fname, load_data=True)
        os.remove(fname)

    assert ug.nodes.shape == (4, 2)
    assert ug.nodes.shape == grid.nodes.shape

    # FIXME: Not ideal to pull specific values out, but how else to test?
    assert np.array_equal(ug.nodes[0, :], (0.1, 0.1))
    assert np.array_equal(ug.nodes[-1, :], (3.1, 2.1))
    assert np.array_equal(ug.nodes, grid.nodes)

    assert ug.faces.shape == grid.faces.shape

    assert ug.edges is None

    depths = find_depths(ug)
    assert depths.data.shape == (4,)
    assert depths.data[0] == 1
    assert depths.attributes['units'] == 'unknown'
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:26,代碼來源:test_find_uvar.py

示例6: test_with_just_nodes_and_depths

def test_with_just_nodes_and_depths():
    expected = two_triangles()
    del expected.faces
    del expected.edges

    depth = UVar(
        "depth",
        "node",
        np.array([1.0, 2.0, 3.0, 4.0]),
        {"units": "m", "positive": "down", "standard_name": "sea_floor_depth_below_geoid"},
    )
    expected.add_data(depth)

    fname = "2_triangles_depth.nc"
    with chdir(test_files):
        expected.save_as_netcdf(fname)
        grid = UGrid.from_ncfile(fname, load_data=True)
        os.remove(fname)

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

    assert np.array_equal(expected.data["depth"].data, grid.data["depth"].data)
    assert expected.data["depth"].attributes == grid.data["depth"].attributes
開發者ID:NESII,項目名稱:pyugrid,代碼行數:25,代碼來源:test_write_read.py

示例7: test_without_faces

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

    fname = '2_triangles.nc'
    with chdir(test_files):
        expected.save_as_netcdf(fname)
        grid = UGrid.from_ncfile(fname)
        os.remove(fname)

    assert grid.faces is None
    assert np.array_equal(expected.faces, grid.faces)
    assert np.array_equal(expected.edges, grid.edges)
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:14,代碼來源:test_write_read.py

示例8: 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

示例9: test_21_triangles

def test_21_triangles():
    grid = twenty_one_triangles_with_depths()

    grid.save_as_netcdf("21_triangles.nc")

    # read it back in and check it out
    ug = UGrid.from_ncfile("21_triangles.nc", load_data=True)

    assert ug.nodes.shape == grid.nodes.shape

    # not ideal to pull specific values out, but how else to test?
    assert np.array_equal(ug.nodes, grid.nodes)

    depths = find_depths(ug)
    assert depths.data.shape == (20,)
    assert depths.data[0] == 1
    assert depths.attributes["units"] == "unknown"
開發者ID:rsignell-usgs,項目名稱:pyugrid,代碼行數:17,代碼來源:test_find_uvar.py

示例10: test_with_faces

def test_with_faces():
    """
    Test with faces, edges, but no `face_coordinates` or `edge_coordinates`.

    """

    expected = two_triangles()

    fname = '2_triangles.nc'
    with chdir(test_files):
        expected.save_as_netcdf(fname)
        grid = UGrid.from_ncfile(fname)
        os.remove(fname)

    assert np.array_equal(expected.nodes, grid.nodes)
    assert np.array_equal(expected.faces, grid.faces)
    assert np.array_equal(expected.edges, grid.edges)
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:17,代碼來源:test_write_read.py

示例11: test_21_triangles

def test_21_triangles():
    grid = twenty_one_triangles_with_depths()

    fname = '21_triangles.nc'
    with chdir(test_files):
        grid.save_as_netcdf(fname)
        ug = UGrid.from_ncfile(fname, load_data=True)
        os.remove(fname)

    assert ug.nodes.shape == grid.nodes.shape

    # FIXME: Not ideal to pull specific values out, but how else to test?
    assert np.array_equal(ug.nodes, grid.nodes)

    depths = find_depths(ug)
    assert depths.data.shape == (20,)
    assert depths.data[0] == 1
    assert depths.attributes['units'] == 'unknown'
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:18,代碼來源:test_find_uvar.py

示例12: test_with_faces

def test_with_faces():
    """
    test with faces, edges, but no face_coordintates or edge_coordinates
    """

    with chdir('files'):
        grid = two_triangles()

        grid.save_as_netcdf('2_triangles.nc')

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

    assert np.array_equal(grid.nodes, grid2.nodes)
    assert np.array_equal(grid.faces, grid2.faces)

    print grid2.edges

    assert np.array_equal(grid.edges, grid2.edges)
開發者ID:bjlittle,項目名稱:pyugrid,代碼行數:19,代碼來源:test_write_read.py

示例13: test_write_everything


#.........這裏部分代碼省略.........

    grid.add_data(depths)

    # velocities on the faces:
    u_vel = DataSet('u', location='face', data=np.sin(np.linspace(3,12,21)))
    u_vel.attributes['units'] = 'm/s'
    u_vel.attributes["standard_name"] = "eastward_sea_water_velocity"

    grid.add_data(u_vel)

    # create a dataset object for v velocity:
    v_vel = DataSet('v', location='face', data=np.sin(np.linspace(12,15,21)))
    v_vel.attributes['units'] = 'm/s'
    v_vel.attributes["standard_name"] = "northward_sea_water_velocity"

    grid.add_data(v_vel)

    # fluxes on the edges:
    flux = DataSet('flux', location='edge', data=np.linspace(1000,2000,41))
    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)

    # Some boundary conditions:

    bounds = np.zeros( (19,), dtype=np.uint8 )
    bounds[7] = 1
    bnds = DataSet('bnd_cond', location='boundary', data=bounds)
    bnds.attributes["long_name"] = "model boundary conditions"
    bnds.attributes["flag_values"] = "0 1"
    bnds.attributes["flag_meanings"] = "no_flow_boundary  open_boundary"

    grid.add_data(bnds)

    grid.save_as_netcdf(fname)

    ## now the tests:
    with netCDF4.Dataset(fname) as ds:

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

        assert nc_var_has_attr_vals(ds, 'depth', {"coordinates" : "mesh_node_lon mesh_node_lat",
                                                  "location" : "node"})

        assert nc_has_variable(ds, 'u')
        assert nc_has_variable(ds, 'v')

        assert nc_var_has_attr_vals(ds, 'u', {
                                              "coordinates" : "mesh_face_lon mesh_face_lat",
                                              "location" : "face",
                                              "mesh": "mesh"
                                              })

        assert nc_var_has_attr_vals(ds, 'v', {
                                              "coordinates" : "mesh_face_lon mesh_face_lat",
                                              "location" : "face",
                                              "mesh": "mesh",
                                              })

        assert nc_has_variable(ds, 'flux')

        assert nc_var_has_attr_vals(ds, 'flux', {
                                              "coordinates" : "mesh_edge_lon mesh_edge_lat",
                                              "location" : "edge",
                                              'units' : 'm^3/s',
                                              "mesh": "mesh",
                                              })
        assert nc_has_variable(ds, 'mesh')
        assert nc_has_variable(ds, 'bnd_cond')

        assert nc_var_has_attr_vals(ds, 'mesh', {
                                              "boundary_node_connectivity" : "mesh_boundary_nodes",
                                              })

        assert nc_var_has_attr_vals(ds, 'bnd_cond', {
                                              "location" : "boundary",
                                              "flag_values" : "0 1",
                                              "flag_meanings" : "no_flow_boundary  open_boundary",
                                              "mesh": "mesh",
                                              })
    # and make sure pyugrid can reload it!
    grid = UGrid.from_ncfile(fname,load_data=True)
    # and that some things are the same:
    # note:  more testing might be good here...
    #        maybe some grid comparison functions? 

    assert grid.mesh_name == 'mesh'

    print "grid data:", grid.data
    assert len(grid.nodes) == 20


    depth = grid.data['depth']
    assert depth.attributes['units'] == 'm'

    u = grid.data['u']
    assert u.attributes['units'] == 'm/s'
開發者ID:bjlittle,項目名稱:pyugrid,代碼行數:101,代碼來源:test_save_as_netcdf.py

示例14: test_write_everything

def test_write_everything():
    """An example with all features enabled, and a less trivial grid."""

    grid = twenty_one_triangles()

    grid.build_edges()
    grid.build_face_face_connectivity()

    grid.build_edge_coordinates()
    grid.build_face_coordinates()
    grid.build_boundary_coordinates()

    # Depth on the nodes.
    depths = UVar('depth', location='node', data=np.linspace(1, 10, 20))
    depths.attributes['units'] = 'm'
    depths.attributes['standard_name'] = 'sea_floor_depth_below_geoid'
    depths.attributes['positive'] = 'down'
    grid.add_data(depths)

    # Create a UVar object for u velocity:
    u_vel = UVar('u', location='face', data=np.sin(np.linspace(3, 12, 21)))
    u_vel.attributes['units'] = 'm/s'
    u_vel.attributes['standard_name'] = 'eastward_sea_water_velocity'

    grid.add_data(u_vel)

    # Create a UVar object for v velocity:
    v_vel = UVar('v', location='face', data=np.sin(np.linspace(12, 15, 21)))
    v_vel.attributes['units'] = 'm/s'
    v_vel.attributes['standard_name'] = 'northward_sea_water_velocity'

    grid.add_data(v_vel)

    # Fluxes on the edges:
    flux = UVar('flux', location='edge', data=np.linspace(1000, 2000, 41))
    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)

    # Boundary conditions:
    bounds = np.zeros((19,), dtype=np.uint8)
    bounds[7] = 1
    bnds = UVar('bnd_cond', location='boundary', data=bounds)
    bnds.attributes['long_name'] = 'model boundary conditions'
    bnds.attributes['flag_values'] = '0 1'
    bnds.attributes['flag_meanings'] = 'no_flow_boundary  open_boundary'

    grid.add_data(bnds)

    fname = 'full_example.nc'
    with chdir(test_files):
        grid.save_as_netcdf(fname)
        ds = netCDF4.Dataset(fname)

        # Now the tests:
        assert nc_has_variable(ds, 'mesh')
        assert nc_has_variable(ds, 'depth')
        assert nc_var_has_attr_vals(ds, 'depth', {
            'coordinates': 'mesh_node_lon mesh_node_lat',
            'location': 'node'})
        assert nc_has_variable(ds, 'u')
        assert nc_has_variable(ds, 'v')
        assert nc_var_has_attr_vals(ds, 'u', {
            'coordinates': 'mesh_face_lon mesh_face_lat',
            'location': 'face',
            'mesh': 'mesh'})
        assert nc_var_has_attr_vals(ds, 'v', {
            'coordinates': 'mesh_face_lon mesh_face_lat',
            'location': 'face',
            'mesh': 'mesh',
            })
        assert nc_has_variable(ds, 'flux')
        assert nc_var_has_attr_vals(ds, 'flux', {
            'coordinates': 'mesh_edge_lon mesh_edge_lat',
            'location': 'edge',
            'units': 'm^3/s',
            'mesh': 'mesh'})
        assert nc_has_variable(ds, 'mesh')
        assert nc_has_variable(ds, 'bnd_cond')
        assert nc_var_has_attr_vals(ds, 'mesh', {
            'boundary_node_connectivity': 'mesh_boundary_nodes',
            })
        assert nc_var_has_attr_vals(ds, 'bnd_cond', {
            'location': 'boundary',
            'flag_values': '0 1',
            'flag_meanings': 'no_flow_boundary  open_boundary',
            'mesh': 'mesh',
            })
        ds.close()

        # And make sure pyugrid can reload it!
        with chdir(test_files):
            grid = UGrid.from_ncfile('full_example.nc', load_data=True)
        # And that some things are the same.
        # NOTE: more testing might be good here.
        # maybe some grid comparison functions?

        assert grid.mesh_name == 'mesh'
#.........這裏部分代碼省略.........
開發者ID:NOAA-ORR-ERD,項目名稱:pyugrid,代碼行數:101,代碼來源:test_save_as_netcdf.py


注:本文中的pyugrid.ugrid.UGrid類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。