Modify project file structure

This commit is contained in:
KenanZhu111 committed 2025-01-09 14:13:24 +08:00
1 parent 26e95e7e39
commit a00aeda756
3 files changed

No files matched your search

+775
View File
@@ -0,0 +1,775 @@
# @ File : KNZ_Convert.py
#
# @ Brief : GUI main functions.
#
# Copyright (c) 2024 - 2024 KenanZhu. All Right Reserved.
#
# @ Author : KenanZhu
# @ Time stamp : [2024/11/13] First release.
# @ IDE : PyCharm
#
# ----------------------------------------------------------------------------------------
# ---SELPORT--- #
import rnx_convert as conv
# ---STDPORT--- #
import queue
import threading
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk
from base64 import b64decode
from tkinter import filedialog
# ------------- #
# global const
InPaths = []
# io oath combox index
I_Box_Counter=0
O_Box_Counter=0
# io format list & index
I_Format_Rnx_List=0
I_RINEX_BoxList=['2','3']
O_Format_Rnx_List=0
O_RINEX_BoxList=['2.10','2.11','2.12','3.00','3.01','3.02','3.03','3.04','3.05']
# ------------------------------------------------------------------------------------- #
def instanceOPT(parenthwnd, func):
OPTIONS(parenthwnd, func)
class CALLBACK:
@staticmethod
def Get_I_File(File_I_Box):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global I_Box_Counter
path = filedialog.askopenfilename(
title='RINEX OBS File',
filetypes=[('RINEX OBS File(*.o*.*.*obs.*.*d)', '*.*o;*.*obs;*.*d'),
('All Files', '*.*')]
)
if path and path not in File_I_Box['value']:
File_I_Box['value'] += (path,)
I_Box_Counter += 1
File_I_Box.current(I_Box_Counter)
@staticmethod
def Get_I_Files(Files_I_ShowText):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global InPaths
paths = filedialog.askopenfilenames(
title='RINEX OBS File',
filetypes=[('RINEX OBS File(*.o*.*.*obs.*.*d)', '*.*o;*.*obs;*.*d'),
('All Files', '*.*')]
)
for path in paths:
if path and path not in InPaths:
InPaths.append(path)
Files_I_ShowText.delete('1.0', 'end')
for path in InPaths:
Files_I_ShowText.insert('end', path + '\n')
@staticmethod
def Clear_I_Files(Files_I_ShowText):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global InPaths
InPaths.clear()
Files_I_ShowText.delete('1.0', 'end')
@staticmethod
def Get_O_Dir(File_O_Box):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global O_Box_Counter
path = filedialog.askdirectory()
if path and path not in File_O_Box['value']:
File_O_Box['value'] += (path + '/',)
O_Box_Counter += 1
File_O_Box.current(O_Box_Counter)
@staticmethod
def Enable_YN(File_O_ynVar, File_O_Box, File_O_Button):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
if File_O_ynVar.get() == 0:
File_O_Box.config(state=tk.DISABLED)
File_O_Button.config(state=tk.DISABLED)
else:
File_O_Box.config(state=tk.NORMAL)
File_O_Button.config(state=tk.NORMAL)
def Dir_or_name_get(self, path, mode):
# -------------------------------------------------------------------------------
# >
# Method: Dir_or_name_get
# Brief : Get the filedir or filename form path
# Param : path : file path
# mode : 0==get file name & 1==get file dir
# Return: mode==0 return filename,mode==1 return file dir
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global nameend, filename, filedir
match mode:
case 0:
path_len = len(path)
while path_len > 0:
sig = path[path_len - 1:path_len]
if sig == '\\' or sig == '/':
filename = path[path_len:]
return filename
path_len -= 1
case 1:
path_len = len(path)
while path_len > 0:
sig = path[path_len - 1:path_len]
if sig == '\\' or sig == '/':
filedir = path[:path_len]
return filedir
path_len -= 1
def Convert(self,
Pro_style, File_O_ynVar, File_I_BoxVar, File_O_BoxVar, Convertcards, Exec_Progress):
# -------------------------------------------------------------------------------
# >
# Method:
# Brief :
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global InPaths
Counter=0
State_O=0
InPath=[]
ErrorMsg=''
OutDirec=''
out_path=''
Pro_style.configure(
'text.Horizontal.TProgressbar',
text='Converting...')
Exec_Progress.config(value=0)
if Convertcards.index('current')==0:
if not File_I_BoxVar.get(): ErrorMsg+=' path'
else: InPath.append(File_I_BoxVar.get())
elif Convertcards.index('current')==1:
if not InPaths: ErrorMsg+=' path'
else: InPath=InPaths.copy()
if File_O_BoxVar.get(): OutDirec = File_O_BoxVar.get()
if not File_O_BoxVar.get():
if File_O_ynVar.get(): ErrorMsg+=' directory'
else : pass
if ErrorMsg:
ErrorMsg='Error : no'+ErrorMsg+' !'
Exec_Progress.config(value=0)
Pro_style.configure('text.Horizontal.TProgressbar', text=ErrorMsg)
return
#
resqueue=queue.Queue()
Pro_style.configure(
'text.Horizontal.TProgressbar',
text='Converting...')
for in_path in InPath:
if OutDirec:
out_path=OutDirec+'COV-'+self.Dir_or_name_get(in_path,0)
if not OutDirec:
out_path=(self.Dir_or_name_get(in_path,1)+'COV-'+
self.Dir_or_name_get(in_path,0))
State_O+=conv._Convert_Un(in_path,
out_path,
I_RINEX_BoxList[I_Format_Rnx_List],
O_RINEX_BoxList[O_Format_Rnx_List],
resqueue)
Counter+=1
Exec_Progress.config(value=int(Counter*100/len(InPath)))
Pro_style.configure(
'text.Horizontal.TProgressbar',
text='Converting...%d/%d'%(Counter, len(InPath)))
if State_O<=len(InPath):
#Exec_Progress.config(value=0)
Pro_style.configure(
'text.Horizontal.TProgressbar',
text='Complete ! %d successful. %d fails.'%(State_O, len(InPath)-State_O))
def _Convert(self,
Pro_style, File_O_ynVar, File_I_BoxVar, File_O_BoxVar, Convertcards, Exec_Progress):
T=threading.Thread(target=lambda :
self.Convert(Pro_style, File_O_ynVar, File_I_BoxVar, File_O_BoxVar, Convertcards, Exec_Progress))
T.start()
@staticmethod
def Move_center(hwnd, win_x, win_y):
# -------------------------------------------------------------------------------
# >
# Method: Move_Ccenter
# Brief : Move the window to the center of screen.
# Param : hwnd : instance handle of window
# win_x: the x size of window
# win_y: the y size of window
# Return: none
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
position_x = int((hwnd.winfo_screenwidth() - win_x) / 2)
position_y = int((hwnd.winfo_screenheight() - win_y) / 2)
hwnd.geometry(f'{win_x}x{win_y}+{position_x}+{position_y}')
# noinspection PyProtectedMember
class MAINGUI:
def __init__(self, hwnd, func):
# init
# -------------------------------------------------------------------------------
self.hwnd=hwnd
self.func=func
self.Pro_style=None
self.ExecFrame=None
self.BatchFrame=None
self.SingleFrame=None
self.Convertcards=None
self.Exec_Progress=None
self.File_O_ynVar=tk.IntVar()
self.File_I_BoxVar=tk.StringVar()
self.File_O_BoxVar=tk.StringVar()
self.iconoptions=(b'AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOrq6v/q6ur/6urq/+rq6'
b'v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v+CgoL/dnZ2/1RUVP9UVFT/VFRU'
b'/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/3Z2dv+CgoL/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P'
b'/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/'
b'6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/4KCgv92dnb/VFRU/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP9'
b'UVFT/VFRU/1RUVP9UVFT/dnZ2/4KCgv/Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8'
b'PDw//Dw8P/w8PD/8PDw//Dw8P/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6urqGAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAADq6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+r'
b'q6v/q6ur/goKC/3Z2dv9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP92dnb/go'
b'KC/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw/8AA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAP//'
b'AAAAAAAAAAAAAAAAAAD//wAA//8AAAAAAAAAAAAAAAAAAP//AAD/fwAAAAAAAAAAAAAAAAAA//8AAA==')
self.iconoptions=b64decode(self.iconoptions)
self.iconoptions=ImageTk.PhotoImage(data=self.iconoptions)
self.initGUI()
def initGUI(self):
# -------------------------------------------------------------------------------
# >
# Method: initGUI
# Brief : init of main gui
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.hwnd.title("KNZ_Convert")
self.func.Move_center(self.hwnd, 400, 243)
self.hwnd.maxsize( 1000, 243)
self.hwnd.minsize( 400, 243)
#
icon_ico = (b'AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAADjsAAA47AAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAA'
b'AAAAAAAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAA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AAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAA////////////////QAGAApf0L+lAAYACgAAAAYAAAAGAAAABhdALoYQQCCGF0AghhAmQIYSpmGGEAAAhhA'
b'AAIYQAACGEAAAhhKmYYYQJkCGF0AghhBAIIYXQC6GAAAABgAAAAYAAAAFAAYACl/Qv6UABgAL///////////////8=')
icon_ico = b64decode(icon_ico)
icon_ico = ImageTk.PhotoImage(data=icon_ico)
self.hwnd.tk.call('wm', 'iconphoto', self.hwnd._w, icon_ico)
#
self.initCONVERT()
#
self.initExecCtrl()
#
self.hwnd.protocol('WM_DELETE_WINDOW',self.hwnd.quit)
self.hwnd.mainloop()
def initCONVERT(self):
# -------------------------------------------------------------------------------
# >
# Method: initCONVERT
# Brief : init of convert gui
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.Convertcards=tk.ttk.Notebook(self.hwnd)
# Single convert
# -------------------------------------------------------------------------------
self.SingleConv()
self.Convertcards.add(self.SingleFrame, text='Single Convert')
# Batch convert
# -------------------------------------------------------------------------------
self.BatchConv()
self.Convertcards.add(self.BatchFrame, text='Batch Convert')
self.Convertcards.pack(side=tk.TOP, fill=tk.BOTH, expand=True, padx='0px', pady='0px')
def SingleConv(self):
# -------------------------------------------------------------------------------
# >
# Method: SingleConv
# Brief : Contrls of single convert
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.SingleFrame=ttk.Frame(self.hwnd)
# Initialize of input frame
File_I_Frame=tk.LabelFrame(
self.SingleFrame,
text='Object Observation of RINEX')
File_I_Frame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='0px')
# Initialize of input box
File_I_Box=ttk.Combobox(
File_I_Frame,
width=47,
height=4,
values=('',),
textvariable=self.File_I_BoxVar)
File_I_Box.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES, anchor='w', padx='1px', pady='1px')
# Initialize of input Button
File_I_Bbutton=ttk.Button(
File_I_Frame,
text='...',
width=3,
command=lambda :self.func.Get_I_File(File_I_Box))
File_I_Bbutton.pack(side=tk.RIGHT, anchor='e', padx='1px', pady='1px')
def BatchConv(self):
# -------------------------------------------------------------------------------
# >
# Method: BatchConv
# Brief : Contrls of batch convert
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.BatchFrame=ttk.Frame(self.hwnd)
#
Files_I_Frame=tk.LabelFrame(
self.BatchFrame,
text='Objects Observation of RINEX')
Files_I_Frame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='0px')
#
Files_I_CtrlFrame=ttk.Frame(Files_I_Frame)
Files_I_CtrlFrame.pack(side=tk.RIGHT, fill=tk.Y, anchor='e', padx='1px', pady='1px')
#
Files_I_CtrlInput=ttk.Button(
Files_I_CtrlFrame,
text='...',
width=3,
command=lambda :self.func.Get_I_Files(Files_I_ShowText))
Files_I_CtrlInput.pack(side=tk.TOP, anchor='e', padx='1px', pady='1px')
Files_I_CtrlClear=ttk.Button(
Files_I_CtrlFrame,
text='x',
width=3,
command=lambda :self.func.Clear_I_Files(Files_I_ShowText))
Files_I_CtrlClear.pack(side=tk.BOTTOM, anchor='e', padx='1px', pady='1px')
#
Files_I_ShowFrame=ttk.Frame(Files_I_Frame)
Files_I_ShowFrame.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES, anchor='e', padx='1px', pady='1px')
#
ScrollbarX=ttk.Scrollbar(Files_I_ShowFrame,orient=tk.HORIZONTAL)
ScrollbarX.pack(side=tk.BOTTOM, fill=tk.X)
ScrollbarY=ttk.Scrollbar(Files_I_ShowFrame)
ScrollbarY.pack(side=tk.RIGHT, fill=tk.Y)
#
Files_I_ShowText=tk.Text(
Files_I_ShowFrame,
xscrollcommand=ScrollbarX.set,
yscrollcommand=ScrollbarY.set,
height=4, wrap='none', font=('Segoe UI',9))
Files_I_ShowText.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES, anchor='w', padx='1px', pady='1px')
ScrollbarX.config(command=Files_I_ShowText.xview)
ScrollbarY.config(command=Files_I_ShowText.yview)
def initExecCtrl(self):
# -------------------------------------------------------------------------------
# >
# Method: initExecCtrl
# Brief : init of contrls
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.ExecFrame=ttk.Frame(self.hwnd)
self.ExecFrame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='0px')
#
# -------------------------------------------------------------------------------
self.ConvOut()
#
# -------------------------------------------------------------------------------
self.ExecCtrl()
def ConvOut(self):
# -------------------------------------------------------------------------------
# >
# Method: ConvOut
# Brief : Contrls of output
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
###
File_O_Frame=tk.LabelFrame(
self.ExecFrame,
text='Output directory')
File_O_Frame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='1px')
#
File_O_yn=ttk.Checkbutton(
File_O_Frame,
text='Directory',
variable=self.File_O_ynVar,
onvalue=1,
offvalue=0,
command=lambda :self.func.Enable_YN(
self.File_O_ynVar,
File_O_Box,
File_O_Button))
File_O_yn.pack(side=tk.LEFT, anchor='w', padx='1px', pady='0px')
#
File_O_Box=ttk.Combobox(
File_O_Frame,
width=36,
height=4,
values=('',),
state=tk.DISABLED,
textvariable=self.File_O_BoxVar)
File_O_Box.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES, anchor='w', padx='1px', pady='0px')
#
File_O_Button=ttk.Button(
File_O_Frame,
text='...',
width=3,
state=tk.DISABLED,
command=lambda :self.func.Get_O_Dir(File_O_Box))
File_O_Button.pack(side=tk.RIGHT, anchor='e', padx='1px', pady='0px')
def ExecCtrl(self):
# -------------------------------------------------------------------------------
# >
# Method: ExecCtrl
# Brief : Contrls of exe
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
CtrlButtonFrame=ttk.Frame(self.ExecFrame)
CtrlButtonFrame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='0px')
Conv_Option = ttk.Button(
CtrlButtonFrame,
image=self.iconoptions,
width=3,
command=lambda :instanceOPT(self.hwnd,self.func)
)
Conv_Option.pack(side=tk.RIGHT, padx='1px', pady='0px')
#
Conv_Button=ttk.Button(
CtrlButtonFrame,
text='Convert',
width=10,
command=lambda :self.func._Convert(
self.Pro_style,
self.File_O_ynVar,
self.File_I_BoxVar,
self.File_O_BoxVar,
self.Convertcards,
self.Exec_Progress))
Conv_Button.pack(side=tk.RIGHT, padx='1px', pady='0px')
#
Exit_button=ttk.Button(
CtrlButtonFrame,
text='Exit',
width=10,
command=self.hwnd.quit)
Exit_button.pack(side=tk.LEFT, padx='1px', pady='0px')
#
StateFrame=ttk.Frame(self.ExecFrame)
StateFrame.pack(side=tk.TOP, fill=tk.X, padx='1px', pady='4px')
self.Pro_style=ttk.Style(StateFrame)
self.Pro_style.layout(
'text.Horizontal.TProgressbar',
[
('Horizontal.Progressbar.trough',
{'children': [('Horizontal.Progressbar.pbar',{'side': 'left', 'sticky': 'ns'})],
'sticky': 'nswe'}
),
('Horizontal.Progressbar.label',{'sticky': ''})
]
)
self.Pro_style.configure(
'text.Horizontal.TProgressbar',
text='No task.',
foreground='#000000',
font=('Segoe UI',9))
self.Exec_Progress=ttk.Progressbar(
StateFrame,
value=0,
length=400,
maximum=100,
mode='determinate',
style='text.Horizontal.TProgressbar')
self.Exec_Progress.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES)
class OPTIONS:
def __init__(self, parenthwnd, func):
# init
# -------------------------------------------------------------------------------
self.func=func
self.parenthwnd=parenthwnd
self.opthwnd=None
self.OptFrame=None
self.ExeFrame=None
self.MainFrame=None
self.I_RINEX_Box=None
self.O_RINEX_Box=None
self.initGUI()
def initGUI(self):
# -------------------------------------------------------------------------------
# >
# Method: initGUI
# Brief : init of main gui
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.opthwnd=tk.Toplevel(self.parenthwnd)
self.opthwnd.title("Options")
self.opthwnd.resizable(0, 0)
self.func.Move_center(self.opthwnd, 310, 110)
# Set icon
icon_ico=(b'AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOrq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6'
b'urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v+CgoL/dnZ2/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU/1RUVP9UVFT/VFRU'
b'/1RUVP9UVFT/VFRU/3Z2dv+CgoL/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//Dw8P/w8PD/8PDw//D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'
b'AAAAAAAAAAAAAAAAP//AAD/fwAAAAAAAAAAAAAAAAAA//8AAA==')
icon_ico=b64decode(icon_ico)
icon_ico=ImageTk.PhotoImage(data=icon_ico)
self.opthwnd.tk.call('wm', 'iconphoto', self.opthwnd._w, icon_ico)
# Mian frame
self.MainFrame=ttk.Frame(self.opthwnd)
self.MainFrame.pack()
# init
self.initOPTIONS()
self.initEXECTRL()
def initOPTIONS(self):
# -------------------------------------------------------------------------------
# >
# Method: initOPTIONS
# Brief : Init options of format choose
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.OptFrame=ttk.Frame(self.MainFrame)
self.OptFrame.pack(side=tk.TOP, fill=tk.BOTH)
# -------------------------------------------------------------------------------
# Origin format frame
# -------------------------------------------------------------------------------
I_FormatFrame=tk.LabelFrame(
self.OptFrame,
text='Origin Format')
I_FormatFrame.pack(side=tk.LEFT, expand=tk.YES, padx='2px')
Rnx_I_Frame=ttk.Frame(I_FormatFrame)
Rnx_I_Frame.pack(side=tk.TOP, fill=tk.X, pady='2px', padx='2px')
I_RINEX=ttk.Label(
Rnx_I_Frame,
text='RINEX:',
style='I_RINEX.TLabel')
I_RINEX.pack(side=tk.LEFT)
self.I_RINEX_Box=ttk.Combobox(
Rnx_I_Frame,
width=10,
values=I_RINEX_BoxList)
self.I_RINEX_Box.set(I_RINEX_BoxList[I_Format_Rnx_List])
self.I_RINEX_Box['state']='readonly'
self.I_RINEX_Box.pack(side=tk.RIGHT)
Rtc_I_Frame=ttk.Frame(I_FormatFrame)
Rtc_I_Frame.pack(side=tk.TOP, fill=tk.X, pady='2px', padx='2px')
I_RTCM=ttk.Label(
Rtc_I_Frame,
text='RTCM :',
style='I_RTCM.TLabel')
I_RTCM.pack(side=tk.LEFT)
I_RTCM_BoxList=['2', '3', '4']
I_RTCM_Box=ttk.Combobox(
Rtc_I_Frame,
width=10,
state=tk.DISABLED,
values=I_RTCM_BoxList)
I_RTCM_Box.set(I_RTCM_BoxList[0])
# I_RTCM_Box['state']='readonly'
I_RTCM_Box.pack(side=tk.RIGHT)
# -------------------------------------------------------------------------------
# Target format frame
# -------------------------------------------------------------------------------
O_FormatFrame = tk.LabelFrame(
self.OptFrame,
text='Target Format')
O_FormatFrame.pack(side=tk.RIGHT, expand=tk.YES, padx='2px')
Rnx_O_Frame=ttk.Frame(O_FormatFrame)
Rnx_O_Frame.pack(side=tk.TOP, fill=tk.X, pady='2px', padx='2px')
O_RINEX=ttk.Label(
Rnx_O_Frame,
text='RINEX:',
style='I_RINEX.TLabel')
O_RINEX.pack(side=tk.LEFT)
self.O_RINEX_Box=ttk.Combobox(
Rnx_O_Frame,
width=10,
values=O_RINEX_BoxList)
self.O_RINEX_Box.set(O_RINEX_BoxList[O_Format_Rnx_List])
self.O_RINEX_Box['state']='readonly'
self.O_RINEX_Box.pack(side=tk.RIGHT)
Rtc_O_Frame=ttk.Frame(O_FormatFrame)
Rtc_O_Frame.pack(side=tk.TOP, fill=tk.X, pady='2px', padx='2px')
O_RTCM=ttk.Label(
Rtc_O_Frame,
text='RTCM :',
style='I_RTCM.TLabel')
O_RTCM.pack(side=tk.LEFT)
O_RTCM_BoxList=['2', '3', '4']
O_RTCM_Box=ttk.Combobox(
Rtc_O_Frame,
width=10,
state=tk.DISABLED,
values=O_RTCM_BoxList)
O_RTCM_Box.set(I_RTCM_BoxList[0])
# O_RTCM_Box['state']='readonly'
O_RTCM_Box.pack(side=tk.RIGHT)
def initEXECTRL(self):
# -------------------------------------------------------------------------------
# >
# Method: initEXECTRL
# Brief : Init the gui of contrl frame
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
self.ExeFrame=ttk.Frame(self.MainFrame)
self.ExeFrame.pack(side=tk.TOP, fill=tk.X, pady='2px', padx='2px')
Cancel_Button = ttk.Button(
self.ExeFrame,
text='Cancel',
command=self.opthwnd.destroy)
Cancel_Button.pack(side=tk.LEFT)
Confirm_Button = ttk.Button(
self.ExeFrame,
text='Confirm',
command=lambda :[
self.Get_IO_Format(),
self.opthwnd.destroy()
])
Confirm_Button.pack(side=tk.RIGHT)
def Get_IO_Format(self):
# -------------------------------------------------------------------------------
# >
# Method: Get_IO_Format
# Brief : Get the origin & target file format
# Author: @KenanZhu All Right Reserved.
# -------------------------------------------------------------------------------
global I_Format_Rnx_List, O_Format_Rnx_List
I_Format_Rnx_List=I_RINEX_BoxList.index(self.I_RINEX_Box.get())
O_Format_Rnx_List=O_RINEX_BoxList.index(self.O_RINEX_Box.get())
# Main program entry ---------------------------- #
if __name__ == "__main__":
root=tk.Tk()
call=CALLBACK()
initGUI=MAINGUI(root, call)
+801
View File
@@ -0,0 +1,801 @@
# @ File : rnx_convert.py
#
# @ Brief : RINEX Convert functions.
#
# Copyright (c) 2024 - 2024 KenanZhu. All Right Reserved.
#
# @ Author : KenanZhu
# @ Time stamp : [2024/11/13] First release.
# : [2024/11/14] Correct: convert of observation type of
# 'P1/P2' of GPS is correct into 'C1W/C2W'.
# : [2024/11/15] Fix bug: remove the empty observation of
# RINEX 2.xx format.
# : [2024/11/17] Add new: complish the funtions of convert
# form RINEX 3.xx to RINEX 2.xx and also support
# convert in major version of RINEX.
# : [2024/11/18] Fix bug: correct the bug when Convert RINEX file
# with comment in the middle of data will cause
# crash.
# Correct: correct the mistake in the functions
# below:
# 1. Correct function: getsys_rnx3()
# 2. Correct function: obstype3_conv()
# 3. Correct function: rnx2uni3_data()
# 4. Correct function: rnx2_data2uni()
# 5. Correct function: rnx3rnx2_data()
# Optimze: enhance the speed of converting.
#
#
# @ IDE/Editor : PyCharm / VisualStudio Code
#
# ----------------------------------------------------------------------------------------
# ---STDPORT--- #
import re
import time
import math
import threading
# ------------- #
emp=''
bnk=' '
# Get local time of converting ----------------------- #
def conv_time():
# generate convert timestamp
covpro='KNZ_Convert ver1.2.6'
covcom='COMMENT'
# Get the locate time and transform to Uni-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=('%04d'%y +
'%02d'%m +
'%02d'%d +bnk+
'%02d'%h +
'%02d'%min+
'%02d'%sec+bnk+
'LLC' +bnk)
outline=(covpro +
20*bnk +
localtime+
covcom +
'\n')
return outline
# Convert data format --------------------------- #
def datefmt2_conv(inline):
hou=inline[49:51]
min=inline[52:54]
sec=inline[55:57]
return (inline[0:49] +
hou +
min +
sec +
bnk + "UTC" +
bnk + "PGM / RUN BY / DATE\n")
# Convert data format --------------------------- #
def datefmt3_conv(inline):
hou=inline[49:51]
min=inline[51:53]
sec=inline[53:55]
return (inline[0:49] +
hou + ':' +
min + ':' +
sec +
'UTCPGM / RUN BY / DATE\n')
# Convert observ type of RINEX 2.xx to Uni-format ------------- #
def obsfmt2_conv(obstypes, sys):
counter =0
obstypex=[]
obsbomit=emp
match sys:
case 'G':
for obs in obstypes:
counter+=1
if obs[1:2]=='1':
if obs[0:1]=='P': obs='C1W'
else: obs+='C'
elif obs[1:2]=='2':
if obs[0:1]=='P': obs='C2W'
else: obs+='C'
elif obs[1:2]=='5': obs+='I'
else:
obsbomit+=('%02d'%counter)
continue
obstypex.append(obs)
case 'E':
for obs in obstypes:
counter+=1
if obs[1:2]=='1':
if obs[0:1]=='P':
obsbomit+=('%02d'%counter)
continue
else: obs+='C'
elif obs[1:2]=='5': obs+='I'
elif obs[1:2]=='6': obs+='C'
elif obs[1:2]=='7': obs+='I'
elif obs[1:2]=='8': obs+='I'
else:
obsbomit+=('%02d'%counter)
continue
obstypex.append(obs)
case 'R':
for obs in obstypes:
counter+=1
if obs[1:2]=='1':
if obs[0:1]=='P': obs='C1P'
else: obs+='C'
elif obs[1:2]=='2':
if obs[0:1]=='P': obs='C2P'
else: obs+='C'
else:
obsbomit+=('%02d'%counter)
continue
obstypex.append(obs)
case 'S':
for obs in obstypes:
counter+=1
if obs[1:2]=='1':
if obs[0:1]=='P':
obsbomit+=('%02d'%counter)
continue
else: obs+='C'
elif obs[1:2]=='5': obs+='I'
else:
obsbomit+=('%02d'%counter)
continue
obstypex.append(obs)
obstypex.append(obsbomit)
return obstypex
# Convert observ msg of RINEX 2.xx to Uni-format ---------------- #
def obstype2_conv(inline, in_f, omilist):
# uni-format message label
obsobs='SYS / # / OBS TYPES'
outlines=[]
obstypes=[]
obstypex=[]
system=['G', 'E', 'R', 'S']
obsnum=int(inline[0:6])
omilist.append(obsnum)
for i in range(math.ceil(obsnum/9)):
obstypes.extend(inline[6:60].split())
if i+1==math.ceil(obsnum/9): break
inline = in_f.readline()
for sys in system:
obstypex=obsfmt2_conv(obstypes, sys)
omilist.append(obstypex[-1])
# S___2D_
num =len(obstypex)-1
outline=sys+3*bnk+'%2d'%num+bnk
for i in range(num):
outline+=obstypex[i]+bnk
if (i+1)==num:
bnx=((13-num%13)*4+1)*bnk
if num%13==0: bnx=bnk
outlines.append(outline+bnx+obsobs+'\n')
outline=0*bnk
elif (i+1)%13==0:
outlines.append(outline+bnk+obsobs+'\n')
outline=7*bnk
return outlines
# Generate the convert stamp ------------------------ #
def conv_stamp(inline, outlines, desver):
oriver=inline[ 5: 9]
# generate convert stamp
obscov='COV-OBSERVATION DATA'
obscom='COMMENT'
outlines.append( 5*bnk+
oriver+
'->' +
desver+
1*bnk+
obscov+
24*bnk+
obscom+
'\n')
outlines.append(conv_time())
outlines.append(
inline.replace('%s'%re.search(r'[1-9]\d*.\d*|0\.\d*[1-9]\d*', inline).group(), desver))
return
# Convert RINEX 2.xx(header) to Uni-format -------------- #
def rnx2_head2uni(in_f, desver, outlines, omilist):
# rinex message label
obscom='COMMENT'
obstpe='RINEX VERSION / TYPE'
obsl12='WAVELENGTH FACT L1/2'
obspro='PGM / RUN BY / DATE'
obsobs='# / TYPES OF OBSERV'
obsend='END OF HEADER'
# get input head file & convert
while True:
inline=in_f.readline()
# file is aleady checked so no need to judge again
if not inline: break
if inline.find(obscom)>=0: outlines.append(inline)
elif inline.find(obspro)>=0: outlines.append(datefmt2_conv(inline))
elif inline.find(obsobs)>=0: outlines.extend(obstype2_conv(inline, in_f, omilist))
elif inline.find(obstpe)>=0: conv_stamp(inline, outlines, desver)
elif inline.find(obsl12)>=0: continue
elif inline.find(obsend)>=0: break
else : outlines.append(inline)
# get the end message after break
outlines.append(60*bnk+obsend+'\n')
return 1
# Convert RINEX 2.xx(data) to Uni-Format ------------------- #
def rnx2_data2uni(in_f, outlines, omilist, obsnum):
sPRN=[]
scounter=0
outline=emp
# return false when file end
inline=in_f.readline()
if not inline: return False
if not inline[28:29]=='0':
outlines.append(inline)
for i in range(int(inline[29:32])):
outlines.append(in_f.readline())
return True
# get epoch message & flag state
year = int(inline[0 :3])
month = int(inline[0+3 :3+3])
day = int(inline[0+3+3 :3+3+3])
hour = int(inline[0+3+3+3 :3+3+3+3])
minute= int(inline[0+3+3+3+3 :3+3+3+3+3])
second=float(inline[0+3+3+3+3+3 :3+3+3+3+3+11])
e_flag= int(inline[0+3+3+3+3+3+11 :3+3+3+3+3+11+3])
satnum= int(inline[0+3+3+3+3+3+11+3:3+3+3+3+3+11+3+3])
if not e_flag==0: return True
# time to Uni-Format
outlines.append(
"> %4d %02d %02d %02d %02d %10.7f %2d %2d\n" \
% (year + 2000, month, day, hour, minute, second, e_flag, satnum))
# get list of sPRN
for i in range(math.ceil(satnum/12)):
if not i==0 : inline =in_f.readline()
if i+1< math.ceil(satnum/12): scounter=12
if i+1==math.ceil(satnum/12): scounter=satnum-i*12
for j in range(scounter):
sPRN.append(inline[32+3*j:32+3*(j+1)].replace(bnk,'0'))
# convert epoch data to Uni-Format
for i in range(satnum):
oulist=[]
outline=emp
# get omit list
match sPRN[i][0:1]:
case 'G': omitlis=omilist[0]
case 'E': omitlis=omilist[1]
case 'R': omitlis=omilist[2]
case 'S': omitlis=omilist[3]
# observ amount lower than 5. no need to enter
if obsnum <= 5:
outline=in_f.readline()
outline=inline.replace('\n',emp).replace('\r',emp)
# elif, need to enter
elif obsnum > 5:
for j in range(math.ceil(obsnum/5)):
inline=in_f.readline()
outline+=inline.replace('\n',emp).replace('\r',emp)
if len(outline)%16==15: outline+=bnk
if len(outline)%16==14: outline+=2*bnk
outline+=(5 - int(len(outline)/16))*16*bnk
# omit the empty observ by ''
# outline be divide into parts
for j in range(obsnum):
oulist.append(outline[16*j:16*j+16])
for j in range(len(omitlis)):
oulist[omitlis[j]-1]=emp
# remerge into outline
outline=emp.join(oulist)
outlines.append(sPRN[i]+outline+"\n")
return True
# Convert Uni-format to RINEX 3.xx --------------------- #
def uni2rnx3_data(outlines, out_f):
out_f.writelines(outlines)
return
# Get observ type need be omitted --------------------- #
def getomit(omilist):
for i in range(len(omilist)):
sysomit=[]
omitlis=omilist[0]
omitnum=len(omitlis)/2
for j in range(int(omitnum)):
sysomit.append(int(omitlis[j*2+0:j*2+2]))
omilist.append(sysomit)
omilist.pop(0)
return
# Convert RINEX 2.xx to Des-format --------------------- #
def rnx2des(in_path, out_path, oriver, desver):
headread=False
outlines=[]
omilist=[]
in_f=open(in_path, 'r')
out_f=open(out_path, 'a')
# convert RINEX 2.xx(header) to Uni-format
match rnx2_head2uni(in_f, desver, outlines, omilist):
case 1: headread=True
case 0: headread=False
if headread:
# convert Uni-foramt(header) to Des-format
match desver[0:1]:
case '2': addemp=uni2rnx2_data(4, outlines, out_f, True, None)
case '3': uni2rnx3_data(outlines, out_f)
outlines=[]
# get each observ type and omit the empty
obsnum=omilist[0]
omilist.pop(0)
getomit(omilist)
# convert RINEX 2.xx(data) to Uni-format
while rnx2_data2uni(in_f, outlines, omilist, obsnum):
# convert Uni-foramt(data) to Des-format
match desver[0:1]:
case '2': uni2rnx2_data(4, outlines, out_f, False, addemp)
case '3': uni2rnx3_data(outlines, out_f)
outlines=[]
elif not headread: return 0
in_f.close()
out_f.close()
return 1
# Get the position of new add observ type ----------------- #
def getaddemp(alltypes, sysstype):
addemp=[[],[],[],[]]
for i in range(len(sysstype)):
for j in range(len(sysstype[i])):
for k in range(len(alltypes)):
if sysstype[i][j]==alltypes[k]:
addemp[i].append(k)
return addemp
# Filter the same obs fmt in RINEX 2.xx ----------------- #
def obsfmt_filter(alltypes):
empemp=[]
spos=npos=0
empemp.append(len(alltypes))
while True:
npos+=1
if spos==empemp[0]: break
if npos==empemp[0]:
spos+=1
npos=spos
continue
if not alltypes[spos]: continue
if not alltypes[npos]: continue
if alltypes[spos]==alltypes[npos]:
alltypes[npos]=emp
empemp.append(npos)
# restruct the data
totnum=empemp[0]
empemp=sorted(empemp[1:])
empemp.insert(0,totnum)
empemp.clear()
# addemp.append(empemp)
# clear the empty
alltypes=[obs for obs in alltypes if obs!=emp]
return alltypes
# Sort by observ type --------------------------- #
def sort_observ(alltypes):
alltypex=[]
temtypes=[]
freindex=['1','2','3','4',
'5','6','7','8']
obsetype=['C','L','D','S']
for type in alltypes:
freidx=freindex.index(type[1:2])/ 1
if type=='P1C' or type=='P2C':
tyeidx=obsetype.index(type[2:3])/10
else:
tyeidx=obsetype.index(type[0:1])/10
alltypex.append(freidx+tyeidx)
sdx=ndx=0
while True:
if len(alltypex)==0:
break
if (ndx+1)==len(alltypex):
temtypes.append(alltypes[sdx])
alltypes.pop(sdx)
alltypex.pop(sdx)
sdx=ndx=0
continue
ndx+=1
if alltypex[ndx]<=alltypex[sdx]:
sdx=ndx
continue
return temtypes
# Convert observ type of RINEX 3.xx to Uni-Format --------------- #
def obsfmt3_conv(alltypes):
alltypex=[]
for type in alltypes:
if type[1:2]=='1':
if type=='C1W': type='P1'
elif type[1:2]=='2':
if type=='C2W': type='P2'
else: pass
alltypex.append(type[0:2])
return alltypex
# Convert observ msg of RINEX 3.xx to Uni-Format ---------------- #
def obstype3_conv(i, sysnum, outlines, outlinex):
alltypes=[]
obstypes=[]
sysstype=[[],[],[],[]]
# rinex message label
obsobs='# / TYPES OF OBSERV'
for j in range(sysnum):
obstypes=[]
# reject system not support in Uni-Format
match outlines[i][0:1]:
case 'G': obstypes.append(0)
case 'E': obstypes.append(1)
case 'R': obstypes.append(2)
case 'S': obstypes.append(3)
case 'C':
i+=math.ceil(int(outlines[i][1:6])/13)
continue
case 'I':
i+=math.ceil(int(outlines[i][1:6])/13)
continue
case 'J':
i+=math.ceil(int(outlines[i][1:6])/13)
continue
case _:
i+=1
continue
obsnum=int(outlines[i][1:6])
for k in range(math.ceil(obsnum/13)):
obstypes.extend(outlines[i][6:60].split())
if k+1==math.ceil(obsnum/13): break
i+=1
# check the differ observ type in glonass
if obstypes[0]==2:
try:
pos=obstypes.index('C1P')
obstypes[pos]='P1C'
except ValueError: pass
try:
pos=obstypes.index('C2P')
obstypes[pos]='P2C'
except ValueError: pass
sysstype[obstypes[0]]=obsfmt3_conv(obstypes[1:])
alltypes=list(set(obstypes[1:]+alltypes))
i+=1
# sort observ types
alltypes=sort_observ(alltypes)
# convert observ type into des-format
alltypes=obsfmt3_conv(alltypes)
# fliter the same observ type
alltypes=obsfmt_filter(alltypes)
# get new added pos
addemp=getaddemp(alltypes, sysstype)
num =len(alltypes)
outline=4*bnk+'%2d'%num
for j in range(num):
outline+=4*bnk+alltypes[j]
if (j+1)==num:
bnx=((9-num%9)*6)*bnk
if num%9==0: bnx=emp
outlinex.append(outline+bnx+obsobs+'\n')
outline=0*bnk
elif (j+1)%9==0:
bnx=0*bnk
outlinex.append(outline+bnx+obsobs+'\n')
outline=6*bnk
# get amout of observ tyeps
addemp.append(num)
return addemp
# Get the total amount of sat system -------------------- #
def getsys_rnx3(in_f):
# rinex message label
obsobs='SYS / # / OBS TYPES'
readst=False
syslis=[]
sysnum=0
while True:
inline=in_f.readline()
if not inline: break
if inline.find(obsobs)>=0:
readst=True
sys=inline[0:1]
if sys==bnk: continue
if sys not in syslis:
syslis.append(sys)
sysnum+=1
elif readst and inline.find(obsobs)<0: break
in_f.seek(0)
return sysnum
# Convert head_data of RINEX 3.xx to Uni-format -------------- #
def rnx3_head2uni(in_f, desver, outlines):
# rinex message label
# obscom='COMMENT'
obstpe='RINEX VERSION / TYPE'
# obspro='PGM / RUN BY / DATE'
# obsobs='SYS / # / OBS TYPES'
obsshi='SYS / PHASE SHIFT'
obsrsb='GLONASS COD/PHS/BIS'
obsrsl='GLONASS SLOT / FRQ #'
obsend='END OF HEADER'
# get input head file & convert
while True:
inline=in_f.readline()
# file is aleady checked so no need to judge again
if not inline: break
#if inline.find(obscom)>=0: outlines.append(inline)
#elif inline.find(obspro)>=0: outlines.append(inline)
#elif inline.find(obsobs)>=0: outlines.append(inline)
elif inline.find(obstpe)>=0: conv_stamp(inline, outlines, desver)
elif inline.find(obsshi)>=0: continue
elif inline.find(obsrsb)>=0: continue
elif inline.find(obsrsl)>=0: continue
elif inline.find(obsend)>=0: break
else : outlines.append(inline)
# get the end message after break
outlines.append(60*bnk+obsend+'\n')
return 1
# Convert obs of RINEX 3.xx to Uni-format ------------------- #
def rnx2uni3_data(outlines, in_f):
inline=in_f.readline()
if not inline: return False
if not inline[0:1]=='>': return True
if not int(inline[30:32])==0: return True
outlines.append(inline)
satnum=int(inline[33:35])
for i in range(satnum):
outlines.append(in_f.readline())
return True
# Convert RINEX 3.xx(epoch msg) to RINEX 2.xx --------------- #
def rnx3rnx2_epo(outline, sPRN):
outlines=[]
datedat=outline.split()
# omit data when flag !=0
if not int(datedat[7])==0: return outlines
outline=(
'%3d%3d%3d%3d%3d%11.7f%3d%3d'
%(int(datedat[1])-2000,int(datedat[2]), int(datedat[3]),# |year |month |day
int(datedat[4]) ,int(datedat[5]),float(datedat[6]),# |hour |minute |second
int(datedat[7]) ,len(sPRN))) # |flag |satnum |
# convert to RINEX 2.xx
satnum=len(sPRN)
for i in range(satnum):
outline+=sPRN[i]
if (i+1)==len(sPRN):
outlines.append(outline+'\n')
elif (i+1)%12==0:
outlines.append(outline+'\n')
outline=32*bnk
return outlines
# Convert RINEX 3.xx(data of each sat) to RINEX 2.xx ------------ #
def rnx3rnx2_dat(addemp, obsnum, outline):
outlines=[]
num=range(len(addemp))
empdat=16*bnk
outlinx=[empdat for i in range(obsnum)]
for i,j in zip(num,addemp):
if not outlinx[j]==empdat: continue
if outline[i*16+3:i*16+16+3]:
outlinx[j]=outline[i*16+3:i*16+16+3]\
.replace('\n',2*bnk).replace('\r',2*bnk)
else: continue
outline=emp
for i in range(len(outlinx)):
outline+=outlinx[i]
for i in range(math.ceil(len(outline)/80)):
outlines.append(outline[i*80:i*80+80]+'\n')
return outlines
# Convert RINEX 3.xx to RINEX 2.xx --------------------- #
def rnx3rnx2_data(outlines, addemp):
sPRN=[]
datline=[]
outlinex=[]
# filter the sat system ecxcept:#
# ---GPS-Galileo-GLONASS-SBAS---#
for i in range(len(outlines)):
if outlines[i][0:1]=='G': pass
elif outlines[i][0:1]=='E': pass
elif outlines[i][0:1]=='R': pass
elif outlines[i][0:1]=='S': pass
else: continue
datline.append(i)
sPRN.append(outlines[i][0:3])
outlinex.extend(rnx3rnx2_epo(outlines[0], sPRN))
for i in datline:
if outlines[i][0:1]=='G': idx=0
elif outlines[i][0:1]=='E': idx=1
elif outlines[i][0:1]=='R': idx=2
elif outlines[i][0:1]=='S': idx=3
else: continue
outlinex.extend(rnx3rnx2_dat(addemp[idx], addemp[4], outlines[i]))
return outlinex
# Convert Uni-format to RINEX 2.xx --------------------- #
def uni2rnx2_data(sysnum, outlines, out_f, headordata, add_emp):
# rinex message label
obspro='PGM / RUN BY / DATE'
obsobs='SYS / # / OBS TYPES'
obsend='END OF HEADER'
outlinex=[]
obsread=False
# convert Uni-format to RINEX 2.xx(header)
if headordata:
for i in range(len(outlines)):
if outlines[i].find(obspro)>=0: outlinex.append(datefmt3_conv(outlines[i]))
elif outlines[i].find(obsobs)>=0:
if not obsread:
obsread=True
addemp=obstype3_conv(i, sysnum, outlines, outlinex)
else: continue
elif outlines[i].find(obsend)>=0: outlinex.append(outlines[i])
else:outlinex.append(outlines[i])
# convert Uni-format to RINEX 2.xx(data)
elif not headordata:
if not outlines: return 0
outlinex=rnx3rnx2_data(outlines, add_emp)
# output to destination file
out_f.writelines(outlinex)
if headordata: return addemp
elif not headordata: return 0
# Convert data of RINEX 3.xx to Des-format ----------------- #
def rnx3des(in_path, out_path, oriver, desver):
headread=False
outlines=[]
in_f=open(in_path, 'r')
out_f=open(out_path, 'a')
# get the amount of sat system
sysnum=getsys_rnx3(in_f)
# convert RINEX 3.xx(header) to Uni-format
match rnx3_head2uni(in_f, desver, outlines):
case 1: headread=True
case 0: headread=False
# convert Uni-foramt(header) to Des-format
if headread:
match desver[0:1]:
case '2': addemp=uni2rnx2_data(sysnum, outlines, out_f, True, None)
case '3': uni2rnx3_data(outlines, out_f)
outlines=[]
# convert RINEX 3.xx(data) to Uni-format
while rnx2uni3_data(outlines, in_f):
# convert Uni-foramt(data) to Des-format
match desver[0:1]:
case '2': uni2rnx2_data(sysnum, outlines, out_f, False, addemp)
case '3': uni2rnx3_data(outlines, out_f)
outlines=[]
elif not headread: return 0
in_f.close()
out_f.close()
return 1
# Reject data of invaild input ----------------------- #
def rnx_reject(in_path, out_path, oriver):
# rinex message label
obstpe='RINEX VERSION / TYPE'
obsmsg='OBSERVATION DATA'
obsend='END OF HEADER'
# reject cause cant input file
try:
with open(in_path, 'r'): pass
except FileNotFoundError: return 0
# reject wrong format or version
in_f=open(in_path, 'r')
while True:
inline=in_f.readline()
if not inline: return 0
if inline.find(obstpe)>=0:
if not inline.find(obsmsg)>=0: return 0
if not inline[ 5: 6]==oriver : return 0
elif inline.find(obsend)>=0: break
# reject cause cant output file
try:
with open(out_path, 'w'): pass
except PermissionError: return 0
return 1
# ---------------------------------------------------------------------------------------
# CONVERT FUNCTION
#
# Brief :Determine the file format and assign handlers
# Return :
# queue msg==0: fail.
# queue msg==1: ok.
# ---------------------------------------------------------------------------------------
def Convert_Un(in_path, out_path, oriver, desver, resqueue):
file_state=False
match rnx_reject(in_path, out_path, oriver):
case 1: file_state=True
case 0: file_state=False
if file_state:
match oriver:
case '2': rnx2des(in_path, out_path, oriver, desver)
case '3': rnx3des(in_path, out_path, oriver, desver)
else : return resqueue.put(0)
return resqueue.put(1)
# Multi-threading task --------------------------- #
def _Convert_Un(in_path, out_path, oriver, desver, resqueue):
T=threading.Thread(
target=lambda :Convert_Un(in_path, out_path, oriver, desver, resqueue)
)
T.start()
T.join()
return resqueue.get()
+18
View File
@@ -0,0 +1,18 @@
# @ File : rtcm_convert.py.py
#
# Copyright (c) 2024 - 2024 KenanZhu. All Right Reserved.
#
# @ Author : KenanZhu
# @ Time : 2024/11/16
# @ Brief :
# :
# @ IDE : PyCharm
#
# ----------------------------------------------------------------------------------------
# ---SELPORT--- #
# ---STDPORT--- #
# ------------- #
def Convert_Un():
return 0