Пример #1
0
def test_find_nearest():
    coords = Coordinates([1, 0], [1, 1], [0, 1])
    point = Coordinates(1, 1, 0)

    dist, idx = coords.find_nearest_point(point)

    assert idx == 0
Пример #2
0
def test_getter_ele():
    value = np.pi / 2
    coords = Coordinates()
    coords.z = 0
    coords.y = 0
    coords.x = 1
    npt.assert_allclose(coords.elevation, value)
Пример #3
0
def test_getter_azi():
    azi = np.pi / 2
    coords = Coordinates()
    coords.z = 0
    coords.y = 1
    coords.x = 0
    npt.assert_allclose(coords.azimuth, azi)
Пример #4
0
def test_getter_radius():
    value = 1
    coords = Coordinates()
    coords.z = 0
    coords.y = 1
    coords.x = 0
    npt.assert_allclose(coords.radius, value)
Пример #5
0
def test_setter_cartesian():
    x = np.array([1, 0, 0, 0])
    y = np.array([0, 1, 0, 0])
    z = np.array([0, 0, 1, 0])
    cart = np.vstack((x, y, z))
    coords = Coordinates()
    coords.cartesian = cart
    npt.assert_allclose(coords.cartesian, cart)
Пример #6
0
def test_merge():
    s1 = Coordinates(1, 0, 0)
    s2 = Coordinates(0, 2, 0)

    s1.merge(s2)

    truth = np.array([[1, 0], [0, 2], [0, 0]])
    npt.assert_allclose(truth, s1.cartesian)
Пример #7
0
def test_setter_azi():
    eps = np.spacing(1)
    azi = np.pi / 2
    x = 0
    y = 1
    z = 0
    coords = Coordinates(1, 0, 0)
    coords.azimuth = azi
    npt.assert_allclose(coords._x, x, atol=eps)
    npt.assert_allclose(coords._y, y, atol=eps)
    npt.assert_allclose(coords._z, z, atol=eps)
Пример #8
0
def test_setter_ele():
    eps = np.spacing(1)
    ele = 0
    x = 0
    y = 0
    z = 1
    coords = Coordinates(1, 0, 0)
    coords.elevation = ele
    npt.assert_allclose(coords._x, x, atol=eps)
    npt.assert_allclose(coords._y, y, atol=eps)
    npt.assert_allclose(coords._z, z, atol=eps)
Пример #9
0
def test_setter_rad():
    eps = np.spacing(1)
    rad = 0.5
    x = 0.5
    y = 0
    z = 0
    coords = Coordinates(1, 0, 0)
    coords.radius = rad
    npt.assert_allclose(coords._x, x, atol=eps)
    npt.assert_allclose(coords._y, y, atol=eps)
    npt.assert_allclose(coords._z, z, atol=eps)
Пример #10
0
def test_setter_spherical():
    eps = np.spacing(1)
    x = np.array([1, 0, 0, 1], dtype=np.float64)
    y = np.array([0, 1, 0, 1], dtype=np.float64)
    z = np.array([0, 0, 1, 1], dtype=np.float64)
    rad, theta, phi = cart2sph(x, y, z)
    spherial = np.vstack((rad, theta, phi))
    coords = Coordinates()
    coords.spherical = spherial
    npt.assert_allclose(coords._x, x, atol=eps)
    npt.assert_allclose(coords._y, y, atol=eps)
    npt.assert_allclose(coords._z, z, atol=eps)
Пример #11
0
def test_coordinates_init_incomplete():
    x = [1, 2]
    y = 1
    z = 1
    with pytest.raises(ValueError):
        Coordinates(x, y, z)
        pytest.fail("Input arrays need to have same dimensions.")
Пример #12
0
def test_getter_longitude():
    x = 1
    y = 0
    z = 0.5

    height, lat, lon = cart2latlon(x, y, z)
    coords = Coordinates(x, y, z)
    npt.assert_allclose(coords.longitude, lon)
Пример #13
0
def test_coordinates_init_from_cartesian():
    x = 1
    y = 0
    z = 0
    coords = Coordinates.from_cartesian(x, y, z)
    npt.assert_allclose(coords._x, x)
    npt.assert_allclose(coords._y, y)
    npt.assert_allclose(coords._z, z)
Пример #14
0
def test_getter_cartesian():
    x = [1, 0, 0, 0]
    y = [0, 1, 0, 0]
    z = [0, 0, 1, 0]

    coords = Coordinates(x, y, z)
    ref = np.vstack((x, y, z))
    npt.assert_allclose(coords.cartesian, ref)
Пример #15
0
def test_getter_spherical():
    x = np.array([1, 0, 0, 1], dtype=np.float64)
    y = np.array([0, 1, 0, 1], dtype=np.float64)
    z = np.array([0, 0, 1, 1], dtype=np.float64)

    rad, theta, phi = cart2sph(x, y, z)

    coords = Coordinates(x, y, z)
    ref = np.vstack((rad, theta, phi))
    npt.assert_allclose(coords.spherical, ref)
