Beispiel #1
0
    def _transform_grid(cls, grid_cart, R_b_to_dbcs, ibulkv_dbcs_par, frame):
        """Transforms the grid from the frame of interest to the
        instrument frame. Returns the grid expressed in the spherical system.

        Parameters
        ----------
        grid_s
            the transformed grid, in spherical coordinates, (3, N, N, N)
        grid_cart
            cartesian interpolation grid, (3, N, N, N)
        R_b_to_dbcs
            rotation matrix from B to DBCS, (3, 3)
        ibulkv_dbcs_par
            ion bulk velocity at particles' time, (3,)
        frame: str
            frame of interest.
        """
        # This copy of grid_cart will be rotated, every scan differently.
        grid_c = grid_cart.copy()
        # For now grid_c is in the frame of interest, EB, GSE, or any.
        if frame == 'instrument':
            pass
        elif frame == 'B':
            grid_c = np.dot(R_b_to_dbcs, grid_c.reshape(3, -1)).reshape(
                grid_cart.shape)  ## Rotation.
            grid_c += ibulkv_dbcs_par[:, None, None, None]  ## Translation.
        else:
            raise ValueError('{}: unknown frame.'.format(frame))
        # We now go for the spherical system, the natural instrument
        #     coordinate system. Here, the -1 is reversing velocity vector to
        #     viewing direction, in which the instrument tables are expressed.
        grid_s = vdfu.cart2spher(-1 * grid_c)
        return grid_s
Beispiel #2
0
def test_cart2spher():
    """Unit test on vdfu.cart2spher method."""
    reso = 5
    grid_cart_dummy = np.ones((3, reso, reso, reso))
    grid_spher = vdfu.cart2spher(grid_cart_dummy)
    assert grid_spher.shape == (3, reso, reso, reso)
    assert np.allclose(grid_cart_dummy, vdfu.spher2cart(grid_spher))
Beispiel #3
0
def test_init_grid():
    """Unit test on vdfu.init_grid method."""
    reso = 5
    grid_cart, grid_spher, grid_cyl, \
    dvvv = vdfu.init_grid(v_max=1., resolution=reso,
                          grid_geom='spher')
    assert grid_cart.shape == (3, reso, reso, reso)
    assert grid_spher.shape == (3, reso, reso, reso)
    assert grid_cyl.shape == (3, reso, reso, reso)
    assert dvvv.shape == (reso, reso, reso)
    # Testing that the grid values are strictly increasing.
    assert np.all(grid_spher[0][1:] > grid_spher[0][:-1])
    assert np.all(grid_spher[1][:, 1:] > grid_spher[1][:, :-1])
    assert np.all(grid_spher[2][:, :, 1:] > grid_spher[2][:, :, :-1])
    # Testing that grid_cart and grid_spher are one and the same grid.
    assert np.allclose(grid_spher, vdfu.cart2spher(grid_cart))
    assert np.allclose(grid_cyl, vdfu.cart2cyl(grid_cart))
Beispiel #4
0
def test_transform_grid():
    """Unit test on AidaAccessorVDF.transform_grid method."""
    reso = 5
    grid_cart = np.zeros((3, reso, reso, reso))
    grid_cart[0] = 1.
    frame = 'instrument'
    R_b_to_dbcs = np.eye(3)
    ibulkv_dbcs_par = np.zeros(3)
    grid_s = AidaAccessorVDF._transform_grid(grid_cart, R_b_to_dbcs,
                                             ibulkv_dbcs_par, frame)
    assert grid_s.shape == (3, reso, reso, reso)
    assert np.allclose(grid_s, vdfu.cart2spher(-1 * grid_cart))

    frame = 'B'
    grid_s = AidaAccessorVDF._transform_grid(grid_cart, R_b_to_dbcs,
                                             ibulkv_dbcs_par, frame)
    assert np.allclose(grid_s[0], 1.)
    assert np.allclose(grid_s[1], np.pi / 2.)
    assert np.allclose(grid_s[2], np.pi)