Esempio n. 1
0
def test_grid_from_sph_coords():
    x = np.arange(0.0, 360.0, 40.0)  # longitude
    y = np.arange(0.0, 181.0, 60.0)  # colatitude
    z = [1]  # elevation (radius)
    g = pyvista.grid_from_sph_coords(x, y, z)
    assert g.n_cells == 24
    assert g.n_points == 36
    assert np.allclose(
        g.bounds,
        [
            -0.8137976813493738,
            0.8660254037844387,
            -0.8528685319524434,
            0.8528685319524433,
            -1.0,
            1.0,
        ],
    )
    assert np.allclose(g.points[1], [0.8660254037844386, 0.0, 0.5])
    z = np.linspace(10, 30, 3)
    g = pyvista.grid_from_sph_coords(x, y, z)
    assert g.n_cells == 48
    assert g.n_points == 108
    assert np.allclose(g.points[0], [0.0, 0.0, 10.0])
Esempio n. 2
0
u_vec = np.cos(np.radians(xx))  # zonal
v_vec = np.sin(np.radians(yy))  # meridional

# Scalar data
scalar = u_vec**2 + v_vec**2

# Create arrays of grid cell boundaries, which have shape of (x.shape[0] + 1)
xx_bounds = _cell_bounds(x)
yy_bounds = _cell_bounds(y_polar)
# Vertical levels
# in this case a single level slightly above the surface of a sphere
levels = [RADIUS * 1.01]

###############################################################################
# Create a structured grid
grid_scalar = pv.grid_from_sph_coords(xx_bounds, yy_bounds, levels)

# And fill its cell arrays with the scalar data
grid_scalar.cell_data["example"] = np.array(scalar).swapaxes(-2, -1).ravel("C")

# Make a plot
p = pv.Plotter()
p.add_mesh(pv.Sphere(radius=RADIUS))
p.add_mesh(grid_scalar, clim=[0.1, 2.0], opacity=0.5, cmap="plasma")
p.show()

###############################################################################
# Visualize vectors in spherical coordinates
# Vertical wind
w_vec = np.random.rand(*u_vec.shape)
Esempio n. 3
0
x = np.linspace(-180.0, 180.0, 200)
y = np.linspace(-90, 91, 200)
y_polar = 90.0 - y

# Create arrays of grid cell boundaries, which have shape of (x.shape[0] + 1)
xx_bounds = _cell_bounds(x)
yy_bounds = _cell_bounds(y_polar)
levels = [RADIUS * 1.01]

positions_mars = mouton_3_corps(0, 14 * 24 * 3600, 2000, sys_TMS_stable, F_TMS, slice=2)
positions_lune = mouton_3_corps(0, 14 * 24 * 3600, 2000, sys_TMS, F_TLS, slice=2)
a = grid_mouton(200, Equilibrium, positions_mars, m_M)
b = grid_mouton(200, Equilibrium, positions_lune, m_L)

# Remplir la grille de valeurs scalaires
grid_scalar_mars = pv.grid_from_sph_coords(xx_bounds, yy_bounds, levels)
grid_scalar_mars.cell_arrays["Hauteur de la marée avec Mars (m)"] = np.array(a[0]).swapaxes(-2, -1).ravel("C")
grid_scalar_lune = pv.grid_from_sph_coords(xx_bounds, yy_bounds, levels)
grid_scalar_lune.cell_arrays["Hauteur de la marée avec la Lune (m)"] = np.array(b[0]).swapaxes(-2, -1).ravel("C")


# Fonction qui calcule les coordonnées et retourne un array (x,y,z)
def points(lon, lat):
    R = RADIUS
    return np.array(
        [1.01 * R * np.cos(lat) * np.cos(lon), 1.01 * R * np.cos(lat) * np.sin(lon), 1.01 * R * np.sin(lat)])


# Crée des points sur la sphère
label = ["Québec", "Paris", "Tokyo", "Brasilia"]
Quebec = points(-1.2428137, 0.8170563)