Пример #1
0
def importar_swia(year, month, day, ti, tf):
    date_orbit = dt.date(int(year), int(month), int(day))
    year = date_orbit.strftime("%Y")
    month = date_orbit.strftime("%m")
    day = date_orbit.strftime("%d")

    # if gethostname() == "magneto2":
    #     path = f"../../../../media/gabybosc/datos/SWIA/"
    # elif gethostname() == "gabybosc":
    #     path = "../../datos/SWIA/"
    # else:
    path = f"../../../datos/SWIA/"

    swia = cdf.CDF(path +
                   f"mvn_swi_l2_onboardsvymom_{year}{month}{day}_v01_r01.cdf")

    t_unix = swia.varget("time_unix")
    density = swia.varget("density")  # cm⁻³
    temperature = swia.varget("temperature_mso")  # eV
    vel_mso_xyz = swia.varget("velocity_mso")  # km/s

    t_swia = unix_to_decimal(t_unix)
    inicio = donde(t_swia, ti)
    fin = donde(t_swia, tf)

    t_cut = t_swia[inicio:fin]
    density_cut = density[inicio:fin]
    temperature_cut = temperature[inicio:fin]
    vel_mso_cut = vel_mso_xyz[inicio:fin]  # km/s

    return swia, t_cut, density_cut, temperature_cut, vel_mso_cut
Пример #2
0
def importar_swea(year, month, day, ti, tf):
    date_orbit = dt.date(int(year), int(month), int(day))
    year = date_orbit.strftime("%Y")
    month = date_orbit.strftime("%m")
    day = date_orbit.strftime("%d")

    if gethostname() == "magneto2":
        path = f"../../../../media/gabybosc/datos/SWEA/"
    elif gethostname() == "gabybosc":
        path = "../../datos/SWEA/"
    else:
        path = f"../../../datos/SWEA/"

    swea = cdf.CDF(path +
                   f"/mvn_swe_l2_svyspec_{year}{month}{day}_v04_r01.cdf")

    flux_all = swea.varget("diff_en_fluxes")
    energia = swea.varget("energy")
    t_unix = swea.varget("time_unix")

    t = unix_to_decimal(t_unix)

    inicio = donde(t, ti)
    fin = donde(t, tf)

    t_cut = t[inicio:fin]

    flux = flux_all[inicio:fin]
    flux_plot = np.transpose(flux)[::-1]

    return swea, t_cut, energia, flux_plot
Пример #3
0
def importar_static(year, month, day, ti, tf):
    date_orbit = dt.date(int(year), int(month), int(day))
    year = date_orbit.strftime("%Y")
    month = date_orbit.strftime("%m")
    day = date_orbit.strftime("%d")

    if gethostname() == "magneto2":
        path = f"../../../../media/gabybosc/datos/STATIC/"
    elif gethostname() == "gabybosc":
        path = "../../datos/STATIC/"
    else:
        path = f"../../../datos/STATIC/"

    static = cdf.CDF(path +
                     f"mvn_sta_l2_c6-32e64m_{year}{month}{day}_v02_r01.cdf")

    t_unix = static.varget("time_unix")
    mass = static.varget("mass_arr")
    energy = static.varget("energy")

    t = unix_to_decimal(t_unix)

    inicio = donde(t, ti)
    fin = donde(t, tf)

    t_cut = t[inicio:fin]
    mass_cut = mass[inicio:fin]
    energy_cut = energy[inicio:fin]

    return static, t_cut, mass_cut, energy_cut
