Esempio n. 1
0
def test_squeeze():
    a = generate_test_dataarray(dims={'y': 1})
    value = a.values[0]
    squeezed = utils.squeeze(a)
    assert isinstance(squeezed, float)
    assert value == squeezed

    b = generate_test_dataarray(dims={'y': 2})
    xr_assert_identical(b, utils.squeeze(b))
Esempio n. 2
0
def test_disassemble_complex_dataarray():
    # Create complex dataset
    da = generate_test_dataarray(name='data')
    complex_data = np.random.rand(*da.shape) + 1j * np.random.rand(*da.shape)
    da.values = complex_data
    ds_real = disassemble_complex(da)
    assert_equal(set(ds_real.data_vars), {'data__re', 'data__im'})
    xr_assert_equal(da.real, ds_real['data__re'])
    xr_assert_equal(da.imag, ds_real['data__im'])
Esempio n. 3
0
def test_expand_var_to_xy(extra, dims):
    ref = generate_test_dataarray(
        dims=OrderedDict([('y', 30), ('x', 20), ('time', 5)])
    )
    da = generate_test_dataarray(dims=dims)
    expanded = warp._expand_var_to_xy(da, ref.coords)

    # Check that the variance along added dimensions is zero
    assert np.all(
        expanded.var(extra) < 1e-16
    )

    # Check that the new DataArray contains x and y coordinates
    xr_assert_equal(
        expanded.coords['x'], ref.coords['x'])
    xr_assert_equal(
        expanded.coords['y'], ref.coords['y'])

    # Check that the DataArray is unchanged if x and y were already
    # dimensions
    if 'x' in dims and 'y' in dims:
        xr_assert_equal(da, expanded)
Esempio n. 4
0
def test_get_extent_dataarray():
    extent = (-10.0, 50.0, 0.0, 60.0)
    da = generate_test_dataarray(extent=extent, crs=epsg4326)
    assert_equal(extent, get_extent(da))
Esempio n. 5
0
def test_get_bounds_dataarray():
    bounds = (-10.0, 50.0, 0.0, 60.0)
    da = generate_test_dataarray(extent=bounds)
    assert_equal(bounds, get_bounds(da))