r2sonic_extract_truepix
Description
r2sonic_extract_truepix is a utility designed to extract TruePix data from R2Sonic multibeam sonar .r2s files. TruePix is a raw data format from R2Sonic sonars that contains beam-formed magnitude and angle time series for both port and starboard sides.
This tool processes the .r2s file, extracts the TruePix data, converts it into 8-bit image data (for magnitude and angle separately), and optionally dumps detailed time-series data for a specific ping to an ASCII file. This is crucial for visualizing the raw backscatter and angle responses, which can be used for advanced bottom classification or quality control.
Usage
r2sonic_extract_truepix -r2s <input.r2s> -outprefix <output_prefix> [-ping <ping_number>] [-v]
Arguments
| Option | Description | |—|—| | -r2s <input.r2s> | Required. Path to the input R2Sonic .r2s file. | | -outprefix <output_prefix> | Required. Prefix for the output files. The tool will generate: * <output_prefix>_mag.8bit: 8-bit magnitude image data. * <output_prefix>_angle.8bit: 8-bit angle image data. * <output_prefix>_timeseries.out (optional): ASCII time-series data for a specific ping. | | -ping <ping_number> | Dumps detailed time-series data for the specified ping_number (0-indexed). | | -v | Enable verbose output. | |
How It Works
- Initialization: Parses command-line arguments to get input/output filenames and the
desired_pingnumber. - File Opening: Opens the input
.r2sfile for reading. Opens two 8-bit output files (_mag.8bit,_angle.8bit) for writing magnitude and angle image data. Ifdesired_pingis specified, it also opens a_timeseries.outfile. - R2Sonic Indexing: Calls
build_R2SONIC_INDEX()(an external function) to build an index of the.r2sfile, locating all TruePix records (R2SONIC_ID_TPX0). - TruePix Data Extraction: Iterates through each TruePix record found in the index:
- Seeks to the
file_offsetof the current TruePix record. - Reads the
R2SONIC_TRUEPIXdata (tpx) usingread_R2SONIC_TRUEPIX(). - Magnitude Image Generation:
- Allocates an output buffer (
outbuffer) oftpx.D1_TotalSamplessize. - For the port magnitude data (
tpx.D1_Data_PortMagnitude), it converts the magnitude values to an 8-bit logarithmic scale (2.0 * 20.0 * log10(...)) and stores them in theoutbuffer(reversed order). - Writes the
outbufferto_mag.8bit. - Repeats the process for starboard magnitude data (
tpx.D1_Data_StbdMagnitude), storing them inoutbuffer(normal order). - Writes the
outbufferto_mag.8bit.
- Allocates an output buffer (
- Angle Image Generation:
- For the port angle data (
tpx.D1_Data_PortAngle), it converts the angle values to an 8-bit scaled representation (fabs(...) * AngleScalingFactor * 180.0/M_PI * 3.0) and stores them inoutbuffer(reversed order). - Writes the
outbufferto_angle.8bit. - Repeats the process for starboard angle data (
tpx.D1_Data_StbdAngle), storing them inoutbuffer(normal order). - Writes the
outbufferto_angle.8bit.
- For the port angle data (
- Time Series Dump (
-ping): If the currentpingmatchesdesired_ping:- Calculates
rangefromrx_sample_rateandsound_speed. - For each sample in the TruePix data, it prints detailed information (sample index, port magnitude, port angle, starboard magnitude, starboard angle, and calculated X/Y coordinates in meters) to
_timeseries.out.
- Calculates
- Seeks to the
- Cleanup: Closes all open files.
Output Files
<output_prefix>_mag.8bit: Binary file containing 8-bit magnitude data.<output_prefix>_angle.8bit: Binary file containing 8-bit angle data.<output_prefix>_timeseries.out: ASCII file with detailed time-series data for a specified ping (if-pingis used).
Dependencies
R2Sonic_parser.h: For R2Sonic data structures and parsing functions (build_R2SONIC_INDEX,read_R2SONIC_TRUEPIX).support.h: For general utility functions and error handling.array.h: ForJHC_headerstructure.
Notes
TruePix data provides raw beam-formed information crucial for advanced backscatter analysis and bottom classification. This tool allows for the extraction and visualization of these raw signals, which can be invaluable for developing custom processing algorithms or for quality control. The output images can be viewed using image viewers that support raw 8-bit data, and the time-series dump provides detailed numeric insight into the waveforms.