diff --git a/.gitignore b/.gitignore index a50ae45..be736c0 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,9 @@ env /geodepy/XVSOLFIN_20220115.SNX.AUS /geodepy/XVSOLFIN_20220115.SNX /geodepy/REDX.SNX +/geodepy/splitApref.py +/geodepy/SNXEPO.SNX +/geodepy/exciseStationsNGCA.py +/geodepy/XVSOLFIN_20220326.SNX +/geodepy/exciseStationsAPREF.py +/geodepy/gda2020.dat diff --git a/geodepy/gnss.py b/geodepy/gnss.py index fdcc175..43146a8 100644 --- a/geodepy/gnss.py +++ b/geodepy/gnss.py @@ -7,9 +7,74 @@ In Development """ +import sys +from datetime import datetime from numpy import zeros from geodepy.angles import DMSAngle -import sys + + +def list_sinex_blocks(file): + """This script lists the blocks in a SINEX file + + :param str file: the input SINEX file + """ + blocks = [] + with open(file) as f: + for line in f.readlines(): + if line.startswith('+'): + col = line.split(' ') + block = col[0].replace('+', '') + blocks.append(block.strip()) + for block in blocks: + print(block) + + +def print_sinex_comments(file): + """This script lists prints comments in a SINEX file + + :param str file: the input SINEX file + """ + go = False + with open(file) as f: + for line in f.readlines(): + if line.startswith('+FILE/COMMENT'): + go = True + if go: + print(line.strip()) + if line.startswith('-FILE/COMMENT'): + go = False + +def set_creation_time(): + """This function sets the creation time, in format YY:DDD:SSSSS, for use + in the SINEX header line + + :return: creation_time + :rtype: str + """ + now = datetime.now() + time_tup = now.timetuple() + year = str(time_tup.tm_year)[2:] + doy = time_tup.tm_yday + doy = '{:03d}'.format(doy) + seconds = (now - now.replace(hour=0, minute=0, second=0, microsecond=0))\ + .total_seconds() + seconds = '{:.0f}'.format(seconds) + creation_time = year + ':' + doy + ':' + seconds + + return creation_time + + +def read_sinex_header_line(file): + """This function reads the header line of a SINEX file into a string + + :param str file: the input SINEX file + :return: header_line + :rtype: str + """ + with open(file) as f: + header_line = f.readline() + + return header_line def read_sinex_estimate(file): @@ -386,6 +451,7 @@ def read_sinex_header_block(sinex): block = [] with open(sinex, 'r') as f: + line = f.readline() line = f.readline() while line: block.append(line) @@ -495,13 +561,36 @@ def remove_stns_sinex(sinex, sites): :return: SINEX file output.snx """ + # The block separator separator = '*' + '-' * 79 + '\n' + # Open the output file with open('output.snx', 'w') as out: - header = read_sinex_header_block(sinex) - for line in header: - out.write(line) - del header + + # Get header line and update the creation time and the number of + # parameter estimates. Write the updated header line to the new file + header = read_sinex_header_line(sinex) + old_creation_time = header[15:27] + creation_time = set_creation_time() + header = header.replace(old_creation_time, creation_time) + old_num_params = int(header[60:65]) + if header[70:71] == 'V': + num_stn_params = 6 + else: + num_stn_params = 3 + solution_epochs = read_sinex_solution_epochs_block(sinex) + num_stns_to_remove = 0 + for line in solution_epochs: + site = line[1:5] + if site in sites: + num_stns_to_remove += 1 + del solution_epochs + num_params = old_num_params - num_stn_params * num_stns_to_remove + header = header.replace(str(old_num_params), str(num_params)) + out.write(header) + out.write(separator) + + # Read in the site ID block and write out the sites not being removed site_id = read_sinex_site_id_block(sinex) for line in site_id: if line.startswith('*') or line.startswith('+') or \ @@ -513,6 +602,9 @@ def remove_stns_sinex(sinex, sites): out.write(line) del site_id out.write(separator) + + # Read in the solution epochs block and write out the epochs of the + # sites not being removed solution_epochs = read_sinex_solution_epochs_block(sinex) for line in solution_epochs: if line.startswith('*') or line.startswith('+') or \ @@ -524,6 +616,9 @@ def remove_stns_sinex(sinex, sites): out.write(line) del solution_epochs out.write(separator) + + # Read in the solution estimate block and write out the estimates of + # the sites not being removed skip = [] estimate_number = 0 solution_estimate = read_sinex_solution_estimate_block(sinex) @@ -543,6 +638,9 @@ def remove_stns_sinex(sinex, sites): out.write(line) del solution_estimate out.write(separator) + + # Read in the matrix estimate block and write out minus the sites + # being removed vcv = {} solution_matrix_estimate = \ read_sinex_solution_matrix_estimate_block(sinex) @@ -558,7 +656,7 @@ def remove_stns_sinex(sinex, sites): except KeyError: vcv[row] = [] vcv[row].append(cols[i]) - block_close = solution_matrix_estimate[-1] + block_end = solution_matrix_estimate[-1] del solution_matrix_estimate sub_vcv = {} sub_row = 0 @@ -584,7 +682,9 @@ def remove_stns_sinex(sinex, sites): val = sub_vcv[str(i)].pop(0) line += ' ' + val out.write(line + '\n') - out.write(block_close) + out.write(block_end) + + # Write out the trailer line out.write('%ENDSNX\n') return