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

Python testing.assert_array_almost_equal函数代码示例

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

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



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

示例1: test_basic

    def test_basic(self):
        levels = np.array([1000., 900., 800., 700., 600., 500., 400.]) * units.mbar
        true_prof = np.array([303.15, 294.16, 288.026, 283.073, 277.058, 269.402,
                              258.966]) * units.kelvin

        prof = parcel_profile(levels, 30. * units.degC, 20. * units.degC)
        assert_array_almost_equal(prof, true_prof, 2)
开发者ID:DBaryudin,项目名称:MetPy,代码行数:7,代码来源:test_thermo.py


示例2: test_temperature_from_potential_temperature

def test_temperature_from_potential_temperature():
    """Test temperature_from_potential_temperature calculation."""
    theta = np.array([286.12859679, 288.22362587, 290.31865495, 292.41368403]) * units.kelvin
    pres = np.array([850] * 4) * units.mbar
    real_t = np.array([273.15, 275.15, 277.15, 279.15]) * units.kelvin
    assert_array_almost_equal(temperature_from_potential_temperature(pres, theta),
                              real_t, 2)
开发者ID:dodolooking,项目名称:MetPy,代码行数:7,代码来源:test_thermo.py


示例3: test_second_derivative

def test_second_derivative(deriv_1d_data):
    """Test second_derivative with a simple 1D array."""
    d2v_dx2 = second_derivative(deriv_1d_data.values, x=deriv_1d_data.x)

    # Worked by hand
    truth = np.ones_like(deriv_1d_data.values) * 0.2133333 * units('delta_degC/cm**2')
    assert_array_almost_equal(d2v_dx2, truth, 5)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例4: test_laplacian

def test_laplacian(deriv_1d_data):
    """Test laplacian with simple 1D data."""
    laplac = laplacian(deriv_1d_data.values, coordinates=(deriv_1d_data.x,))

    # Worked by hand
    truth = np.ones_like(deriv_1d_data.values) * 0.2133333 * units('delta_degC/cm**2')
    assert_array_almost_equal(laplac, truth, 5)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例5: test_find_intersections

def test_find_intersections(direction, expected):
    """Test finding the intersection of two curves functionality."""
    x = np.linspace(5, 30, 17)
    y1 = 3 * x**2
    y2 = 100 * x - 650
    # Note: Truth is what we will get with this sampling, not the mathematical intersection
    assert_array_almost_equal(expected, find_intersections(x, y1, y2, direction=direction), 2)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例6: test_first_derivative

def test_first_derivative(deriv_1d_data):
    """Test first_derivative with a simple 1D array."""
    dv_dx = first_derivative(deriv_1d_data.values, x=deriv_1d_data.x)

    # Worked by hand and taken from Chapra and Canale 23.2
    truth = np.array([-1.333333, -1.06666667, -0.5333333]) * units('delta_degC / cm')
    assert_array_almost_equal(dv_dx, truth, 5)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例7: test_smooth_gaussian

def test_smooth_gaussian():
    """Test the smooth_gaussian function with a larger n."""
    m = 10
    s = np.zeros((m, m))
    for i in np.ndindex(s.shape):
        s[i] = i[0] + i[1]**2
    s = smooth_gaussian(s, 4)
    s_true = np.array([[0.40077472, 1.59215426, 4.59665817, 9.59665817, 16.59665817,
                        25.59665817, 36.59665817, 49.59665817, 64.51108392, 77.87487258],
                       [1.20939518, 2.40077472, 5.40527863, 10.40527863, 17.40527863,
                        26.40527863, 37.40527863, 50.40527863, 65.31970438, 78.68349304],
                       [2.20489127, 3.39627081, 6.40077472, 11.40077472, 18.40077472,
                        27.40077472, 38.40077472, 51.40077472, 66.31520047, 79.67898913],
                       [3.20489127, 4.39627081, 7.40077472, 12.40077472, 19.40077472,
                        28.40077472, 39.40077472, 52.40077472, 67.31520047, 80.67898913],
                       [4.20489127, 5.39627081, 8.40077472, 13.40077472, 20.40077472,
                        29.40077472, 40.40077472, 53.40077472, 68.31520047, 81.67898913],
                       [5.20489127, 6.39627081, 9.40077472, 14.40077472, 21.40077472,
                        30.40077472, 41.40077472, 54.40077472, 69.31520047, 82.67898913],
                       [6.20489127, 7.39627081, 10.40077472, 15.40077472, 22.40077472,
                        31.40077472, 42.40077472, 55.40077472, 70.31520047, 83.67898913],
                       [7.20489127, 8.39627081, 11.40077472, 16.40077472, 23.40077472,
                        32.40077472, 43.40077472, 56.40077472, 71.31520047, 84.67898913],
                       [8.20038736, 9.3917669, 12.39627081, 17.39627081, 24.39627081,
                        33.39627081, 44.39627081, 57.39627081, 72.31069656, 85.67448522],
                       [9.00900782, 10.20038736, 13.20489127, 18.20489127, 25.20489127,
                        34.20489127, 45.20489127, 58.20489127, 73.11931702, 86.48310568]])
    assert_array_almost_equal(s, s_true)
