コード例 #1
0
ファイル: MVA_sin_spreadsheet.py プロジェクト: gabybosc/MPB
def ajuste(year, month, day, doy, ti_MVA, tf_MVA):

    datos_tiempo = np.loadtxt("../outputs/t1t2t3t4.txt")
    idx_d = np.where(int(doy) == datos_tiempo[:, 1].astype(int))[0]
    idx_h = np.where(int(ti_MVA) == datos_tiempo[:, 2].astype(int))[0]
    idx = np.intersect1d(idx_d, idx_h)[0]
    t1 = datos_tiempo[idx, 2]
    t2 = datos_tiempo[idx, 3]
    t3 = datos_tiempo[idx, 4]
    t4 = datos_tiempo[idx, 5]

    mag, t, B, posicion = importar_mag(year, month, day, ti_MVA, tf_MVA)

    t_nave = find_nearest(t, (t2 + t3) / 2)
    # el tiempo en el medio de la hoja de corriente
    index = np.where(t == t_nave)[0][0]
    # x0 = 0.78
    # e = 0.9
    normal_ajuste, L0 = normal_fit(posicion, index)

    B3_fit = np.dot(B, normal_ajuste)

    print(f"La normal del fit es {normal_ajuste}")
    # print(f"B3 del fit es {B3_fit}")
    print("Ajuste terminado")

    return normal_ajuste, t1, t2, t3, t4
コード例 #2
0
ファイル: MVA_hires.py プロジェクト: gabybosc/MPB
def ajuste(year, month, day, doy, ti_MVA, tf_MVA, nr):
    datos_tiempo = np.loadtxt("../outputs/t1t2t3t4.txt")
    idx_d = np.where(int(doy) == datos_tiempo[:, 1].astype(int))[0]
    idx_h = np.where(int(ti_MVA) == datos_tiempo[:, 2].astype(int))[0]
    idx = np.intersect1d(idx_d, idx_h)[0]
    t1 = datos_tiempo[idx, 2]
    t2 = datos_tiempo[idx, 3]
    t3 = datos_tiempo[idx, 4]
    t4 = datos_tiempo[idx, 5]
    tiempos = [t1, t2, t3, t4]

    mag, t, B, posicion = importar_mag(year, month, day, ti_MVA, tf_MVA)

    t_nave = find_nearest(t, (t2 + t3) / 2)
    # el tiempo en el medio de la hoja de corriente
    index = np.where(t == t_nave)[0][0]
    x0 = 0.78
    e = 0.9
    normal_ajuste, L0 = normal_fit(posicion, index)

    B3_fit = np.dot(B, normal_ajuste)
    print("Fin del ajuste. ")

    (
        hoja_parametros,
        hoja_mva,
        hoja_boot,
        hoja_fit,
        fecha_sheet,
        hora_sheet,
    ) = acceso_spreadsheet()

    cell_times = hoja_parametros.range(f"F{nr}:I{nr}")
    for i, cell in enumerate(cell_times):
        cell.value = tiempos[i]
        hoja_parametros.update_cells(cell_times)

    hoja_fit.update_acell(f"D{nr}", f"{L0}")
    hoja_fit.update_acell(f"E{nr}", f"{e}")
    hoja_fit.update_acell(f"F{nr}", f"{x0}")

    cell_normal = hoja_fit.range(f"G{nr}:I{nr}")
    for i, cell in enumerate(cell_normal):
        cell.value = round(normal_ajuste[i], 3)
    hoja_fit.update_cells(cell_normal)

    hoja_fit.update_acell(f"K{nr}", f"{round(np.mean(B3_fit),2)}")
    print("Escribió la spreadsheet del ajuste.")

    return normal_ajuste, t1, t2, t3, t4
コード例 #3
0
beta = P_plasma / P_B

