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

Python cbook.get_test_data函数代码示例

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

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



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

示例1: test_interpolate_to_points

def test_interpolate_to_points(method, test_data):
    r"""Test main grid interpolation function."""
    xp, yp, z = test_data
    obs_points = np.vstack([xp, yp]).transpose() * 10

    with get_test_data('interpolation_test_points.npz') as fobj:
        test_points = np.load(fobj)['points']

    extra_kw = {}
    if method == 'cressman':
        extra_kw['search_radius'] = 200
        extra_kw['minimum_neighbors'] = 1
    elif method == 'barnes':
        extra_kw['search_radius'] = 400
        extra_kw['minimum_neighbors'] = 1
        extra_kw['gamma'] = 1
    elif method == 'shouldraise':
        with pytest.raises(ValueError):
            interpolate_to_points(
                obs_points, z, test_points, interp_type=method, **extra_kw)
        return

    img = interpolate_to_points(obs_points, z, test_points, interp_type=method, **extra_kw)

    with get_test_data('{0}_test.npz'.format(method)) as fobj:
        truth = np.load(fobj)['img'].reshape(-1)

    assert_array_almost_equal(truth, img)
开发者ID:akrherz,项目名称:MetPy,代码行数:28,代码来源:test_points.py


示例2: test_basic

def test_basic():
    """Test reading one specific NEXRAD NIDS file based on the filename."""
    f = Level3File(get_test_data('nids/Level3_FFC_N0Q_20140407_1805.nids', as_file_obj=False))
    assert f.metadata['prod_time'].replace(second=0) == datetime(2014, 4, 7, 18, 5)
    assert f.metadata['vol_time'].replace(second=0) == datetime(2014, 4, 7, 18, 5)
    assert f.metadata['msg_time'].replace(second=0) == datetime(2014, 4, 7, 18, 6)
    assert f.filename == get_test_data('nids/Level3_FFC_N0Q_20140407_1805.nids',
                                       as_file_obj=False)

    # At this point, really just want to make sure that __str__ is able to run and produce
    # something not empty, the format is still up for grabs.
    assert str(f)
开发者ID:akrherz,项目名称:MetPy,代码行数:12,代码来源:test_nexrad.py


示例3: test_latlon

def test_latlon():
    """Test our handling of lat/lon information."""
    data = xr.open_dataset(get_test_data('irma_gfs_example.nc', as_file_obj=False))

    img = ImagePlot()
    img.data = data
    img.field = 'Temperature_isobaric'
    img.level = 500 * units.hPa
    img.time = datetime(2017, 9, 5, 15, 0, 0)

    contour = ContourPlot()
    contour.data = data
    contour.field = 'Geopotential_height_isobaric'
    contour.level = img.level
    contour.time = img.time

    panel = MapPanel()
    panel.projection = 'lcc'
    panel.area = 'us'
    panel.plots = [img, contour]

    pc = PanelContainer()
    pc.panel = panel
    pc.draw()

    return pc.figure
开发者ID:akrherz,项目名称:MetPy,代码行数:26,代码来源:test_declarative.py


示例4: test_gini_basic

def test_gini_basic():
    'Basic test of GINI reading'
    f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'West CONUS'
    assert pdb.channel == 'WV (6.5/6.7 micron)'
    assert pdb.num_records == 1280
    assert pdb.record_len == 1100
    assert pdb.datetime == datetime(2015, 12, 8, 22, 0, 19)
    assert pdb.projection == GiniProjection.lambert_conformal
    assert pdb.nx == 1100
    assert pdb.ny == 1280
    assert_almost_equal(pdb.la1, 12.19, 4)
    assert_almost_equal(pdb.lo1, -133.4588, 4)

    proj = f.proj_info
    assert proj.reserved == 0
    assert_almost_equal(proj.lov, -95.0, 4)
    assert_almost_equal(proj.dx, 4.0635, 4)
    assert_almost_equal(proj.dy, 4.0635, 4)
    assert proj.proj_center == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 25.0, 4)
    assert pdb2.resolution == 4
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512

    assert f.data.shape, (pdb.num_records == pdb.record_len)
