forked from icsm-au/datum-modernisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AUSPOS_submission.py
160 lines (115 loc) · 4.06 KB
/
AUSPOS_submission.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# ----------------------------------------------------------------------
# AUSPOS_submission.py
# ----------------------------------------------------------------------
# Author: Nic Gowans
# Date: 22AUG2019
# Purpose: To read a list of RINEX files and metadata, and one-by-one
# submit to the AUSPOS online GPS processing service
# ----------------------------------------------------------------------
# Usage: CMD:\>python AUSPOS_submission.py <Rinex_metadata_files.csv>
# ----------------------------------------------------------------------
# Notes: Before running, the user must update:
# - the directory where the RINEX files are stored
# - their preferred email address
# ----------------------------------------------------------------------
import os
import requests
import re
import time
import timeit
import datetime
start = timeit.default_timer()
# ----------------------------------------------------------------------
# set script input files, targets and directories
# ----------------------------------------------------------------------
# input data file
rnx_list = os.sys.argv[1]
# AUSPOS website
post_target = 'http://www.ga.gov.au/bin/gps.pl'
# User input
rnx_dir = r''
email_add = ''
# ----------------------------------------------------------------------
# read RINEX metadata .csv file
# ----------------------------------------------------------------------
print()
print(' Consuming input file: {:s}'.format(rnx_list))
meta_dict = {}
csv_fh = open(rnx_list,'r')
# write session metadata to dictionary
for line in csv_fh:
items = line.split(',')
if len(items) > 2:
rnx_file = items[0]
HI = items[1]
ant = items[2].strip()
meta_dict[rnx_file] = {
'HI': HI,
'ant': ant
}
csv_fh.close()
# ----------------------------------------------------------------------
# submit data to AUSPOS, one-by-one
# ----------------------------------------------------------------------
print()
print(' Submitting data to AUSPOS:')
submitted_count = 0
total_rnx = int(len(meta_dict))
rnx_count = 0
for rnx in meta_dict:
rnx_count += 1
# update screen
print(' Submitting session {:d}/{:d} - {:s}'.format(rnx_count, total_rnx, rnx))
# set path to rinex file
rnx_path = os.path.join(rnx_dir, rnx)
form_file = {
'upload1': open(rnx_path)
}
# set metadata for rinex session
form_data = {
'num_files': '1',
'submit_files': 'upload',
'height1': meta_dict[rnx]['HI'],
'type1': meta_dict[rnx]['ant'],
'email': email_add,
'submit': 'submit'
}
# log AUSPOS response
response = requests.post(post_target, files=form_file, data=form_data)
AUSPOS_message = str(response.content)
# find referenceID with regex
referenceID_list = re.findall('[#][0-9]+[\.]', AUSPOS_message)
referenceID = referenceID_list[0][1:-1]
meta_dict[rnx]['job_ref'] = referenceID
submitted_count += 1
# wait a few seconds as not to overwhelm AUSPOS
time.sleep(5)
# ----------------------------------------------------------------------
# write reference ID to file
# ----------------------------------------------------------------------
results_file = rnx_list[:-4] + '_results.csv'
results_fh = open(results_file, 'w')
outStr = ''
for rnx in meta_dict:
HI = meta_dict[rnx]['HI']
ant = meta_dict[rnx]['ant']
job_ref = meta_dict[rnx]['job_ref']
outStr += '{:s},{:s},{:s},{:s}\n'.format(rnx, HI, ant, job_ref)
results_fh.write(outStr)
results_fh.close()
# ----------------------------------------------------------------------
# print summary
# ----------------------------------------------------------------------
stop = timeit.default_timer()
time_diff = stop - start
run_time = str(datetime.timedelta(seconds=time_diff))
print()
print('-'*50)
print('AUSPOS_submission.py Summary Report')
print('-'*50)
print()
print(' Completed in {:s}'.format(run_time[:-4]))
print()
print(' {:d} files submitted'.format(submitted_count))
print()
print(' See {:s}'.format(results_file))