-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexciseStationsNGCA.py
66 lines (56 loc) · 1.98 KB
/
exciseStationsNGCA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# This script removes stations that are outside the extent of GDA2020 from an
# NGCA SINEX file
#
# Requirements:
# - GMT program select
# - GA program rdsinex
#
# Usage: exciseStationsNGCA.pl <files>
#
# Note: wildcards are accepted
import os
import glob
import subprocess
import geodepy.gnss
# Copy over gda2020.dat
os.system('cp ~/apref/workDir/gda2020.dat ../sinexFiles')
# Create a list of APREF stations to exclude
exclude = ['MAC1', 'CEDU', 'CA19', 'HOBA'];
# Loop over the input SINEX files
os.chdir('../sinexFiles')
for f in glob.glob('*.SNX'):
# Use subprocess to run rdsinex and GMT and create a list of stations
# outside GDA2020
stns = set()
rdsnx = subprocess.Popen(["rdsinex","-P",f], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
gmt = subprocess.Popen(["gmt", "select", "-Ef","-Fgda2020.dat", "-If"],
stdin=rdsnx.stdout, stdout=subprocess.PIPE)
all_details_b = gmt.stdout.read()
all_details = all_details_b.decode()
stns_details = all_details.split('\n')
for stn_details in stns_details:
if stn_details != '':
details = stn_details.split()
stns.add(details[6])
# Check to see if any of the excluded stations are in the SINEX file and add
# them to the stations to be removed
rdsnx = subprocess.Popen(["rdsinex","-P",f], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
all_details_b = rdsnx.stdout.read()
all_details = all_details_b.decode()
stns_details = all_details.split('\n')
for stn_details in stns_details:
if stn_details != '':
details = stn_details.split()
if details[6] in exclude:
stns.add(details[6])
# Remove stations and rename output file
geodepy.gnss.remove_stns_sinex(f, stns)
ofile = f + '.AUS'
os.rename('output.snx', ofile)
# Tidy up
os.remove('gda2020.dat')
print('*** EXCLUDING ***')
print(exclude)