Exemplo n.º 1
0
def example2():
    """
    Plot difference between modelled and observed field strength using Swarm A
    data in August 2018 from a cdf-file.

    """
    import cdflib

    model = load_CHAOS_matfile(FILEPATH_CHAOS)
    print(model)

    cdf_file = cdflib.CDF(
        'data/SW_OPER_MAGA_LR_1B_'
        '20180801T000000_20180801T235959'
        '_PT15S.cdf', 'r')
    # print(cdf_file.cdf_info())  # print cdf info/contents

    radius = cdf_file.varget('Radius') / 1000  # km
    theta = 90. - cdf_file.varget('Latitude')  # colat deg
    phi = cdf_file.varget('Longitude')  # deg
    time = cdf_file.varget('Timestamp')  # milli seconds since year 1
    time = time / (1e3 * 3600 *
                   24) - 730485  # time in modified Julian date 2000
    F_swarm = cdf_file.varget('F')
    cdf_file.close()

    theta_gsm, phi_gsm = transform_points(theta,
                                          phi,
                                          time=time,
                                          reference='gsm')
    index_day = np.logical_and(phi_gsm < 90, phi_gsm > -90)
    index_night = np.logical_not(index_day)

    # complete forward computation: pre-built not customizable (see ex. 1)
    B_radius, B_theta, B_phi = model(time, radius, theta, phi)

    # compute field strength and plot together with data
    F = np.sqrt(B_radius**2 + B_theta**2 + B_phi**2)

    print('RMSE of F: {:.5f} nT'.format(np.std(F - F_swarm)))

    plt.scatter(theta_gsm[index_day],
                F_swarm[index_day] - F[index_day],
                s=0.5,
                c='r',
                label='dayside')
    plt.scatter(theta_gsm[index_night],
                F_swarm[index_night] - F[index_night],
                s=0.5,
                c='b',
                label='nightside')
    plt.xlabel('dipole colatitude ($^\\circ$)')
    plt.ylabel('$\\mathrm{d} F$ (nT)')
    plt.legend(loc=2)
    plt.show()
Exemplo n.º 2
0
    def test_geo_to_gsm(self):

        time = np.linspace(1, 100, 10)
        theta_geo = np.linspace(1, 179, 10)
        phi_geo = np.linspace(-180, 179, 10)

        # load matfile
        test = load_matfile(MATFILE_PATH, 'test_geo_to_gsm')

        # reduce 2-D matrix to 1-D vectors
        theta_gsm_mat = np.ravel(test['theta_gsm'])
        phi_gsm_mat = np.ravel(test['phi_gsm'])

        theta_gsm, phi_gsm = c.transform_points(
            theta_geo, phi_geo, time=time, reference='gsm')

        self.assertIsNone(np.testing.assert_allclose(theta_gsm, theta_gsm_mat))
        self.assertIsNone(np.testing.assert_allclose(phi_gsm, phi_gsm_mat))