def diferencias_tleCODS(salida, tles, linea_interpol, data): """ Toma la lista de archivos TLEs y propaga cada uno hasta la epoca de la linea interpolada. Luego compara los valores de las coordenadas propagadas con los valores de la linea interpolada y genera las diferencias. Imprime los resultados en el archivo salida. ---------------------------------------------------------------------------------------------------------- input salida: archivo donde se escribe (Instancia de apertura de archivo) tles: lista de nombres de archivos tle (diccionario) linea_interpol: Linea interpolada de los datos CODS para la epoca del TLE primario. (String) output difTot_satId_fini_ffin.cods: Archivo con todas las diferencias ('../Comparar/diferencias/') """ fecha = linea_interpol[:26] d = datetime.strptime(fecha, '%Y-%m-%d %H:%M:%S.%f') r = np.array([ float(linea_interpol.split()[2]), float(linea_interpol.split()[3]), float(linea_interpol.split()[4]) ]) rp = np.array([ float(linea_interpol.split()[5]), float(linea_interpol.split()[6]), float(linea_interpol.split()[7]) ]) item = range(0, len(tles)) whichconst = wgs72 for j in item: tle0 = Tle.creadoxArchivo('../TleAdmin/tle/' + tles[j][0]) fecha_tle = tle0.epoca() if fecha_tle <= d: dif_fechas = (d - fecha_tle).total_seconds() / 86400.0 line1 = tle0.linea1 line2 = tle0.linea2 satrec = twoline2rv(line1, line2, whichconst) pos1, vel1 = satrec.propagate(d.year, d.month, d.day, d.hour, d.minute, d.second) pos = teme2tod(fecha_tle, pos1) vel = teme2tod(fecha_tle, vel1) difx = [pos[0, 0] - r[0], pos[0, 1] - r[1], pos[0, 2] - r[2]] difv = [vel[0, 0] - rp[0], vel[0, 1] - rp[1], vel[0, 2] - rp[2]] # difx=[pos1[0]-r[0],pos1[1]-r[1],pos1[2]-r[2]] # difv=[vel1[0]-rp[0],vel1[1]-rp[1],vel1[2]-rp[2]] v, n, c = vncSis(r, rp, difx) vv, nn, cc = vncSis(r, rp, difv) dato = str(fecha_tle) + ' ' + str(v) + ' ' + str(n) + ' ' + str( c) + ' ' + str(vv) + ' ' + str(nn) + ' ' + str(cc) + '\n' salida.write(dato) data[0].append(fecha_tle) data[1].append(v) data[2].append(n) data[3].append(c) data[4].append(vv) data[5].append(nn) data[6].append(cc) data[7].append(dif_fechas) return data
def calcula_matriz_OSWcorregido(cat_id, tca0, tca1, crudo, diferencias): """ Metodo de Osweiler pero contra el vector de estado del Tle primario corregido. """ files = glob.glob('../TleAdmin/tle/*') for filename in files: os.unlink(filename) set_deb = SetTLE(cat_id, tca0, tca1, crudo) set_deb.divide_setTLE() tles = glob.glob('../TleAdmin/tle/*') dic_tles = generadorDatos(tles) tle_ordenados = ordenaTles(dic_tles) tle_primario = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[-1][0]) epoca_primario = tle_primario.epoca() # En TEME r0 = np.array([diferencias[0], diferencias[1], diferencias[2]]) rp0 = np.array([diferencias[3], diferencias[4], diferencias[5]]) nombre_archivo = 'difRTN_' + str(cat_id) + '_' + tca1.strftime( '%Y%m%d') + '.TLE' archivo_dif_rsw = open('../AjustarTLE/diferencias/' + nombre_archivo + '', 'w') # listas de diferencias (RTN) dr = [] dt = [] dn = [] drr = [] dtt = [] dnn = [] item = range(len(tle_ordenados) - 2, -1, -1) for j in item: tle1 = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[j][0]) fsec = tle1.epoca() pos, vel = tle1.propagaTLE(epoca_primario) pos = np.array([pos[0], pos[1], pos[2]]) vel = np.array([vel[0], vel[1], vel[2]]) # Calculo de Diferencias d_r = pos - r0 d_v = vel - rp0 r, t, n = vncSis(r0, rp0, d_r) rr, tt, nn = vncSis(r0, rp0, d_v) # r,t,n=ricSis(r0, rp0, d_r) # rr,tt,nn=ricSis(r0,rp0,d_v) ''' Sistema RTN ''' dr.append(r) dt.append(t) dn.append(n) drr.append(rr) dtt.append(tt) dnn.append(nn) infodifRST = fsec.strftime('%Y-%m-%d %H:%M:%S') + ' ' + str( r) + ' ' + str(t) + ' ' + str(n) + ' ' + str(rr) + ' ' + str( tt) + ' ' + str(nn) + '\n' archivo_dif_rsw.write(infodifRST) var_r = np.var(dr) var_t = np.var(dt) var_n = np.var(dn) return nombre_archivo, var_r, var_t, var_n
dif_n = [] dif_c = [] while epoca_ini_prop < epoca_fin_prop: #propago r, v = tle_dia1.propagaTLE(epoca_ini_prop) r_tod = teme2tod(epoca_ini_prop, r) #extraigo datos cods x = ephem_dic[epoca_ini_prop]['x'] y = ephem_dic[epoca_ini_prop]['y'] z = ephem_dic[epoca_ini_prop]['z'] vx = ephem_dic[epoca_ini_prop]['vx'] vy = ephem_dic[epoca_ini_prop]['vy'] vz = ephem_dic[epoca_ini_prop]['vz'] r_cods = np.array([float(x), float(y), float(z)]) v_cods = np.array([float(vx), float(vy), float(vz)]) resta = r_cods[0] - r_tod.item(0), r_cods[1] - r_tod.item( 1), r_cods[2] - r_tod.item(2) v, n, c = vncSis(r_cods, v_cods, resta) dif_r.append(resta) dif_v.append(v) dif_n.append(n) dif_c.append(c) epoca_ini_prop = epoca_ini_prop + timedelta(seconds=1) print 'Promedio de dv = ', np.mean(dif_v), np.var(dif_v) print 'Promedio de dn = ', np.mean(dif_n), np.var(dif_n) print 'Promedio de dc = ', np.mean(dif_c), np.var(dif_c)
print "Epoch: ", t0 # print satellite.epoch for hora in range(0, 24): for minuto in range(0, 60): for segundo in range(0, 60): datos = cods[segundo + minuto * 60 + hora * 3600].split() xcods = float(datos[2]) ycods = float(datos[3]) zcods = float(datos[4]) xpcods = float(datos[5]) ypcods = float(datos[6]) zpcods = float(datos[7]) # zosition, velocity = satellite.propagate(t0.year, t0.month, t0.day, t0.hour, t0.minute, t0.second) position, velocity = satellite.propagate(t0.year, t0.month, 5, hora, minuto, segundo) fechahora = datetime(t0.year, t0.month, t0.day, hora, minuto, segundo) # print "teme" , fechahora, position[0], position[1], position[2] r_tod = teme2tod(fechahora, position) # print "tod" , fechahora, r_tod.item(0), r_tod.item(1), r_tod.item(2) # print "delta", fechahora, r_tod.item(0)-position[0] , r_tod.item(1)-position[1] , r_tod.item(2)-position[2] # dif = (r_tod.item(0)-position[0] , r_tod.item(1)-position[1] , r_tod.item(2)-position[2]) dif = (xcods - r_tod.item(0), ycods - r_tod.item(1), zcods - r_tod.item(2)) poscods = (xcods, ycods, zcods) velcods = (xpcods, ypcods, zpcods) # (v,n,c) = vncSis(position, velocity, dif) (v, n, c) = vncSis(poscods, velcods, dif) print fechahora, v, n, c #print "fin"
def difPrimario(): """ Extrae todos los TLEs que contiene la carpeta tle del administrador de TLEs. Propaga cada TLEs a la epoca del ultimo del set y calcula las diferencias. (falta que sea opcional el sistema de ref) NOTA: Transforma los resultados al sistema TOD. ---------------------------------------------------------------- output: set de datos ... describir. """ tles = glob.glob('../TleAdmin/tle/*') dic_tles = generadorDatos(tles) tle_ordenados = ordenaTles(dic_tles) tle_inicio = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[0][0]) cat_id = tle_inicio.catID() epoca_ini = tle_inicio.epoca() #========================= # Ultimo TLE del set #========================= tle_primario = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[-1][0]) epoca_fin = tle_primario.epoca() epoca_ffin = epoca_fin epoca15dias = epoca_ffin - timedelta(days=15) nombre = 'difPri_' + str(cat_id) + '_' + epoca_ffin.strftime( '%Y%m%d') + '_' + epoca_ini.strftime('%Y%m%d') + '.TLE' nombre2 = 'difPri_xyz_' + str(cat_id) + '_' + epoca_ffin.strftime( '%Y%m%d') + '_' + epoca_ini.strftime('%Y%m%d') + '.TLE' dtot = open('../AjustarTLE/diferencias/' + nombre + '', 'w') dtot2 = open('../AjustarTLE/diferencias/' + nombre2 + '', 'w') dt_tle = [] dt_frac = [] dv = [] dn = [] dc = [] dvv = [] dnn = [] dcc = [] dx = [] dy = [] dz = [] dxx = [] dyy = [] dzz = [] tlepri = tle_ordenados[-1][0] r, rp, ffin = tlePrimario(tlepri) # En TEME """ Transformacion del TEME al TOD. """ r = teme2tod(ffin, r) r = np.array([r[0, 0], r[0, 1], r[0, 2]]) rp = teme2tod(ffin, rp) rp = np.array([rp[0, 0], rp[0, 1], rp[0, 2]]) """ fin de la transformacion """ item = range(len(tle_ordenados) - 2, -1, -1) for j in item: tlesec = tle_ordenados[j][0] tle1 = Tle.creadoxArchivo('../TleAdmin/tle/' + tlesec) tle1_epoca = tle1.epoca() if tle1_epoca >= epoca15dias: pos, vel, fsec = tleSecundario(tlesec, ffin) """ Transformacion del TEME al TOD. """ pos = teme2tod(fsec, pos) pos = np.array([pos[0, 0], pos[0, 1], pos[0, 2]]) vel = teme2tod(fsec, vel) vel = np.array([vel[0, 0], vel[0, 1], vel[0, 2]]) """ fin de la transformacion """ dt_tle.append(fsec) dr = pos - r d_v = vel - rp x = dr[0] y = dr[1] z = dr[2] xx = d_v[0] yy = d_v[1] zz = d_v[2] dt = abs(fsec - ffin) dtfracdias = dt.total_seconds() / 86400.0 v, n, c = vncSis(r, rp, dr) vv, nn, cc = vncSis(r, rp, d_v) # v,n,c=ricSis(r, rp, dr) # vv,nn,cc=ricSis(r,rp,dv) infodifpri = str(fsec) + ' ' + str(v) + ' ' + str(n) + ' ' + str( c) + ' ' + str(vv) + ' ' + str(nn) + ' ' + str( cc) + ' ' + tlesec + '\n' infodifpri2 = str(fsec) + ' ' + str(x) + ' ' + str(y) + ' ' + str( z) + ' ' + str(xx) + ' ' + str(yy) + ' ' + str( zz) + ' ' + tlesec + '\n' dtot.write(infodifpri) dtot2.write(infodifpri2) dt_frac.append(dtfracdias) ''' Sistema VNC ''' dv.append(v) dn.append(n) dc.append(c) dvv.append(vv) dnn.append(nn) dcc.append(cc) ''' Sistema TEME ''' dx.append(x) dy.append(y) dz.append(z) dxx.append(xx) dyy.append(yy) dzz.append(zz) data1 = [dt_tle, dv, dn, dc, dvv, dnn, dnn, dt_frac] var_v = np.var(dv) var_n = np.var(dn) var_c = np.var(dc) print '*******************************************************' print '-----------------Varianzas---------------------------' print '*******************************************************' print 'Var en R = ', var_v print 'Var en T = ', var_n print 'Var en N = ', var_c # print '++++++++++++GRADO 2++++++++++++++++++' dt, coef, statsReport = ajustar_diferencias(epoca_ffin, data1, 2) # print coef # print statsReport # # print '++++++++++++GRADO 1++++++++++++++++++' dt1, coef1, statsReport1 = ajustar_diferencias(epoca_ffin, data1, 1) # print coef1 # print statsReport1 data = [dt, data1, coef, nombre] dtot.close() dtot2.close() return data #if __name__=='__main__': # # d1='../TleAdmin/tle' # if not os.path.exists(d1): # os.mkdir(d1) # d2='../AjustarTLE/diferencias' # if not os.path.exists(d2): # os.mkdir(d2) # d3='../main/matrices/' # if not os.path.exists(d3): # os.mkdir(d3) # d4='../visual/archivos' # if not os.path.exists(d4): # os.mkdir(d4) # # ejecuta_procesamiento_TLE(): # """ # Se crean los directorios necesarios. # """ # # d1='../TleAdmin/tle' # if not os.path.exists(d1): # os.mkdir(d1) # d2='../AjustarTLE/diferencias' # if not os.path.exists(d2): # os.mkdir(d2) # d3='../main/matrices/' # if not os.path.exists(d3): # os.mkdir(d3) # d4='../visual/archivos' # if not os.path.exists(d4): # os.mkdir(d4) # # files=glob.glob('../AjustarTLE/diferencias/*') # for filename in files: # os.unlink(filename) # # self.bin=difTle(self.tleOrdenados, self.tles) # self.cantxbin,self.mediaxbin=genera_estadisticaBin(self.bin) # self.diferencias=difPrimario(self.filename,self.tles-1) # # t=[] # dv=[] # dn=[] # dc=[] # # # archivo=open('../AjustarTLE/diferencias/difTotal','r') # contenido=archivo.readlines() # # for c in contenido: # campos=c.split(',') # t.append(float(campos[0])) # dv.append(float(campos[1])) # dn.append(float(campos[2])) # dc.append(float(campos[3])) # # c, b, a = P.polynomial.polyfit(t, dv, deg=2) # print c,b,a # # x=np.linspace(0,30, 60) # y=[] # for i in x: # y.append(-0.002373*i*i+0.061160*i-0.077031) # # plt.plot(t,dv,'x') # plt.plot(x,y,'-') # plt.show() # """ # Verificacion de generacion del archivo con las diferencias # """ # print '---------------------------------------------------------------------------------' # print "Verifiacion de la Generacion del archivo de diferencias: ",salida # print "Ultima modificacion %s" % time.ctime(os.path.getmtime('../AjustarTLE/diferencias/difTotal')) # print "creado: %s" % time.ctime(os.path.getctime('../AjustarTLE/diferencias/difTotal')) # print ' ' # print ' ' # """ # generacion de graficos # """ # gegrafTot('../AjustarTLE/diferencias/difTotal'+setID,setID) # #gegraf('../AjustarTLE/diferencias/diferencias'+tlepri,tlepri)
def difTle(tleOrdenados, cantidad_tles): """ --------------------------------------------------------------- Diferencias de Osweiler. (Pair-Wise Differencing) Calcula las diferencias entre TLE primario y secundarios en el sistema v,n y c; o (ric). Lo hace en forma iterativa, recorriendo todos los TLE a fin de que todos son primarios en algun momento. --------------------------------------------------------------- input: tleOrdeandos: lista de TLEs y sus 2-lineas (lista de lista) output: difTotal# : archivo de texto plano (4 columnas) para cada set [AjustarTLE/diferencias/difTotal_satID_fechaIni#] bin : lista de listas, con las diferencias por bin. data: lista de listas, [dt_frac,dv,dn,dc] """ print 'Procesando datos TLE...' tles = glob.glob('../TleAdmin/tle/*') dic_tles = generadorDatos(tles) tle_ordenados = ordenaTles(dic_tles) tle_inicio = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[0][0]) cat_id = tle_inicio.catID() epoca_ini = tle_inicio.epoca() tle_primario = Tle.creadoxArchivo('../TleAdmin/tle/' + tle_ordenados[-1][0]) epoca_fin = tle_primario.epoca() epoca_ffin = epoca_fin nombre = 'difTot_' + str(cat_id) + '_' + epoca_ffin.strftime( '%Y%m%d') + '_' + epoca_ini.strftime('%Y%m%d') + '.TLE' nombre2 = 'difTot_xyz_' + str(cat_id) + '_' + epoca_ffin.strftime( '%Y%m%d') + '_' + epoca_ini.strftime('%Y%m%d') + '.TLE' dtot = open('../AjustarTLE/diferencias/' + nombre + '', 'w') dtot2 = open('../AjustarTLE/diferencias/' + nombre2 + '', 'w') dt_tle = [] dt_frac = [] dv = [] dn = [] dc = [] dvv = [] dnn = [] dcc = [] dx = [] dy = [] dz = [] dxx = [] dyy = [] dzz = [] bin = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], []] m = 0 for i in range(cantidad_tles - 1, 0, -1): tlepri = tleOrdenados[i][0] r, rp, ffin = tlePrimario(tlepri) item = range(i - 1, -1, -1) for j in item: tlesec = tleOrdenados[j][0] pos, vel, fsec = tleSecundario(tlesec, ffin) dt_tle.append(fsec) dr = pos - r d_v = vel - rp x = dr[0] y = dr[1] z = dr[2] xx = d_v[0] yy = d_v[1] zz = d_v[2] dt = abs(fsec - ffin) dtfracdias = dt.total_seconds() / 86400.0 v, n, c = vncSis(r, rp, dr) vv, nn, cc = vncSis(r, rp, d_v) # v,n,c=ricSis(r, rp, dr) # vv,nn,cc=ricSis(r,rp,dv) infodiftot = str(fsec) + ' ' + str(v) + ' ' + str(n) + ' ' + str( c) + ' ' + str(vv) + ' ' + str(nn) + ' ' + str( cc) + ' ' + tlesec + '\n' infodiftot2 = str(fsec) + ' ' + str(x) + ' ' + str(y) + ' ' + str( z) + ' ' + str(xx) + ' ' + str(yy) + ' ' + str( zz) + ' ' + tlesec + '\n' dtot.write(infodiftot) dtot2.write(infodiftot2) dt_frac.append(dtfracdias) ''' Sistema VNC ''' dv.append(v) dn.append(n) dc.append(c) dvv.append(vv) dnn.append(nn) dcc.append(cc) ''' Sistema TEMA ''' dx.append(x) dy.append(y) dz.append(z) dxx.append(xx) dyy.append(yy) dzz.append(zz) """ Clasificacion por bin. """ rangos = np.array([[0, 0.5], [0.5, 1.5], [1.5, 2.5], [2.5, 3.5], [3.5, 4.5], [4.5, 5.5], [5.5, 6.5], [6.5, 7.5], [7.5, 8.5], [8.5, 9.5], [9.5, 10.5], [10.5, 11.5], [11.5, 12.5], [12.5, 13.5], [13.5, 14.5]]) for k in range(len(rangos)): if dtfracdias >= rangos[k][0] and dtfracdias < rangos[k][1]: bin[k].append(infodiftot) m = m + 1 dataPri = [ dt_tle[:15], dv[:15], dn[:15], dc[:15], dvv[:15], dnn[:15], dcc[:15], dt_frac[:15] ] data1 = [dt_tle, dv, dn, dc, dvv, dnn, dnn, dt_frac] print '++++++++++++GRADO 2++++++++++++++++++' dt, coef, statsReport = ajustar_diferencias(epoca_ffin, dataPri, 2) print coef print statsReport print '++++++++++++GRADO 1++++++++++++++++++' dt1, coef1, statsReport1 = ajustar_diferencias(epoca_ffin, dataPri, 1) print coef1 print statsReport1 data = [dt, data1, coef, nombre] dtot.close() return bin, data, dataPri, coef1