density_mean = [np.mean(HpRho[i : i + 50]) for i in range(len(HpRho) - 50)]
ion_length = 2.28e07 / np.sqrt(density_mean) * 1e-5  # km
ion_length = np.append(ion_length, ion_length[-51:-1])
plt.plot(x, kT_H)
plt.plot(x, Pe / rho)
# plt.plot(x, kT_O)
# plt.plot(x, kT_O2)
# plt.plot(x, kT_CO2)
plt.show()


# Datos de MAVEN
mag, t, B_mag, posicion = importar_mag(2016, "03", 16, 17.7, 19)
swia, t_swia, proton_density = importar_swia(2016, "03", 16, 17.7, 19)

# Datos del análisis de MAVEN
R = [1.082, -0.064, 0.515]
normal = [0.920, -0.302, 0.251]
j_maven = 23.2  # mA/m

# hay 10 órbitas, cada una de 1620 puntos
"""Plotea nuestra MPB y la órbita de la simu que estamos usando"""
L = 0.96
x0 = 0.78
e = 0.9
theta = np.linspace(0, np.pi * 3 / 4, 100)
phi = np.linspace(0, 2 * np.pi, 100)
THETA, PHI = np.meshgrid(theta, phi)
コード例 #4
0
ファイル: Analisis_outbound.py プロジェクト: gabybosc/MPB
Hace el MVA
calcula el ángulo entre normales
calcula el ancho de la mpb
calcula la corriente
No estoy segura de si debería cambiar algo más que simplemente el orden como tomo t1 t2 t3 t4
"""

year, month, day, doy = fechas()
ti, tf = tiempos("Región de análisis (no MVA)")
ti_MVA, tf_MVA = tiempos("Intervalo del MVA")

print(
    "Si tira error de que no encuentra el path, hay que abrir una vez el disco manualmente para que lo monte"
)

mag, t, B, posicion = importar_mag(year, month, day, ti, tf)
lpw, t_lpw, e_density = importar_lpw(year, month, day, ti, tf)
x3, B_cut, t_cut, posicion_cut, nr = MVA(year, month, day, ti_MVA, tf_MVA)
normal_ajuste, t4, t3, t2, t1 = ajuste(year, month, day, doy, ti_MVA, tf_MVA,
                                       nr)

M = len(t)
M_cut = len(t_cut)

normal_boot = bootstrap_completo(B_cut, M_cut, nr, 1000)

######
# constantes
q_e = 1.6e-19  # carga electron #C

#########
コード例 #5
0
ファイル: Analisis_post_MVA.py プロジェクト: gabybosc/MPB
)
from MVA_hires import MVA
from importar_datos import importar_lpw, importar_mag
"""
Hace el MVA
calcula el ángulo entre normales
calcula el ancho de la mpb
calcula la corriente