开发者ID:akrherz,项目名称:MetPy,代码行数:28,代码来源:test_basic.py


示例8: test_first_derivative_xarray_pint_conversion

def test_first_derivative_xarray_pint_conversion(test_da_lonlat):
    """Test first derivative with implicit xarray to pint quantity conversion."""
    dx, _ = grid_deltas_from_dataarray(test_da_lonlat)
    deriv = first_derivative(test_da_lonlat, delta=dx, axis=-1)
    truth = np.array([[[-3.30782978e-06] * 4, [-3.42816074e-06] * 4, [-3.57012948e-06] * 4,
                       [-3.73759364e-06] * 4]] * 3) * units('kelvin / meter')
    assert_array_almost_equal(deriv, truth, 12)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例9: test_grid_deltas_from_dataarray_xy

def test_grid_deltas_from_dataarray_xy(test_da_xy):
    """Test grid_deltas_from_dataarray with a xy grid."""
    dx, dy = grid_deltas_from_dataarray(test_da_xy)
    true_dx = np.array([[[[500] * 3]]]) * units('km')
    true_dy = np.array([[[[500]] * 3]]) * units('km')
    assert_array_almost_equal(dx, true_dx, 5)
    assert_array_almost_equal(dy, true_dy, 5)
开发者ID:dopplershift,项目名称:MetPy,代码行数:7,代码来源:test_calc_tools.py


示例10: test_basic

    def test_basic(self):
        'Test the basic heat index calculation.'
        temp = np.array([80, 88, 92, 110]) * units.degF
        rh = np.array([40, 100, 70, 40])

        hi = heat_index(temp, rh)
        values = np.array([80, 121, 112, 136]) * units.degF
        assert_array_almost_equal(hi, values, 0)
开发者ID:rinckd,项目名称:MetPy,代码行数:8,代码来源:test_basic.py


示例11: test_face_level

    def test_face_level(self):
        'Tests using the face_level flag'
        temp = np.array([20, 0, -20, -40]) * units.degF
        speed = np.array([15, 30, 45, 60]) * units.mph

        wc = windchill(temp, speed, face_level_winds=True)
        values = np.array([3, -30, -64, -98]) * units.degF
        assert_array_almost_equal(wc, values, 0)
开发者ID:rinckd,项目名称:MetPy,代码行数:8,代码来源:test_basic.py


示例12: test_heat_index_basic

def test_heat_index_basic():
    """Test the basic heat index calculation."""
    temp = np.array([80, 88, 92, 110]) * units.degF
    rh = np.array([40, 100, 70, 40]) * units.percent

    hi = heat_index(temp, rh)
    values = np.array([80, 121, 112, 136]) * units.degF
    assert_array_almost_equal(hi, values, 0)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_basic.py


示例13: test_log_interpolate_4d