Пример #4
0
def importar_lpw(year, month, day, ti, tf):
    date_orbit = dt.date(int(year), int(month), int(day))
    year = date_orbit.strftime("%Y")
    month = date_orbit.strftime("%m")
    day = date_orbit.strftime("%d")

    if gethostname() == "magneto2":
        path = f"../../../../media/gabybosc/datos/LPW/"
    elif gethostname() == "gabybosc":
        path = "../../datos/LPW/"
    else:
        path = f"../../../datos/LPW/"

    lpw = cdf.CDF(path + f"mvn_lpw_l2_lpnt_{year}{month}{day}_v03_r02.cdf")

    t_unix = lpw.varget("time_unix")
    e_density = lpw.varget("data")[:, 3]

    t = unix_to_decimal(t_unix)

    inicio = donde(t, ti)
    fin = donde(t, tf)

    t_cut = t[inicio:fin]
    e_density_cut = e_density[inicio:fin]

    return lpw, t_cut, e_density_cut
Пример #5
0
def importar_swia(year, month, day, ti, tf):
    date_orbit = dt.date(int(year), int(month), int(day))
    year = date_orbit.strftime("%Y")
    month = date_orbit.strftime("%m")
    day = date_orbit.strftime("%d")

    if gethostname() == "magneto2":
        path = "../../../../media/gabybosc/datos/SWIA/"
    elif gethostname() == "gabybosc":
        path = "../../datos/SWIA/"
    else:
        path = "../../../datos/SWIA/"

    if os.path.isfile(
            path + f"mvn_swi_l2_coarsearc3d_{year}{month}{day}_v01_r01.cdf"):
        # si no existe SWICA, usa los onboard
        swia = cdf.CDF(
            path +
            f"mvn_swi_l2_coarsearc3d_{year}{month}{day}_v01_r01_orig.cdf")
    else:
        swia = cdf.CDF(
            path + f"mvn_swi_l2_onboardsvymom_{year}{month}{day}_v01_r01.cdf")

    t_unix = swia.varget("time_unix")
    density = swia.varget("density")  # cm⁻³
    # creo que en los datos de PDS, SWICA no tiene estos ya calculados (son justamente los moments)
    temperature = swia.varget("temperature_mso")  # eV
    vel_mso_xyz = swia.varget("velocity_mso")  # km/s

    t_swia = unix_to_decimal(t_unix)
    inicio = donde(t_swia, ti)
    fin = donde(t_swia, tf)

    t_cut = t_swia[inicio:fin]
    density_cut = density[inicio:fin]
    temperature_cut = temperature[inicio:fin]
    vel_mso_cut = vel_mso_xyz[inicio:fin]  # km/s

    return swia, t_cut, density_cut, temperature_cut, vel_mso_cut
Пример #6
0
    'La corriente en volumen con la normal del ajuste es Jv = {} nA/m², |Jv| = {} nA/m²'
    .format(J_v_ajuste, np.linalg.norm(J_v_ajuste)))

# fuerza_mva = np.cross(J_v * 1E-9, B[inicio_up:fin_down, :] * 1E-9) #A/m² * T = N/m³
# fuerza_ajuste = np.cross(J_v_ajuste * 1E-9, B[inicio_up:fin_down, :] * 1E-9) #A/m² * T = N/m³
fuerza_mva = np.cross(J_v * 1E-9, B[inicio_down, :] * 1E-9)  #N/m^3 #en t4
fuerza_ajuste = np.cross(J_v_ajuste * 1E-9,
                         B[inicio_down, :] * 1E-9)  #N/m^3 #en t4
print('La fuerza de lorentz del MVA es {} V/m, su magnitud es {}'.format(
    fuerza_mva, np.linalg.norm(fuerza_mva)))
print('La fuerza de lorentz del ajuste es {} V/m, su magnitud es {}'.format(
    fuerza_ajuste, np.linalg.norm(fuerza_ajuste)))

e_density = lpw.varget('data')[:, 3]
t_unix = lpw.varget('time_unix')
t_lpw = unix_to_decimal(t_unix)
ti_lpw = np.where(t_lpw == find_nearest(t_lpw, t2))[0][0]
tf_lpw = np.where(t_lpw == find_nearest(t_lpw, t3))[0][0]
n_e = np.nanmean(
    e_density[ti_lpw:tf_lpw])  #hace el mean ignorando los nans #cm⁻³
