B_cut, t1, t2, t3, t4, B_medio_vectorial, fila, hoja_parametros, hoja_mva, hoja_boot, hoja_fit, ) = MVA(year, month, day, doy, ti_MVA, tf_MVA, t, B, posicion) ######### # buscamos el ángulo entre las normales angulo_mva = angulo(normal_fit, x3) angulo_boot = angulo(normal_boot, x3) ############## # Calculo la velocidad de la nave v_punto = np.zeros((fin - inicio, 3)) norma_v = np.zeros(fin - inicio) posicion_cut = posicion[inicio:fin + 1, :] t_cut = t[inicio:fin + 1] * 3600 # en segundos for i in range(fin - inicio): v_punto[i, :] = (posicion[inicio + 1, :] - posicion[inicio]) / ( t_cut[i + 1] - t_cut[i]) # en km/s norma_v[i] = np.linalg.norm(v_punto[i, :]) # veamos que no cambia mucho punto a punto, usemos la norma diff = max(norma_v) - min(norma_v) # la velocidad promedio
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 ######### # buscamos el ángulo entre las normales angulo_mva = angulo(normal_ajuste, x3) angulo_boot = angulo(normal_boot, x3) ############## # Calculo la velocidad de la nave v_punto = np.zeros((M_cut - 1, 3)) norma_v = np.zeros(M_cut - 1) for i in range(len(v_punto)): v_punto[i, :] = (posicion_cut[i + 1, :] - posicion_cut[i]) / (1 / 32) # en km/s, tiene resolución de 32Hz norma_v[i] = np.linalg.norm(v_punto[i, :]) # la velocidad promedio v_media = np.mean(v_punto, axis=0) # ahora quiero ver si la nave atraviesa perpendicularmente a la MPB
cociente[i, j] = lamb[1] / lamb[2] normales[i, j] = x3 program_ends = time.time() print(f"El loop tardó {program_ends-program_starts:.2f} s") """ Quiero el ángulo contra la normal del MVA para cada tiempo t con escala r = 15s """ normal = [0.920, -0.302, 0.251] rr = 17 # radio normales_radio = normales[:, rr - 1, :] angle = np.zeros(len(normales_radio)) for i in range(len(normales_radio)): angle[i] = angulo(normal, normales_radio[i]) * 180 / np.pi tiempos_MVA = [18.2258, 18.235] tMVA1 = donde(tiempo_central, tiempos_MVA[0]) tMVA2 = donde(tiempo_central, tiempos_MVA[1]) angulo_medio = np.mean(angle[tMVA1:tMVA2]) print(f"el ángulo medio es {angulo_medio}") times = array_datenums(year, month, day, tiempo_central) t_graph = md.date2num(times) plt.figure() plt.subplots_adjust(bottom=0.2) plt.xticks(rotation=25) ax = plt.gca() xfmt = md.DateFormatter("%H:%M:%S") ax.xaxis.set_major_formatter(xfmt)
plt.ylabel("Radius (s)") # frames = [] n = 1 b = [i for i in range(20)] histograma = 0 for k in range(int(len(tiempo_central) / n)): NN = int(k * n) # tiempo_central[NN] normales_t1 = normales[NN] angle = np.zeros((len(normales_t1), len(normales_t1))) thdec = hdec_to_UTC(tiempo_central[NN]) for i in range(len(normales_t1)): for j in range(len(normales_t1)): angle[i, j] = angulo(normales_t1[i], normales_t1[j]) * 180 / np.pi # frame = plot(thdec, angle) # frames.append(frame) hist, bins = np.histogram(angle, bins=b) hist[0] = hist[0] - 29 # saco los 29 ceros de la diagonal histograma += hist t = 0 s = 0 for i in range(len(histograma)): s += histograma[i] * ((bins[i] + bins[i + 1]) / 2) mean = s / np.sum(histograma) for i in range(len(histograma)): t += histograma[i] * (bins[i] - mean)**2 std = np.sqrt(t / np.sum(histograma)) # gif.save(frames, "heatmap.gif", duration=500)
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
#se invoca la funcion desplazamiento dh = funciones.desplazamientox(segundos, velocidad) #se muestra el label con el desplzamiento horizontal etiqueta2 = label(pos=(-posinicial, -altura * 3, 0), text="Desplazamiento horizontal: " + str(dh) + " m") #se le indica que hacer al programa cuando el usuario elije la opcion tres elif op == "3": #se imprime el titulo del simulador print "" print "Menu de Tiro Parabolico 1" print "--------------------------" #se invocan las funciones que se van a utilizar velocidad = funciones.IngVelocidad() posinicial = velocidad * 4 angulo = funciones.angulo() scene = funciones.pantalla2(velocidad * 3) pelota1 = funciones.pelota2(velocidad * 3) piso = funciones.piso2(velocidad * 3) #se asigna el valor de las varibales gravedad = 9.8 segundos = 0 dt = 0.01 #se convierte los angulos de grados a radianes angulo = angulo * (pi / 180) #se asigna el valor de las velocidades en los dos ejes por medio de la formulas velocidady = velocidad * sin(angulo) velocidadx = velocidad * cos(angulo)
beta = Ptermica / P_mag beta_str = (Ptermica + P_dyn) / P_mag densidad_heavies = densidad_O + densidad_O2 + densidad_CO2 density_ratio = densidad_H / densidad_heavies mass_ratio = densidad_H / (densidad_O * 16 + densidad_O2 * 32 + densidad_CO2 * 44) x_MSE = np.array([1, 0, 0]) # esto se puede después cambiar a que sea v_sw upstream = donde(posicion[:, 0], 2.5) B_sw = B[upstream, :] z_MSE = np.cross(x_MSE, B_sw) z_MSE = z_MSE / np.linalg.norm(z_MSE) y_MSE = np.cross(z_MSE, x_MSE) y_MSE = y_MSE / np.linalg.norm(y_MSE) theta = angulo(y_MSE, [0, 1, 0]) """ahora que tengo el ángulo de la rotación entre MSO/MSE simplemente tengo que rotar la grilla con la matriz 1 0 0 0 c s 0 -s c https://en.wikipedia.org/wiki/Rotation_of_axes """ matriz = np.array( [[1, 0, 0], [0, np.cos(theta), np.sin(theta)], [0, -np.sin(theta), np.cos(theta)]] ) # Descomentar la siguiente parte para chequear que MSE es lo que debería # MSO = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
# ti_MVA, tf_MVA = 13.07388889,13.08055556 # ti, tf = 12.45, 13.15 mag, t, B, posicion = importar_mag(year, month, day, ti, tf) lpw, t_lpw, e_density = importar_lpw(year, month, day, ti, tf) swia, t_swia, density, temperature, vel_mso = importar_swia( year, month, day, ti, tf) x3, B_cut, t_cut, posicion_cut = MVA(year, month, day, ti_MVA, tf_MVA) normal_ajuste, t1, t2, t3, t4 = ajuste(year, month, day, doy, ti_MVA, tf_MVA) M = len(t) M_cut = len(t_cut) normal_boot, phi, delta_B3, out, out_phi = bootstrap(1000, B_cut) # buscamos el ángulo entre las normales angulo_mva = angulo(normal_ajuste, x3) angulo_boot = angulo(normal_boot, x3) # Es importante que los vectoers estén normalizados! ############## # Calculo la velocidad de la nave v_punto = np.zeros((M_cut - 1, 3)) norma_v = np.zeros(M_cut - 1) for i in range(len(v_punto)): v_punto[i, :] = (posicion_cut[i + 1, :] - posicion_cut[i]) / (1 / 32) # en km/s, tiene resolución de 32Hz norma_v[i] = np.linalg.norm(v_punto[i, :]) # la velocidad promedio v_media = np.mean(v_punto, axis=0) # ahora quiero ver si la nave atraviesa perpendicularmente a la 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
beta_str = (Ptermica + P_ram) / P_B rho_heavies = OpRho + O2pRho + CO2pRho density_ratio = HpRho / rho_heavies mass_ratio = HpRho / (OpRho * 16 + O2pRho * 32 + CO2pRho * 44) upstream = donde(posicion[:, 0], 2.5) v_sw = velocidad_i[upstream, :] B_sw = B[upstream, :] x_MSE = -v_sw / np.linalg.norm(v_sw) z_MSE = np.cross(-v_sw, B_sw) z_MSE = z_MSE / np.linalg.norm(z_MSE) y_MSE = np.cross(z_MSE, x_MSE) y_MSE = y_MSE / np.linalg.norm(y_MSE) theta = angulo(z_MSE, [0, 0, 1]) # phi = angulo() """ahora que tengo el ángulo de la rotación entre MSO/MSE simplemente tengo que rotar la grilla con tres matrices (yaw-pitch-roll) | ca sa 0| | cb 0 sb| |1 0 0 | |-sa ca 0| | 0 1 0| |0 cc -sc| | 0 0 1| |-sb 0 cb| |0 sc cc| La matriz final queda: |ca*cb ca*sb*sc-sa*cc ca*sb*cc+sa*sc| |sa*cb sa*sb*sc+ca*cc sa*sb*cc-ca*sc| | -sb cb*sc cb*cc | https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions La matriz es para vectores en vertical """
reordenados = np.array(sorted(Z, key=lambda f: f[0])) pos = 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) MPB = donde(pos[:, 0], 1.26) # 1.26 es donde es máx la J en x. BS = donde(pos[:, 0], 1.7) B = reordenados[:, 7:10] J = reordenados[:, -3:] * 1000 print("Angulo J, B en la MPB:", angulo(J[MPB, :], B[MPB, :]) * 180 / np.pi) print("Angulo J, B en el BS:", angulo(J[BS, :], B[BS, :]) * 180 / np.pi) MPB = np.array([Z[i, :] for i in range(len(Z)) if 1.2 <= Z[i, 0] <= 1.36]) pos = MPB[:, :3] B = MPB[:, 7:10] J = MPB[:, -3:] * 1000 plt.plot(J[:, 1], J[:, 2], ".") plt.plot(B[:, 1], B[:, 2], ".") plt.show() # # fig = plt.figure() # ax = fig.gca(projection="3d")