start_time = time.time() sIP = mSF.coord_satellite(rinex_nav, rinex_obs, sats_write_1) print "Coord satellites has been computed in" print("--- %s seconds ---" % (time.time() - start_time)) except ValueError: print 'station ' + str(rinex_obs.nam) + ' has been skipped' continue ################################################################################ lista_G = [] sIP_G_list = [] data_list = [] start_time = time.time() for sa in sats_write_1: varion = mO.obs_sat(rinex_obs.data[0], rinex_obs.data[1], rinex_obs.data[2], rinex_obs.data[3], rinex_obs.data[4], sa) data_list.append(rinex_obs.data) lista_G.append(varion) sIP_sat = mSF.track_sat(sIP, sa, start, stop) #### phi_ipp, lambda_ipp, h_ipp = mSF.coord_ipps( rinex_obs.xyz[0], rinex_obs.xyz[1], rinex_obs.xyz[2], sIP_sat[2], sIP_sat[3], sIP_sat[4], h_iono) sIP_G_list.append((sIP_sat[0], sIP_sat[1], phi_ipp, lambda_ipp, sIP_sat[6], sIP_sat[7])) print "VARION algorithm has been computed and" print "IPP location has been computed for the satellites selected in" print("--- %s seconds ---" % (time.time() - start_time)) ################################################################################
def coord_satellite(rinex_nav, rinex_obs, sats_write): ''' inputs: - rinex navigation file (also brdc) - rinex obs file outputs: - array of the prn - array of the sod - array of the X of the satellites - array of the Y of the satellites - array of the Z of the satellites - array of the time of Time of Ephemeris (seconds into GPS week) ''' ##### CONSTANTS # WGS 84 value of earth's univ. grav. par. mu = 3.986005e14 # WGS 84 value of earth's rotation rate omegae = 7.2921151467e-5 pigreco = 3.1415926535898 speedOfLight = 299792458.0 # relativistic correction term constant (not used so far) F = -4.442807633E-10 # WGS-84 earth rotation rate we = 7.292115e-5 ## READING THE NAVIGATION RINEX data = RN.readRinexNav(rinex_nav) prn = (np.asarray(data['sv'])) # PRN number te = (np.asarray(data['TimeEph']) ) # Time of Ephemeris (seconds into GPS week) a = (np.asarray(data['sqrtA']))**2 # Semi-major axis (meters) mo = (np.asarray(data['M0'])) # Mean anomaly at reference time (radians) e = (np.asarray(data['Eccentricity'])) # Eccentricity (unitless) cuc = ( np.asarray(data['Cuc']) ) # Amplitude of the cosine harmonic correction term to the argument of latitude (radians) cus = ( np.asarray(data['Cus']) ) # Amplitude of the sine harmonic correction term to the argument of latitude (radians) crc = ( np.asarray(data['Crc']) ) # Amplitude of the cosine harmonic correction term to the orbit radius (meters) crs = ( np.asarray(data['Crs']) ) # Amplitude of the sine harmonic correction term to the orbit radius (meters) cic = ( np.asarray(data['Cic']) ) # Amplitude of the cosine harmonic correction term to the angle of inclination (radians) cis = ( np.asarray(data['CIS']) ) # Amplitude of the sine harmonic correction term to the angle of inclination (radians) dn = (np.asarray(data['DeltaN']) ) # Mean motion difference from computed value (radians/sec) lo = (np.asarray(data['OMEGA']) ) # longitude of ascending node of orbit plane at weekly epoch ome = (np.asarray(data['omega'])) # argument of perigee (radians) ome_dot = (np.asarray(data['OMEGA DOT']) ) # Rate of right ascension (radians/sec) i_init = (np.asarray(data['Io']) ) # Inclination angle at reference time (radians) i_rate = (np.asarray(data['IDOT']) ) # Rate of inclination angle (radians/sec) gps_week_sat = np.asarray(data['GPSWeek']) no = (mu / (a**3))**0.5 n = no + dn ## READING THE OBSERVATION RINEX -- > in order to compute the Xs,Ys,Zs at the epochs we want data_obs = rinex_obs.data prn_sat_list = [] Xk_list = [] Yk_list = [] Zk_list = [] Az_list = [] El_list = [] sod_list = [] toe_list = [] for s in sats_write: prn_sat = int(s[1:3]) varion, ora, sod = mO.obs_sat(data_obs[0], data_obs[1], data_obs[2], data_obs[3], data_obs[4], s) for i in xrange(len(sod)): # Time of flight tof = data_obs[-1][1:][i] / speedOfLight ### correction due to the earth rotation # alpha = tof * we trasmitTime = (sod[i] + rinex_obs.gps_sow_ref) - tof tk_arr = (trasmitTime - te[prn == prn_sat]) # tk = t - te val, idx = min( (val, idx) for (idx, val) in enumerate(np.abs(tk_arr))) # vedo quale tk è min tk = tk_arr[idx] + (rinex_obs.gps_week_ref - gps_week_sat[prn == prn_sat][idx]) * 604800 ## TEST if tk > 302400: tk = tk - 604800 if tk < -302400: tk = tk + 604800 mk = mo[prn == prn_sat][idx] + n[prn == prn_sat][idx] * tk ## iterazioni per calcolare Ek eko = mk for j in xrange(50): ek = mk + e[prn == prn_sat][idx] * np.sin(eko) if abs(ek - eko) <= 10e-10: break else: eko = ek if j == 49: print "WARNING: Kepler Eqn didn't converge for sat " + str( s) break ## vk = np.arctan2( (((1 - (e[prn == prn_sat][idx])**2)**0.5) * np.sin(ek)), (np.cos(ek) - e[prn == prn_sat][idx])) uk = ome[prn == prn_sat][idx] + vk duk = (cuc[prn == prn_sat][idx] * np.cos(2 * uk) + (cus[prn == prn_sat][idx] * np.sin(2 * uk))) drk = (crc[prn == prn_sat][idx] * np.cos(2 * uk) + (crs[prn == prn_sat][idx] * np.sin(2 * uk))) dik = (cic[prn == prn_sat][idx] * np.cos(2 * uk) + (cis[prn == prn_sat][idx] * np.sin(2 * uk))) omek = ome[prn == prn_sat][idx] + duk rk = a[prn == prn_sat][idx] * ( 1 - e[prn == prn_sat][idx] * np.cos(ek)) + drk ik = i_init[prn == prn_sat][idx] + i_rate[prn == prn_sat][idx] * tk + dik xk = rk * np.cos(omek + vk) yk = rk * np.sin(omek + vk) lk = lo[prn == prn_sat][idx] + ome_dot[prn == prn_sat][ idx] * tk - omegae * (sod[i] + rinex_obs.gps_sow_ref) Xk = xk * np.cos(lk) - yk * np.sin(lk) * np.cos(ik) Yk = xk * np.sin(lk) + yk * np.cos(lk) * np.cos(ik) Zk = yk * np.sin(ik) # Correction the satellite position for the time it took the message to get to the reciver #Xk = Xk * np.cos(alpha) + Yk * np.sin(alpha) #Yk = -Xk * np.sin(alpha) + Yk * np.cos(alpha) Az, El = calculateAzimuthElevation(Xk, Yk, Zk, rinex_obs) Xk_list.append(Xk) Yk_list.append(Yk) Zk_list.append(Zk) Az_list.append(Az) El_list.append(El) prn_sat_list.append(s) sod_list.append(sod[i]) toe_list.append(te[prn == prn_sat][idx]) prn_sat_arr = np.asarray(prn_sat_list) sod_arr = np.asarray(sod_list) toe_arr = np.asarray(toe_list) Xk_arr = np.asarray(Xk_list) Yk_arr = np.asarray(Yk_list) Zk_arr = np.asarray(Zk_list) Az_arr = np.asarray(Az_list) El_arr = np.asarray(El_list) return prn_sat_arr, sod_arr, Xk_arr, Yk_arr, Zk_arr, toe_arr, Az_arr, El_arr
def coord_satellite(rinex_nav, rinex_obs, sats_write): ''' inputs: - rinex navigation file (also brdc) - rinex obs file outputs: - array of the prn - array of the sod - array of the X of the satellites - array of the Y of the satellites - array of the Z of the satellites - array of the time of Time of Ephemeris (seconds into GPS week) ''' ##### CONSTANTS # WGS 84 value of earth's univ. grav. par. mu = 3.986005e14 # WGS 84 value of earth's rotation rate omegae = 7.2921151467e-5 pigreco = 3.1415926535898 speedOfLight = 299792458.0 # relativistic correction term constant (not used so far) F = -4.442807633E-10 # WGS-84 earth rotation rate we = 7.292115e-5 ## READING THE NAVIGATION RINEX epoch, sow, prn, te, a, mo, e, cuc, cus, crc, crs, cic, cis, dn, lo, ome, ome_dot, i_init, i_rate, gps_week_sat = RN.nav_gps_v2_new( rinex_nav) no = (mu / (a**3))**0.5 n = no + dn ## READING THE OBSERVATION RINEX -- > in order to compute the Xs,Ys,Zs at the epochs we want rinex_obs.data = skip_nan(rinex_obs, rinex_obs.data[5]) data_obs = rinex_obs.data sat_gps = rinex_obs.data[0] ora_gps = rinex_obs.data[1] sod_gps = rinex_obs.data[2] c1c_gps = rinex_obs.data[5] l1c_gps = rinex_obs.data[3] c2w_gps = rinex_obs.data[6] l2w_gps = rinex_obs.data[4] c5_gps = rinex_obs.data[9] l5_gps = rinex_obs.data[10] prn_sat_list = [] Xk_list = [] Yk_list = [] Zk_list = [] Az_list = [] El_list = [] sod_list = [] toe_list = [] for s in sats_write: prn_sat = int(s[1:3]) print s varion, ora, sod = mO.obs_sat(sat_gps, ora_gps, sod_gps, l1c_gps, l2w_gps, s) for i in xrange(len(sod)): # Time of flight tof = c1c_gps[1:][i] / speedOfLight ### correction due to the earth rotation # alpha = tof * we trasmitTime = (sod[i] + rinex_obs.gps_sow_ref) - tof tk_arr = (trasmitTime - te[prn == prn_sat]) # tk = t - te val, idx = min( (val, idx) for (idx, val) in enumerate(np.abs(tk_arr))) # vedo quale tk è min tk = tk_arr[idx] + (rinex_obs.gps_week_ref - gps_week_sat[prn == prn_sat][idx]) * 604800 ## TEST if tk > 302400: tk = tk - 604800 if tk < -302400: tk = tk + 604800 mk = mo[prn == prn_sat][idx] + n[prn == prn_sat][idx] * tk ## iterazioni per calcolare Ek eko = mk for j in xrange(50): ek = mk + e[prn == prn_sat][idx] * np.sin(eko) if np.isnan(abs(ek - eko)) == True: pdb.set_trace() if abs(ek - eko) <= 10e-10: break else: eko = ek if j == 49: print "WARNING: Kepler Eqn didn't converge for sat " + str( s) break ## vk = np.arctan2( (((1 - (e[prn == prn_sat][idx])**2)**0.5) * np.sin(ek)), (np.cos(ek) - e[prn == prn_sat][idx])) uk = ome[prn == prn_sat][idx] + vk duk = (cuc[prn == prn_sat][idx] * np.cos(2 * uk) + (cus[prn == prn_sat][idx] * np.sin(2 * uk))) drk = (crc[prn == prn_sat][idx] * np.cos(2 * uk) + (crs[prn == prn_sat][idx] * np.sin(2 * uk))) dik = (cic[prn == prn_sat][idx] * np.cos(2 * uk) + (cis[prn == prn_sat][idx] * np.sin(2 * uk))) omek = ome[prn == prn_sat][idx] + duk rk = a[prn == prn_sat][idx] * ( 1 - e[prn == prn_sat][idx] * np.cos(ek)) + drk ik = i_init[prn == prn_sat][idx] + i_rate[prn == prn_sat][idx] * tk + dik xk = rk * np.cos(omek + vk) yk = rk * np.sin(omek + vk) lk = lo[prn == prn_sat][idx] + ome_dot[prn == prn_sat][ idx] * tk - omegae * (sod[i] + rinex_obs.gps_sow_ref) Xk = xk * np.cos(lk) - yk * np.sin(lk) * np.cos(ik) Yk = xk * np.sin(lk) + yk * np.cos(lk) * np.cos(ik) Zk = yk * np.sin(ik) # Correction the satellite position for the time it took the message to get to the reciver #Xk = Xk * np.cos(alpha) + Yk * np.sin(alpha) #Yk = -Xk * np.sin(alpha) + Yk * np.cos(alpha) Az, El = calculateAzimuthElevation(Xk, Yk, Zk, rinex_obs) Xk_list.append(Xk) Yk_list.append(Yk) Zk_list.append(Zk) Az_list.append(Az) El_list.append(El) prn_sat_list.append(s) sod_list.append(sod[i]) toe_list.append(te[prn == prn_sat][idx]) prn_sat_arr = np.asarray(prn_sat_list) sod_arr = np.asarray(sod_list) toe_arr = np.asarray(toe_list) Xk_arr = np.asarray(Xk_list) Yk_arr = np.asarray(Yk_list) Zk_arr = np.asarray(Zk_list) Az_arr = np.asarray(Az_list) El_arr = np.asarray(El_list) return prn_sat_arr, sod_arr, Xk_arr, Yk_arr, Zk_arr, toe_arr, Az_arr, El_arr