开发者ID:DBaryudin,项目名称:MetPy,代码行数:33,代码来源:test_gini.py


示例5: test_raw_gini

def test_raw_gini(filename, pdb, pdb2, proj_info):
    """Test raw GINI parsing."""
    f = GiniFile(get_test_data(filename))
    assert f.prod_desc == pdb
    assert f.prod_desc2 == pdb2
    assert f.proj_info == proj_info
    assert f.data.shape == (pdb.num_records, pdb.record_len)
开发者ID:akrherz,项目名称:MetPy,代码行数:7,代码来源:test_gini.py


示例6: test_gini_ak_regional

def test_gini_ak_regional():
    'Test reading of AK Regional Gini file'
    f = GiniFile(get_test_data('AK-REGIONAL_8km_3.9_20160408_1445.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'Alaska Regional'
    assert pdb.channel == 'IR (3.9 micron)'
    assert pdb.num_records == 408
    assert pdb.record_len == 576
    assert pdb.datetime == datetime(2016, 4, 8, 14, 45, 20)
    assert pdb.projection == GiniProjection.polar_stereographic
    assert pdb.nx == 576
    assert pdb.ny == 408
    assert_almost_equal(pdb.la1, 42.0846, 4)
    assert_almost_equal(pdb.lo1, -175.641, 4)

    proj = f.proj_info
    assert proj.reserved == 0
    assert_almost_equal(proj.lov, 210.0, 1)
    assert_almost_equal(proj.dx, 7.9375, 4)
    assert_almost_equal(proj.dy, 7.9375, 4)
    assert proj.proj_center == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 0.0, 4)
    assert pdb2.resolution == 8
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512
    assert pdb2.nav_cal == 0

    assert f.data.shape, (pdb.num_records == pdb.record_len)
开发者ID:DBaryudin,项目名称:MetPy,代码行数:34,代码来源:test_gini.py


示例7: test_gini_mercator

def test_gini_mercator():
    'Test reading of GINI file with Mercator projection (from HI)'
    f = GiniFile(get_test_data('HI-REGIONAL_4km_3.9_20160616_1715.gini'))
    pdb = f.prod_desc
    assert pdb.source == 1
    assert pdb.creating_entity == 'GOES-15'
    assert pdb.sector_id == 'Hawaii Regional'
    assert pdb.channel == 'IR (3.9 micron)'
    assert pdb.num_records == 520
    assert pdb.record_len == 560
    assert pdb.datetime == datetime(2016, 6, 16, 17, 15, 18)

    assert pdb.projection == GiniProjection.mercator
    assert pdb.nx == 560
    assert pdb.ny == 520
    assert_almost_equal(pdb.la1, 9.343, 4)
    assert_almost_equal(pdb.lo1, -167.315, 4)

    proj = f.proj_info
    assert proj.resolution == 0
    assert_almost_equal(proj.la2, 28.0922, 4)
    assert_almost_equal(proj.lo2, -145.878, 4)
    assert proj.di == 0
    assert proj.dj == 0

    pdb2 = f.prod_desc2
    assert pdb2.scanning_mode == [False, False, False]
    assert_almost_equal(pdb2.lat_in, 20.0, 4)
    assert pdb2.resolution == 4
    assert pdb2.compression == 0
    assert pdb2.version == 1
    assert pdb2.pdb_size == 512
    assert pdb2.nav_cal == 0

    assert f.data.shape, (pdb.num_records == pdb.record_len)
开发者ID:DBaryudin,项目名称:MetPy,代码行数:35,代码来源:test_gini.py


示例8: test_gini_xarray

def test_gini_xarray(filename, bounds, data_var, proj_attrs, image, dt):
    """Test that GINIFile can be passed to XArray as a datastore."""
    f = GiniFile(get_test_data(filename))
    ds = xr.open_dataset(f)

    # Check our calculated x and y arrays
    x0, x1, y0, y1 = bounds
    x = ds.variables['x']
    assert_almost_equal(x[0], x0, 4)
    assert_almost_equal(x[-1], x1, 4)

    # Because the actual data raster has the top row first, the maximum y value is y[0],
    # while the minimum y value is y[-1]
    y = ds.variables['y']
    assert_almost_equal(y[-1], y0, 4)
    assert_almost_equal(y[0], y1, 4)

    # Check the projection metadata
    proj_name = ds.variables[data_var].attrs['grid_mapping']
    proj_var = ds.variables[proj_name]
    for attr, val in proj_attrs.items():
        assert proj_var.attrs[attr] == val, 'Values mismatch for ' + attr

    # Check the lower left lon/lat corner
    assert_almost_equal(ds.variables['lon'][-1, 0], f.prod_desc.lo1, 4)
    assert_almost_equal(ds.variables['lat'][-1, 0], f.prod_desc.la1, 4)

    # Check a pixel of the image to make sure we're decoding correctly
    x_ind, y_ind, val = image
    assert val == ds.variables[data_var][x_ind, y_ind]

    # Check time decoding
    assert np.asarray(dt, dtype='datetime64[ms]') == ds.variables['time']
开发者ID:akrherz,项目名称:MetPy,代码行数:33,代码来源:test_gini.py


示例9: basic_test

    def basic_test():
        'Basic test of GINI reading'
        f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
        pdb = f.prod_desc
        eq_(pdb.source, 1)
        eq_(pdb.creating_entity, 'GOES-15')
        eq_(pdb.sector_id, 'West CONUS')
        eq_(pdb.channel, 'WV (6.5/6.7 micron)')
        eq_(pdb.num_records, 1280)
        eq_(pdb.record_len, 1100)
        eq_(pdb.datetime, datetime(2015, 12, 8, 22, 0, 19, 0))
        eq_(pdb.projection, GiniProjection.lambert_conformal)
        eq_(pdb.nx, 1100)
        eq_(pdb.ny, 1280)
        assert_almost_equal(pdb.la1, 12.19, 4)
        assert_almost_equal(pdb.lo1, -133.4588, 4)

        proj = f.proj_info
        eq_(proj.reserved, 0)
        assert_almost_equal(proj.lov, -95.0, 4)
        assert_almost_equal(proj.dx, 4.0635, 4)
        assert_almost_equal(proj.dy, 4.0635, 4)
        eq_(proj.proj_center, 0)

        pdb2 = f.prod_desc2
        eq_(pdb2.scanning_mode, [False, False, False])
        assert_almost_equal(pdb2.lat_in, 25.0, 4)
        eq_(pdb2.resolution, 4)
        eq_(pdb2.compression, 0)
        eq_(pdb2.version, 1)
        eq_(pdb2.pdb_size, 512)

        eq_(f.data.shape, (pdb.num_records, pdb.record_len))
开发者ID:garimamalhotra,项目名称:MetPy,代码行数:33,代码来源:test_gini.py


示例10: get_upper_air_data

def get_upper_air_data(date, station):
    """Get upper air observations from the test data cache.

    Parameters
     ----------
    time : datetime
          The date and time of the desired observation.
    station : str
         The three letter ICAO identifier of the station for which data should be
         downloaded.
    Returns
    -------
        dict : upper air data

    """
    sounding_key = '{0:%Y-%m-%dT%HZ}_{1:}'.format(date, station)
    sounding_files = {'2016-05-22T00Z_DDC': 'may22_sounding.txt',
                      '2013-01-20T12Z_OUN': 'jan20_sounding.txt',
                      '1999-05-04T00Z_OUN': 'may4_sounding.txt',
                      '2002-11-11T00Z_BNA': 'nov11_sounding.txt',
                      '2010-12-09T12Z_BOI': 'dec9_sounding.txt'}

    fname = sounding_files[sounding_key]
    fobj = get_test_data(fname)

    def to_float(s):
        # Remove all whitespace and replace empty values with NaN
        if not s.strip():
            s = 'nan'
        return float(s)

    # Skip dashes, column names, units, and more dashes
    for _ in range(4):
        fobj.readline()

    # Initiate lists for variables
    arr_data = []

    # Read all lines of data and append to lists only if there is some data
    for row in fobj:
        level = to_float(row[0:7])
        values = (to_float(row[7:14]), to_float(row[14:21]), to_float(row[21:28]),
                  to_float(row[42:49]), to_float(row[49:56]))

        if any(np.invert(np.isnan(values[1:]))):
            arr_data.append((level,) + values)

    p, z, t, td, direc, spd = np.array(arr_data).T

    p = p * units.hPa
    z = z * units.meters
    t = t * units.degC
    td = td * units.degC
    direc = direc * units.degrees
    spd = spd * units.knots

    u, v = wind_components(spd, direc)

    return {'pressure': p, 'height': z, 'temperature': t,
            'dewpoint': td, 'direction': direc, 'speed': spd, 'u_wind': u, 'v_wind': v}
开发者ID:akrherz,项目名称:MetPy,代码行数:60,代码来源:testing.py


示例11: station_test_data

def station_test_data(variable_names, proj_from=None, proj_to=None):
    with get_test_data('station_data.txt') as f:
        all_data = np.loadtxt(f, skiprows=1, delimiter=',',
                              usecols=(1, 2, 3, 4, 5, 6, 7, 17, 18, 19),
                              dtype=np.dtype([('stid', '3S'), ('lat', 'f'), ('lon', 'f'),
                                              ('slp', 'f'), ('air_temperature', 'f'),
                                              ('cloud_fraction', 'f'), ('dewpoint', 'f'),
                                              ('weather', '16S'),
                                              ('wind_dir', 'f'), ('wind_speed', 'f')]))

    all_stids = [s.decode('ascii') for s in all_data['stid']]

    data = np.concatenate([all_data[all_stids.index(site)].reshape(1, ) for site in all_stids])

    value = data[variable_names]
    lon = data['lon']
    lat = data['lat']

    if proj_from is not None and proj_to is not None:

        try:

            proj_points = proj_to.transform_points(proj_from, lon, lat)
            return proj_points[:, 0], proj_points[:, 1], value

        except Exception as e:

            print(e)
            return None

    return lon, lat, value
开发者ID:akrherz,项目名称:MetPy,代码行数:31,代码来源:Point_Interpolation.py


示例12: test_tracks

 def test_tracks(self):
     f = Level3File(get_test_data('nids/KOUN_SDUS34_NSTTLX_201305202016'))
     for data in f.sym_block[0]:
         if 'track' in data:
             x, y = np.array(data['track']).T
             assert len(x)
             assert len(y)
开发者ID:NicWayand,项目名称:MetPy,代码行数:7,代码来源:test_nexrad.py


示例13: test_interpolate

def test_interpolate(method, test_coords, boundary_coords):
    r"""Test deprecated main interpolate function."""
    xp, yp = test_coords

    xp *= 10
    yp *= 10

    z = np.array([0.064, 4.489, 6.241, 0.1, 2.704, 2.809, 9.604, 1.156,
                  0.225, 3.364])

    extra_kw = {}
    if method == 'cressman':
        extra_kw['search_radius'] = 200
        extra_kw['minimum_neighbors'] = 1
    elif method == 'barnes':
        extra_kw['search_radius'] = 400
        extra_kw['minimum_neighbors'] = 1
        extra_kw['gamma'] = 1

    if boundary_coords is not None:
        extra_kw['boundary_coords'] = boundary_coords

    with pytest.warns(MetpyDeprecationWarning):
        _, _, img = interpolate(xp, yp, z, hres=10, interp_type=method, **extra_kw)

    with get_test_data('{0}_test.npz'.format(method)) as fobj:
        truth = np.load(fobj)['img']

    assert_array_almost_equal(truth, img)
开发者ID:dodolooking,项目名称:MetPy,代码行数:29,代码来源:test_grid.py


示例14: test_inverse_distance_to_points

def test_inverse_distance_to_points(method, test_data, test_points):
    r"""Test inverse distance interpolation to grid function."""
    xp, yp, z = test_data
    obs_points = np.vstack([xp, yp]).transpose()

    extra_kw = {}
    if method == 'cressman':
        extra_kw['r'] = 20
        extra_kw['min_neighbors'] = 1
        test_file = 'cressman_r20_mn1.npz'
    elif method == 'barnes':
        extra_kw['r'] = 40
        extra_kw['kappa'] = 100
        test_file = 'barnes_r40_k100.npz'
    elif method == 'shouldraise':
        extra_kw['r'] = 40
        with pytest.raises(ValueError):
            inverse_distance_to_points(
                obs_points, z, test_points, kind=method, **extra_kw)
        return

    img = inverse_distance_to_points(obs_points, z, test_points, kind=method, **extra_kw)

    with get_test_data(test_file) as fobj:
        truth = np.load(fobj)['img'].reshape(-1)

    assert_array_almost_equal(truth, img)
开发者ID:akrherz,项目名称:MetPy,代码行数:27,代码来源:test_points.py


示例15: test_tracks

def test_tracks():
    'Check that tracks are properly decoded'
    f = Level3File(get_test_data('nids/KOUN_SDUS34_NSTTLX_201305202016'))
    for data in f.sym_block[0]:
        if 'track' in data:
            x, y = np.array(data['track']).T
            assert len(x)
            assert len(y)
开发者ID:Cloudmon88,项目名称:MetPy,代码行数:8,代码来源:test_nexrad.py


示例16: test_str

 def test_str():
     'Test the str representation of GiniFile'
     f = GiniFile(get_test_data('WEST-CONUS_4km_WV_20151208_2200.gini'))
     truth = ('GiniFile: GOES-15 West CONUS WV (6.5/6.7 micron)\n'
              '\tTime: 2015-12-08 22:00:19\n\tSize: 1280x1100\n'
              '\tProjection: lambert_conformal\n'
              '\tLower Left Corner (Lon, Lat): (-133.4588, 12.19)\n\tResolution: 4km')
     assert str(f) == truth
开发者ID:garimamalhotra,项目名称:MetPy,代码行数:8,代码来源:test_gini.py


示例17: test_unidata_composite

def test_unidata_composite():
    """Test reading radar composites in GINI format made by Unidata."""
    f = GiniFile(get_test_data('Level3_Composite_dhr_1km_20180309_2225.gini'))

    # Check the time stamp
    assert datetime(2018, 3, 9, 22, 25) == f.prod_desc.datetime

    # Check data value
    assert 66 == f.data[2160, 2130]
开发者ID:akrherz,项目名称:MetPy,代码行数:9,代码来源:test_gini.py


示例18: test_vector_packet

 def test_vector_packet(self):
     f = Level3File(get_test_data('nids/KOUN_SDUS64_NHITLX_201305202016'))
     for page in f.graph_pages:
         for item in page:
             if 'vectors' in item:
                 x1, x2, y1, y2 = np.array(item['vectors']).T
                 assert len(x1)
                 assert len(x2)
                 assert len(y1)
                 assert len(y2)
开发者ID:NicWayand,项目名称:MetPy,代码行数:10,代码来源:test_nexrad.py


示例19: test_natural_neighbor

def test_natural_neighbor(test_data, test_grid):
    r"""Test natural neighbor interpolation function."""
    xp, yp, z = test_data
    xg, yg = test_grid

    img = natural_neighbor(xp, yp, z, xg, yg)

    truth = np.load(get_test_data('nn_bbox0to100.npz'))['img']

    assert_array_almost_equal(truth, img)
开发者ID:ahill818,项目名称:MetPy,代码行数:10,代码来源:test_interpolation.py


示例20: test_bad_length

def test_bad_length(caplog):
    """Test reading a product with too many bytes produces a log message."""
    fname = get_test_data('nids/KOUN_SDUS84_DAATLX_201305202016', as_file_obj=False)
    with open(fname, 'rb') as inf:
        data = inf.read()
        fobj = BytesIO(data + data)

    with caplog.at_level(logging.WARNING, 'metpy.io.nexrad'):
        Level3File(fobj)
        assert 'This product may not parse correctly' in caplog.records[0].message
开发者ID:dodolooking,项目名称:MetPy,代码行数:10,代码来源:test_nexrad.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_almost_equal函数代码示例发布时间:2022-05-27
下一篇:
Python methods.normalize函数代码示例发布时间: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