pys7k 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
PYS7K/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ """
2
+ pys7k: a pure-Python reader and writer for Teledyne RESON s7k sonar files
3
+ (7k Data Format Definition 3.10).
4
+ """
5
+
6
+ from .frame import (FLAG_CHECKSUM_VALID, FLAG_RECORDED_DATA, S7KChecksumError,
7
+ S7KError, S7KFormatError, checksum, epoch_to_time7k,
8
+ time7k_to_epoch)
9
+ from .registry import (DEVICE_IDENTIFIERS, RECORD_CODECS,
10
+ RECORD_TYPE_DESCRIPTIONS, decode_record, encode_record,
11
+ new, record_name)
12
+ from .s7k import main, resolve_record_type, s7k
13
+
14
+ __version__ = "0.1.0"
15
+
16
+ __all__ = [
17
+ "s7k", "main", "new", "decode_record", "encode_record", "record_name",
18
+ "resolve_record_type", "checksum", "time7k_to_epoch", "epoch_to_time7k",
19
+ "RECORD_CODECS", "RECORD_TYPE_DESCRIPTIONS", "DEVICE_IDENTIFIERS",
20
+ "FLAG_CHECKSUM_VALID", "FLAG_RECORDED_DATA",
21
+ "S7KError", "S7KFormatError", "S7KChecksumError",
22
+ ]
PYS7K/__main__.py ADDED
@@ -0,0 +1,7 @@
1
+ """Allow ``python -m PYS7K -f FILE ...``."""
2
+
3
+ import sys
4
+
5
+ from .s7k import main
6
+
7
+ sys.exit(main())
PYS7K/bitfields.py ADDED
@@ -0,0 +1,193 @@
1
+ """
2
+ Named bit-field specifications from DFD 3.10, and a vectorized decoder.
3
+
4
+ Records keep bit fields as the integers stored in the file. These specs let
5
+ you expand them when you want named values::
6
+
7
+ from PYS7K.bitfields import decode_bits, CONTROL_FLAGS_7000
8
+ decode_bits(rec["RTH"]["ControlFlags"], CONTROL_FLAGS_7000)
9
+ {'AutoRangeMethod': 0, 'AutoBottomDetectionFilterMethod': 0, ...}
10
+
11
+ Each spec is a list of ``(name, first_bit, width)``. ``decode_bits`` works
12
+ on a scalar or on a numpy array (for example a column of per-detection
13
+ flags), returning a dictionary of the same shape.
14
+ """
15
+
16
+ import numpy as np
17
+
18
+ __all__ = [
19
+ "decode_bits",
20
+ "CONTROL_FLAGS_7000", "TRANSMIT_FLAGS_7000", "RECEIVE_FLAGS_7000",
21
+ "FLAGS_7006", "QUALITY_7006",
22
+ "FLAGS_7017", "DETECTION_FLAGS_7017",
23
+ "FLAGS_7027", "DETECTION_FLAGS_7027", "QUALITY_7027",
24
+ "FLAGS_7028", "DATA_SAMPLE_TYPE_7008", "FLAGS_7042",
25
+ "FRAME_FLAGS", "BIT_FIELDS",
26
+ ]
27
+
28
+
29
+ def decode_bits(value, spec):
30
+ """
31
+ Split an integer bit field (or an array of them) into named parts.
32
+
33
+ :param value: an int or an integer numpy array.
34
+ :param spec: a list of ``(name, first_bit, width)``.
35
+ :return: a dictionary mapping each name to an int, or to an array the
36
+ shape of ``value``.
37
+ """
38
+ scalar = np.isscalar(value)
39
+ v = np.asarray(value).astype(np.uint64)
40
+ out = {}
41
+ for name, bit, width in spec:
42
+ part = (v >> np.uint64(bit)) & np.uint64((1 << width) - 1)
43
+ out[name] = int(part) if scalar else part.astype(np.uint32 if width > 8 else np.uint8)
44
+ return out
45
+
46
+
47
+ # Table 5: DRF Flags. Bit 0 is the checksum flag (verified on real data;
48
+ # the DFD's checksum row says "bit 1", which is a typo).
49
+ FRAME_FLAGS = [
50
+ ("ChecksumValid", 0, 1),
51
+ ("RecordedData", 15, 1),
52
+ ]
53
+
54
+ # Table 39: 7000 Control flags (also used by 7503).
55
+ CONTROL_FLAGS_7000 = [
56
+ ("AutoRangeMethod", 0, 4),
57
+ ("AutoBottomDetectionFilterMethod", 4, 4),
58
+ ("BottomDetectionRangeFilterEnabled", 8, 1),
59
+ ("BottomDetectionDepthFilterEnabled", 9, 1),
60
+ ("ReceiverGainAutoGain", 10, 1),
61
+ ("ReceiverGainFixedGain", 11, 1),
62
+ ("ReceiverGainReserved", 12, 1),
63
+ ("Reserved13", 13, 1),
64
+ ("TriggerOutHighForRxDuration", 14, 1),
65
+ ("SystemActive", 15, 1),
66
+ ("ReservedBottomDetection", 16, 4),
67
+ ("PipeGatingFilter", 20, 1),
68
+ ("AdaptiveGateDepthFilterFixed", 21, 1),
69
+ ("AdaptiveGate", 22, 1),
70
+ ("AdaptiveGateDepthFilter", 23, 1),
71
+ ("TriggerOut", 24, 1),
72
+ ("TriggerInEdgeNegative", 25, 1),
73
+ ("PPSEdgeNegative", 26, 1),
74
+ ("TimestampState", 27, 2), # 0 n/a, 1 error, 2 warning, 3 ok
75
+ ("DepthFilterFollowsSeafloor", 29, 1),
76
+ ("ReducedCoverageForConstantSpacing", 30, 1),
77
+ ("Simulator", 31, 1),
78
+ ]
79
+
80
+ # Table 39: Transmit flags.
81
+ TRANSMIT_FLAGS_7000 = [
82
+ ("PitchStabilizationMethod", 0, 4),
83
+ ("YawStabilizationMethod", 4, 4),
84
+ ]
85
+
86
+ # Table 39: Receive flags.
87
+ RECEIVE_FLAGS_7000 = [
88
+ ("RollCompensation", 0, 1),
89
+ ("HeaveCompensation", 2, 1),
90
+ ("DynamicFocusingMethod", 4, 4),
91
+ ("DopplerCompensationMethod", 8, 4),
92
+ ("MatchFilteringMethod", 12, 4),
93
+ ("TVGMethod", 16, 4),
94
+ ("MultiPingMode", 20, 4),
95
+ ]
96
+
97
+ # Table 46: 7006 Flags, and Table 47: 7006 Quality.
98
+ FLAGS_7006 = [
99
+ ("LayerCompensation", 0, 1),
100
+ ("XYZCompensation", 1, 1),
101
+ ]
102
+ QUALITY_7006 = [
103
+ ("BrightnessPass", 0, 1),
104
+ ("ColinearityPass", 1, 1),
105
+ ("IntensityDetectionUsed", 2, 1),
106
+ ("PhaseDetectionUsed", 3, 1),
107
+ ("InternalUse", 4, 1),
108
+ ("PDSNadirFilterFail", 5, 1),
109
+ ]
110
+
111
+ # Table 60: 7017 Flags, and Table 61: per-detection Flags.
112
+ FLAGS_7017 = [
113
+ ("UserDepthFilterEnabled", 0, 1),
114
+ ("UserRangeFilterEnabled", 1, 1),
115
+ ("AutomaticFilterEnabled", 2, 1),
116
+ ("NadirSearchLimitsEnabled", 3, 1),
117
+ ("AutomaticWindowLimitsEnabled", 4, 1),
118
+ ("QualityFilterEnabled", 5, 1),
119
+ ("MultiDetectionEnabled", 6, 1),
120
+ ]
121
+ DETECTION_FLAGS_7017 = [
122
+ ("AutomaticLimitsValid", 0, 1),
123
+ ("UserDefinedLimitsValid", 1, 1),
124
+ ("QualityType", 2, 7),
125
+ ("QualityPassesUserCriteria", 9, 1),
126
+ ("MagnitudeDetect", 10, 1),
127
+ ("PhaseDetect", 11, 1),
128
+ ("DetectionPriority", 16, 4),
129
+ ]
130
+
131
+ # Table 71: 7027 Flags, Table 72: per-detection Flags, Table 73: Quality
132
+ # (when the quality type is 1).
133
+ FLAGS_7027 = [
134
+ ("UncertaintyMethod", 0, 4), # 0 none, 1 Rob Hare, 2 Ifremer
135
+ ("MultiDetectionEnabled", 4, 1),
136
+ ("HasSnippetsDetectionPointFlag", 6, 1),
137
+ ]
138
+ DETECTION_FLAGS_7027 = [
139
+ ("MagnitudeDetect", 0, 1),
140
+ ("PhaseDetect", 1, 1),
141
+ ("QualityType", 2, 7),
142
+ ("DetectionPriority", 9, 4),
143
+ ("NotUsedInSnippet", 14, 1),
144
+ ]
145
+ QUALITY_7027 = [
146
+ ("BrightnessPass", 0, 1),
147
+ ("ColinearityPass", 1, 1),
148
+ ]
149
+
150
+ # Table 74: 7028 Flags.
151
+ FLAGS_7028 = [("Samples32Bit", 0, 1)]
152
+
153
+ # Table 50: 7008 Data sample type.
154
+ DATA_SAMPLE_TYPE_7008 = [
155
+ ("Magnitude", 0, 4), # 0 none, 2 16-bit, 3 32-bit
156
+ ("Phase", 4, 4), # 0 none, 2 16-bit, 3 32-bit
157
+ ("IQ", 8, 4), # 0 none, 1 16-bit, 2 32-bit
158
+ ("ElementData", 12, 3), # 0 beamformed, 1 element data
159
+ ]
160
+
161
+ # Table 82: 7042 Flags.
162
+ FLAGS_7042 = [
163
+ ("UseMaximumBottomDetection", 0, 1),
164
+ ("MagnitudeOnly", 1, 1),
165
+ ("Magnitude8BitdB", 2, 1),
166
+ ("Reserved3", 3, 1),
167
+ ("DownsamplingDivisor", 4, 4),
168
+ ("DownsamplingType", 8, 4), # 0 none, 1 middle, 2 peak, 3 average
169
+ ("Data32Bit", 12, 1),
170
+ ("CompressionFactorAvailable", 13, 1),
171
+ ("SegmentNumbersAvailable", 14, 1),
172
+ ("FirstSampleContainsRxDelay", 15, 1),
173
+ ]
174
+
175
+ # Bit fields indexed by (record type, section, field name), for tools that
176
+ # want to expand every known bit field in a record.
177
+ BIT_FIELDS = {
178
+ (7000, "RTH", "ControlFlags"): CONTROL_FLAGS_7000,
179
+ (7000, "RTH", "TransmitFlags"): TRANSMIT_FLAGS_7000,
180
+ (7000, "RTH", "ReceiveFlags"): RECEIVE_FLAGS_7000,
181
+ (7503, "RTH", "ControlFlags"): CONTROL_FLAGS_7000,
182
+ (7503, "RTH", "TransmitFlags"): TRANSMIT_FLAGS_7000,
183
+ (7503, "RTH", "ReceiveFlags"): RECEIVE_FLAGS_7000,
184
+ (7006, "RTH", "Flags"): FLAGS_7006,
185
+ (7006, "Beams", "Quality"): QUALITY_7006,
186
+ (7008, "RTH", "DataSampleType"): DATA_SAMPLE_TYPE_7008,
187
+ (7017, "RTH", "Flags"): FLAGS_7017,
188
+ (7017, "Detections", "Flags"): DETECTION_FLAGS_7017,
189
+ (7027, "RTH", "Flags"): FLAGS_7027,
190
+ (7027, "Detections", "Flags"): DETECTION_FLAGS_7027,
191
+ (7028, "RTH", "Flags"): FLAGS_7028,
192
+ (7042, "RTH", "Flags"): FLAGS_7042,
193
+ }