def read_clockFile(clkFile): """ Read Clock file """ isexist(clkFile) start = time.time() f = open(clkFile) clk = f.readlines() line = 0 prnlist = [] while True: if 'OF SOLN SATS' not in clk[line]: del clk[line] else: noprn = int(clk[line][4:6]) line +=1 break while True: if 'PRN LIST' in clk[line]: prnlist.extend(clk[line]) prnlist = ''.join(prnlist) prnlist= prnlist.split() prnlist.remove('PRN') prnlist.remove('LIST') line +=1 else: break SV = [] for a in range(0, len(prnlist[0]),3): SV.extend([prnlist[0][a:a+3]]) if len(prnlist) > 1: SV.extend(prnlist[1:]) line = 0 while True: if 'END OF HEADER' not in clk[line]: line +=1 else: del clk[0:line+1] break timelist = [] for i in range(len(clk)): if clk[i][0:2]=='AS': timelist.append(clk[i].split()) Sat = [] Epochlist = [] SVtime = [] for i in range(len(timelist)): Sat.append(timelist[i][1]) Epochlist.append((datetime.datetime(year = int(timelist[i][2]), month = int(timelist[i][3]), day = int(timelist[i][4]), hour = int(timelist[i][5]), minute = int(timelist[i][6]), second =int(float(timelist[i][7]))))) SVtime.append(float(timelist[i][9])) SVTimelist = pd.DataFrame(list(zip(Epochlist, SVtime)), index = Sat, columns=['Epoch','DeltaTSV']) end = time.time() print('{}'.format(clkFile), 'file is read in', '{0:.2f}'.format(end-start), 'seconds') return SVTimelist
def read_ionFile(IonFile): """ Function that reads Ionosphere file """ # check if observationFile exists or not isexist(IonFile) # ---------------------------------------------- start = time.time() f = open(IonFile, errors='ignore') obsLines = f.readlines() line = 0 while True: if 'END OF HEADER' in obsLines[line]: line += 1 break else: line += 1 del obsLines[0:line] # -------------------------------------------------------------------------------------- tecuList = np.zeros([13, 71, 72]) for etime in range(13): line = 0 del obsLines[0] # start of tec map epochLine = obsLines[0].split() epoch = datetime.datetime(year=int(epochLine[0]), month=int(epochLine[1]), day=int(epochLine[2]), hour=int(epochLine[3]), minute=int(epochLine[4]), second=int(epochLine[5])) del obsLines[0] # delete epoch line for phi in range(71): temp = obsLines[0].split() LAT, LON1, LON2, DLON, H = temp[0], temp[1], temp[2], temp[ 3], temp[4] tecu = obsLines[1] + obsLines[2] + obsLines[3] + obsLines[ 4] + obsLines[5] tecu = tecu.split() tecu = [int(tec) for tec in tecu] for lamda in range(len(tecu) - 1): tecuList[etime, phi, lamda] = tecu[lamda] del obsLines[0:6] del obsLines[0] #--------------------------------------------------------------------------------------- f.close() # close the file finish = time.time() print("Ionosphere file ", IonFile, " is read in", "{0:.2f}".format(finish - start), "seconds.") return tecuList
def read_obsFile(observationFile): if observationFile.endswith(".Z")==True: raise Warning("All I/O functions take uncompressed files as an input (remove .Z/.gz from filename) | Next release will include this feature...") # check if observationFile exists or not isexist(observationFile) # open file f = open(observationFile, errors = 'ignore') obsLines = f.readlines() line = 0 while True: if 'RINEX VERSION / TYPE' in obsLines[line]: version = obsLines[line][0:-20].split()[0] break else: line += 1 if version.startswith("2"): return read_obsFile_v2(observationFile) elif version.startswith("3"): return read_obsFile_v3(observationFile)
def read_sp3File(sp3file): start = time.time() isexist(sp3file) f = open(sp3file) sp3 = f.readlines() line = 0 search = '/*' SVNo = sp3[2].split()[1] while True: if search in sp3[line]: if search in sp3[line+1]: line +=1 else: line +=1 break else: line +=1 del sp3[0:line] sp3 = [i.replace('P ', 'PG0') for i in sp3] sp3 = [i.replace('P ', 'PG') for i in sp3] header = ['X', 'Y', 'Z', 'deltaT', 'sigmaX', 'sigmaY', 'sigmaZ', 'sigmadeltaT', 'Epoch'] sat, pos = [], [] while True: for i in range(int(SVNo)+1): if '*' in sp3[i]: sp3[i] = sp3[i].split() epoch=datetime.datetime(year = int(sp3[i][1]), month = int(sp3[i][2]), day = int(sp3[i][3]), hour = int(sp3[i][4]), minute =int(sp3[i][5]), second = 0) else: if '999999.999999' in sp3[i]: sp3[i] = sp3[i].replace(' 999999.999999', ' None') else: if sp3[i][60:].isspace() == True: sp3[i] = sp3[i][:60] if sp3[i][60:63].isspace() == True: sp3[i] = sp3[i][:60] + " XX" + sp3[i][63:] if sp3[i][63:66].isspace() == True: sp3[i] = sp3[i][:63] + " XX" + sp3[i][66:] if sp3[i][66:69].isspace() == True: sp3[i] = sp3[i][:66] + " XX" + sp3[i][69:] if sp3[i][69:73].isspace() == True: sp3[i] = sp3[i][:69] + " XX" + sp3[i][73:] # ------------------------------------------- sp3[i] = sp3[i].split() if len(sp3[i][1:]) == 4: sp3[i].extend(['None', 'None', 'None', 'None']) sat.append(sp3[i][0][1:]) sp3[i] = [float(j) if isfloat(j) == True else None for j in sp3[i]] sp3[i].append(epoch) pos.append(sp3[i][1:]) del sp3[0:int(SVNo)+1] if 'EOF' in sp3[0]: break position = pd.DataFrame(pos, index = sat, columns = header) position.index.name = 'SV' position.set_index('Epoch', append=True, inplace=True) position = position.reorder_levels(["Epoch","SV"]) # ------------------------------------------------------------------ end = time.time() print('{}'.format(sp3file), 'file is read in', '{0:.2f}'.format(end-start), 'seconds') return position