Home > Blockchain >  how to read sonar data in python
how to read sonar data in python

Time:11-23

I need to read sonar datatype file in python. Sonar data contains the ocean details, It used to measure the depth of the sea. The file contains binary data and extension as .s7k format.

CodePudding user response:

I downloaded a sample s7k file to test whether I could read it---and I could. (The sample file I used to test can be downloaded here.)

  1. First, in a new project folder, download this dg_formats.py file, which contains a list of reson datagram codes and helpers.

  2. Next, download this reader.py file to the same folder.

  3. Line #9 of reader.py is the following:

    from hyo2.openbst.lib.raw.parsers.reson.dg_formats import parse, ResonDatagrams, reson_datagram_code
    

    Change this to:

    from dg_formats import parse, ResonDatagrams, reson_datagram_code
    

    Basically we skip installing the hyo2-qc library, we just take the parsing and reader code.

Afterwards, I can simply do:

from pathlib import Path
from reader import Reson
from dg_formats import parse, ResonDatagrams, reson_datagram_code

input_path = Path("20190730_144835.s7k") # the sample I downloaded

sonar_file = Reson(input_path)
sonar_file.is_mapped()

We can check the attributes with the class dict:

>>> sonar_file.__dict__
{'_valid': True,
 'data': None,
 'map': {7200: [[64, 1564498115590.0002, 334, 386]],
  7022: [[466, 1564495196916.9998, 32, 0]],
  7001: [[566, 1564495197011.0015, 7699, 0]],
  7021: [[8333, 1564498114898.9983, 20116, 0],
   [2340566, 1564498116758.9988, 20116, 0],
   [5031198, 1564498118618.9995, 20116, 0],
...
 '_reson_sync_patt': 65535,
 'format_type': 's7k',
 'file_length': 88684918,
 'file_location': 88684918,
 'file_end': True}

We can also see a list of map keys like this:

>>> print(sorted(sonar_file.map.keys()))
[1003, 1012, 1013, 7000, 7001, 7002, 7004, 7007, 7010, 7021, 7022, 7027, 7028, 7058, 7200, 7300, 7503, 7504, 7610]

This is basically what information is inside. From dg_formats.py, we can match the code and see what's what. For example, 1003 is position, so:

>>> position_data = sonar_file.get_datagram(ResonDatagrams.POSITION)
>>> print(position_data)

[<dg_formats.Data1003 at 0x7f4946c1c5e0>,
 <dg_formats.Data1003 at 0x7f4946c1c130>,
...
...
 <dg_formats.Data1003 at 0x7f493e28d880>]

# let's get information of first position
>>> print(position_data[0].__dict__)

{'desc': 'Position', 'time': 1564498113624.0005, 'num_beams_max': 512, 'parse_check': True, 'header_fmt': '<If3d5B', 'header_size': 37, 'datum': 'WGS', 'latency': 0.0, 'latitude': 0.7517794800836651, 'longitude': -1.2341624217514013, 'datum_height': 1.32, 'position_flag': 0, 'qual_flag': 0, 'position_method': 0, 'num_of_satelites': 15}

There isn't helpers for all the codes (for example, nothing for 7200, 7300, 7503, 7504, 7610), but I hope it's a start to how to get info out of the file!

  • Related