-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathh52mat.py
executable file
·111 lines (92 loc) · 2.4 KB
/
h52mat.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
#! /usr/bin/python
#
# This script will export radar data from an HDF5 file to a MATLAB *.mat file.
# To work, everything required for irlib needs to be working, however this
# provides an option for folks who prefer to work in MATLAB over Python.
#
import os, sys, getopt
import irlib
from scipy.io import savemat
import traceback
def print_syntax():
s = """
SYNTAX: h52mat SURVEYFILE OUTFILE [options]
SURVEYFILE is the HDF5 file generated by IceRadar.
OUTFILE is the anme of the *.mat file to be generated.
Options:
g fix static GPS issues
s smoothen coordinates
b remove blank traces (trigger failure)
r remove stationary traces
o overwrite
q silence standard output
"""
print(s)
return
optlist, fins = getopt.gnu_getopt(sys.argv[1:], 'd:gsbroq')
optdict = dict(optlist)
if '-d' in optdict.keys():
cache_dir = optdict['-d']
else:
cache_dir = "cache"
if '-g' in optdict.keys():
fix_gps = True
else:
fix_gps = False
if '-s' in optdict.keys():
smoothen_gps = True
else:
smoothen_gps = False
if '-r' in optdict.keys():
remove_stationary = True
else:
remove_stationary = False
if '-b' in optdict.keys():
remove_blanks = True
else:
remove_blanks = False
if '-o' in optdict.keys():
overwrite = True
else:
overwrite = False
if '-q' in optdict.keys():
be_quiet = True
else:
be_quiet = False
try:
survey_fnm = sys.argv[1]
outfnm = sys.argv[2]
except IndexError:
print_syntax()
sys.exit()
S = irlib.Survey(survey_fnm)
lines = S.GetLines()
line_dict = {}
metadata_dict = {}
for line in lines:
line_no = line.split('_')[1]
if os.path.isfile(outfnm) and not overwrite:
pass
else:
if not be_quiet:
print("Reading " + str(line))
try:
L = S.ExtractLine(line_no)
if fix_gps:
L.FixStaticGPS()
if smoothen_gps:
L.SmoothenGPS()
if remove_blanks:
L.RemoveBlankTraces()
if remove_stationary:
L.RemoveStationary(3.0)
line_dict[line] = L.data
metadata_dict[line] = L.metadata
except AttributeError:
print("\tfailed")
except KeyboardInterrupt:
sys.exit(0)
try:
savemat(outfnm, line_dict, oned_as='row')
except:
traceback.print_exc()