NO NECESITA YA ACTUALIZAR LA FECHA EN GDOCS
"""

year, month, day, doy = fechas()
ti_MVA, tf_MVA = tiempos()

mag, t, B, posicion = importar_mag(year, month, day, ti_MVA - 1, tf_MVA + 1)
lpw, t_lpw, e_density = importar_lpw(year, month, day, ti_MVA - 1, tf_MVA + 1)

(
    x3,
    normal_boot,
    normal_fit,
    inicio,
    fin,
    B_cut,
    t1,
    t2,
    t3,
    t4,
    B_medio_vectorial,
    fila,
コード例 #6
0
fila = input("En qué fila del gdoc estamos?\n")
tf_MPR = float(hoja_parametros.cell(fila, 6).value)
ti_MPR = tf_MPR - 0.015
normal = [
    float(hoja_MVA.cell(fila, 16).value),
    float(hoja_MVA.cell(fila, 17).value),
    float(hoja_MVA.cell(fila, 18).value),
]

swifa, t_sw, density_sw, vel_sw, vel_norm_sw = importar_swifa(
    year, month, day, ti_sw, tf_sw)
# swica, t_swica, density_swica, vel_swica, vel_norm_swica = importar_swica(
#     year, month, day, tf_sw, tf_MPR
# )

mag, t_mag, B_mag, posicion = importar_mag(year, month, day, ti_MPR, tf_sw)
B_norm = np.linalg.norm(B_mag, axis=1) * 1e-9  # Tesla
""" Solar wind """
v_parallel_sw = np.dot(vel_sw, normal)

v_mean_sw = np.mean(v_parallel_sw)  # km/s
density_sw_mean = np.mean(density_sw)  # 1/cm3
error_v_sw = np.std(v_parallel_sw)
error_density_sw = np.std(density_sw)
# print(
#     f"La velocidad media en el viento solar en dirección de la normal es {v_mean_sw:.3g} km/s"
# )

v_sw = ufloat(v_mean_sw, error_v_sw)
n_sw = ufloat(density_sw_mean, error_density_sw)
p_ram = mp * (v_sw * 1e3)**2 * (n_sw * 1e6)  # J/m3
コード例 #7
0
ファイル: MVA_sin_spreadsheet.py プロジェクト: gabybosc/MPB
def MVA(year, month, day, ti_MVA, tf_MVA):
    date_entry = f"{year}-{month}-{day}"

    mag, t, B, posicion = importar_mag(year, month, day, ti_MVA, tf_MVA)
    # ya los importa cortados a los datos, entonces no hace falta que haga el cut yo

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

    # la matriz diaria:
    MD = np.zeros((M, 9))
    MD[:, 0] = t
    for i in range(1, 4):
        MD[:, i] = B[:, i - 1]
    MD[:, 4] = Bnorm
    for i in range(5, 8):
        MD[:, i] = posicion[:, i - 5] / 3390  # en radios marcianos
    MD[:, 8] = np.linalg.norm(posicion, axis=1) - 3390  # altitud en km

    n_p = int(M / 2)

    M_ij = Mij(B)

    # 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]

    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

    print("la normal del MVA es ", x3)

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

    # el B medio
    B_medio_vectorial = np.mean(B, axis=0)
    altitud = np.mean(MD[:, 8])

    SZA = angulo(posicion[n_p, :], [1, 0, 0]) * 180 / np.pi
    print(f"altitud = {altitud}, SZA = {SZA}")

    print("cociente de lambdas = ", lamb[1] / lamb[2])
    B_norm_medio = np.linalg.norm(B_medio_vectorial)

    print(f"El B medio es {B_norm_medio}")
    hodograma(B1, B2, B3)

    # el error
    phi, delta_B3 = error(lamb, B, x)
    print("MVA terminado")
    return x3, B, t, posicion
コード例 #8
0
ファイル: MVA_hires.py プロジェクト: gabybosc/MPB
def MVA(year, month, day, ti_MVA, tf_MVA):
    date_entry = f"{year}-{month}-{day}"

    mag, t, B, posicion = importar_mag(year, month, day, ti_MVA, tf_MVA)

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

    # la matriz diaria:
    MD = np.zeros((M, 9))
    MD[:, 0] = t
    for i in range(1, 4):
        MD[:, i] = B[:, i - 1]
    MD[:, 4] = Bnorm
    for i in range(5, 8):
        MD[:, i] = posicion[:, i - 5] / 3390  # en radios marcianos
    MD[:, 8] = np.linalg.norm(posicion, axis=1) - 3390  # altitud en km

    n_p = int(M / 2)

    M_ij = Mij(B)

    # 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]

    if x3[0] < 0:  # si la normal apunta 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

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

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

    # el B medio
    B_medio_vectorial = np.mean(B, axis=0)
    altitud = np.mean(MD[:, 8])
    SZA = angulo(posicion[n_p, :], [1, 0, 0]) * 180 / np.pi

    if posicion[n_p, 2] < 0:
        SZA = -SZA

    B_norm_medio = np.linalg.norm(B_medio_vectorial)

    hodograma(B1, B2, B3, date_entry)

    # el error
    phi, delta_B3 = error(lamb, B, M, x)
    if phi[2, 1] > phi[2, 0]:
        error_normal = phi[2, 1] * 180 / np.pi
    else:
        error_normal = phi[2, 0] * 180 / np.pi

    print("Fin del MVA.")

    # ######update la hoja de los parámetros
    (
        hoja_parametros,
        hoja_mva,
        hoja_boot,
        hoja_fit,
        fecha_sheet,
        hora_sheet,
    ) = acceso_spreadsheet()

    nr = que_linea(date_entry, fecha_sheet, hora_sheet, hoja_mva, int(ti_MVA))
    hojas = [hoja_parametros, hoja_mva, hoja_boot, hoja_fit]
    for hoja in hojas:  # pone la fecha en todas las hojas
        poner_fecha(hoja, nr, date_entry, int(ti_MVA))

    hoja_parametros.update_acell(f"D{nr}", f"{SZA:.3g}")
    hoja_parametros.update_acell(f"E{nr}", f"{int(altitud)}")
    hoja_parametros.update_acell(f"O{nr}", f"{round(B_norm_medio,2)}")

    cell_B = hoja_parametros.range(f"L{nr}:N{nr}")
    for i, cell in enumerate(cell_B):
        cell.value = round(B_medio_vectorial[i], 2)
    hoja_parametros.update_cells(cell_B)

    # #######update la hoja de MVA
    hoja_mva.update_acell(f"D{nr}", f"{ti_MVA}")
    hoja_mva.update_acell(f"E{nr}", f"{tf_MVA}")
    hoja_mva.update_acell(f"I{nr}", f"{lamb[1]/lamb[2]:.3g}")

    hoja_mva.update_acell(f"S{nr}", f"{error_normal:.3g}")
    hoja_mva.update_acell(f"T{nr}", f"{round(np.mean(B3),2)}")
    hoja_mva.update_acell(f"U{nr}", f"{round(delta_B3,2)}")
    hoja_mva.update_acell(f"V{nr}",
                          f"{abs(round(np.mean(B3)/B_norm_medio,2))}")

    cell_lambda = hoja_mva.range(f"F{nr}:H{nr}")
    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{nr}:R{nr}")
    for i, cell in enumerate(cell_av):
        cell.value = round(av[i], 3)
    hoja_mva.update_cells(cell_av)
    print("Escribió la spreadsheet del MVA.")
    return x3, B, t, posicion, nr
コード例 #9
0
import numpy as np
import matplotlib.pyplot as plt
from importar_datos import importar_mag
from funciones import donde

mu0 = 4 * np.pi * 1e-7

mag, t, B, posicion = importar_mag(2016, "03", 16, 0.1, 23.9)
Bcut = B[400000:]
Bnorm = np.linalg.norm(Bcut, axis=1)
pos = np.linalg.norm(posicion[400000:], axis=1)
# puntos = int(len(Bnorm) / 7)

plt.plot(Bnorm[:512000])
plt.show()

puntos = 512000 + 5908
plt.figure()
for i in range(6):
    plt.plot(pos[int(i * puntos):int((i + 1) * puntos)])
    # están perfectamente superpuestas las posiciones

plt.figure()
for i in range(6):
    plt.plot(Bnorm[int(i * puntos):int((i + 1) * puntos)])
    plt.legend(["1", "2", "3", "4", "5"])
plt.show()

lista = np.array(
    [Bnorm[int(i * puntos):int((i + 1) * puntos - 200000)] for i in range(4)])
prom = np.mean(lista, axis=0)
コード例 #10
0
ファイル: MVA_rapido.py プロジェクト: gabybosc/MPB

"""
Hace el MVA y nada más. Es para correr rápido buscando la hoja de corriente.
"""


np.set_printoptions(precision=4)

year, month, day, doy = fechas()
# ti_MVA = input("hora aproximada\n")
ti_MVA, tf_MVA = tiempos()
t1, t2, t3, t4 = importar_t1t2t3t4(year, month, day, doy, int(ti_MVA))


mag, t, B, posicion = importar_mag(year, month, day, t1 - 0.5, t4 + 0.5)

# ti_MVA = t2  # comentar si quiero elegir los propios
# tf_MVA = t3

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

#################
B_cut = B[inicio:fin]

M_ij = Mij(B_cut)

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