77In Development
88"""
99
10- import sys
1110from datetime import datetime
1211from numpy import zeros
1312from geodepy .angles import DMSAngle
@@ -44,6 +43,7 @@ def print_sinex_comments(file):
4443 if line .startswith ('-FILE/COMMENT' ):
4544 go = False
4645
46+
4747def 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