n_e = n_e * 1E6  #m⁻³
# n_e = 1E7
q_e = 1.6E-19  #carga electron #C

E_Hall = np.cross(J_v * 1E-9, B[inicio_down, :] * 1E-9) / (q_e * n_e)  #V/m
print('El campo de Hall del MVA es {} mV/m, su magnitud es {}'.format(
    E_Hall * 1E3,
    np.linalg.norm(E_Hall) * 1E3))

E_Hall_ajuste = np.cross(J_v_ajuste * 1E-9, B[inicio_down, :] * 1E-9) / (
    q_e * n_e)  #V/m
Пример #7
0
def flujo_energia(t1, t2, cdf_file):

    # np.set_printoptions(precision=4)

    path = '../../datos/SWEA/'  #path a los datos
    cdf_file = cdf.CDF(path + 'mvn_swe_l2_svyspec_20160402_v04_r01.cdf')

    flux = cdf_file.varget('diff_en_fluxes')
    energia = cdf_file.varget('energy')
    t_unix = cdf_file.varget('time_unix')

    tu = unix_to_decimal(t_unix)
    ti = np.where(tu == find_nearest(tu, t1))[0][0]
    tf = np.where(tu == find_nearest(tu, t2))[0][0]
    t = tu[ti:tf]
    flux = flux[ti:tf]

    #elijo la energia mas baja
    Ei = find_nearest(energia, 20)
    inicio = np.where(energia == Ei)[0][0]

    #empiezo un array al que le voy a meter las energias
    E = Ei
    i = inicio
    E = np.append(E, find_nearest(energia, E + 20))
    i = np.append(i, np.where(energia == E[1])[0][0])

    for j in range(len(energia)):
        if E[j + 1] > 100:
            break
        else:
            E = np.append(E, find_nearest(energia, E[j + 1] + 20))
            i = np.append(i, np.where(energia == E[j + 2])[0][0])

    E = np.append(E, find_nearest(energia, 220))
    E = np.append(E, find_nearest(energia, 300))
    i = np.append(i, np.where(energia == E[-2])[0][0])
    i = np.append(i, np.where(energia == E[-1])[0][0])

    flux_cut = np.zeros((len(flux), len(i)))

    for j in range(len(i)):
        flux_cut[:, j] = flux[:, int(i[j])]

    #borramos el punto donde el log(0) = inf
    for j in range(len(flux_cut[:, 0])):
        for i in range(len(flux_cut[0, :])):
            if np.log(flux_cut[j, i]) < 1:
                flux_cut[j, i] = None

    t1 = t_unix[np.where(tu == find_nearest(tu, 18.2193))[0][0]]
    t2 = t_unix[np.where(tu == find_nearest(tu, 18.2272))[0][0]]
    t3 = t_unix[np.where(tu == find_nearest(tu, 18.2331))[0][0]]
    t4 = t_unix[np.where(tu == find_nearest(tu, 18.2476))[0][0]]

    n = len(flux_cut)
    t_inicial = t_unix[ti]
    t_final = t_unix[tf]
    timestamps = np.linspace(t_inicial, t_final, n)
    dates = [dt.datetime.utcfromtimestamp(ts)
             for ts in timestamps]  #me lo da en UTC
    datenums = md.date2num(dates)

    # flux = cdf_file.varget('diff_en_fluxes')
    # energia = cdf_file.varget('energy')
    # t_unix = cdf_file.varget('time_unix')
    #
    # tu = unix_to_decimal(t_unix)
    # ti = np.where(tu == find_nearest(tu, t1))[0][0]
    # tf = np.where(tu == find_nearest(tu, t2))[0][0]
    # t = tu[ti:tf]
    # flux = flux[ti:tf]
    #
    #
    # #elijo la energia mas baja
    # Ei = find_nearest(energia, 20)
    # inicio = np.where(energia == Ei)[0][0]
    #
    # #empiezo un array al que le voy a meter las energias
    # E = Ei
    # i = inicio
    # E = np.append(E, find_nearest(energia, E+20))
    # i = np.append(i, np.where(energia == E[1])[0][0])
    #
    # for j in range(len(energia)):
    #     if E[j+1] > 100:
    #         break
    #     else:
    #         E = np.append(E, find_nearest(energia, E[j+1]+20))
    #         i = np.append(i, np.where(energia == E[j+2])[0][0])
    #
    # E = np.append(E, find_nearest(energia, 220))
    # E = np.append(E,find_nearest(energia, 300))
    # i = np.append(i, np.where(energia == E[-2])[0][0])
    # i = np.append(i, np.where(energia == E[-1])[0][0])
    #
    # flux_cut = np.zeros((len(flux), len(i)))
    #
    # for j in range(len(i)):
    #     flux_cut[:, j] = flux[:, int(i[j])]
    #
    # #borramos el punto donde el log(0) = inf
    # for j in range(len(flux_cut[:,0])):
    #     for i in range(len(flux_cut[0,:])):
    #         if np.log(flux_cut[j,i]) < 1:
    #             flux_cut[j, i] = None

    return (t, flux_cut, E)
