/
VectorParameters.py
287 lines (245 loc) · 8.86 KB
/
VectorParameters.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# -*- coding: utf-8 -*-
"""
The SRP definition for CPHD 0.3.
"""
from typing import Union
from sarpy.compliance import integer_types
from ..cphd1_elements.base import DEFAULT_STRICT
# noinspection PyProtectedMember
from ...complex.sicd_elements.base import Serializable, _SerializableDescriptor, \
_IntegerEnumDescriptor
__classification__ = "UNCLASSIFIED"
__author__ = "Thomas McCullough"
class FxParametersType(Serializable):
"""
The FX vector parameters.
"""
_fields = ('Fx0', 'Fx_SS', 'Fx1', 'Fx2')
_required = _fields
# descriptors
Fx0 = _IntegerEnumDescriptor(
'Fx0', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the Fx0 field') # type: int
Fx_SS = _IntegerEnumDescriptor(
'Fx_SS', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the Fx_SS field') # type: int
Fx1 = _IntegerEnumDescriptor(
'Fx1', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the Fx1 field') # type: int
Fx2 = _IntegerEnumDescriptor(
'Fx2', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the Fx2 field') # type: int
def __init__(self, Fx0=8, Fx_SS=8, Fx1=8, Fx2=8, **kwargs):
if '_xml_ns' in kwargs:
self._xml_ns = kwargs['_xml_ns']
if '_xml_ns_key' in kwargs:
self._xml_ns_key = kwargs['_xml_ns_key']
self.Fx0 = Fx0
self.Fx1 = Fx1
self.Fx2 = Fx2
self.Fx_SS = Fx_SS
super(FxParametersType, self).__init__(**kwargs)
@staticmethod
def get_size():
"""
The size in bytes of this component of the vector.
Returns
-------
int
"""
return 32
def get_position_offset_and_size(self, field):
"""
Get the offset and size of the given field from the beginning of the vector.
Parameters
----------
field : str
Returns
-------
None|int
"""
if field not in self._fields:
return None
out = 0
for fld in self._fields:
val = getattr(self, fld)
if fld == field:
return out, val
else:
out += val
return None
class TOAParametersType(Serializable):
"""
The TOA vector parameters.
"""
_fields = ('DeltaTOA0', 'TOA_SS')
_required = _fields
# descriptors
DeltaTOA0 = _IntegerEnumDescriptor(
'DeltaTOA0', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the DeltaTOA0 field') # type: int
TOA_SS = _IntegerEnumDescriptor(
'TOA_SS', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the TOA_SS field') # type: int
def __init__(self, DeltaTOA0=8, TOA_SS=8, **kwargs):
if '_xml_ns' in kwargs:
self._xml_ns = kwargs['_xml_ns']
if '_xml_ns_key' in kwargs:
self._xml_ns_key = kwargs['_xml_ns_key']
self.DeltaTOA0 = DeltaTOA0
self.TOA_SS = TOA_SS
super(TOAParametersType, self).__init__(**kwargs)
@staticmethod
def get_size():
"""
The size in bytes of this component of the vector.
Returns
-------
int
"""
return 16
def get_position_offset_and_size(self, field):
"""
Get the offset and size of the given field from the beginning of the vector.
Parameters
----------
field : str
Returns
-------
None|(int, int)
"""
if field not in self._fields:
return None
out = 0
for fld in self._fields:
val = getattr(self, fld)
if fld == field:
return out, val
else:
out += val
return None
class VectorParametersType(Serializable):
"""
The vector parameters sizes object.
"""
_fields = (
'TxTime', 'TxPos', 'RcvTime', 'RcvPos', 'SRPTime', 'SRPPos', 'AmpSF', 'TropoSRP',
'FxParameters', 'TOAParameters')
_required = (
'TxTime', 'TxPos', 'RcvTime', 'RcvPos', 'SRPPos')
_choice = [{'required': False, 'collection': ('FxParameters', 'TOAParameters')}]
# descriptors
TxTime = _IntegerEnumDescriptor(
'TxTime', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the TxTime field') # type: int
TxPos = _IntegerEnumDescriptor(
'TxPos', (24, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the TxPos field') # type: int
RcvTime = _IntegerEnumDescriptor(
'RcvTime', (8, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the RcvTime field') # type: int
RcvPos = _IntegerEnumDescriptor(
'RcvPos', (24, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the RcvPos field') # type: int
SRPTime = _IntegerEnumDescriptor(
'SRPTime', (8, ), _required, strict=DEFAULT_STRICT, default_value=None,
docstring='The size of the SRPTime field') # type: int
SRPPos = _IntegerEnumDescriptor(
'SRPPos', (24, ), _required, strict=DEFAULT_STRICT, default_value=8,
docstring='The size of the SRPPos field') # type: int
AmpSF = _IntegerEnumDescriptor(
'AmpSF', (8, ), _required, strict=DEFAULT_STRICT, default_value=None,
docstring='The size of the AmpSF field') # type: int
TropoSRP = _IntegerEnumDescriptor(
'TropoSRP', (8, ), _required, strict=DEFAULT_STRICT, default_value=None,
docstring='The size of the TropoSRP field') # type: int
FxParameters = _SerializableDescriptor(
'FxParameters', FxParametersType, _required, strict=DEFAULT_STRICT,
docstring='The frequency parameters, only present when DomainType is '
'FX.') # type: Union[None, FxParametersType]
TOAParameters = _SerializableDescriptor(
'TOAParameters', FxParametersType, _required, strict=DEFAULT_STRICT,
docstring='The TOA parameters, only present when DomainType is '
'TOA.') # type: Union[None, TOAParametersType]
def __init__(self, TxTime=8, TxPos=24, RcvTime=8, RcvPos=24, SRPTime=None, SRPPos=24,
AmpSF=None, TropoSRP=None, FxParameters=None, TOAParameters=None, **kwargs):
"""
Parameters
----------
TxTime : int
TxPos : int
RcvTime : int
RcvPos : int
SRPTime : None|int
SRPPos : int
AmpSF : None|int
TropoSRP : None|int
FxParameters : None|FxParametersType
TOAParameters : None|TOAParametersType
kwargs
"""
if '_xml_ns' in kwargs:
self._xml_ns = kwargs['_xml_ns']
if '_xml_ns_key' in kwargs:
self._xml_ns_key = kwargs['_xml_ns_key']
self.TxTime = TxTime
self.TxPos = TxPos
self.RcvTime = RcvTime
self.RcvPos = RcvPos
self.SRPTime = SRPTime
self.SRPPos = SRPPos
self.AmpSF = AmpSF
self.TropoSRP = TropoSRP
self.FxParameters = FxParameters
self.TOAParameters = TOAParameters
super(VectorParametersType, self).__init__(**kwargs)
def get_size(self):
"""
The size in bytes of this component of the vector.
Returns
-------
int
"""
out = 0
for fld in self._fields:
val = getattr(self, fld)
if val is None:
pass
elif isinstance(val, integer_types):
out += val
elif isinstance(val, (FxParametersType, TOAParametersType)):
out += val.get_size()
else:
raise TypeError('Got unhandled type {}'.format(type(val)))
return out
def get_position_offset_and_size(self, field):
"""
Get the offset and size of the given field from the beginning of the vector.
Parameters
----------
field : str
Returns
-------
None|(int, int)
"""
out = 0
for fld in self._fields:
val = getattr(self, fld)
if fld == field:
if val is not None:
return out, val
else:
return None
if val is None:
pass
elif isinstance(val, integer_types):
out += val
elif isinstance(val, (FxParametersType, TOAParametersType)):
res = val.get_position_offset_and_size(field)
if res is not None:
return out+res[0], res[1]
else:
out += val.get_size()
else:
raise TypeError('Got unhandled type {}'.format(type(val)))
return None