Ejemplo n.º 1
0
def load_and_interpolate_plasma_params(time_start,
                                       time_end,
                                       probe,
                                       pad,
                                       nsec=None,
                                       rbsp_path='G://DATA//RBSP//',
                                       HM_filter_mhz=None):
    '''
    Outputs as SI units: B0 in T, densities in /m3, temperatures in eV (pseudo SI)
    
    nsec is cadence of interpolated array in seconds. If None, defaults to using den_times
    as interpolant.
    
    If HOPE or RBSPICE data does not exist, file retrieval returns NoneType - have to deal 
    with that.
    '''
    print('Loading and interpolating satellite data')

    # Cold (total?) electron plasma density
    den_times, edens, dens_err = rfr.retrieve_RBSP_electron_density_data(
        rbsp_path, time_start, time_end, probe, pad=pad)

    # Magnetic magnitude
    mag_times, raw_mags = rfl.load_magnetic_field(rbsp_path,
                                                  time_start,
                                                  time_end,
                                                  probe,
                                                  return_raw=True,
                                                  pad=3600)

    # Filter out EMIC waves (background plus HM)
    if HM_filter_mhz is not None:
        filt_mags = np.zeros(raw_mags.shape)
        for ii in range(3):
            filt_mags[:, ii] = ascr.clw_low_pass(raw_mags[:, ii],
                                                 HM_filter_mhz,
                                                 1. / 64.,
                                                 filt_order=4)
    else:
        filt_mags = raw_mags

    # HOPE data
    itime, etime, pdict, perr = rfr.retrieve_RBSP_hope_moment_data(rbsp_path,
                                                                   time_start,
                                                                   time_end,
                                                                   padding=pad,
                                                                   probe=probe)
    hope_dens = np.array(
        [pdict['Dens_p_30'], pdict['Dens_he_30'], pdict['Dens_o_30']])
    hope_temp = np.array(
        [pdict['Tperp_p_30'], pdict['Tperp_he_30'], pdict['Tperp_o_30']])
    hope_anis = np.array([
        pdict['Tperp_Tpar_p_30'], pdict['Tperp_Tpar_he_30'],
        pdict['Tperp_Tpar_o_30']
    ]) - 1

    # SPICE data
    spice_dens = []
    spice_temp = []
    spice_anis = []
    spice_times = []
    for product, spec in zip(['TOFxEH', 'TOFxEHe', 'TOFxEO'],
                             ['P', 'He', 'O']):
        spice_epoch, spice_dict = rfr.retrieve_RBSPICE_data(rbsp_path,
                                                            time_start,
                                                            time_end,
                                                            product,
                                                            padding=pad,
                                                            probe=probe)

        # Collect all times (don't assume every file is good)
        spice_times.append(spice_epoch)

        if spice_dict is not None:
            this_dens = spice_dict['F{}DU_Density'.format(spec)]
            this_anis = spice_dict['F{}DU_PerpPressure'.format(
                spec)] / spice_dict['F{}DU_ParaPressure'.format(spec)] - 1

            # Perp Temperature - Calculate as T = P/nk
            kB = 1.381e-23
            q = 1.602e-19
            t_perp_kelvin = 1e-9 * spice_dict['F{}DU_PerpPressure'.format(
                spec)] / (kB * 1e6 * spice_dict['F{}DU_Density'.format(spec)])
            this_temp = kB * t_perp_kelvin / q  # Convert from K to eV

            spice_dens.append(this_dens)
            spice_temp.append(this_temp)
            spice_anis.append(this_anis)
        else:
            spice_dens.append(None)
            spice_temp.append(None)
            spice_anis.append(None)

    # Interpolation step
    if nsec is None:
        time_array = den_times.copy()
        iedens = edens.copy()
    else:
        time_array = np.arange(time_start,
                               time_end,
                               np.timedelta64(nsec, 's'),
                               dtype='datetime64[us]')
        iedens = interpolate_ne(time_array, den_times, edens)

    ihope_dens, ihope_temp, ihope_anis = HOPE_interpolate_to_time(
        time_array, itime, hope_dens, hope_temp, hope_anis)

    ispice_dens, ispice_temp, ispice_anis = SPICE_interpolate_to_time(
        time_array, spice_times, np.array(spice_dens), np.array(spice_temp),
        np.array(spice_anis))

    Bi = interpolate_B(time_array, mag_times, filt_mags, nsec, LP_filter=False)

    # Subtract energetic components from total electron density (assuming each is singly charged)
    cold_dens = iedens - ihope_dens.sum(axis=0) - ispice_dens.sum(axis=0)
    return time_array, Bi * 1e-9, cold_dens * 1e6, ihope_dens * 1e6, ihope_temp, ihope_anis, ispice_dens * 1e6, ispice_temp, ispice_anis