def test_log_interpolate_4d():
    """Test interpolating with log x-scale 4 dimensions."""
    x_log = np.ones((2, 2, 3, 4)) * np.array([1e3, 1e4, 1e5, 1e6])
    y_log = np.log(x_log) * 2 + 3
    x_interp = np.array([5e3, 5e4, 5e5])
    y_interp_truth = np.array([20.0343863828, 24.6395565688, 29.2447267548])
    y_interp = log_interpolate_1d(x_interp, x_log, y_log, axis=3)
    assert_array_almost_equal(y_interp[0, 0, 0, :], y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例14: test_log_interpolate_2d

def test_log_interpolate_2d():
    """Test interpolating with log x-scale in 2 dimensions."""
    x_log = np.array([[1e3, 1e4, 1e5, 1e6], [1e3, 1e4, 1e5, 1e6]])
    y_log = np.log(x_log) * 2 + 3
    x_interp = np.array([5e3, 5e4, 5e5])
    y_interp_truth = np.array([20.0343863828, 24.6395565688, 29.2447267548])
    y_interp = log_interpolate_1d(x_interp, x_log, y_log, axis=1)
    assert_array_almost_equal(y_interp[1], y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例15: test_log_interpolate_3d

def test_log_interpolate_3d():
    """Test interpolating with log x-scale 3 dimensions along second axis."""
    x_log = np.ones((3, 4, 3)) * np.array([1e3, 1e4, 1e5, 1e6]).reshape(-1, 1)
    y_log = np.log(x_log) * 2 + 3
    x_interp = np.array([5e3, 5e4, 5e5])
    y_interp_truth = np.array([20.0343863828, 24.6395565688, 29.2447267548])
    y_interp = log_interpolate_1d(x_interp, x_log, y_log, axis=1)
    assert_array_almost_equal(y_interp[0, :, 0], y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例16: test_interpolate_nans_1d_log

def test_interpolate_nans_1d_log():
    """Test log interpolation of arrays with NaNs in the y-coordinate."""
    x = np.logspace(1, 5, 15)
    y = 5 * np.log(x) + 3
    nan_indexes = [1, 5, 11, 12]
    y_with_nan = y.copy()
    y_with_nan[nan_indexes] = np.nan
    assert_array_almost_equal(y, interpolate_nans_1d(x, y_with_nan, kind='log'), 2)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例17: test_log_interpolate_1d_units

def test_log_interpolate_1d_units():
    """Test interpolating with log x-scale with units."""
    x_log = np.array([1e3, 1e4, 1e5, 1e6]) * units.hPa
    y_log = (np.log(x_log.m) * 2 + 3) * units.degC
    x_interp = np.array([5e5, 5e6, 5e7]) * units.Pa
    y_interp_truth = np.array([20.0343863828, 24.6395565688, 29.2447267548]) * units.degC
    y_interp = log_interpolate_1d(x_interp, x_log, y_log)
    assert_array_almost_equal(y_interp, y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例18: test_interpolate_end_point

def test_interpolate_end_point():
    """Test interpolation with point at data endpoints."""
    x = np.array([1., 2., 3., 4.])
    y = x
    x_interp = np.array([1.0, 4.0])
    y_interp_truth = np.array([1.0, 4.0])
    y_interp = interpolate_1d(x_interp, x, y)
    assert_array_almost_equal(y_interp, y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例19: test_interpolate_masked_units

def test_interpolate_masked_units():
    """Test interpolating with masked arrays with units."""
    x = np.ma.array([1., 2., 3., 4.]) * units.m
    y = np.ma.array([50., 60., 70., 80.]) * units.degC
    x_interp = np.array([250., 350.]) * units.cm
    y_interp_truth = np.array([65., 75.]) * units.degC
    y_interp = interpolate_1d(x_interp, x, y)
    assert_array_almost_equal(y_interp, y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py


示例20: test_interpolate_decrease

def test_interpolate_decrease():
    """Test interpolation with decreasing interpolation points."""
    x = np.array([1., 2., 3., 4.])
    y = x
    x_interp = np.array([3.5000000, 2.5000000])
    y_interp_truth = np.array([3.5000000, 2.5000000])
    y_interp = interpolate_1d(x_interp, x, y)
    assert_array_almost_equal(y_interp, y_interp_truth, 7)
开发者ID:akrherz,项目名称:MetPy,代码行数:8,代码来源:test_one_dimension.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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