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


Python Grid.from_nemo方法代码示例

本文整理汇总了Python中parcels.Grid.from_nemo方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.from_nemo方法的具体用法?Python Grid.from_nemo怎么用?Python Grid.from_nemo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在parcels.Grid的用法示例。


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

示例1: test_delay_start_example

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
def test_delay_start_example(mode, npart=10, show_movie=False):
    """Example script that shows how to 'delay' the start of particle advection.
    This is useful for example when particles need to be started at different times

    In this example, we use pset.add statements to add one particle every hour
    in the peninsula grid. Note that the title in the movie may not show correct time"""

    grid = Grid.from_nemo('examples/Peninsula_data/peninsula', extra_vars={'P': 'P'})

    # Initialise particles as in the Peninsula example
    x = 3. * (1. / 1.852 / 60)  # 3 km offset from boundary
    y = (grid.U.lat[0] + x, grid.U.lat[-1] - x)  # latitude range, including offsets

    lat = np.linspace(y[0], y[1], npart, dtype=np.float32)
    pset = grid.ParticleSet(0, lon=[], lat=[], pclass=ptype[mode])

    delaytime = delta(hours=1)  # delay time between particle releases
    for t in range(npart):
        pset.add(ptype[mode](lon=x, lat=lat[t], grid=grid))
        pset.execute(AdvectionRK4, runtime=delaytime, dt=delta(minutes=5),
                     interval=delta(hours=1), show_movie=show_movie)

    # Note that time on the movie is not parsed correctly
    pset.execute(AdvectionRK4, runtime=delta(hours=24)-npart*delaytime,
                 dt=delta(minutes=5), interval=delta(hours=1), show_movie=show_movie)

    londist = np.array([(p.lon - x) for p in pset])
    assert(londist > 0.1).all()
开发者ID:OceanPARCELS,项目名称:parcels,代码行数:30,代码来源:example_delay_start.py

示例2: test_peninsula_file

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
def test_peninsula_file(gridfile, mode):
    """Open grid files and execute"""
    grid = Grid.from_nemo(gridfile, extra_vars={'P': 'P'})
    pset = pensinsula_example(grid, 100, mode=mode, degree=1)
    # Test advection accuracy by comparing streamline values
    err_adv = np.array([abs(p.p_start - p.p) for p in pset])
    assert(err_adv <= 1.e-3).all()
    # Test grid sampling accuracy by comparing kernel against grid sampling
    err_smpl = np.array([abs(p.p - pset.grid.P[0., p.lon, p.lat]) for p in pset])
    assert(err_smpl <= 1.e-3).all()
开发者ID:erikvansebille,项目名称:parcels,代码行数:12,代码来源:example_peninsula.py

示例3: test_grid_from_nemo

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
def test_grid_from_nemo(xdim, ydim, tmpdir, filename='test_nemo'):
    """ Simple test for grid initialisation from NEMO file format. """
    filepath = tmpdir.join(filename)
    u, v, lon, lat, depth, time = generate_grid(xdim, ydim)
    grid_out = Grid.from_data(u, lon, lat, v, lon, lat, depth, time)
    grid_out.write(filepath)
    grid = Grid.from_nemo(filepath)
    u_t = np.transpose(u).reshape((lat.size, lon.size))
    v_t = np.transpose(v).reshape((lat.size, lon.size))
    assert len(grid.U.data.shape) == 3  # Will be 4 once we use depth
    assert len(grid.V.data.shape) == 3
    assert np.allclose(grid.U.data[0, :], u_t, rtol=1e-12)
    assert np.allclose(grid.V.data[0, :], v_t, rtol=1e-12)
开发者ID:nathanieltarshish,项目名称:parcels,代码行数:15,代码来源:test_grid.py

示例4: test_moving_eddies_file

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
def test_moving_eddies_file(gridfile, mode):
    grid = Grid.from_nemo(gridfile, extra_vars={'P': 'P'})
    pset = moving_eddies_example(grid, 2, mode=mode)
    assert(pset[0].lon < 0.5 and 46.0 < pset[0].lat < 46.35)
    assert(pset[1].lon < 0.5 and 49.4 < pset[1].lat < 49.8)
开发者ID:OceanPARCELS,项目名称:parcels,代码行数:7,代码来源:example_moving_eddies.py

