コード例 #1
0
ファイル: test_secs.py プロジェクト: greglucas/pysecs
def test_divergence_free_magnetic_directions():
    "Make sure the divergence free magnetic field angles are correct"
    # Place the SEC at the equator
    sec_r = R_EARTH + 100
    sec_latlonr = np.array([[0., 0., sec_r]])
    # Going around in a circle from the point
    obs_latlonr = np.array([[5., 0., R_EARTH], [0., 5., R_EARTH],
                            [-5, 0., R_EARTH], [0., -5., R_EARTH]])

    B = np.squeeze(pysecs.T_df(obs_latlonr, sec_latlonr))

    angles = np.arctan2(B[:, 0], B[:, 1])
    # southward, westward, northward, eastward
    expected_angles = np.deg2rad([-90, 180., 90., 0.])
    assert_allclose(angles, expected_angles, rtol=1e-10, atol=1e-10)
コード例 #2
0
ファイル: test_secs.py プロジェクト: greglucas/pysecs
def test_divergence_free_magnetic_magnitudes_obs_under():
    "Make sure the divergence free magnetic amplitudes are correct."
    # Place the SEC at the North Pole
    sec_r = R_EARTH + 100
    sec_latlonr = np.array([[0., 0., sec_r]])
    # Going out in an angle from the SEC (in longitude)
    angles = np.linspace(0.1, 180)
    obs_r = R_EARTH
    obs_latlonr = np.zeros(angles.shape + (3, ))
    obs_latlonr[:, 1] = angles
    obs_latlonr[:, 2] = obs_r

    B = np.squeeze(pysecs.T_df(obs_latlonr, sec_latlonr))

    # All x components should be zero (angles goes around the equator and all
    # quantities should be parallel to that)
    assert_allclose(np.zeros(angles.shape), B[:, 0], atol=1e-16)

    # Actual magnitude
    mu0 = 4 * np.pi * 1e-7

    # simplify calculations by storing this ratio
    x = obs_r / sec_r

    sin_theta = np.sin(np.deg2rad(angles))
    cos_theta = np.cos(np.deg2rad(angles))
    factor = 1. / np.sqrt(1 - 2 * x * cos_theta + x**2)

    # Amm & Viljanen: Equation 9
    Br = mu0 / (4 * np.pi * obs_r) * (factor - 1)
    # Bz in opposite direction of Br
    assert_allclose(-Br, B[:, 2])

    # Amm & Viljanen: Equation 10
    Btheta = -mu0 / (4 * np.pi * obs_r) * (factor *
                                           (x - cos_theta) + cos_theta)
    Btheta = np.divide(Btheta,
                       sin_theta,
                       out=np.zeros_like(sin_theta),
                       where=sin_theta != 0)
    assert_allclose(Btheta, B[:, 1])