forked from reachsubseaau/pygsf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpygsf.py
More file actions
1880 lines (1652 loc) · 72.5 KB
/
Copy pathpygsf.py
File metadata and controls
1880 lines (1652 loc) · 72.5 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#name: pygsf
#created: July 2017
#by: p.kennedy@guardiangeomatics.com
#description: python module to read and write a Generic Sensor Formaty (GSF) file natively
#notes: See main at end of script for example how to use this
#based on GSF Version 3.05
# See readme.md for more details
# # Record Decriptions (See page 82)
# HEADER = 1
# SWATH_BATHYMETRY = 2
# SOUND_VELOCITY_PROFILE = 3
# PROCESSING_PARAMETERS = 4
# SENSOR_PARAMETERS = 5
# COMMENT = 6
# HISTORY = 7
# NAVIGATION_ERROR = 8
# SWATH_BATHY_SUMMARY = 9
# SINGLE_BEAM_SOUNDING = 10
# HV_NAVIGATION_ERROR = 11
# ATTITUDE = 12
import os.path
import struct
import pprint
import time
import datetime
import math
import random
from datetime import datetime
from datetime import timedelta
from statistics import mean
# import mmap
from delivershared import log as log, makedirs
# for testing only...
import numpy as np
#/* The high order 4 bits are used to define the field size for this array */
GSF_FIELD_SIZE_DEFAULT = 0x00 #/* Default values for field size are used used for all beam arrays */
GSF_FIELD_SIZE_ONE = 0x10 #/* value saved as a one byte value after applying scale and offset */
GSF_FIELD_SIZE_TWO = 0x20 #/* value saved as a two byte value after applying scale and offset */
GSF_FIELD_SIZE_FOUR = 0x40 #/* value saved as a four byte value after applying scale and offset */
GSF_MAX_PING_ARRAY_SUBRECORDS = 26
# Record Decriptions (See page 82)
HEADER = 1
SWATH_BATHYMETRY = 2
SOUND_VELOCITY_PROFILE = 3
PROCESSING_PARAMETERS = 4
SENSOR_PARAMETERS = 5
COMMENT = 6
HISTORY = 7
NAVIGATION_ERROR = 8
SWATH_BATHY_SUMMARY = 9
SINGLE_BEAM_SOUNDING = 10
HV_NAVIGATION_ERROR = 11
ATTITUDE = 12
SNIPPET_NONE = 0 # extract the mean value from the snippet array
SNIPPET_MEAN = 1 # extract the mean value from the snippet array
SNIPPET_MAX = 2 # extract the maximum value from the snippet array
SNIPPET_DETECT = 3 # extract the bottom detect snippet value from the snippet array
SNIPPET_MEAN5DB = 4 # extract the mean of all snippets within 5dB of the mean
# the various frequencies we support in the R2Sonic multispectral files
ARCIdx = {100000: 0, 200000: 1, 400000: 2}
# the rejection flags used by this software
REJECT_CLIP = -1
REJECT_RANGE= -2
REJECT_INTENSITY= -4
# Subrecord Description Subrecord Identifier
DEPTH_ARRAY = 1
ACROSS_TRACK_ARRAY = 2
ALONG_TRACK_ARRAY = 3
TRAVEL_TIME_ARRAY = 4
BEAM_ANGLE_ARRAY = 5
MEAN_CAL_AMPLITUDE_ARRAY = 6
MEAN_REL_AMPLITUDE_ARRAY = 7
ECHO_WIDTH_ARRAY = 8
QUALITY_FACTOR_ARRAY = 9
RECEIVE_HEAVE_ARRAY = 10
DEPTH_ERROR_ARRAY = 11
ACROSS_TRACK_ERROR_ARRAY = 12
ALONG_TRACK_ERROR_ARRAY = 13
NOMINAL_DEPTH_ARRAY = 14
QUALITY_FLAGS_ARRAY = 15
BEAM_FLAGS_ARRAY = 16
SIGNAL_TO_NOISE_ARRAY = 17
BEAM_ANGLE_FORWARD_ARRAY = 18
VERTICAL_ERROR_ARRAY = 19
HORIZONTAL_ERROR_ARRAY = 20
INTENSITY_SERIES_ARRAY = 21
SECTOR_NUMBER_ARRAY = 22
DETECTION_INFO_ARRAY = 23
INCIDENT_BEAM_ADJ_ARRAY = 24
SYSTEM_CLEANING_ARRAY = 25
DOPPLER_CORRECTION_ARRAY = 26
SONAR_VERT_UNCERTAINTY_ARRAY = 27
SCALE_FACTORS = 100
# SEABEAM_SPECIFIC = 102
# EM12_SPECIFIC = 103
# EM100_SPECIFIC = 104
# EM950_SPECIFIC 105
# EM121A_SPECIFIC 106
# EM121_SPECIFIC 107
# SASS_SPECIFIC (To Be Replaced By CMP_SASS) 108
# SEAMAP_SPECIFIC 109
# SEABAT_SPECIFIC 110
# EM1000_SPECIFIC 111
# TYPEIII_SEABEAM_SPECIFIC (To Be Replaced By CMP_SASS ) 112
# SB_AMP_SPECIFIC 113
# SEABAT_II_SPECIFIC 114
# SEABAT_8101_SPECIFIC (obsolete) 115
# SEABEAM_2112_SPECIFIC 116
# ELAC_MKII_SPECIFIC 117
# EM3000_SPECIFIC 118
# EM1002_SPECIFIC 119
# EM300_SPECIFIC 120
# CMP_SASS_SPECIFIC (To replace SASS and TYPEIII_SEABEAM) 121
# RESON_8101_SPECIFIC 122
# RESON_8111_SPECIFIC 123
# RESON_8124_SPECIFIC 124
# RESON_8125_SPECIFIC 125
# RESON_8150_SPECIFIC 126
# RESON_8160_SPECIFIC 127
# EM120_SPECIFIC 128
# EM3002_SPECIFIC 129
# EM3000D_SPECIFIC 130
# EM3002D_SPECIFIC 131
# EM121A_SIS_SPECIFIC 132
# EM710_SPECIFIC 133
# EM302_SPECIFIC 134
# EM122_SPECIFIC 135
# GEOSWATH_PLUS_SPECIFIC 136
# KLEIN_5410_BSS_SPECIFIC 137
# RESON_7125_SPECIFIC 138
# EM2000_SPECIFIC 139
# EM300_RAW_SPECIFIC 140
# EM1002_RAW_SPECIFIC 141
# EM2000_RAW_SPECIFIC 142
# EM3000_RAW_SPECIFIC 143
# EM120_RAW_SPECIFIC 144
# EM3002_RAW_SPECIFIC 145
# EM3000D_RAW_SPECIFIC 146
# EM3002D_RAW_SPECIFIC 147
# EM121A_SIS_RAW_SPECIFIC 148
# EM2040_SPECIFIC 149
# DELTA_T_SPECIFIC 150
# R2SONIC_2022_SPECIFIC 151
# R2SONIC_2024_SPECIFIC 152
# R2SONIC_2020_SPECIFIC 153
# SB_ECHOTRAC_SPECIFIC (obsolete) 206
# SB_BATHY2000_SPECIFIC (obsolete) 207
# SB_MGD77_SPECIFIC (obsolete) 208
# SB_BDB_SPECIFIC (obsolete) 209
# SB_NOSHDB_SPECIFIC (obsolete) 210
# SB_PDD_SPECIFIC (obsolete) 211
# SB_NAVISOUND_SPECIFIC (obsolete) 212
###############################################################################
def main():
# testR2SonicAdjustment()
testreader()
# conditioner()
###############################################################################
def testreader():
'''
sample read script so we can see how to use the code
'''
start_time = time.time() # time the process so we can keep it quick
# filename = "C:/projects/multispectral/PatriciaBasin/20161130-1907 - 0001-2026_1.gsf"
# filename = "C:/development/python/sample_subset.gsf"
# filename = "F:/Projects/multispectral/_BedfordBasin2016/20160331 - 125110 - 0001-2026_1.gsf"
# filename = "F:/Projects/multispectral/_Newbex/20170524-134208 - 0001-2026_1.gsf"
# filename = "F:/Projects/multispectral/_BedfordBasin2017/20170502 - 131750 - 0001-2026_1.gsf"
# filename = "C:/projects/multispectral/_BedfordBasin2017/20170502 - 150058 - 0001-2026_1.gsf"
# filename = "C:/development/ggtools/kmall2gsf/20160331-165252-0001-2026.gsf"
# filename = "v:/jp/C_S20230_0491_20211228_004807.gsf"
# filename = "D:/LogData/gsf/20220512_161545_1_Hydro2_P21050_NEOM.gsf"
# filename = "C://sampledata/gsf/Block_G_X_P4000.gsf"
# filename = "C:/sampledata/gsf/IDN-ME-SR23_1-P-B46-01-CL_1075_20220530_112406.gsf"
# filename = "C:/sampledata/gsf/IDN-ME-SR23_1-RD14-B46-S200_0565_20220605_134739.gsf"
# filename = "C:/sampledata/gsf/20220512_182628_1_Hydro2_P21050_NEOM.gsf"
# filename = "C:/sampledata/gsf/0095_20220701_033832.gsf"
# filename = "F:/projects/ggmatch/lazgsfcomparisontest/IDN-JI-SR23_1-PH-B46-001_0000_20220419_162536.gsf"
filename = "D:/projects/likehart/01_GSF/0116_20220728_075347.gsf"
print (filename)
pingcount = 0
# create a GSFREADER class and pass the filename
r = GSFREADER(filename)
# r.loadscalefactors()
navigation = r.loadnavigation()
# ts, roll, pitch, heave, heading = r.loadattitude()
while r.moreData():
# read a datagram. If we support it, return the datagram type and aclass for that datagram
# The user then needs to call the read() method for the class to undertake a fileread and binary decode. This keeps the read super quick.
startbyte = r.fileptr.tell()
numberofbytes, recordidentifier, datagram = r.readDatagram()
# print(recordidentifier)
if recordidentifier == HEADER:
datagram.read()
# print(datagram)
if recordidentifier == SWATH_BATHY_SUMMARY:
datagram.read()
# print(datagram)
if recordidentifier == COMMENT:
datagram.read()
# print(datagram)
if recordidentifier == PROCESSING_PARAMETERS:
datagram.read()
# print(datagram)
if recordidentifier == SOUND_VELOCITY_PROFILE:
datagram.read()
# print(datagram)
# if recordidentifier == ATTITUDE:
# datagram.read()
# r.attitudedata = np.append(r.attitudedata, datagram.attitudearray, axis=0)
# print(datagram)
if recordidentifier == SWATH_BATHYMETRY:
r.scalefactorsd = datagram.read(r.scalefactorsd, False)
# print ( datagram.from_timestamp(datagram.timestamp), datagram.timestamp, datagram.longitude, datagram.latitude, datagram.heading, datagram.DEPTH_ARRAY[0])
print("Duration %.3fs" % (time.time() - start_time )) # time the process
# print ("PingCount:", pingcount)
return
###############################################################################
class UNKNOWN_RECORD:
'''used as a convenience tool for datagrams we have no bespoke classes. Better to make a bespoke class'''
def __init__(self, fileptr, numbytes, recordidentifier, hdrlen):
self.recordidentifier = recordidentifier
self.offset = fileptr.tell()
self.hdrlen = hdrlen
self.numbytes = numbytes
self.fileptr = fileptr
self.fileptr.seek(numbytes, 1) # set the file ptr to the end of the record
self.data = ""
def read(self):
self.data = self.fileptr.read(self.numberofbytes)
##################################################################################################
class SCALEFACTOR:
def __init__(self):
self.subrecordID = 0
self.compressionFlag = 0 #/* Specifies bytes of storage in high order nibble and type of compression in low order nibble */
self.multiplier = 0.0
self.offset = 0
##################################################################################################
class SWATH_BATHYMETRY_PING :
def __init__(self, fileptr, numbytes, recordidentifier, hdrlen):
self.recordidentifier = recordidentifier # assign the GSF code for this datagram type
self.offset = fileptr.tell() # remember where this packet resides in the file so we can return if needed
self.hdrlen = hdrlen # remember the header length. it should be 8 bytes, but if checksum then it is 12
self.numbytes = numbytes # remember how many bytes this packet contains
self.fileptr = fileptr # remember the file pointer so we do not need to pass from the host process
self.fileptr.seek(numbytes, 1) # move the file pointer to the end of the record so we can skip as the default actions
self.scalefactorsd = {}
# self.scalefactors = []
self.DEPTH_ARRAY = []
self.ACROSS_TRACK_ARRAY = []
self.ALONG_TRACK_ARRAY = []
self.TRAVEL_TIME_ARRAY = []
self.BEAM_ANGLE_ARRAY = []
self.MEAN_CAL_AMPLITUDE_ARRAY = []
self.MEAN_REL_AMPLITUDE_ARRAY = []
self.QUALITY_FACTOR_ARRAY = []
self.QUALITY_FLAGS_ARRAY = []
self.BEAM_FLAGS_ARRAY = []
self.BEAM_ANGLE_FORWARD_ARRAY = []
self.VERTICAL_ERROR_ARRAY = []
self.HORIZONTAL_ERROR_ARRAY = []
self.SECTOR_NUMBER_ARRAY = []
# self.INTENSITY_SERIES_ARRAY = []
self.SNIPPET_SERIES_ARRAY = []
self.perbeam = True
self.snippettype = SNIPPET_MAX
self.numbeams = 0
self.time = 0
self.pingnanotime = 0
self.frequency = 0
###############################################################################
# def readscalefactors(self, headeronly=False):
# '''read the scale facttors
# '''
# # read ping header
# hdrfmt = '>llll5hLH3h2Hlllh'
# hdrlen = struct.calcsize(hdrfmt)
# rec_unpack = struct.Struct(hdrfmt).unpack
# self.fileptr.seek(self.offset + self.hdrlen, 0) # move the file pointer to the start of the record so we can read from disc
# # self.fileptr.seek(self.offset + self.hdrlen , 0) # move the file pointer to the start of the record so we can read from disc
# data = self.fileptr.read(hdrlen)
# s = rec_unpack(data)
# self.time = s[0]
# self.pingnanotime = s[1]
# self.timestamp = self.time + (self.pingnanotime/1000000000)
# self.longitude = s[2] / 10000000
# self.latitude = s[3] / 10000000
# self.numbeams = s[4]
# self.centrebeam = s[5]
# self.pingflags = s[6]
# self.reserved = s[7]
# self.tidecorrector = s[8] / 100
# self.depthcorrector = s[9] / 100
# self.heading = s[10] / 100
# self.pitch = s[11] / 100
# self.roll = s[12] / 100
# self.heave = s[13] / 100
# self.course = s[14] / 100
# self.speed = s[15] / 100
# self.height = s[16] / 100
# self.separation = s[17] / 100
# self.gpstidecorrector = s[18] / 100
# self.spare = s[19]
# # skip the record for performance reasons. Very handy in some circumstances
# if headeronly:
# self.fileptr.seek(self.offset + self.numbytes, 0) #move forwards to the end of the record as we cannot trust the record length from the 2024
# return
# while (self.fileptr.tell() <= self.offset + self.numbytes): #dont read past the end of the packet length. This should never happen!
# fmt = '>l'
# fmtlen = struct.calcsize(fmt)
# rec_unpack = struct.Struct(fmt).unpack
# data = self.fileptr.read(fmtlen) # read the record from disc
# s = rec_unpack(data)
# subrecord_id = (s[0] & 0xFF000000) >> 24
# subrecord_size = s[0] & 0x00FFFFFF
# # print("id %d size %d" % (subrecord_id, subrecord_size))
# # if subrecord_id == 21:
# # self.fileptr.seek(self.offset + self.numbytes, 0) #move forwards to the end of the record as we cannot trust the record length from the 2024
# # else:
# # self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
# # continue
# # now decode the subrecord
# # curr = self.fileptr.tell()
# if subrecord_id == 100:
# sf = self.readscalefactorrecord()
# return sf
###############################################################################
# Subrecord Description Subrecord Identifier
# DEPTH_ARRAY 1
# ACROSS_TRACK_ARRAY 2
# ALONG_TRACK_ARRAY 3
# TRAVEL_TIME_ARRAY 4
# BEAM_ANGLE_ARRAY 5
# MEAN_CAL_AMPLITUDE_ARRAY 6
# MEAN_REL_AMPLITUDE_ARRAY 7
# ECHO_WIDTH_ARRAY 8
# QUALITY_FACTOR_ARRAY 9
# RECEIVE_HEAVE_ARRAY 10
# DEPTH_ERROR_ARRAY (obsolete) 11
# ACROSS_TRACK_ERROR_ARRAY (obsolete) 12
# ALONG_TRACK_ERROR_ARRAY (obsolete) 13
# NOMINAL_DEPTH_ARRAY 14
# QUALITY_FLAGS_ARRAY 15
# BEAM_FLAGS_ARRAY 16
# SIGNAL_TO_NOISE_ARRAY 17
# BEAM_ANGLE_FORWARD_ARRAY 18
# VERTICAL_ERROR_ARRAY 19
# HORIZONTAL_ERROR_ARRAY 20
# INTENSITY_SERIES_ARRAY 21
# SECTOR_NUMBER_ARRAY 22
# DETECTION_INFO_ARRAY 23
# INCIDENT_BEAM_ADJ_ARRAY 24
# SYSTEM_CLEANING_ARRAY 25
# DOPPLER_CORRECTION_ARRAY 26
# SONAR_VERT_UNCERTAINTY_ARRAY 27
# SCALE_FACTORS 100
# SEABEAM_SPECIFIC 102
# EM12_SPECIFIC 103
# EM100_SPECIFIC 104
# EM950_SPECIFIC 105
# EM121A_SPECIFIC 106
# EM121_SPECIFIC 107
# SASS_SPECIFIC (To Be Replaced By CMP_SASS) 108
# SEAMAP_SPECIFIC 109
# SEABAT_SPECIFIC 110
# EM1000_SPECIFIC 111
# TYPEIII_SEABEAM_SPECIFIC (To Be Replaced By CMP_SASS ) 112
# SB_AMP_SPECIFIC 113
# SEABAT_II_SPECIFIC 114
# SEABAT_8101_SPECIFIC (obsolete) 115
# SEABEAM_2112_SPECIFIC 116
# ELAC_MKII_SPECIFIC 117
# EM3000_SPECIFIC 118
# EM1002_SPECIFIC 119
# EM300_SPECIFIC 120
# CMP_SASS_SPECIFIC (To replace SASS and TYPEIII_SEABEAM) 121
# RESON_8101_SPECIFIC 122
# RESON_8111_SPECIFIC 123
# RESON_8124_SPECIFIC 124
# RESON_8125_SPECIFIC 125
# RESON_8150_SPECIFIC 126
# RESON_8160_SPECIFIC 127
# EM120_SPECIFIC 128
# EM3002_SPECIFIC 129
# EM3000D_SPECIFIC 130
# EM3002D_SPECIFIC 131
# EM121A_SIS_SPECIFIC 132
# EM710_SPECIFIC 133
# EM302_SPECIFIC 134
# EM122_SPECIFIC 135
# GEOSWATH_PLUS_SPECIFIC 136
# KLEIN_5410_BSS_SPECIFIC 137
# RESON_7125_SPECIFIC 138
# EM2000_SPECIFIC 139
# EM300_RAW_SPECIFIC 140
# EM1002_RAW_SPECIFIC 141
# EM2000_RAW_SPECIFIC 142
# EM3000_RAW_SPECIFIC 143
# EM120_RAW_SPECIFIC 144
# EM3002_RAW_SPECIFIC 145
# EM3000D_RAW_SPECIFIC 146
# EM3002D_RAW_SPECIFIC 147
# EM121A_SIS_RAW_SPECIFIC 148
# EM2040_SPECIFIC 149
# DELTA_T_SPECIFIC 150
# R2SONIC_2022_SPECIFIC 151
# R2SONIC_2024_SPECIFIC 152
# R2SONIC_2020_SPECIFIC 153
# SB_ECHOTRAC_SPECIFIC (obsolete) 206
# SB_BATHY2000_SPECIFIC (obsolete) 207
# SB_MGD77_SPECIFIC (obsolete) 208
# SB_BDB_SPECIFIC (obsolete) 209
# SB_NOSHDB_SPECIFIC (obsolete) 210
# SB_PDD_SPECIFIC (obsolete) 211
# SB_NAVISOUND_SPECIFIC (obsolete) 212
###############################################################################
def read(self, previousscalefactors={}, headeronly=False):
# read ping header
hdrfmt = '>llll5hlH3h2Hlllh'
hdrlen = struct.calcsize(hdrfmt)
rec_unpack = struct.Struct(hdrfmt).unpack
self.fileptr.seek(self.offset + self.hdrlen, 0) # move the file pointer to the start of the record so we can read from disc
# self.fileptr.seek(self.offset + self.hdrlen , 0) # move the file pointer to the start of the record so we can read from disc
data = self.fileptr.read(hdrlen)
s = rec_unpack(data)
self.time = s[0]
self.pingnanotime = s[1]
self.timestamp = self.time + (self.pingnanotime/1000000000)
self.longitude = s[2] / 10000000
self.latitude = s[3] / 10000000
self.numbeams = s[4]
self.centrebeam = s[5]
self.pingflags = s[6]
self.reserved = s[7]
self.tidecorrector = s[8] / 100
self.depthcorrector = s[9] / 100
self.heading = s[10] / 100
self.pitch = s[11] / 100
self.roll = s[12] / 100
self.heave = s[13] / 100
self.course = s[14] / 100
self.speed = s[15] / 100
self.height = s[16] / 100
self.separation = s[17] / 100
self.gpstidecorrector = s[18] / 100
self.spare = s[19]
# SCALE FACTORS ARE NOT ON EVERYPING SO CARRY FORWARDS
self.scalefactorsd = previousscalefactors
# skip the record for performance reasons. Very handy in some circumstances
if headeronly:
self.fileptr.seek(self.offset + self.numbytes, 0) #move forwards to the end of the record as we cannot trust the record length from the 2024
return
while (self.fileptr.tell() <= self.offset + self.numbytes): #dont read past the end of the packet length. This should never happen!
subrecfmt = '>l'
subrecfmtlen = struct.calcsize(subrecfmt)
subrecrec_unpack = struct.Struct(subrecfmt).unpack
data = self.fileptr.read(subrecfmtlen) # read the record from disc
s = subrecrec_unpack(data)
subrecord_id = (s[0] & 0xFF000000) >> 24
subrecord_size = s[0] & 0x00FFFFFF
# print("id %d size %d" % (subrecord_id, subrecord_size))
# if subrecord_id == 21:
# self.fileptr.seek(self.offset + self.numbytes, 0) #move forwards to the end of the record as we cannot trust the record length from the 2024
# else:
# self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
# continue
# now decode the subrecord
# curr = self.fileptr.tell()
if subrecord_id == SCALE_FACTORS:
self.readscalefactorrecord()
continue
# for s in self.scalefactors:
# if s.subrecordID == 1:
# print (s.subrecordID, s.multiplier, s.offset, s.compressionFlag)
# continue
# else:
# scale, offset, compressionFlag, datatype = self.getscalefactor(subrecord_id, subrecord_size / int(self.numbeams))
if subrecord_id == 0:
self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
continue
if subrecord_id > len(self.scalefactorsd):
self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
continue
sf = self.scalefactorsd[subrecord_id]
datatype = self.getdatatype(subrecord_id, subrecord_size / int(self.numbeams))
# skip records we do not support
if datatype == -999:
self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
continue
if subrecord_id == 1:
# scale, offset, compressionFlag, datatype = self.getscalefactor(subrecord_id, subrecord_size / int(self.numbeams))
# print (sf.multiplier, sf.offset)
# print ("DEPTH ARRAY")
self.DEPTH_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 2:
# print ("ACROSS ARRAY")
self.ACROSS_TRACK_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 3:
# print ("ALONG ARRAY")
self.ALONG_TRACK_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 4:
# print ("TT ARRAY")
self.TRAVEL_TIME_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 5:
# print ("BA ARRAY")
self.BEAM_ANGLE_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 6:
# print ("MC ARRAY")
self.MEAN_CAL_AMPLITUDE_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 7:
# print ("MR ARRAY")
self.MEAN_REL_AMPLITUDE_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 9:
# print ("QF ARRAY")
self.QUALITY_FACTOR_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 15:
# print ("QF ARRAY")
self.QUALITY_FLAGS_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 16:
# print ("BF ARRAY")
self.BEAM_FLAGS_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 18:
# print ("BA ARRAY")
self.BEAM_ANGLE_FORWARD_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 19:
# print ("VA ARRAY")
self.VERTICAL_ERROR_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 20:
# print ("VE ARRAY")
self.VERTICAL_ERROR_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
elif subrecord_id == 21:
before = self.fileptr.tell()
# print ("SN ARRAY")
self.SNIPPET_SERIES_ARRAY = self.readintensityarray(sf.multiplier, sf.offset, datatype, self.snippettype)
if subrecord_size % 4 > 0:
self.fileptr.seek(4 - (subrecord_size % 4), 1) #pkpk we should not need this!!!
elif subrecord_id == 22:
# print ("SE ARRAY")
self.SECTOR_NUMBER_ARRAY = self.readarray(sf.multiplier, sf.offset, datatype)
else:
# read to the end of the record to keep in alignment. This permits us to not have all the decodes in place
self.fileptr.seek(subrecord_size, 1) #move forwards to the end of teh record
self.fileptr.seek(self.offset + self.numbytes, 0) #move forwards to the end of the record as we cannot trust the record length from the 2024
return self.scalefactorsd
###############################################################################
def __str__(self):
'''
pretty print this class
'''
return pprint.pformat(vars(self))
###############################################################################
def clippolar(self, leftclipdegrees, rightclipdegrees):
'''sets the processing flags to rejected if the beam angle is beyond the clip parameters'''
if self.numbeams == 0:
return
if len(self.QUALITY_FACTOR_ARRAY) != len(self.TRAVEL_TIME_ARRAY):
return
for i, s in enumerate(self.BEAM_ANGLE_ARRAY):
if (s <= leftclipdegrees) or (s >= rightclipdegrees):
self.QUALITY_FACTOR_ARRAY[i] += REJECT_CLIP
# self.MEAN_REL_AMPLITUDE_ARRAY[i] = 0
# self.ACROSS_TRACK_ARRAY[i] = 0
return
###############################################################################
def cliptwtt(self, minimumtraveltime=0.0):
'''sets the processing flags to rejected if the two way travel time is less than the clip parameters'''
if self.numbeams == 0:
return
if len(self.QUALITY_FACTOR_ARRAY) != len(self.TRAVEL_TIME_ARRAY):
return
for i, s in enumerate(self.TRAVEL_TIME_ARRAY):
if (s <= minimumtraveltime):
self.QUALITY_FACTOR_ARRAY[i] += REJECT_RANGE
return
###############################################################################
def clipintensity(self, minimumintenisty=0.0):
'''sets the processing flags to rejected if the two way travel time is less than the clip parameters'''
if self.numbeams == 0:
return
if len(self.QUALITY_FACTOR_ARRAY) != len(self.TRAVEL_TIME_ARRAY):
return
for i, s in enumerate(self.MEAN_REL_AMPLITUDE_ARRAY):
if (s <= minimumintenisty):
self.QUALITY_FACTOR_ARRAY[i] += REJECT_INTENSITY
return
###############################################################################
def getdatatype(self, ID, bytes_per_value):
datatype = -999
if ID == DEPTH_ARRAY:
if bytes_per_value == 2:
datatype = 'H' #unsigned values
elif bytes_per_value == 4:
datatype = 'L' #unsigned values
elif ID == NOMINAL_DEPTH_ARRAY:
if bytes_per_value == 2:
datatype = 'H' #unsigned values
elif bytes_per_value == 4:
datatype = 'L' #unsigned values
elif ID == ACROSS_TRACK_ARRAY:
if bytes_per_value == 2:
datatype = 'h' #signed values
elif bytes_per_value == 4:
datatype = 'l' #signed values
elif ID == ALONG_TRACK_ARRAY:
if bytes_per_value == 2:
datatype = 'h' #signed values
elif bytes_per_value == 4:
datatype = 'l' #signed values
elif ID == TRAVEL_TIME_ARRAY:
if bytes_per_value == 2:
datatype = 'H' #unsigned values
elif bytes_per_value == 4:
datatype = 'L' #unsigned values
elif ID == BEAM_ANGLE_ARRAY:
if bytes_per_value == 2:
datatype = 'h' #signed values
elif bytes_per_value == 4:
datatype = 'l' #signed values
elif ID == MEAN_CAL_AMPLITUDE_ARRAY:
if bytes_per_value == 1:
datatype = 'b' #signed values
if bytes_per_value == 2:
datatype = 'h' #signed values
elif ID == MEAN_REL_AMPLITUDE_ARRAY:
if bytes_per_value == 1:
datatype = 'B' #unsigned values
if bytes_per_value == 2:
datatype = 'H' #unsigned values
elif ID == ECHO_WIDTH_ARRAY:
if bytes_per_value == 1:
datatype = 'B' #unsigned values
if bytes_per_value == 2:
datatype = 'H' #unsigned values
elif ID == QUALITY_FACTOR_ARRAY:
datatype = 'B' #unsigned values
elif ID == RECEIVE_HEAVE_ARRAY:
datatype = 'b' #signed values
elif ID == DEPTH_ERROR_ARRAY:
datatype = 'H' #unsigned values
elif ID == ACROSS_TRACK_ERROR_ARRAY:
datatype = 'H' #unsigned values
elif ID == ALONG_TRACK_ERROR_ARRAY:
datatype = 'H' #unsigned values
elif ID == BEAM_FLAGS_ARRAY:
datatype = 'B' #unsigned values
elif ID == QUALITY_FLAGS_ARRAY:
datatype = 'B' #unsigned values
elif ID == SIGNAL_TO_NOISE_ARRAY:
datatype = 'b' #signed values
elif ID == BEAM_ANGLE_FORWARD_ARRAY:
datatype = 'H' #signed values
elif ID == VERTICAL_ERROR_ARRAY:
datatype = 'H' #signed values
elif ID == HORIZONTAL_ERROR_ARRAY:
datatype = 'H' #signed values
elif ID == SECTOR_NUMBER_ARRAY:
datatype = 'B' #unsigned values
elif ID == DETECTION_INFO_ARRAY:
datatype = 'B' #unsigned values
else:
return -999
return datatype
###############################################################################
# def getscalefactor(self, ID, bytes_per_value):
# for s in self.scalefactors:
# if s.subrecordID == ID: # DEPTH_ARRAY array
# if bytes_per_value == 1:
# datatype = 'B' #unsigned values
# elif bytes_per_value == 2:
# datatype = 'H' #unsigned values
# if ID == 2: #ACROSS_TRACK_ARRAY array
# datatype = 'h' #unsigned values
# if ID == 3: #ACROSS_TRACK_ARRAY array
# datatype = 'h' #unsigned values
# if ID == 5: #beam angle array
# datatype = 'h' #unsigned values
# elif bytes_per_value == 4:
# datatype = 'L' #unsigned values
# if ID == 2: #ACROSS_TRACK_ARRAY array
# datatype = 'l' #unsigned values
# if ID == 5: #beam angle array
# datatype = 'l' #unsigned values
# else:
# datatype = 'L' #unsigned values not sure about this one. needs test data
# return s.multiplier, s.offset, s.compressionFlag, datatype
# return 1,0,0, 'h'
###############################################################################
def readscalefactorrecord(self):
# /* First four byte integer contains the number of scale factors */
# now read all scale factors
scalefmt = '>l'
scalelen = struct.calcsize(scalefmt)
rec_unpack = struct.Struct(scalefmt).unpack
data = self.fileptr.read(scalelen)
s = rec_unpack(data)
self.numscalefactors = s[0]
scalefmt = '>lll'
scalelen = struct.calcsize(scalefmt)
rec_unpack = struct.Struct(scalefmt).unpack
# self.scalefactorsd = {}
for i in range(self.numscalefactors):
data = self.fileptr.read(scalelen)
s = rec_unpack(data)
sf = SCALEFACTOR()
sf.subrecordID = (s[0] & 0xFF000000) >> 24;
sf.compressionFlag = (s[0] & 0x00FF0000) >> 16;
sf.compressionFlag = s[0] & 0xF0;
sf.multiplier = s[1]
sf.offset = s[2]
sf.datatype = sf.compressionFlag
# ALONG_ACROSS_TRACK_ARRAY = 2
# TRACK_ARRAY = 3
# TRAVEL_TIME_ARRAY = 4
# BEAM_ANGLE_ARRAY = 5
# MEAN_CAL_AMPLITUDE_ARRAY = 6
# MEAN_REL_AMPLITUDE_ARRAY = 7
# ECHO_WIDTH_ARRAY = 8
# QUALITY_FACTOR_ARRAY = 9
# RECEIVE_HEAVE_ARRAY = 10
# DEPTH_ERROR_ARRAY = 11
# ACROSS_TRACK_ERROR_ARRAY = 12
# ALONG_TRACK_ERROR_ARRAY = 13
# NOMINAL_DEPTH_ARRAY = 14
# QUALITY_FLAGS_ARRAY = 15
# BEAM_FLAGS_ARRAY = 16
# SIGNAL_TO_NOISE_ARRAY = 17
# BEAM_ANGLE_FORWARD_ARRAY = 18
# VERTICAL_ERROR_ARRAY = 19
# if sf.subrecordID == DEPTH_ARRAY: # DEPTH_ARRAY array
# if bytes_per_value == 1:
# sf.datatype = 'B' #unsigned values
# elif bytes_per_value == 2:
# sf.datatype = 'H' #unsigned values
# if ID == 2: #ACROSS_TRACK_ARRAY array
# sf.datatype = 'h' #unsigned values
# if ID == 3: #ACROSS_TRACK_ARRAY array
# sf.datatype = 'h' #unsigned values
# if ID == 5: #beam angle array
# sf.datatype = 'h' #unsigned values
# elif bytes_per_value == 4:
# sf.datatype = 'L' #unsigned values
# if ID == 2: #ACROSS_TRACK_ARRAY array
# sf.datatype = 'l' #unsigned values
# if ID == 5: #beam angle array
# sf.datatype = 'l' #unsigned values
# else:
# datatype = 'L' #unsigned values not sure about this one. needs test data
# print (sf.subrecordID, sf.compressionFlag, sf.multiplier, sf.offset)
self.scalefactorsd[sf.subrecordID] = sf
# self.scalefactors=[]
# for i in range(self.numscalefactors):
# data = self.fileptr.read(scalelen)
# s = rec_unpack(data)
# sf = SCALEFACTOR()
# sf.subrecordID = (s[0] & 0xFF000000) >> 24;
# sf.compressionFlag = (s[0] & 0x00FF0000) >> 16;
# sf.multiplier = s[1]
# sf.offset = s[2]
# self.scalefactors.append(sf)
# # print (sf.subrecordID, sf.compressionFlag, sf.multiplier, sf.offset)
# return self.scalefactors
###############################################################################
def readintensityarray(self, snippets, scale, offset, datatype, snippettype):
'''
read the time series intensity array type 21 subrecord
'''
hdrfmt = '>bl16s'
hdrlen = struct.calcsize(hdrfmt)
rec_unpack = struct.Struct(hdrfmt).unpack
hdr = self.fileptr.read(hdrlen)
s = rec_unpack(hdr)
bitspersample = s[0]
appliedcorrections = s[1]
# before we decode the intentisty data, read the sensor specific header
#for now just read the r2sonic as that is what we need. For other sensors we need to implement decodes
self.decodeR2SonicImagerySpecific()
for b in range(self.numbeams):
hdrfmt = '>hh8s'
hdrlen = struct.calcsize(hdrfmt)
rec_unpack = struct.Struct(hdrfmt).unpack
hdr = self.fileptr.read(hdrlen)
s = rec_unpack(hdr)
numsamples = s[0]
bottomdetectsamplenumber = s[1]
spare = s[2]
fmt = '>' + str(numsamples) + 'H'
l = struct.calcsize(fmt)
rec_unpack = struct.Struct(fmt).unpack
data = self.fileptr.read(l)
raw = rec_unpack(data)
# strip out zero values
raw = [s for s in raw if s != 0]
if snippettype == SNIPPET_NONE:
snippets.append(0)
continue
elif snippettype == SNIPPET_MEAN5DB:
# populate the array with the mean of all samples withing a 5dB range of the mean. As per QPS
if len(raw) > 0:
raw2 = [20.0 * math.log10(s / scale + offset) for s in raw]
mean = (sum(raw2) / float(len(raw2) ))
highcut = [s for s in raw2 if s < mean + 5] #high cut +5dB
highlowcut = [s for s in highcut if s > mean - 5] #low cut -5dB
else:
snippets.append(0)
continue
if len(highlowcut) > 0:
snippets.append((sum(highlowcut) / float(len(highlowcut) / scale) + offset))
else:
snippets.append((mean / scale) + offset)
elif snippettype == SNIPPET_MEAN:
# populate the array with the mean of all samples
if len(raw) > 0:
snippets.append((sum(raw) / float(len(raw) / scale) + offset))
else:
snippets.append(0)
elif snippettype == SNIPPET_MAX:
# populate the array with the MAX of all samples
if len(raw) > 0:
snippets.append(max(raw) / scale + offset)
else:
snippets.append(0)
elif snippettype == SNIPPET_MEAN:
# populate with a single value as identified by the bottom detect
if bottomdetectsamplenumber > 0:
snippets.append ((raw[bottomdetectsamplenumber] / scale) + offset)
else:
snippets.append (0)
return
###############################################################################
def R2Soniccorrection(self):
'''entry point for r2sonic backscatter TVG, Gain and footprint correction algorithm'''
if self.perbeam:
samplearray = self.MEAN_REL_AMPLITUDE_ARRAY
return samplearray
else:
samplearray = self.SNIPPET_SERIES_ARRAY
return samplearray
# an implementation of the backscatter correction algorithm from Norm Campbell at CSIRO
H0_TxPower = self.transmitsourcelevel
H0_SoundSpeed = self.soundspeed
H0_RxAbsorption = self.absorptioncoefficient
H0_TxBeamWidthVert = self.beamwidthvertical
H0_TxBeamWidthHoriz = self.beamwidthhorizontal
H0_TxPulseWidth = self.pulsewidth
H0_RxSpreading = self.receiverspreadingloss
H0_RxGain = self.receivergain
H0_VTX_Offset = self.vtxoffset
for i in range(self.numbeams):
if self.BEAM_FLAGS_ARRAY[i] < 0:
continue
S1_angle = self.BEAM_ANGLE_ARRAY[i] #angle in degrees
S1_twtt = self.TRAVEL_TIME_ARRAY[i]
S1_range = math.sqrt((self.ACROSS_TRACK_ARRAY[i] ** 2) + (self.ALONG_TRACK_ARRAY[i] ** 2))
if samplearray[i] != 0:
S1_uPa = samplearray[i]
# adjusted = 0
# a test on request from Norm....
# adjusted = 20 * math.log10(S1_uPa) - 100
# the formal adjustment from Norm Campbell...
# if i == 127:
adjusted = self.backscatteradjustment( S1_angle, S1_twtt, S1_range, S1_uPa, H0_TxPower, H0_SoundSpeed, H0_RxAbsorption, H0_TxBeamWidthVert, H0_TxBeamWidthHoriz, H0_TxPulseWidth, H0_RxSpreading, H0_RxGain, H0_VTX_Offset)
samplearray[i] = adjusted
return samplearray
###############################################################################
def backscatteradjustment(self, S1_angle, S1_twtt, S1_range, S1_Magnitude, H0_TxPower, H0_SoundSpeed, H0_RxAbsorption, H0_TxBeamWidthVert, H0_TxBeamWidthHoriz, H0_TxPulseWidth, H0_RxSpreading, H0_RxGain, H0_VTX_Offset):
'''R2Sonic backscatter correction algorithm from Norm Camblell at CSIRO. This is a port from F77 fortran code, and has been tested and confirmed to provide identical results'''
# the following code uses the names for the various packets as listed in the R2Sonic SONIC 2024 Operation Manual v6.0
# so names beginning with
# H0_ denote parameters from the BATHY (BTH) and Snippet (SNI) packets from section H0
# R0_ denote parameters from the BATHY (BTH) packets from section R0
# S1_ denote parameters from the Snippet (SNI) packets from section S1
# names beginning with
# z_ denote values derived from the packet parameters
# the range, z_range_m, can be found from the two-way travel time (and scaling factor), and the sound speed, as follows:
one_rad = 57.29577951308232
S1_angle_rad = S1_angle / one_rad
z_one_way_travel_secs = S1_twtt / 2.0
z_range_m = z_one_way_travel_secs * H0_SoundSpeed
# there is a range of zero, so this is an invalid beam, so quit
if z_range_m == 0:
return 0
###### TRANSMISSION LOSS CORRECTION ##########################################
# according to Lurton, Augustin and Le Bouffant (Femme 2011), the basic Sonar equation is
# received_level = source_level - 2 * transmission_loss + target_strength + receiver_gain
# note that this last term does not always appear explicitly in the sonar equation
# more specifically:
# transmission_loss = H0_RxAbsorption * range_m + 40 log10 ( range_m )
# target_strength = backscatter_dB_m + 10 log10 ( z_area_of_insonification )
# receiver_gain = TVG + H0_RxGain
# the components of the Sonar equation can be calculated as follows:
# u16 S1_Magnitude[S1_Samples]; // [micropascals] = S1_Magnitude[n]
z_received_level = 20.0 * math.log10 ( S1_Magnitude )
z_source_level = H0_TxPower # [dB re 1 uPa at 1 meter]
z_transmission_loss_t1 = 2.0 * H0_RxAbsorption * z_range_m / 1000.0 # [dB per kilometer]
z_transmission_loss_t2 = 40.0 * math.log10(z_range_m)
z_transmission_loss = z_transmission_loss_t1 + z_transmission_loss_t2
###### INSONIFICATION AREA CORRECTION Checked 19 August 2017 p.kennedy@fugr.com ##########################################
# for oblique angles
# area_of_insonification = along_track_beam_width * range * sound_speed * pulse_width / 2 sin ( incidence_angle)
# for normal incidence
# area_of_insonification = along_track_beam_width * across_track_beam_width * range ** 2
sin_S1_angle = math.sin ( abs ( S1_angle_rad ) )
# from Hammerstad 00 EM Technical Note Backscattering and Seabed Image Reflectivity.pdf
# A = ψTψr*R^2 around normal incidence
z_area_of_insonification_nml = H0_TxBeamWidthVert * H0_TxBeamWidthHoriz * z_range_m **2
# A = ½cτ ψTR/sinφ elsewhere
if ( abs ( S1_angle ) >= 0.001 ):
z_area_of_insonification_obl = 0.5 * H0_SoundSpeed * H0_TxPulseWidth * H0_TxBeamWidthVert * z_range_m / sin_S1_angle
if ( abs ( S1_angle ) < 25. ):
z_area_of_insonification = z_area_of_insonification_nml
else:
z_area_of_insonification = z_area_of_insonification_obl
if ( abs ( S1_angle ) < 0.001 ):
z_area_of_insonification = z_area_of_insonification_nml
elif ( z_area_of_insonification_nml < z_area_of_insonification_obl ):