예제 #1
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
예제 #2
0
def importar_swea(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    swea = np.loadtxt(path + "SWEA.asc")

    t_swea = np.unique(swea[:, 3] + swea[:, 4] / 60 +
                       swea[:, 5] / 3600)  # hdec

    energias = [50 + i * 50 for i in range(3)]

    energy = swea[:, 7]
    JE_total = swea[:, -1]

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

    t_cut = t_swea[inicio:fin]

    idx = []
    JE = []
    JE_cut = []
    for energia in energias:
        idx.append(donde(energy, energia))
    for i in range(len(idx)):
        JE.append(JE_total[idx[i]])
        JE_cut.append(JE[i][inicio:fin])

    return (swea, t_cut, energias, JE_cut)
예제 #3
0
def importar_swea(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    swea = np.loadtxt(path + "SWEA.asc")
    """
    Los datos de SWEA se ven de la siguiente manera: para cada tiempo hay muchos
    valores de JE y de energía. Por eso sólo recorto el tiempo y dejo el JE entero
    y en tal caso en el script principal lo recorto.
    """

    t_swea, idx = np.unique(swea[:, 3] + swea[:, 4] / 60 + swea[:, 5] / 3600,
                            return_index=True)  # hdec
    # al tomar "unique" estoy borrando los t que se repiten para las diferentes energias

    energias = [50 + i * 50 for i in range(3)]

    inicio = donde(t_swea, ti)
    fin = donde(t_swea, tf)  # este corte no sirve para JE ni para energy!!

    t_cut = t_swea[inicio:fin]

    return swea, t_cut, energias
예제 #4
0
파일: Ecv.py 프로젝트: gabybosc/MPB
def importar_mag(year, month, day, ti, tf):
    path = (
        f"../../datos/clweb/{year}-{month}-{day}/"  # path a los datos desde la laptop
    )
    if os.path.isfile(path + "mag_filtrado.txt"):
        mag = np.loadtxt(path + "mag_filtrado.txt", skiprows=2)
        B = mag[:, :3]
        mag = np.loadtxt(path + "MAG.asc")

    else:
        mag = np.loadtxt(path + "MAG.asc")
        B = mag[:, 6:9]

    hh = mag[:, 3]
    mm = mag[:, 4]
    ss = mag[:, 5]

    t = hh + mm / 60 + ss / 3600  # hdec

    posicion = np.zeros((len(t), 3))
    for i in range(9, 12):
        posicion[:, i - 9] = mag[:, i]

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

    t_cut = t[inicio:fin]
    B_cut = B[inicio:fin]
    posicion_cut = posicion[inicio:fin]
    return mag, t_cut, B_cut, posicion_cut
예제 #5
0
def importar_mag(year, month, day, ti, tf):

    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    if os.path.isfile(path + "mag_filtrado.txt"):
        mag = np.loadtxt(path + "mag_filtrado.txt", skiprows=2)
        B = mag[:, :3]
        mag = np.loadtxt(path + "MAG.asc")

    else:
        mag = np.loadtxt(path + "MAG.asc")
        B = mag[:, 6:9]

    hh = mag[:, 3]
    mm = mag[:, 4]
    ss = mag[:, 5]

    t = hh + mm / 60 + ss / 3600  # hdec
    inicio = donde(t, ti)
    fin = donde(t, tf)

    t_cut = t[inicio:fin]
    posicion_cut = mag[inicio:fin, 9:12]
    B_cut = B[inicio:fin]

    if len(B_cut) != len(t_cut):
        print("no tenemos la misma cantidad de datos t que de B")
    return mag, t_cut, B_cut, posicion_cut
예제 #6
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
예제 #7
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
예제 #8
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
예제 #9
0
def importar_swia(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    swia = np.loadtxt(path + "SWIA.asc")

    t = swia[:, 3] + swia[:, 4] / 60 + swia[:, 5] / 3600  # hdec

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

    t_cut = t[inicio:fin]
    density_cut = swia[inicio:fin, -1]

    return swia, t_cut, density_cut
예제 #10
0
def importar_static(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    static = np.loadtxt(path + "STATIC.asc")

    t = static[:, 3] + static[:, 4] / 60 + static[:, 5] / 3600

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

    t_cut = t[inicio:fin]
    mass = static[inicio:fin, 7]
    counts = static[inicio:fin, -1]

    return static, t_cut, mass, counts
예제 #11
0
def importar_lpw(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    lpw = np.loadtxt(path + "LPW.asc")

    t = lpw[:, 3] + lpw[:, 4] / 60 + lpw[:, 5] / 3600

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

    t_cut = t[inicio:fin]
    e_density_cut = lpw[inicio:fin, 6]
    flag = lpw[inicio:fin, -1]

    return lpw, t_cut, e_density_cut, flag
예제 #12
0
def importar_STATIC(year, month, day, ti, tf):

    STATIC = pd.read_csv("../../../datos/STATIC/STATIC_Ni_2016-03-16.txt")

    t_hdec = []
    for t_UTC in STATIC["Time [UTC]"]:
        (dia, hora) = t_UTC.split("/")
        (h, m, s) = hora.split(":")
        t_hdec.append(int(h) + int(m) / 60 + int(s) / 3600)

    t = np.array(t_hdec)
    inicio = donde(t, ti)
    fin = donde(t, tf)

    t_cut = t[inicio:fin]
    H_density = STATIC["Density H+ [/cc]"][inicio:fin]
    O_density = STATIC["Density O+ [/cc]"][inicio:fin]
    O2_density = STATIC["Density O2+ [/cc]"][inicio:fin]
    CO2_density = STATIC["Density CO2+ [/cc]"][inicio:fin]

    return STATIC, t_cut, H_density, O_density, O2_density, CO2_density
예제 #13
0
def importar_swifa(year, month, day, ti, tf):

    path = f"../../../datos/Ecinetica/{year}-{month}-{day}/"

    swifa = np.loadtxt(path + "SWIFA.asc")

    t = swifa[:, 3] + swifa[:, 4] / 60 + swifa[:, 5] / 3600  # hdec

    density = swifa[:, 6]

    vel_norm = swifa[:, -1]
    vel_mso_xyz = swifa[:, 7:10]

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

    t_cut = t[inicio:fin]
    vel_cut = vel_mso_xyz[inicio:fin]
    vel_norm_cut = vel_norm[inicio:fin]
    d_cut = density[inicio:fin]

    return swifa, t_cut, d_cut, vel_cut, vel_norm_cut
예제 #14
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
예제 #15
0
def importar_mag(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")
    doy = date_orbit.strftime("%j")

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

    mag = np.loadtxt(
        path + f"mvn_mag_l2_{year}{doy}ss_{year}{month}{day}_v01_r01.sts",
        skiprows=160)

    hh = mag[:, 2]
    mm = mag[:, 3]
    ss = mag[:, 4]

    t = hh + mm / 60 + ss / 3600  # hdec

    B = mag[:, 7:10]

    posicion = mag[:, 11:14]

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

    t_cut = t[inicio:fin]
    B_cut = B[inicio:fin]
    posicion_cut = posicion[inicio:fin]
    mag_cut = mag[inicio:fin]

    return mag_cut, t_cut, B_cut, posicion_cut
예제 #16
0
def importar_swia(year, month, day, ti, tf):
    if gethostname() == "magneto2":
        path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"
    else:
        path = f"../../../datos/clweb/{year}-{month}-{day}/"

    if os.path.isfile(path +
                      "SWICA.asc"):  # si no existe uno llamado SWICA, usa SWIA
        swia = np.loadtxt(path + "SWICA.asc")
    else:
        swia = np.loadtxt(path + "SWIA.asc")

    t = swia[:, 3] + swia[:, 4] / 60 + swia[:, 5] / 3600  # hdec

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

    t_cut = t[inicio:fin]
    density_cut = swia[inicio:fin, 6]
    vel_cut = swia[inicio:fin, 7:10]
    vel_norm = swia[inicio:fin, -1]

    return swia, t_cut, density_cut, vel_cut, vel_norm
예제 #17
0
escalas[0] = 1 / 3600  # la escala más chica es de 1s
for i in range(len(escalas) - 1):
    escalas[i + 1] = escalas[i] + 1 / 3600

# print(f'escala mayor = {escalas[-1]*3600}s')

M = len(t)  # el numero de datos


program_starts = time.time()
cociente = np.zeros((len(tiempo_central), len(escalas)))
normales = np.zeros((len(tiempo_central), len(escalas), 3))

for i in range(len(tiempo_central)):
    for j in range(len(escalas)):
        inicio = donde(t, tiempo_central[i] - escalas[j])
        fin = donde(t, tiempo_central[i] + escalas[j])

        # ahora empieza el MVA con los datos que elegí
        B_cut = B[inicio : fin + 1, :]

        M_ij = Mij(B_cut)

        # ahora quiero los autovectores y autovalores
        [lamb, x] = np.linalg.eigh(M_ij)  # uso eigh porque es simetrica

        # Los ordeno de mayor a menor
        idx = lamb.argsort()[::-1]
        lamb = lamb[idx]
        x = x[:, idx]
        # ojo que me da las columnas en vez de las filas como autovectores: el av x1 = x[:,0]
예제 #18
0
# si ahora proyecto sobre la normal del bootstrap
v_para_boot = np.dot(np.array([-2.487, 0.479, 2.836]),
                     normal_boot) * normal_boot
x_14_boot = v_para_boot * deltat_14  # en km
x_23_boot = v_para_boot * deltat_23

# plot_velocidades(X1, Y1, Z1, R, normal_fit, x3, v_media, v_para, v_para_MVA)

###########
# giroradio

#########
# análisis de corrientes

inicio_up = donde(t, t1 - 0.015)  # las 18:12:00
fin_up = donde(t, t1)  # las 18:13:00
B_upstream = np.mean(B[inicio_up:fin_up, :], axis=0)  # nT

inicio_down = donde(t, t4)  # las 18:14:51
fin_down = donde(t, t4 + 0.015)  # las 18:15:52
B_downstream = np.mean(B[inicio_down:fin_down, :], axis=0)  # nT

omega = np.arccos(
    np.dot(B_upstream, B_downstream) /
    (np.linalg.norm(B_upstream) * np.linalg.norm(B_downstream)))

mu = 4 * np.pi * 1e-7  # Henry/m

J_s_MVA, J_v_MVA = corrientes(x3, B_upstream, B_downstream,
                              np.linalg.norm(x_23_MVA))
예제 #19
0
#     minimo = int(i * 1620)
#     maximo = int(minimo + 600)
#     plt.plot(x[minimo:maximo], B[minimo:maximo, 0], label=i)
# for i in range(6):
#     m = int(10200 + 1620 * i)
#     M = int(m + 600)
#     plt.plot(x[m:M], B[m:M, 0], label=i)
#
# plt.show()

"""
Comparación de B y de la densidad de protones
"""

t1t2t3t4 = [18.2167, 18.2204, 18.235, 18.2476]
i1 = donde(t, t1t2t3t4[0])
i2 = donde(t, t1t2t3t4[1])
i3 = donde(t, t1t2t3t4[2])
i4 = donde(t, t1t2t3t4[3])

idx = diezmar(t, t_swia)

plt.figure()
plt.plot(posicion[:, 0] / 3390, np.linalg.norm(B_mag, axis=1), label="MAVEN")
plt.axvline(posicion[i1, 0] / 3390, color="C2", linestyle="--", label="t1")
plt.axvline(posicion[i2, 0] / 3390, color="C3", linestyle="--", label="t2")
plt.axvline(posicion[i3, 0] / 3390, color="C4", linestyle="--", label="t3")
plt.axvline(posicion[i4, 0] / 3390, color="C5", linestyle="--", label="t4")
plt.xlabel("x (RM)")
plt.ylabel("|B| (nT)")
plt.legend()
예제 #20
0
import numpy as np
import matplotlib.pyplot as plt
from importar_datos import importar_mag
from funciones import fechas, tiempos, donde, hdec_to_UTC

year, month, day, doy = fechas()
ti, tf = tiempos()

mag, t, B, posicion = importar_mag(year, month, day, ti, tf)

periapsis = donde(np.linalg.norm(posicion, axis=1),
                  min(np.linalg.norm(posicion, axis=1)))
t_peri = t[periapsis]

print(
    f"el periapsis se alcanza a las {t_peri} (hdec) = {hdec_to_UTC(t_peri)} UTC"
)

plt.plot(t, posicion)

plt.figure()
plt.plot(t, np.linalg.norm(posicion, axis=1))
plt.plot(t, posicion[:, -1])
plt.show()

# year, month, day, hour, minute, second, millisecond, x,y,z
M = len(mag)
date = [np.ones(M) * int(year), np.ones(M) * int(month), np.ones(M) * int(day)]
date = np.transpose(np.array(date))
horario = mag[:, 2:6]
RM = posicion / 3390
예제 #21
0
rho = reordenados[:, 3]
v_plasma = reordenados[:, 4:7]
B = reordenados[:, 7:10]
Ptot = reordenados[:, 10]
HpRho = reordenados[:, 11]
v_i = reordenados[:, 12:15]
HP = reordenados[:, 15]
O2pRho = reordenados[:, 16]
O2P = reordenados[:, 20]
OpRho = reordenados[:, 21]
OP = reordenados[:, 25]
CO2pRho = reordenados[:, 26]
CO2P = reordenados[:, 30]
J = reordenados[:, -3:] * 1000  # J en volumen

inicio_MPB = donde(pos[:, 0], 1.2)
fin_MPB = donde(pos[:, 0], 1.36)
inicio_BS = donde(pos[:, 0], 1.67)
fin_BS = donde(pos[:, 0], 1.72)

B_MPB = B[inicio_MPB:fin_MPB, :]
J_MPB = J[inicio_MPB:fin_MPB, :]  # nA/m²
x_MPB = x[inicio_MPB:fin_MPB]
# MVA:

M_ij = Mij(B_MPB)
[lamb, av] = np.linalg.eigh(M_ij)  # uso eigh porque es simetrica
idx = lamb.argsort()[::-1]
lamb = lamb[idx]
av = av[:, idx]
x1 = av[:, 0]
예제 #22
0
t1 = float(hoja_parametros.cell(fila, 6).value)
t2 = float(hoja_parametros.cell(fila, 7).value)
t3 = float(hoja_parametros.cell(fila, 8).value)
t4 = float(hoja_parametros.cell(fila, 9).value)

mag, t_mag_entero, B_entero, posicion = importar_mag_1s(
    year, month, day, ti, tf)
swia, t_swia_entero, density, temperature, vel_mso_xyz = importar_swia(
    year, month, day, ti, tf)
"""
giroradio: rg = mp * v_perp / (q_e * B)  en la región upstream
where vperp is the component of the velocity perpendicular to the
direction of the magnetic field and B is the strength of the magnetic field
"""
# selecciono la región upstream:
inicio_mag = donde(t_mag_entero, t1 - 0.1)
fin_mag = donde(t_mag_entero, t1 - 0.05)
inicio_swia = donde(t_swia_entero, t1 - 0.1)
fin_swia = donde(t_swia_entero, t1 - 0.05)

t_mag = t_mag_entero[inicio_mag:fin_mag]
B = B_entero[inicio_mag:fin_mag] * 1e-9  # T

t_swia = t_swia_entero[inicio_swia:fin_swia]
velocidad = vel_mso_xyz[inicio_swia:fin_swia]

# para poder proyectar v_para voy a tener que diezmar B
paso = int(len(B) / len(velocidad))
B_diezmado = B[::paso]

# ahora que están recortadas las convierto en lo que busco: la intensidad de B y la v perp
예제 #23
0
파일: E_field.py 프로젝트: gabybosc/MPB
rho = reordenados[:, 3]
v_e = reordenados[:, 4:7]
B = reordenados[:, 7:10]
Ptot = reordenados[:, 10]
HpRho = reordenados[:, 11]
v_i = reordenados[:, 12:15]
HP = reordenados[:, 15]  # P_e = HP en esta simu
O2pRho = reordenados[:, 16]
O2P = reordenados[:, 20]
OpRho = reordenados[:, 21]
OP = reordenados[:, 25]
CO2pRho = reordenados[:, 26]
CO2P = reordenados[:, 30]
J = reordenados[:, -3:]

inicio_MPB = donde(pos[:, 0], 1.2)
fin_MPB = donde(pos[:, 0], 1.36)
inicio_BS = donde(pos[:, 0], 1.67)
fin_BS = donde(pos[:, 0], 1.72)

#
# xi = 1.2
# xf = 1.36
# inicio_up = donde(x, xi - 126)
# fin_up = donde(x, xi)
# B_upstream = np.mean(B[inicio_up:fin_up, :], axis=0)  # nT
#
# inicio_down = donde(x, xf)
# fin_down = donde(x, xf + 146)
# B_downstream = np.mean(B[inicio_down:fin_down, :], axis=0)  # nT
예제 #24
0
"""
year, month, day, doy = 2016, "03", 16, 76
ti, tf = 17.85, 18.4

path = f"../../../datos/clweb/{year}-{month}-{day}/"
# path = f"../../../../../media/gabybosc/datos/clweb/{year}-{month}-{day}/"  # path a los datos desde la desktop.
datos_t = np.loadtxt("../outputs/t1t2t3t4.txt")

mag, t, B, posicion = importar_mag(year, month, day, ti, tf)
t1, t2, t3, t4 = 18.2167, 18.2204, 18.235, 18.2476

t_up = t1 - 0.015
t_down = t4 + 0.015

zoom_inicial = donde(t, t1 - 0.05)
zoom_final = donde(t, t4 + 0.05)

Bnorm = np.linalg.norm(B, axis=1)

mag_low = np.loadtxt(path + "mag_1s.sts", skiprows=160)
tlow = mag_low[:, 6]  # el dia decimal
tlow = (tlow - int(doy)) * 24  # para que me de sobre la cantidad de horas

Mlow = np.size(tlow)  # el numero de datos
# el campo
Blow = np.zeros((Mlow, 3))
for i in range(7, 10):
    Blow[:, i - 7] = mag_low[:, i]

B_para, B_perp_norm, t_plot = Bpara_Bperp(Blow, tlow, t[0], t[-1])
예제 #25
0
Es como la figura pricipal en mi tesis.

"""

# DATOS DE PDS

year, month, day, doy = fechas()
ti, tf = tiempos()

mag, t, B, posicion = importar_mag(year, month, day, ti, tf)
swea = importar_swea(year, month, day, ti, tf)
swia, t_swia, i_density, i_temp, vel_mso = importar_swia(
    year, month, day, ti, tf)
lpw, t_lpw, e_density = importar_lpw(year, month, day, ti, tf)

t1 = donde(t, ti)
t2 = donde(t, tf)

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

# ######### SWEA
# flux_all = swea.varget("diff_en_fluxes")
# energia = swea.varget("energy")
#
# t_unix_e = swea.varget("time_unix")
#
# t_swea = unix_to_decimal(t_unix_e)
# inicio_e = np.where(t_swea == find_nearest(t_swea, 17.85))[0][0]
# fin_e = np.where(t_swea == find_nearest(t_swea, 18.4))[0][0]
#
# ne = len(flux_cut)
예제 #26
0
파일: Ecv.py 프로젝트: gabybosc/MPB

swia, t_swia, density, vel_mso = importar_swia_vel(
    year, month, day, ti_ms, tf_down
)
mag, t_mag, B, posicion = importar_mag(year, month, day, ti_ms, tf_down)


# quiero diezmar el tiempo y el campo para que sean los mismos que tiene swia
idx = diezmar(t_mag, t_swia)

tmag_diezmado = t_mag[idx]
B_cut = B[idx]
posicion_cut = posicion[idx]

inicio_up = donde(t_swia, ti_down)  # tiene que dar lo mismo si uso tswia o tmag
fin_up = donde(t_swia, tf_down)

ti_funda = donde(tmag_diezmado, ti_ms)
tf_funda = donde(tmag_diezmado, tf_ms)
####################


B_avg = np.empty((len(idx), 3))
v_maven = np.empty((len(idx), 3))
v_planet = np.empty((len(idx), 3))


for i in range(len(idx)):
    B_avg[i, :] = np.mean(B_cut[i : i + 30, :], axis=0)
    v_maven[i, :] = (
예제 #27
0
파일: eje_x.py 프로젝트: gabybosc/MPB
ax1 = plt.subplot2grid((2, 1), (0, 0))
plt.plot(x, B_norm, ".")
plt.setp(ax1.get_xticklabels(), visible=False)
ax1.set_ylabel("|B|")
ax1.grid()

ax2 = plt.subplot2grid((2, 1), (1, 0), sharex=ax1)
ax2.plot(x, np.linalg.norm(dBdx, axis=1), ".")
ax2.set_ylabel("dB/dx")
ax2.set_xlabel("x (RM)")
ax2.grid()

multi = MultiCursor(fig.canvas, (ax1, ax2), color="black", lw=1)
plt.show()

x_cut = x[donde(x, 1.20464) : donde(x, 1.26368)]
B_cut = B_norm[donde(x, 1.20464) : donde(x, 1.26368)]

coef = np.polynomial.polynomial.polyfit(x_cut, B_cut, deg=1)

MPR = np.mean(B_norm[donde(x, 1.17) : donde(x, 1.20)])
MS = np.mean(B_norm[donde(x, 1.26) : donde(x, 1.4)])

plt.figure()
plt.title("Campo magnético y ajuste")
plt.plot(x, B_norm, ".")
plt.plot(x, coef[0] + x * coef[1])
plt.axhline(y=MPR, c="k")
plt.axhline(y=MS, c="k")
plt.ylabel("|B|")
plt.xlabel("x (RM)")
예제 #28
0
# inicio_mpr = donde(t_swica, ti_MPR)
# fin_mpr = donde(t_swica, ti_MPR + 0.02)
# v_parallel_mpr = np.dot(vel_swica[inicio_mpr : fin_mpr + 1], normal)
#
# v_mean_mpr = np.mean(v_parallel_mpr)  # km/s
# density_mpr_mean = np.mean(density_swica[inicio_mpr : fin_mpr + 1])  # 1/cm3
# print(
#     f"La velocidad media en la región downstream (ojo que acá SWIA no funciona bien) en dirección de la normal es {v_mean_mpr:.3g} km/s"
# )
#
# p_ram_mpr = mp * (v_mean_mpr * 1e3) ** 2 * (density_mpr_mean * 1e6)  # J/m3
#
# print(
#     f"La ram pressure en la región downstream a partir de los parámetros promedio es {p_ram_mpr*1e9:.3g} nPa"
# )
inicio_mpr_mag = donde(t_mag, ti_MPR)
fin_mpr_mag = donde(t_mag, tf_MPR)
B_mean_mpr = np.mean(B_norm[inicio_mpr_mag:fin_mpr_mag + 1])
error_B = np.std(B_norm[inicio_mpr_mag:fin_mpr_mag])
B_MPR = ufloat(B_mean_mpr, error_B)

p_mag_mpr = B_MPR**2 / (2 * mu_0)  # J/m3

#
# print(
#     f"El B medio en la región downstream a partir de los parámetros promedio es {B_mean_mpr:.3g} T"
# )

print(
    f"La presión magnética en la región downstream a partir de los parámetros promedio es {p_mag_mpr*1e9:.3g} nPa"
)
예제 #29
0
파일: MVA_hires.py 프로젝트: gabybosc/MPB
def MVA(year, month, day, doy, ti_MVA, tf_MVA, t, B, posicion):

    fila, hoja_parametros, hoja_MVA, hoja_Bootstrap, hoja_fit = importar_fila(
        year, month, day, doy, ti_MVA
    )
    t1 = float(hoja_parametros.cell(fila, 6).value)
    t2 = float(hoja_parametros.cell(fila, 7).value)
    t3 = float(hoja_parametros.cell(fila, 8).value)
    t4 = float(hoja_parametros.cell(fila, 9).value)

    inicio = donde(t, ti_MVA)
    fin = donde(t, tf_MVA)

    B_cut = B[inicio:fin, :]

    # ahora empieza el MVA con los datos que elegí
    posicion_cut = posicion[inicio : fin + 1, :]
    altitud = np.mean(np.linalg.norm(posicion_cut, axis=1) - 3390)

    M_ij = Mij(B_cut)

    # ahora quiero los autovectores y autovalores
    [lamb, x] = np.linalg.eigh(M_ij)  # uso eigh porque es simetrica

    # Los ordeno de mayor a menor
    idx = lamb.argsort()[::-1]
    lamb = lamb[idx]
    x = x[:, idx]
    # ojo que me da las columnas en vez de las filas como autovectores: el av x1 = x[:,0]
    x1 = x[:, 0]
    x2 = x[:, 1]
    x3 = x[:, 2]

    av = np.concatenate([x1, x2, x3])

    if x3[0] < 0:  # si la normal aputna para adentro me la da vuelta
        x3 = -x3
    if any(np.cross(x1, x2) - x3) > 0.01:
        print("Cambio el signo de x1 para que los av formen terna derecha")
        x1 = -x1

    # las proyecciones
    B1 = np.dot(B_cut, x1)
    B2 = np.dot(B_cut, x2)
    B3 = np.dot(B_cut, x3)

    # el B medio
    B_medio_vectorial = np.mean(B_cut, axis=0)
    SZAngle = SZA(posicion_cut, 0)
    if any(posicion_cut[:, 2]) < 0:
        SZAngle = -SZAngle

    B_norm_medio = np.linalg.norm(B_medio_vectorial)

    hodograma(B1, B2, B3)
    # el error
    phi, delta_B3 = error(lamb, B_cut, x)

    ###############
    # ###fit
    orbita = posicion[donde(t, t1 - 1) : donde(t, t4 + 1)] / 3390  # radios marcianos

    index = donde(t, (t2 + t3) / 2)
    x0 = 0.78
    e = 0.9
    L0 = 0.96
    normal_fit, X1, Y1, Z1, R, L0 = ajuste_conico(
        posicion, index, orbita, x3, x0, e, L0
    )

    B3_fit = np.dot(B_cut, normal_fit)

    ###############
    # #Bootstrap

    N_boot = 1000
    normal_boot, phi_boot, delta_B3_boot, out, out_phi = bootstrap(N_boot, B_cut)

    muB, sigmaB, mu31, sigma31, mu32, sigma32 = plot_bootstrap(out, out_phi)

    B3_boot = np.dot(B_cut, normal_boot)

    #######
    # Errores
    if phi[2, 1] > phi[2, 0]:
        error_normal = phi[2, 1] * 57.2958
    else:
        error_normal = phi[2, 0] * 57.2958
        # quiero ver si el error más grande es phi31 o phi32

    if sigma31 > sigma32:
        error_boot = sigma31
    else:
        error_boot = sigma32

    print("Fin del MVA")
    #############
    # ahora guardo todo en una spreadsheet
    # ######updateo la hoja de los parámetros
    # hoja_parametros.update_acell(f"D{fila}", f"{SZAngle:.3g}")
    # hoja_parametros.update_acell(f"E{fila}", f"{int(altitud)}")
    # hoja_parametros.update_acell(f"O{fila}", f"{round(B_norm_medio,2)}")
    #
    # cell_B = hoja_parametros.range(f"L{fila}:N{fila}")
    # for i, cell in enumerate(cell_B):
    #     cell.value = round(B_medio_vectorial[i], 2)
    # hoja_parametros.update_cells(cell_B)
    #
    # # if (
    # #     type(B_filtrado) != int
    # # ):  # si no es un int, en particular 0, agrega los datos a la lista
    # #     hoja_parametros.update_acell(f"J{fila}", f"{orden_filtro}")
    # #     hoja_parametros.update_acell(f"K{fila}", f"{frec_filtro}")
    # # else:
    # #     hoja_parametros.update_acell(f"J{fila}", "Sin filtrar")
    #
    # # #######update la hoja de MVA
    # hoja_MVA.update_acell(f"D{fila}", f"{ti_MVA}")
    # hoja_MVA.update_acell(f"E{fila}", f"{tf_MVA}")
    # hoja_MVA.update_acell(f"I{fila}", f"{lamb[1]/lamb[2]:.3g}")
    #
    # hoja_MVA.update_acell(f"S{fila}", f"{error_normal:.3g}")
    # hoja_MVA.update_acell(f"T{fila}", f"{round(np.mean(B3),2)}")
    # hoja_MVA.update_acell(f"U{fila}", f"{round(delta_B3,2)}")
    # hoja_MVA.update_acell(f"V{fila}", f"{abs(round(np.mean(B3)/B_norm_medio,2))}")
    #
    # cell_lambda = hoja_MVA.range(f"F{fila}:H{fila}")
    # for i, cell in enumerate(cell_lambda):
    #     cell.value = round(lamb[i], 2)
    # hoja_MVA.update_cells(cell_lambda)
    #
    # cell_av = hoja_MVA.range(f"J{fila}:R{fila}")
    # for i, cell in enumerate(cell_av):
    #     cell.value = round(av[i], 3)
    # hoja_MVA.update_cells(cell_av)
    #
    # # #######update la hoja de bootstrap
    # hoja_Bootstrap.update_acell(f"D{fila}", f"{len(B)}")
    # hoja_Bootstrap.update_acell(f"E{fila}", f"{N_boot}")
    #
    # cell_normal = hoja_Bootstrap.range(f"F{fila}:H{fila}")
    # for i, cell in enumerate(cell_normal):
    #     cell.value = round(normal_boot[i], 3)
    # hoja_Bootstrap.update_cells(cell_normal)
    #
    # hoja_Bootstrap.update_acell(f"I{fila}", f"{error_boot:.3g}")
    # hoja_Bootstrap.update_acell(f"J{fila}", f"{round(np.mean(B3_boot),2)}")
    # hoja_Bootstrap.update_acell(f"K{fila}", f"{round(sigmaB,2)}")
    # hoja_Bootstrap.update_acell(
    #     f"L{fila}", f"{abs(round(np.mean(B3_boot)/B_norm_medio,2))}"
    # )
    #
    # # #######update la hoja del ajuste
    # hoja_fit.update_acell(f"D{fila}", f"{L0}")
    # hoja_fit.update_acell(f"E{fila}", f"{e}")
    # hoja_fit.update_acell(f"F{fila}", f"{x0}")
    #
    # cell_normal = hoja_fit.range(f"G{fila}:I{fila}")
    # for i, cell in enumerate(cell_normal):
    #     cell.value = round(normal_fit[i], 3)
    # hoja_fit.update_cells(cell_normal)
    #
    # hoja_fit.update_acell(f"K{fila}", f"{round(np.mean(B3_fit),2)}")
    # hoja_fit.update_acell(f"L{fila}", f"{abs(round(np.mean(B3_fit)/B_norm_medio,2))}")
    #
    # print("escribe la spreadsheet")
    return (
        x3,
        normal_boot,
        normal_fit,
        inicio,
        fin,
        B_cut,
        t1,
        t2,
        t3,
        t4,
        B_medio_vectorial,
        fila,
        hoja_parametros,
        hoja_MVA,
        hoja_Bootstrap,
        hoja_fit,
    )
예제 #30
0
파일: plot_mpb.py 프로젝트: gabybosc/MPB
Mlow = np.size(tlow)  # el numero de datos
# el campo
Blow = np.zeros((Mlow, 3))
for i in range(7, 10):
    Blow[:, i - 7] = mag_low[:, i]

B_para, B_perp_norm, t_plot = Bpara_Bperp(Blow, tlow, t[0], t[-1])

# ######### SWEA

swea, t_swea, energias = importar_swea(year, month, day, ti, tf)
energy = swea[:, 7]
JE_total = swea[:, -1]

inicio_swea = donde(t_swea, ti)  # debería ser 0
fin_swea = donde(t_swea, tf)

# ######################################################################## SWIA

swia, t_swia, density = importar_swia(year, month, day, ti, tf)

# t_swica, t_swifa, density_swica, density_swifa = importar_swicfa(
#     year, month, day, ti, tf
# )

# ########################## STATIC
static, t_static, mass, counts = importar_static(year, month, day, ti, tf)

# ############ tiempos UTC
year = int(year)