Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_xtf.py 3.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. import pyxtf
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. # Read the test file
  5. # Note that at this point, the header_7125 and header_7125_snippet is not implemented, which is why a warning is shown
  6. # The bathymetry and sonar headers are implemented, however - which can be read while ignoring the unimplemented packets
  7. test_file = "/home/ps/PycharmProjects/mines_rocks/data/JNCC2013_03BassSandRawAcousticssraw_data/BoxA/20130328042943L.xtf"
  8. (fh, p) = pyxtf.xtf_read(test_file)
  9. # This prints all the ctypes fields present
  10. print(fh)
  11. # The ChanInfo field is an array of XTFChanInfo objects
  12. # Note that the ChanInfo field always has a size of 6, even if the number of channels is less.
  13. # Use the fh.NumXChannels fields to calculate the number (the function xtf_channel_count does this)
  14. n_channels = fh.channel_count(verbose=True)
  15. actual_chan_info = [fh.ChanInfo[i] for i in range(0, n_channels)]
  16. print('Number of data channels: {}\n'.format(n_channels))
  17. # Print the first channel
  18. print(actual_chan_info[0])
  19. # Print the keys in the packets-dictionary
  20. print([key for key in p])
  21. # The returned packets is a Dict[XTFHeaderType, List[XTFClass]]
  22. # The values in the dict are lists of pings, of the class in question
  23. sonar_ch = p[pyxtf.XTFHeaderType.sonar] # type: List[pyxtf.XTFPingHeader]
  24. # Each element in the list is a ping (XTFPingHeader)
  25. # This retrieves the first ping in the file of the sonar type
  26. sonar_ch_ping1 = sonar_ch[0]
  27. # The properties in the header defines the attributes common for all subchannels
  28. # (e.g sonar often has port/stbd subchannels)
  29. print(sonar_ch_ping1)
  30. # The data and header for each subchannel is contained in the data and ping_chan_headers respectively.
  31. # The data is a list of numpy arrays (one for each subchannel)
  32. sonar_subchan0 = sonar_ch_ping1.data[0] # type: np.ndarray
  33. sonar_subchan1 = sonar_ch_ping1.data[1] # type: np.ndarray
  34. print(sonar_subchan0.shape)
  35. print(sonar_subchan1.shape)
  36. # Plot a signal-vie of both subchannels of the first ping
  37. fig, (ax1, ax2) = plt.subplots(2,1, figsize=(12,8))
  38. ax1.semilogy(np.arange(0, sonar_subchan0.shape[0]), sonar_subchan0)
  39. ax2.semilogy(np.arange(0, sonar_subchan1.shape[0]), sonar_subchan1)
  40. # Each subchannel has a XTFPingChanHeader,
  41. # which contains information that can change from ping to ping in each of the subchannels
  42. sonar_ping1_ch_header0 = sonar_ch_ping1.ping_chan_headers[0]
  43. print(sonar_ping1_ch_header0)
  44. # Concatenate the sonar data to produce a dense array/image
  45. # The function concatenate_channels concatenates all the individual pings for a channel, and returns it as a dense numpy array
  46. np_chan1 = pyxtf.concatenate_channel(p[pyxtf.XTFHeaderType.sonar], file_header=fh, channel=0, weighted=False)
  47. np_chan2 = pyxtf.concatenate_channel(p[pyxtf.XTFHeaderType.sonar], file_header=fh, channel=1, weighted=False)
  48. # Clip to range (max cannot be used due to outliers)
  49. # More robust methods are possible (through histograms / statistical outlier removal)
  50. upper_limit = 2 ** 14
  51. np_chan1.clip(0, upper_limit-1, out=np_chan1)
  52. np_chan2.clip(0, upper_limit-1, out=np_chan2)
  53. # The sonar data is logarithmic (dB), add small value to avoid log10(0)
  54. np_chan1 = np.log10(np_chan1 + 0.0001)
  55. np_chan2 = np.log10(np_chan2 + 0.0001)
  56. # Transpose so that the largest axis is horizontal
  57. np_chan1 = np_chan1 if np_chan1.shape[0] < np_chan1.shape[1] else np_chan1.T
  58. np_chan2 = np_chan2 if np_chan2.shape[0] < np_chan2.shape[1] else np_chan2.T
  59. # The following plots the waterfall-view in separate subplots
  60. fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))
  61. ax1.imshow(np_chan1, cmap='gray', vmin=0, vmax=np.log10(upper_limit))
  62. ax2.imshow(np_chan2, cmap='gray', vmin=0, vmax=np.log10(upper_limit))
  63. plt.show()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...