Skip to content

Commit dfe0fdb

Browse files
authored
Merge pull request #143
removes_stns_sinex handles upper triangular matrices correctly
2 parents 538de36 + f651b81 commit dfe0fdb

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ env
3434
/geodepy/XVSOLFIN_20220326.SNX
3535
/geodepy/exciseStationsAPREF.py
3636
/geodepy/gda2020.dat
37+
/geodepy/something_list_snx_blks.py
38+
/geodepy/try_remove_stns.py
39+
/geodepy/17143.U.SNX.AUS
40+
/geodepy/17143.L.SNX.AUS
41+
/geodepy/try_remove_stns.py
42+
/geodepy/SNXEPO.CON.SNX
43+
/geodepy/SNXEPO.NONCON.SNX
44+
/geodepy/SNXEPO.SNX.CON.AUS
45+
/geodepy/SNXEPO.SNX.NONCON.AUS
46+
/geodepy/output.l.snx
47+
/geodepy/output.u.snx

geodepy/gnss.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
In Development
88
"""
99

10-
import sys
1110
from datetime import datetime
1211
from numpy import zeros
1312
from geodepy.angles import DMSAngle
@@ -44,6 +43,7 @@ def print_sinex_comments(file):
4443
if line.startswith('-FILE/COMMENT'):
4544
go = False
4645

46+
4747
def set_creation_time():
4848
"""This function sets the creation time, in format YY:DDD:SSSSS, for use
4949
in the SINEX header line
@@ -451,7 +451,7 @@ def read_sinex_header_block(sinex):
451451

452452
block = []
453453
with open(sinex, 'r') as f:
454-
line = f.readline()
454+
next(f)
455455
line = f.readline()
456456
while line:
457457
block.append(line)
@@ -561,9 +561,6 @@ def remove_stns_sinex(sinex, sites):
561561
:return: SINEX file output.snx
562562
"""
563563

564-
# The block separator
565-
separator = '*' + '-' * 79 + '\n'
566-
567564
# Open the output file
568565
with open('output.snx', 'w') as out:
569566

@@ -573,7 +570,7 @@ def remove_stns_sinex(sinex, sites):
573570
old_creation_time = header[15:27]
574571
creation_time = set_creation_time()
575572
header = header.replace(old_creation_time, creation_time)
576-
old_num_params = int(header[60:65])
573+
old_num_params = header[60:65]
577574
if header[70:71] == 'V':
578575
num_stn_params = 6
579576
else:
@@ -585,11 +582,10 @@ def remove_stns_sinex(sinex, sites):
585582
if site in sites:
586583
num_stns_to_remove += 1
587584
del solution_epochs
588-
num_params = old_num_params - num_stn_params * num_stns_to_remove
585+
num_params = int(old_num_params) - num_stn_params * num_stns_to_remove
589586
num_params = '{:05d}'.format(num_params)
590587
header = header.replace(str(old_num_params), str(num_params))
591588
out.write(header)
592-
out.write(separator)
593589

594590
# Read in the site ID block and write out the sites not being removed
595591
site_id = read_sinex_site_id_block(sinex)
@@ -602,7 +598,6 @@ def remove_stns_sinex(sinex, sites):
602598
if site not in sites:
603599
out.write(line)
604600
del site_id
605-
out.write(separator)
606601

607602
# Read in the solution epochs block and write out the epochs of the
608603
# sites not being removed
@@ -616,7 +611,6 @@ def remove_stns_sinex(sinex, sites):
616611
if site not in sites:
617612
out.write(line)
618613
del solution_epochs
619-
out.write(separator)
620614

621615
# Read in the solution estimate block and write out the estimates of
622616
# the sites not being removed
@@ -638,15 +632,19 @@ def remove_stns_sinex(sinex, sites):
638632
line = ' ' + number + line[6:]
639633
out.write(line)
640634
del solution_estimate
641-
out.write(separator)
642635

643636
# Read in the matrix estimate block and write out minus the sites
644637
# being removed
645638
vcv = {}
646639
solution_matrix_estimate = \
647640
read_sinex_solution_matrix_estimate_block(sinex)
641+
if solution_matrix_estimate[0][26:27] == 'L':
642+
matrix = 'lower'
643+
elif solution_matrix_estimate[0][26:27] == 'U':
644+
matrix = 'upper'
648645
out.write(solution_matrix_estimate[0])
649-
out.write(solution_matrix_estimate[1])
646+
if solution_matrix_estimate[1].startswith('*'):
647+
out.write(solution_matrix_estimate[1])
650648
for line in solution_matrix_estimate:
651649
if line.startswith(' '):
652650
cols = line.split()
@@ -664,24 +662,36 @@ def remove_stns_sinex(sinex, sites):
664662
for i in range(1, len(vcv)+1):
665663
if i not in skip:
666664
sub_row += 1
667-
for j in range(i):
668-
if j+1 not in skip:
669-
try:
670-
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
671-
except KeyError:
672-
sub_vcv[str(sub_row)] = []
673-
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
665+
if matrix == 'lower':
666+
for j in range(i):
667+
if j+1 not in skip:
668+
try:
669+
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
670+
except KeyError:
671+
sub_vcv[str(sub_row)] = []
672+
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
673+
if matrix == 'upper':
674+
for j in range(len(vcv)-(i-1)):
675+
if j+i not in skip:
676+
try:
677+
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
678+
except KeyError:
679+
sub_vcv[str(sub_row)] = []
680+
sub_vcv[str(sub_row)].append(vcv[str(i)][j])
674681
for i in range(1, len(sub_vcv)+1):
675682
para1 = '{:5d}'.format(i)
676-
j = -2
683+
if matrix == 'lower':
684+
j = -2
685+
elif matrix == 'upper':
686+
j = i - 3
677687
while sub_vcv[str(i)]:
678688
j += 3
679689
para2 = '{:5d}'.format(j)
680690
line = ' ' + para1 + ' ' + para2
681691
n = min([3, len(sub_vcv[str(i)])])
682692
for k in range(n):
683-
val = sub_vcv[str(i)].pop(0)
684-
line += ' ' + val
693+
val = '{:21.14e}'.format(float(sub_vcv[str(i)].pop(0)))
694+
line += ' ' + str(val)
685695
out.write(line + '\n')
686696
out.write(block_end)
687697

0 commit comments

Comments
 (0)