示例5: moving_eddies_grid

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
                   help='Number of particles to advect')
    p.add_argument('-v', '--verbose', action='store_true', default=False,
                   help='Print particle information before and after execution')
    p.add_argument('--profiling', action='store_true', default=False,
                   help='Print profiling information after run')
    p.add_argument('-g', '--grid', type=int, nargs=2, default=None,
                   help='Generate grid file with given dimensions')
    p.add_argument('-m', '--method', choices=('RK4', 'EE', 'RK45'), default='RK4',
                   help='Numerical method used for advection')
    args = p.parse_args()
    filename = 'examples/MovingEddies_data/moving_eddies'

    # Generate grid files according to given dimensions
    if args.grid is not None:
        grid = moving_eddies_grid(args.grid[0], args.grid[1])
        grid.write(filename)

    # Open grid files
    grid = Grid.from_nemo(filename, extra_vars={'P': 'P'})

    if args.profiling:
        from cProfile import runctx
        from pstats import Stats
        runctx("moving_eddies_example(grid, args.particles, mode=args.mode, \
                              verbose=args.verbose, method=method[args.method])",
               globals(), locals(), "Profile.prof")
        Stats("Profile.prof").strip_dirs().sort_stats("time").print_stats(10)
    else:
        moving_eddies_example(grid, args.particles, mode=args.mode,
                              verbose=args.verbose, method=method[args.method])
开发者ID:OceanPARCELS,项目名称:parcels,代码行数:32,代码来源:example_moving_eddies.py

示例6: peninsula_grid

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
    p.add_argument('-o', '--nooutput', action='store_true', default=False,
                   help='Suppress trajectory output')
    p.add_argument('--profiling', action='store_true', default=False,
                   help='Print profiling information after run')
    p.add_argument('-g', '--grid', type=int, nargs=2, default=None,
                   help='Generate grid file with given dimensions')
    p.add_argument('-m', '--method', choices=('RK4', 'EE', 'RK45'), default='RK4',
                   help='Numerical method used for advection')
    args = p.parse_args()

    if args.grid is not None:
        filename = 'peninsula'
        grid = peninsula_grid(args.grid[0], args.grid[1])
        grid.write(filename)

    # Open grid file set
    grid = Grid.from_nemo('peninsula', extra_vars={'P': 'P'})

    if args.profiling:
        from cProfile import runctx
        from pstats import Stats
        runctx("pensinsula_example(grid, args.particles, mode=args.mode,\
                                   degree=args.degree, verbose=args.verbose,\
                                   output=not args.nooutput, method=method[args.method])",
               globals(), locals(), "Profile.prof")
        Stats("Profile.prof").strip_dirs().sort_stats("time").print_stats(10)
    else:
        pensinsula_example(grid, args.particles, mode=args.mode,
                           degree=args.degree, verbose=args.verbose,
                           output=not args.nooutput, method=method[args.method])
开发者ID:erikvansebille,项目名称:parcels,代码行数:32,代码来源:example_peninsula.py

示例7: stommel_grid

# 需要导入模块: from parcels import Grid [as 别名]
# 或者: from parcels.Grid import from_nemo [as 别名]
                   help='Number of particles to advect')
    p.add_argument('-v', '--verbose', action='store_true', default=False,
                   help='Print particle information before and after execution')
    p.add_argument('--profiling', action='store_true', default=False,
                   help='Print profiling information after run')
    p.add_argument('-g', '--grid', type=int, nargs=2, default=None,
                   help='Generate grid file with given dimensions')
    p.add_argument('-m', '--method', choices=('RK4', 'EE', 'RK45'), default='RK4',
                   help='Numerical method used for advection')
    args = p.parse_args()
    filename = 'stommel'

    # Generate grid files according to given dimensions
    if args.grid is not None:
        grid = stommel_grid(args.grid[0], args.grid[1])
        grid.write(filename)

    # Open grid files
    grid = Grid.from_nemo(filename)

    if args.profiling:
        from cProfile import runctx
        from pstats import Stats
        runctx("stommel_example(grid, args.particles, mode=args.mode, \
                              verbose=args.verbose)",
               globals(), locals(), "Profile.prof")
        Stats("Profile.prof").strip_dirs().sort_stats("time").print_stats(10)
    else:
        stommel_example(grid, args.particles, mode=args.mode,
                        verbose=args.verbose, method=method[args.method])
开发者ID:erikvansebille,项目名称:parcels,代码行数:32,代码来源:example_stommel.py


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