Ejemplo n.º 2
0
def load_and_interpolate_plasma_params(time_start,
                                       time_end,
                                       probe,
                                       pad,
                                       rbsp_path='G://DATA//RBSP//',
                                       cold_composition=np.array([70, 20,
                                                                  10])):
    # Cold (total?) electron plasma density
    den_times, edens, dens_err = rfr.retrieve_RBSP_electron_density_data(
        rbsp_path, time_start, time_end, probe, pad=pad)

    # Magnetic magnitude
    mag_times, B_mag = rfl.load_magnetic_field(rbsp_path,
                                               time_start,
                                               time_end,
                                               probe,
                                               return_raw=True)

    # HOPE data
    itime, etime, pdict, perr = rfr.retrieve_RBSP_hope_moment_data(rbsp_path,
                                                                   time_start,
                                                                   time_end,
                                                                   padding=pad,
                                                                   probe=probe)
    hope_dens = np.array(
        [pdict['Dens_p_30'], pdict['Dens_he_30'], pdict['Dens_o_30']])
    hope_temp = np.array(
        [pdict['Tperp_p_30'], pdict['Tperp_he_30'], pdict['Tperp_o_30']])
    hope_anis = np.array([
        pdict['Tperp_Tpar_p_30'], pdict['Tperp_Tpar_he_30'],
        pdict['Tperp_Tpar_o_30']
    ]) - 1

    # SPICE data
    spice_dens = []
    spice_temp = []
    spice_anis = []
    for product, spec in zip(['TOFxEH', 'TOFxEHe', 'TOFxEO'],
                             ['P', 'He', 'O']):
        spice_time, spice_dict = rfr.retrieve_RBSPICE_data(rbsp_path,
                                                           time_start,
                                                           time_end,
                                                           product,
                                                           padding=pad,
                                                           probe=probe)

        this_dens = spice_dict['F{}DU_Density'.format(spec)]
        this_anis = spice_dict['F{}DU_PerpPressure'.format(spec)] / spice_dict[
            'F{}DU_ParaPressure'.format(spec)] - 1

        # Perp Temperature - Calculate as T = P/nk
        kB = 1.381e-23
        q = 1.602e-19
        t_perp_kelvin = 1e-9 * spice_dict['F{}DU_PerpPressure'.format(
            spec)] / (kB * 1e6 * spice_dict['F{}DU_Density'.format(spec)])
        this_temp = kB * t_perp_kelvin / q  # Convert to eV

        spice_dens.append(this_dens)
        spice_temp.append(this_temp)
        spice_anis.append(this_anis)

    ihope_dens, ihope_temp, ihope_anis = interpolate_to_edens(
        den_times, itime, hope_dens, hope_temp, hope_anis)
    ispice_dens, ispice_temp, ispice_anis = interpolate_to_edens(
        den_times, spice_time, np.array(spice_dens), np.array(spice_temp),
        np.array(spice_anis))

    Bi = interpolate_B(den_times, mag_times, B_mag)

    # Subtract energetic components from total electron density (assuming each is singly charged)
    cold_dens = edens - ihope_dens.sum(axis=0) - ispice_dens.sum(axis=0)

    # Calculate cold ion composition. Assumes static percentage composition, but this could be changed.
    cold_comp = np.array([
        cold_composition[0] * cold_dens * 0.01,
        cold_composition[1] * cold_dens * 0.01,
        cold_composition[2] * cold_dens * 0.01
    ])

    param_dict = {}
    param_dict['times'] = den_times
    param_dict['field'] = Bi
    param_dict['ndensc'] = cold_comp
    param_dict['ndensw'] = ihope_dens
    param_dict['temp_perp'] = ihope_temp
    param_dict['A'] = ihope_anis
    param_dict['ndensw2'] = ispice_dens
    param_dict['temp_perp2'] = ispice_temp
    param_dict['A2'] = ispice_anis
    return param_dict
Ejemplo n.º 3
0
            [pdict['Dens_p_30'], pdict['Dens_he_30'], pdict['Dens_o_30']])
        hope_temp = np.array(
            [pdict['Tperp_p_30'], pdict['Tperp_he_30'], pdict['Tperp_o_30']])
        hope_anis = np.array([
            pdict['Tperp_Tpar_p_30'], pdict['Tperp_Tpar_he_30'],
            pdict['Tperp_Tpar_o_30']
        ]) - 1

        spice_dens = []
        spice_temp = []
        spice_anis = []
        for product, spec in zip(['TOFxEH', 'TOFxEHe', 'TOFxEO'],
                                 ['P', 'He', 'O']):
            spice_time, spice_dict = rfr.retrieve_RBSPICE_data(_rbsp_path,
                                                               _time_start,
                                                               _time_end,
                                                               product,
                                                               padding=_pad,
                                                               probe=_probe)

            this_dens = spice_dict['F{}DU_Density'.format(spec)]
            this_anis = spice_dict['F{}DU_PerpPressure'.format(
                spec)] / spice_dict['F{}DU_ParaPressure'.format(spec)] - 1

            # Perp Temperature - Calculate as T = P/nk
            kB = 1.381e-23
            q = 1.602e-19
            t_perp_kelvin = 1e-9 * spice_dict['F{}DU_PerpPressure'.format(
                spec)] / (kB * 1e6 * spice_dict['F{}DU_Density'.format(spec)])
            this_temp = kB * t_perp_kelvin / q  # Convert from K to eV

            spice_dens.append(this_dens)