Пример #16
0
def test_coordinates_init_from_spherical():
    x = 1
    y = 0
    z = 0
    rad, theta, phi = cart2sph(x, y, z)
    coords = Coordinates.from_spherical(rad, theta, phi)
    # use atol here because of numerical rounding issues introduced in
    # the coordinate conversion
    npt.assert_allclose(coords._x, x, atol=1e-15)
    npt.assert_allclose(coords._y, y, atol=1e-15)
    npt.assert_allclose(coords._z, z, atol=1e-15)
Пример #17
0
def test_coordinates_init_from_array_cartesian():
    x = [1, 0, 0, 0]
    y = [0, 1, 0, 0]
    z = [0, 0, 1, 0]

    points = np.array([x, y, z])
    coords = Coordinates.from_array(points)

    npt.assert_allclose(coords._x, x, atol=1e-15)
    npt.assert_allclose(coords._y, y, atol=1e-15)
    npt.assert_allclose(coords._z, z, atol=1e-15)
Пример #18
0
def test_coordinates_init_from_array_spherical():
    rad = [1., 1., 1., 1.]
    ele = [np.pi / 2, np.pi / 2, 0, np.pi / 2]
    azi = [0, np.pi / 2, 0, np.pi / 4]

    points = np.array([rad, ele, azi])
    coords = Coordinates.from_array(points, coordinate_system='spherical')

    npt.assert_allclose(coords.radius, rad, atol=1e-15)
    npt.assert_allclose(coords.elevation, ele, atol=1e-15)
    npt.assert_allclose(coords.azimuth, azi, atol=1e-15)
Пример #19
0
def cube_equidistant(n_points):
    """Create a cuboid sampling with equidistant spacings in x, y, and z.
    The cube will have dimensions 1 x 1 x 1

    Parameters
    ----------
    n_points : int, tuple
        Number of points in the sampling. If a single value is given, the number
        of sampling positions will be the same in every axis. If a tuple is
        given, the number of points will be set as (n_x, n_y, n_z)

    Returns
    -------
    sampling : Coordinates
        Sampling positions as Coordinate object

    """
    if np.size(n_points) == 1:
        n_x = n_points
        n_y = n_points
        n_z = n_points
    elif np.size(n_points) == 3:
        n_x = n_points[0]
        n_y = n_points[1]
        n_z = n_points[2]
    else:
        raise ValueError("The number of points needs to be either an integer \
                or a tuple with 3 elements.")

    x = np.linspace(-1, 1, n_x)
    y = np.linspace(-1, 1, n_y)
    z = np.linspace(-1, 1, n_z)

    x_grid, y_grid, z_grid = np.meshgrid(x, y, z)

    sampling = Coordinates(x_grid.flatten(), y_grid.flatten(),
                           z_grid.flatten())

    return sampling
Пример #20
0
def test_coordinates_init():
    coords = Coordinates()
    assert isinstance(coords, Coordinates)
Пример #21
0
def test_getter_x():
    x = np.array([1, 0], dtype=np.double)
    coords = Coordinates()
    coords._x = x
    npt.assert_allclose(coords.x, x)
Пример #22
0
def test_getter_y():
    y = np.array([1, 0], dtype=np.double)
    coords = Coordinates()
    coords._y = y
    npt.assert_allclose(coords.y, y)
Пример #23
0
def test_coordinates_init_val():

    coords = Coordinates(1, 0, 0)
    assert isinstance(coords, Coordinates)
Пример #24
0
def test_getter_z():
    z = np.array([1, 0], dtype=np.double)
    coords = Coordinates()
    coords._z = z
    npt.assert_allclose(coords.z, z)
Пример #25
0
def test_len():
    coords = Coordinates([1, 0], [1, 1], [0, 1])
    assert len(coords) == 2
Пример #26
0
def test_getitem():
    coords = Coordinates([1, 0], [1, 1], [0, 1])
    getcoords = coords[0]
    npt.assert_allclose(np.squeeze(getcoords.cartesian), np.array([1, 1, 0]))
Пример #27
0
def test_setitem():
    coords = Coordinates([0, 0], [1, 1], [0, 1])
    setcoords = Coordinates(1, 1, 0)
    coords[0] = setcoords
    npt.assert_allclose(np.squeeze(coords.cartesian),
                        np.array([[1, 0], [1, 1], [0, 1]]))
Пример #28
0
def test_setter_x():
    value = np.array([1.0, 1], dtype=np.double)
    coords = Coordinates()
    coords.x = value
    npt.assert_allclose(value, coords._x)
Пример #29
0
def test_n_points():
    coords = Coordinates([1, 0], [1, 1], [0, 1])
    assert coords.n_points == 2