def test_divergence_free_current_magnitudes(): "Make sure the divergence free current 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_latlonr = np.zeros(angles.shape + (3, )) obs_latlonr[:, 1] = angles obs_latlonr[:, 2] = sec_r J = np.squeeze(pysecs.J_df(obs_latlonr, sec_latlonr)) # Make sure all radial components are zero in this system assert np.all(J[:, 2] == 0.) # Also all y components (angles goes around the equator and all # quantities should be perpendicular to that) assert_allclose(np.zeros(angles.shape), J[:, 1], atol=1e-16) # Actual magnitude tan_theta2 = np.tan(np.deg2rad(angles / 2)) J_test = 1. / (4 * np.pi * sec_r) J_test = np.divide(J_test, tan_theta2, out=np.ones_like(tan_theta2) * np.inf, where=tan_theta2 != 0.) assert_allclose(J_test, J[:, 0], atol=1e-16)
def test_outside_current_plane(): "Make sure all currents outside the SEC plane are 0." sec_r = R_EARTH + 100 sec_latlonr = np.array([[0., 0., sec_r]]) # Above and below the plane, also on and off the SEC point obs_latlonr = np.array([[0., 0., sec_r - 100.], [0., 0., sec_r + 100.], [5, 0., sec_r - 100.], [5., 0., sec_r + 100.]]) # df currents J = np.squeeze(pysecs.J_df(obs_latlonr, sec_latlonr)) assert np.all(J == 0.) # cf currents J = np.squeeze(pysecs.J_cf(obs_latlonr, sec_latlonr)) assert np.all(J == 0.)
def test_divergence_free_current_directions(): "Make sure the divergence free current 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., sec_r], [0., 5., sec_r], [-5, 0., sec_r], [0., -5., sec_r]]) J = np.squeeze(pysecs.J_df(obs_latlonr, sec_latlonr)) angles = np.arctan2(J[:, 0], J[:, 1]) # westward, northward, eastward, southward expected_angles = np.deg2rad([-180., 90., 0., -90.]) assert_allclose(angles, expected_angles, atol=1e-16)