Skip to content

Commit 7ae0bd7

Browse files
gshiromaGitHub Enterprise
authored andcommitted
Undelete Python parsers and stripmap code (#734)
* undelete python/packages/isce3/parsers * undelete python/packages/isce3/stripmap
1 parent 1dcb310 commit 7ae0bd7

24 files changed

+1160
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
###SAR Leaderfile Descriptor
2+
def AttitudeDataRecordHeaderType():
3+
'''
4+
Attitude Data Record.
5+
http://www.ga.gov.au/__data/assets/pdf_file/0019/11719/GA10287.pdf Pg:3-42.
6+
'''
7+
from .BasicTypes import IntegerType, MultiType
8+
from .CEOSHeaderType import CEOSHeaderType
9+
10+
return MultiType( CEOSHeaderType().mapping +
11+
[('NumberOfAttitudeDataPoints', IntegerType(4))])
12+
13+
def AttitudeDataRecordStateVectorType():
14+
'''
15+
YPR/ YPR rate section of the record.
16+
'''
17+
from .BasicTypes import (IntegerType,
18+
FloatType,
19+
MultiType)
20+
21+
return MultiType([('DayOfYear', IntegerType(4)),
22+
('MillisecondsOfDay', IntegerType(8)),
23+
('PitchDataQualityFlag', IntegerType(4)),
24+
('RollDataQualityFlag', IntegerType(4)),
25+
('YawDataQualityFlag', IntegerType(4)),
26+
('PitchInDegrees', FloatType(14)),
27+
('RollInDegrees', FloatType(14)),
28+
('YawInDegrees', FloatType(14)),
29+
('PitchRateDataQualityFlag', IntegerType(4)),
30+
('RollRateDataQualityFlag', IntegerType(4)),
31+
('YawRateDataQualityFlag', IntegerType(4)),
32+
('PitchRateInDegreespers', FloatType(14)),
33+
('RollRateInDegreespers', FloatType(14)),
34+
('YawRateInDegreespers', FloatType(14))])
35+
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#Basic types needed for handling CEOS format data
2+
class StringType(object):
3+
'''
4+
Class to read in stream of bytes.
5+
'''
6+
7+
def __init__(self, size):
8+
'''
9+
Constructor takes length of string as input.
10+
'''
11+
12+
self.size = size
13+
self.data = None
14+
15+
def dtype(self):
16+
'''
17+
Return numpy format string to read into.
18+
'''
19+
20+
return 'a{}'.format(self.size)
21+
22+
def fromfile(self, fid):
23+
'''
24+
Read one entry from file into data.
25+
'''
26+
import numpy
27+
28+
self.data = numpy.fromfile(fid, dtype=self.dtype(), count=1)
29+
30+
def assign(self, x):
31+
'''
32+
Assign value to field.
33+
'''
34+
self.data = x
35+
36+
def value(self):
37+
'''
38+
Return value as string.
39+
'''
40+
41+
return self.data[0].decode('utf-8').strip()
42+
43+
class BlankType(StringType):
44+
'''
45+
Class to read in void bytes.
46+
'''
47+
48+
def dtype(self):
49+
'''
50+
Return numpy format string to read into.
51+
'''
52+
53+
return 'V{}'.format(self.size)
54+
55+
def value(self):
56+
'''
57+
Return None for blanks.
58+
'''
59+
60+
return None
61+
62+
class IntegerType(StringType):
63+
'''
64+
Treat the string as an integer.
65+
'''
66+
67+
def value(self):
68+
'''
69+
Read one integer from file.
70+
'''
71+
return int(super().value())
72+
73+
class FloatType(StringType):
74+
'''
75+
Treat the string as an integer.
76+
'''
77+
78+
def value(self):
79+
'''
80+
Read one integer from file.
81+
'''
82+
return float(super().value())
83+
84+
class BinaryType(object):
85+
'''
86+
Class to read in binary data directly.
87+
'''
88+
89+
def __init__(self, intype, count=1):
90+
'''
91+
Constructor takes length of string as input.
92+
'''
93+
import numpy
94+
95+
self.intype = intype
96+
self.size = numpy.dtype(intype).itemsize
97+
self.count = count
98+
self.data = None
99+
100+
def dtype(self):
101+
'''
102+
Return numpy format string to read into.
103+
'''
104+
105+
if self.count != 1:
106+
return (self.intype, self.count)
107+
else:
108+
return self.intype
109+
110+
def fromfile(self, fid):
111+
'''
112+
Read one entry from file into data.
113+
'''
114+
import numpy
115+
self.data = numpy.fromfile(fid, dtype=self.dtype(), count=self.count)
116+
117+
def assign(self, x):
118+
'''
119+
Assign value to field.
120+
'''
121+
self.data = x
122+
123+
def value(self):
124+
'''
125+
Return value as string.
126+
'''
127+
if self.count == 1:
128+
return self.data[0]
129+
else:
130+
return self.data
131+
132+
133+
class MultiType(object):
134+
'''
135+
Generic type.
136+
'''
137+
138+
def __init__(self, inlist):
139+
'''
140+
Initiate type with dictionary.
141+
'''
142+
143+
if not isinstance(inlist, list):
144+
raise Exception('Only lists are supported by CEOS parser.')
145+
146+
self.mapping = inlist
147+
self.data = None
148+
149+
150+
def dtype(self):
151+
'''
152+
Return equivalent numpy dtype.
153+
'''
154+
import numpy
155+
156+
typelist = []
157+
for k, v in self.mapping:
158+
typelist.append((k, v.dtype()))
159+
160+
return numpy.dtype(typelist)
161+
162+
def assign(self, indata):
163+
for k, v in self.mapping:
164+
v.assign(indata[k])
165+
166+
self.data = indata
167+
168+
def fromfile(self, fid):
169+
'''
170+
Parse record from file.
171+
'''
172+
import numpy
173+
self.data = numpy.fromfile(fid, dtype=self.dtype(), count=1)
174+
175+
#Propagate to children
176+
for k, v in self.mapping:
177+
v.assign(self.data[k])
178+
179+
def __getattr__(self, key):
180+
'''
181+
Return parsed value.
182+
'''
183+
for k, v in self.mapping:
184+
if k == key:
185+
if isinstance(v, MultiType):
186+
return v
187+
else:
188+
return v.value()
189+
190+
raise Exception('MultiType record does not contain field named {}'.format(key))
191+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##CEOS Header Type
2+
def CEOSHeaderType():
3+
'''
4+
This is common to all CEOS records.
5+
Reference: http://www.ga.gov.au/__data/assets/pdf_file/0019/11719/GA10287.pdf.
6+
'''
7+
from .BasicTypes import BinaryType, MultiType
8+
return MultiType([('RecordSequenceNumber', BinaryType('>i4')),
9+
('FirstRecordType', BinaryType('>B')),
10+
('RecordTypeCode', BinaryType('>B')),
11+
('SecondRecordSubType', BinaryType('>B')),
12+
('ThirdRecordSubType', BinaryType('>B')),
13+
('RecordLength', BinaryType('>i4'))])
14+
15+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
###SAR Calibration Data Record
2+
def CalibrationDataRecordHeaderType():
3+
'''
4+
Calibration Data Record Header.
5+
http://www.ga.gov.au/__data/assets/pdf_file/0019/11719/GA10287.pdf Pg:3-42.
6+
'''
7+
from .BasicTypes import (IntegerType,
8+
StringType,
9+
MultiType)
10+
from .CEOSHeaderType import CEOSHeaderType
11+
12+
return MultiType( CEOSHeaderType().mapping +
13+
[('CalDataSequenceNumber', IntegerType(4)),
14+
('NumberOfValidSamples', IntegerType(4)),
15+
('StartDateTimeOfChirpReplicaData', StringType(17)),
16+
('StopDateTimeOfChirpReplicaData', StringType(17)),
17+
('ATTSetting', IntegerType(4)),
18+
('ALCSetting', IntegerType(1)),
19+
('AGCorMGC', IntegerType(1)),
20+
('RangePulseLengthInusec', IntegerType(4)),
21+
('BandwidthInMHz', IntegerType(4)),
22+
('SamplingFrequencyinMHz', IntegerType(4)),
23+
('QuantizationBits', IntegerType(4)),
24+
('NumberOfChirpReplicaDataGroups', IntegerType(4)),
25+
('NumberOfChirpReplicaSampleData', IntegerType(4))
26+
])
27+

0 commit comments

Comments
 (0)