Source Code

This commit is contained in:
KenanZhu111 committed 2024-10-18 15:07:17 +08:00
commit 2b5b4f1be7
2 files changed
+650

No files matched your search

+415
View File
@@ -0,0 +1,415 @@
import threading
import tkinter as tk
from base64 import b64decode
from tkinter import filedialog, StringVar, IntVar
from tkinter import messagebox
from tkinter import ttk
from PIL import ImageTk
import Read_o as obs
##Combox Count-er
ComboxCount = 0
ComboxCount1 = 0
ObsPaths = []
def GetObsFilePath(ObsFileSelectBox):
global ComboxCount
path = filedialog.askopenfilename()
if path and path not in ObsFileSelectBox['value']:
ObsFileSelectBox['value'] += (path,)
ComboxCount += 1
ObsFileSelectBox.current(ComboxCount)
def GetObsFilesPath(ObsPathsShow):
global ObsPaths
paths = filedialog.askopenfilenames()
for path in paths:
if path and path not in ObsPaths:
ObsPaths.append(path)
ObsPathsShow.delete('1.0', 'end')
for path in ObsPaths:
ObsPathsShow.insert('end', path + '\n')
def ClearObsFilesPath(ObsPathsShow):
global ObsPaths
ObsPaths.clear()
ObsPathsShow.delete('1.0','end')
def AskDirectory(AskDirectorySelectBox):
global ComboxCount1
path = filedialog.askdirectory()
if path and path not in AskDirectorySelectBox['value']:
AskDirectorySelectBox['value'] += (path + '/',)
ComboxCount1 += 1
AskDirectorySelectBox.current(ComboxCount1)
def AskOrNotCheck(AskOrNotCheckVar,
AskDirectorySelectBox,
AskDirectorySelectButton):
if AskOrNotCheckVar.get() == 0:
AskDirectorySelectBox.config(state=tk.DISABLED)
AskDirectorySelectButton.config(state=tk.DISABLED)
else:
AskDirectorySelectBox.config(state=tk.NORMAL)
AskDirectorySelectButton.config(state=tk.NORMAL)
def ConvertFile(ConvertState,
ObsSelectBoxVar,
AskOrNotCheckVar,
DirectorySelectBoxVar,
MainCradsOption):
global ObsPaths
ObsPath = []
if MainCradsOption.index('current') == 0:
if AskOrNotCheckVar.get():
if not DirectorySelectBoxVar.get() and not ObsSelectBoxVar.get():
ConvertState.config(text='Invalid Path & Directory !')
return
if not DirectorySelectBoxVar.get() and ObsSelectBoxVar.get():
ConvertState.config(text='Invalid Directory !')
return
else:
DirectoryOut = DirectorySelectBoxVar.get()
if not AskOrNotCheckVar.get():
DirectoryOut = ''
if not ObsSelectBoxVar.get():
ObsPath.clear()
ConvertState.config(text='Invalid Path !')
return
else:
ObsPath.clear()
ObsPath.append(ObsSelectBoxVar.get())
if MainCradsOption.index('current') == 1:
if AskOrNotCheckVar.get():
if not DirectorySelectBoxVar.get() and not ObsPaths:
ConvertState.config(text='Invalid Path & Directory !')
return
if not DirectorySelectBoxVar.get() and ObsPaths:
ConvertState.config(text='Invalid Directory !')
return
else:
DirectoryOut = DirectorySelectBoxVar.get()
if not AskOrNotCheckVar.get():
DirectoryOut = ''
if not ObsPaths:
ObsPath.clear()
ConvertState.config(text='Invalid Path !')
return
else:
ObsPath.clear()
ObsPath = ObsPaths.copy()
pass
state = 0
count = 0
ConvertState.config(text='Converting...')
for Path in ObsPath:
ConvertState.config(text='Converting... %d/%d'%(count, len(ObsPath)))
state += obs.ReadObsVersion(Path, DirectoryOut)
count += 1
if state == len(ObsPath):
ConvertState.config(text='Complete ! %d successful, %d fails'%(state, 0) )
elif state and state < len(ObsPath):
ConvertState.config(text='Complete ! %d successful, %d fails'%(state, len(ObsPath)-state) )
elif state == 0:
ConvertState.config(text='Fail ! %d successful, %d fails' % (0, len(ObsPath)) )
ObsPath.clear()
return
def _ConvertFile(ConvertState,
ObsSelectBoxVar,
AskOrNotCheckVar,
DirectorySelectBoxVar,
MainCradsOption):
global ObsPaths
T = threading.Thread(target=lambda :ConvertFile(ConvertState,
ObsSelectBoxVar,
AskOrNotCheckVar,
DirectorySelectBoxVar,
MainCradsOption))
T.start()
def InitGUI(hwnd):
# GUI Instantiate
hwnd.title("KNZ_Convert")
hwnd.geometry('400x400')
hwnd.minsize(400, 230)
hwnd.maxsize(400, 230)
icon_ico =(b'AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAA'
b'ABAAAPY6AQD2OgEAA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'
b'Kf8yLSn/Mi0p/zItKf8yLSn+Mi0p/zItKfgyLSliMi0pADItKQMAAAAA'
b'AAAAADEtKAAyLSgAMi0oADItKAEyLSgBKR8XADItKAAyLSgIMi0oFzIt'
b'KCIyLSgSMi0oADItKQEyLSkAMi0pCTItKTgyLSlPMi0pUTItKVAyLSlR'
b'Mi0pUTItKVEyLSlRMi0pUTItKVAyLSlEMi0pFzItKQAyLSkBMi0pAAAA'
b'AAAAAAAAAAAAADEuKQAyLSgAMi0pADItKQAyLSgBMi0oATItKAAyLSgA'
b'Mi0oADIuKAAyLSkAMi0pADItKQIyLSkBMi0pADItKQAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAMi0pADItKQAyLSkAMi0pAzItKQAyLikA'
b'y/pKL6AAoZdAAEALgABgFYn0IAqIBDEEiAQgBIn0IUKAACCigAAvIYAA'
b'L5GJ9C+RgAAvkYAAT9JAAEABkAEv0kn0gAmAAgACS/IAAYn0AAGJ9C+R'
b'ifQAEYT0L5FFBAABQoQAASAEAAEgjC+RUAQvkagGAAHQAgAC6IUABfRS'
b'X9I=')
icon_ico = b64decode(icon_ico)
icon_ico = ImageTk.PhotoImage(data=icon_ico)
hwnd.tk.call('wm', 'iconphoto', root._w, icon_ico)
class GUI:
def __init__(self, hwnd):
# GUI Initialize
InitGUI(hwnd)
##Combox Var
self.ObsSelectBoxVar = StringVar()
self.DirectorySelectBoxVar = StringVar()
##CheckButton Var
self.AskOrNotCheckButtonVar = IntVar()
# MainFrame Initialize
self.Mainframe0 = None
self.Mainframe1 = None
self.InitMainFrame(hwnd)
hwnd.protocol("WM_DELETE_WINDOW", hwnd.quit)
hwnd.mainloop()
def InitMainFrame(self, hwnd):
# FrameCrads Initialize
self.MainCradsOption = tk.ttk.Notebook(hwnd)
# Obs File Initialize
self.InitSingleObsCtrl(hwnd)
self.InitBatchObsCtrl(hwnd)
# FrameCrads Instantiate
self.MainCradsOption.add(self.Mainframe0, text='Single Convert')
self.MainCradsOption.add(self.Mainframe1, text='Batch Convert')
self.MainCradsOption.pack(side=tk.TOP, fill=tk.BOTH, expand=True, padx='2px', pady='0px')
# Execute Frame Initialize
self.InitExecFrame(hwnd)
def InitSingleObsCtrl(self, hwnd):
# MainFrame Initialize
self.Mainframe0 = ttk.Frame(hwnd)
# Obs File Select Frame Initialize
ObsSelectFrame1 = ttk.LabelFrame(self.Mainframe0, text='Object Observation of RINEX')
ObsSelectFrame1.pack(side=tk.TOP, fill=tk.X, padx='2px', pady='1px')
ObsFileSelectBox = ttk.Combobox(ObsSelectFrame1, width=46, height=4, values=('',),
textvariable=self.ObsSelectBoxVar)
ObsFileSelectBox.pack(side=tk.LEFT, anchor='w', padx='1px', pady='1px')
ObsFileSelectButton = ttk.Button(ObsSelectFrame1, text='...', width=3,
command=lambda: GetObsFilePath(ObsFileSelectBox))
ObsFileSelectButton.pack(side=tk.RIGHT, anchor='e', padx='1px', pady='1px')
def InitBatchObsCtrl(self, hwnd):
# MainFrame Initialize
self.Mainframe1 = ttk.Frame(hwnd)
# Obs FileS Select Frame Initialize
ObsSelectFrame1 = ttk.LabelFrame(self.Mainframe1, text='Objects Observation of RINEX')
ObsSelectFrame1.pack(side=tk.TOP, fill=tk.X, padx='2px', pady='1px')
#
ObsCtrlFrame1 = ttk.Frame(ObsSelectFrame1)
ObsCtrlFrame1.pack(side=tk.RIGHT, fill=tk.Y, anchor='e', padx='1px', pady='0px')
ObsFileSelectButton = ttk.Button(ObsCtrlFrame1, text='...', width=3,
command=lambda: GetObsFilesPath(ObsPathsShow))
ObsFileSelectButton.pack(side=tk.TOP, anchor='e', padx='1px', pady='1px')
ObsFileClearButton = ttk.Button(ObsCtrlFrame1, text='x', width=3,
command=lambda: ClearObsFilesPath(ObsPathsShow))
ObsFileClearButton.pack(side=tk.BOTTOM, anchor='e', padx='1px', pady='1px')
#
ObsShowFrame1 = ttk.Frame(ObsSelectFrame1)
ObsShowFrame1.pack(side=tk.LEFT, fill=tk.Y, padx='1px', pady='0px')
ScrollbarX = ttk.Scrollbar(ObsShowFrame1, orient=tk.HORIZONTAL)
ScrollbarX.pack(side=tk.BOTTOM, fill=tk.X)
ScrollbarY = ttk.Scrollbar(ObsShowFrame1)
ScrollbarY.pack(side=tk.RIGHT, fill=tk.Y)
ObsPathsShow = tk.Text(ObsShowFrame1, xscrollcommand=ScrollbarX.set, yscrollcommand=ScrollbarY.set,
height=4 ,wrap='none')
ObsPathsShow.pack(side=tk.LEFT, fill=tk.X,anchor='w', padx='1px', pady='1px')
ScrollbarX.config(command=ObsPathsShow.xview)
ScrollbarY.config(command=ObsPathsShow.yview)
def InitExecFrame(self, hwnd):
#
BottomExecFrame = ttk.Frame(hwnd)
BottomExecFrame.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, padx='1px', pady='0px')
# Output Directory Frame Initialize
AskDirectoryFrame1 = ttk.LabelFrame(BottomExecFrame, text='Output directory')
AskDirectoryFrame1.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, padx='1px', pady='0px')
## CheckButton Initialize
AskOrNotCheckButton = ttk.Checkbutton(AskDirectoryFrame1, text='Directory',
variable=self.AskOrNotCheckButtonVar, onvalue=1, offvalue=0,
command=lambda: AskOrNotCheck(self.AskOrNotCheckButtonVar,
AskDirectorySelectBox,
AskDirectorySelectButton))
AskOrNotCheckButton.pack(side=tk.LEFT, anchor='w', padx='1px', pady='0px')
## SelectBox Initialize
AskDirectorySelectBox = ttk.Combobox(AskDirectoryFrame1, width=36, height=4, values=('',),
state=tk.DISABLED, textvariable=self.DirectorySelectBoxVar)
AskDirectorySelectBox.pack(side=tk.LEFT, anchor='w', padx='1px', pady='0px')
## SelectButton Initialize
AskDirectorySelectButton = ttk.Button(AskDirectoryFrame1, text='...', width=3,
state=tk.DISABLED, command=lambda: AskDirectory(AskDirectorySelectBox))
AskDirectorySelectButton.pack(side=tk.RIGHT, anchor='e', padx='2px', pady='0px')
# The bottom control buttons
BottomCtrFrame0 = ttk.Frame(BottomExecFrame)
BottomCtrFrame0.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, padx='1px', pady='0px')
ConvertButton = ttk.Button(BottomCtrFrame0, text='Convert', width=8,
command=lambda: _ConvertFile(ConvertState,
self.ObsSelectBoxVar,
self.AskOrNotCheckButtonVar,
self.DirectorySelectBoxVar,
self.MainCradsOption))
ConvertButton.pack(side=tk.RIGHT, expand=tk.YES, padx='1px', pady='0px')
ExitButton = ttk.Button(BottomCtrFrame0, text='Exit', width=8,
command=hwnd.quit)
ExitButton.pack(side=tk.RIGHT, expand=tk.YES, padx='1px', pady='0px')
# Convert state bar
StateFrame = ttk.Frame(BottomExecFrame)
StateFrame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='0px')
ConvertState = ttk.Label(StateFrame, text="None")
ConvertState.pack(side=tk.LEFT, anchor='nw')
if __name__ == "__main__":
# Main window
root = tk.Tk()
myGUI = GUI(root)
+235
View File
@@ -0,0 +1,235 @@
import time
import math
def ConvertObsVersion(ofile_path, out_directory, version, system):
blank = " "
global outf
if version == 2.10 or version == 2.11:
with open(ofile_path, 'r') as f:
with open(out_directory, 'w') as outf:
outf.close()
# Get the locate time and transform to RINEX format
y = time.localtime().tm_year
m = time.localtime().tm_mon
d = time.localtime().tm_mday
h = time.localtime().tm_hour
min = time.localtime().tm_min
sec = time.localtime().tm_sec
localtime = str(y)+str(m)+str(d)+blank+"%02d"%h+"%02d"%min+"%02d"%sec+blank+"LOC"+blank
# Output the convert message
outf = open(out_directory, 'a')
print(" %4.2f->3.04 COV-OBSERVATION DATA %s CONVERT VERSION / TYPE\n"
"KNZ_Convert ver 1.0.6 %sCONVERT BY / TIME\n"
%(version, system, localtime)
, end="", file=outf)
#Refactoring header file format to 3.04
while 1:
line = f.readline()
if line.find("COMMENT") >= 0:
print(line,end="",file=outf)
elif line.find("RINEX VERSION / TYPE") >= 0:
line = "%9s"%("3.04") + line[ 9:80] + "\r"
print(line,end="",file=outf)
elif line.find("PGM / RUN BY / DATE") >= 0:
hour = line[49:51]
min = line[52:54]
sec = line[55:57]
line = line[ 0:49] + hour + min + sec + blank + "UTC" + blank + "PGM / RUN BY / DATE\n"
print(line,end="",file=outf)
elif line.find("WAVELENGTH FACT L1/2") >= 0:
pass
elif line.find("# / TYPES OF OBSERV") >= 0:
global obsnum
obsnum = int(line[ 0: 6])
count0 = 0 # The line counters
count1 = 0 # The total counters
obstypes= []
while 1:
obstypes.append( str.strip(line[ 0 + 6 * (count0 + 1): 6 + 6 * (count0 + 1)]) )
count0 += 1
count1 += 1
if count1 == obsnum:
break
if count0 % 9 == 0:
line = f.readline()
count0 = 0
# #
# #
# #
#Covert the observation types from 2.xx to 3.04
count = 0
for obstype in obstypes:
if obstype.find("5") >= 0 or obstype.find("7") >= 0 or obstype.find("8") >= 0:
obstype = obstype + "I"
elif obstype.find("6") >= 0:
obstype = obstype + "C"
elif obstype.find("1") >= 0 or obstype.find("2") >= 0:
if obstype.find("P") >= 0:
obstype = "C" + obstype[1:2] + "P"
else:
obstype = obstype + "C"
obstypes[count] = obstype
count += 1
#Refactoring observation type format to 3.04
syss = ['G', 'R', 'E', 'S']
for sys in syss:
line = sys + 3*blank + "%2d"%obsnum + blank
count0 = 0
count1 = 0
for obstype in obstypes:
line += obstype + blank
count0 += 1
count1 += 1
# Output the final line
if count1 == obsnum:
line += (13 - count0) * 4 * blank + blank + "SYS / # / OBS TYPES\n"
print(line, end="", file=outf)
break
# Output the first line
if count0 % 13 == 0:
line += blank + "SYS / # / OBS TYPES\n"
print(line, end="", file=outf)
line = 7*blank
count0 = 0
elif line.find("END OF HEADER") >= 0:
print(line,end="",file=outf)
break
else:
print(line,end="",file=outf)
# Refactoring data file format to 3.04
while 1:
line = f.readline()
if line == "":
break
elif line[0:5] == 5*blank:
print(line, end="", file=outf)
elif line.find("COMMENT") >= 0:
print(line, end="", file=outf)
else:
# Refactoring epoch format to 3.04
year = int(line[ 0 : 3])
month = int(line[ 0+3 : 3+3])
day = int(line[ 0+3+3 : 3+3+3])
hour = int(line[ 0+3+3+3 : 3+3+3+3])
minute = int(line[ 0+3+3+3+3 : 3+3+3+3+3])
second = float(line[ 0+3+3+3+3+3 : 3+3+3+3+3+11])
e_flag = int(line[ 0+3+3+3+3+3+11 : 3+3+3+3+3+11+3])
satnum = int(line[ 0+3+3+3+3+3+11+3: 3+3+3+3+3+11+3+3])
sPRN = []
lineo = ">" + blank + "%4d %02d %02d %02d %02d %10.7f %2d %2d\n"\
%(year+2000, month, day, hour, minute, second, e_flag, satnum)
print(lineo, end="", file=outf)
count0 = 0 # The line counters
count1 = 0 # The total counters
while 1:
sPRN.append(line[32+3*count0:32+3*(count0+1)].replace(blank,"0"))
count0 += 1
count1 += 1
if count1 == satnum:
break
if count0 % 12 == 0:
count0 = 0
line = f.readline()
# #
# #
# #
#Refactoring data format to 3.04
count = 0
while 1:
if obsnum <= 5:
line = f.readline()
line = sPRN[count] + line
elif obsnum > 5:
count1 = 0
lineo =""
while 1:
line = f.readline()
lineo += line.replace("\n", "").replace("\r", "")
if len(lineo) % 16 == 15:
lineo += blank
if len(lineo) % 16 == 14:
lineo += 2*blank
if len(line) < 80:
lineo += (5 - int(len(lineo)/16))*16*blank
count1 += 1
if count1 == math.ceil(obsnum/5):
line = sPRN[count] + lineo +"\n"
break
print(line, end="", file=outf)
count += 1
if count == satnum:
break
outf.close()
f.close()
return 1
def ReadObsVersion(ofile_path, out_directory):
obsfile = None
# Get the obs file name---------------------------#
obspath = len(ofile_path)
while obspath > 0:
flag = ofile_path[obspath - 1:obspath]
if flag == "/":
obsfile = ofile_path[obspath:]
break
obspath -= 1
if out_directory == '':
# Get the file's father folder-------------------#
pathlon = len(ofile_path)
while pathlon - 3 > 0:
flag = ofile_path[pathlon - 3 - 1:pathlon - 3]
if flag == "/":
out_directory = ofile_path[:pathlon - 3] + "COV-" + obsfile
break
pathlon -= 1
# -----------------------------------------------#
else:
out_directory += "COV-" + obsfile
with open(ofile_path, 'r') as f:
while 1:
line = f.readline()
if line.find("RINEX VERSION / TYPE") >= 0:
version = float(line[ 5: 9])
system = line[40:41]
f.close()
if version > 2.11:
return 0
return ConvertObsVersion(ofile_path, out_directory, version, system)
else:
return 0