Пример #8
0
    tf = t4 + 0.15

    t_plot, B_para, B_perp_norm = Bpara_Bperp(B, t, ti, tf)

    ###############################################################################################SWEA
    file_size_swea = os.path.getsize(
        path + f'SWEA/mvn_swe_l2_svyspec_{year}{month}{day}_v04_r01.cdf')
    if file_size_swea > 10000000:
        swea = cdf.CDF(
            path + f'SWEA/mvn_swe_l2_svyspec_{year}{month}{day}_v04_r01.cdf')

        flux_all = swea.varget('diff_en_fluxes')
        energia = swea.varget('energy')
        t_unix = swea.varget('time_unix')

        tu = unix_to_decimal(t_unix)
        ti_swea = np.where(tu == find_nearest(tu, ti))[0][0]
        tf_swea = np.where(tu == find_nearest(tu, tf))[0][0]
        t_swea = tu[ti_swea:tf_swea]
        flux = flux_all[ti_swea:tf_swea]
        flux_plot = np.transpose(flux)[::-1]

    else:
        print('no hay datos de SWEA')

    ###############################################################################################SWIA
    file_size_swia = os.path.getsize(
        path + f'SWIA/mvn_swi_l2_onboardsvymom_{year}{month}{day}_v01_r01.cdf')
    if file_size_swia > 2300000:
        swia = cdf.CDF(
            path +
Пример #9
0
from funciones import find_nearest, unix_to_decimal, unix_to_timestamp
from funciones_plot import plot_select
from matplotlib.colors import LogNorm
import datetime as dt
import matplotlib.dates as md
plt.ion()
# np.set_printoptions(precision=4)

path = '../../datos/SWEA/'  #path a los datos
cdf_file = cdf.CDF(path + 'mvn_swe_l2_svyspec_20160316_v04_r01.cdf')

flux_all = cdf_file.varget('diff_en_fluxes')
energia = cdf_file.varget('energy')
t_unix = cdf_file.varget('time_unix')

tu = unix_to_decimal(t_unix)
ti = np.where(tu == find_nearest(tu, 17.85))[0][0]
tf = np.where(tu == find_nearest(tu, 18.5))[0][0]
t = tu[ti:tf]
flux = flux_all[ti:tf]

datenums = unix_to_timestamp(t_unix[ti:tf])

log_flux = np.flip(np.log(flux), axis=1)
log_flux[log_flux < -1000] = None  # np.min(log_flux[log_flux>-1000])

flux_plot = np.transpose(flux)[::-1]

plt.figure()
plt.subplots_adjust(bottom=0.2)
plt.xticks(rotation=25)