Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to apply time latency to kmall/mb261 survey data with mbpreprocess #1264

Open
berkowski opened this issue Feb 3, 2022 · 6 comments
Open

Comments

@berkowski
Copy link

berkowski commented Feb 3, 2022

Describe the bug
Unable to apply time latency to kmall/mb261 survey data with mbpreprocess

To Reproduce

cat datalist.mb-1
0005_20220131_1717_sentry.kmall 261

mbpreprocess --verbose -I datalist.mb-1


Program mbpreprocess
MB-system Version 5.7.9beta27

Program <  mbpreprocess>
MB-system Version   5.7.9beta27
Input survey data to be preprocessed:
     read_file:                    datalist-preprocess.mb-1
     format:                       -1
Output directory:
     output_directory:             not specified, use working directory
     output_datalist:             not specified, use default: datalist.mb-1
Source of platform model:
     platform_file:              not specified
     target_sensor:                -1
Source of navigation data:
     nav_mode:                     0
     nav_file:                     
     nav_file_format:              0
     nav_async:                    1
     nav_sensor:                   -1
Source of sensor depth data:
     sensordepth_mode:             0
     sensordepth_file:             
     sensordepth_file_format:      0
     sensordepth_async:            1
     sensordepth_sensor:           -1
Source of heading data:
     heading_mode:                 0
     heading_file:                 
     heading_file_format:          0
     heading_async:                1
     heading_sensor:               -1
Source of altitude data:
     altitude_mode:                0
     altitude_file:                
     altitude_file_format:         0
     altitude_async:               1
     altitude_sensor:              -1
Source of attitude data:
     attitude_mode:                0
     attitude_file:                
     attitude_file_format:         0
     attitude_async:               1
     attitude_sensor:              -1
Source of soundspeed data:
     soundspeed_mode:              0
     soundspeed_file:              
     soundspeed_file_format:       0
     soundspeed_async:             1
     soundspeed_sensor:            -1
Time latency correction:
     time_latency_mode:            0
     time_latency_constant:        0.000000
     time_latency_file:            
     time_latency_format:          1
     time_latency_apply:           0
Time domain filtering:
     filter_length:                0.000000
     filter_apply:                 0
Miscellaneous controls:
     no_change_survey:             0
     multibeam_sidescan_source:    0
     recalculate_bathymetry:       0
     sounding_amplitude_filter:    0
     sounding_amplitude_threshold: 0.000000
     sounding_altitude_filter:     0
     sounding_target_altitude:     0.000000
     ignore_water_column:          0
     head1_offsets:                0
     head1_offsets_x:              0.000000
     head1_offsets_y:              0.000000
     head1_offsets_z:              0.000000
     head1_offsets_heading:        0.000000
     head1_offsets_roll:           0.000000
     head1_offsets_pitch:          0.000000
     head2_offsets:                0
     head2_offsets_x:              0.000000
     head2_offsets_y:              0.000000
     head2_offsets_z:              0.000000
     head2_offsets_heading:        0.000000
     head2_offsets_roll:           0.000000
     head2_offsets_pitch:          0.000000
Various data fixes (kluges):
     kluge_timejumps:              0
     kluge_timejumps_threshold:    0.000000
     kluge_timejumps_ancilliary:   0
     kluge_timejumps_anc_threshold:0.000000
     kluge_timejumps_mbaripressure:0
     kluge_timejumps_mba_threshold:0.000000
     kluge_beamtweak:              0
     kluge_beamtweak_factor:       1.000000
     kluge_soundspeedtweak:        0
     kluge_soundspeedtweak_factor: 1.000000
     kluge_fix_wissl_timestamps:   0
     kluge_auv_sentry_sensordepth: 0
     kluge_ignore_snippets:        0
Additional output:
     output_sensor_fnv:            0
Skip existing output files:
     skip_existing:                0

Pass 1: Opening file 0005_20220131_1717_sentry.kmall 261
Pass 1: Records read from input file 0: 0005_20220131_1717_sentry.kmall
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records

-----------------------------------------------
Pass 1: Total records read from 1 input files:
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records
Pass 1: Asynchronous data available for merging:
     0 navigation data (mode:2)
     0 sensordepth data (mode:2)
     3157 heading data (mode:2)
     0 altitude data (mode:0)
     3157 attitude data (mode:2)
     0 time_latency data (mode:0)
-----------------------------------------------
-----------------------------------------------
Applying time latency corrections:

-----------------------------------------------
Applying time domain filtering:
-----------------------------------------------

Pass 2: Opening input file:  0005_20220131_1717_sentry.kmall 261
Pass 2: Opening output file: 0005_20220131_1717_sentry.mb261 261
Deleting old ancillary file 0005_20220131_1717_sentry.mb261.bsa
Pass 2: Records read from input file 0: 0005_20220131_1717_sentry.kmall
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records
Pass 2: Records written to output file 0: 0005_20220131_1717_sentry.mb261
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records

Pass 2: Total records read from 1 input files
     6442 survey records
     0 comment records
     64412 nav records
     6314 nav1 records
     64412 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records
Pass 2: Total records written to 1 output files
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records

mbinfo -I 0005_20220131_1717_sentry.kmall

Swath Data File:      0005_20220131_1717_sentry.mb261
MBIO Data Format ID:  261
Format name:          MBF_KEMKMALL
Informal Description: Kongsberg multibeam echosounder system kmall datagram format
Attributes:           Kongsberg fourth generation multibeam sonars (EM2040, EM712, 
                      EM304, EM124), bathymetry, amplitude, backscatter, variable beams, 
                      binary datagrams, Kongsberg.

Data Totals:
Number of Records:                        6442
Bathymetry Data (400 beams):
  Number of Beams:          2576800
  Number of Good Beams:      542480     21.05%
  Number of Zero Beams:     2034311     78.95%
  Number of Flagged Beams:        9      0.00%
Amplitude Data (400 beams):
  Number of Beams:          2576800
  Number of Good Beams:      542480     21.05%
  Number of Zero Beams:     2034311     78.95%
  Number of Flagged Beams:        9      0.00%
Sidescan Data (2048 pixels):
  Number of Pixels:        13193216
  Number of Good Pixels:    2496989     18.93%
  Number of Zero Pixels:          0      0.00%
  Number of Flagged Pixels:10696227     81.07%

Navigation Totals:
Total Time:             0.8946 hours
Total Track Length:     0.9503 km
Average Speed:          1.0622 km/hr ( 0.5742 knots)

Start of Data:
Time:  01 31 2022 18:16:02.632593  JD31 (2022-01-31T18:16:02.632593)
Lon:  -105.918931350     Lat:    -4.587855883     Depth:     0.4334 meters
Speed:  0.0000 km/hr ( 0.0000 knots)  Heading: 249.3385 degrees
Sonar Depth:    0.4334 m  Sonar Altitude:    0.0000 m

End of Data:
Time:  01 31 2022 19:09:43.132661  JD31 (2022-01-31T19:09:43.132661)
Lon:  -105.916698167     Lat:    -4.586998150     Depth:    68.9726 meters
Speed:  3.4259 km/hr ( 1.8518 knots)  Heading: 336.3500 degrees
Sonar Depth:    0.7335 m  Sonar Altitude:   68.9331 m

Limits:
Minimum Longitude:    -105.919778410   Maximum Longitude:    -105.915432616
Minimum Latitude:       -4.589228611   Maximum Latitude:       -4.584667649
Minimum Sonar Depth:    -3.9837   Maximum Sonar Depth:     6.7676
Minimum Altitude:        0.0000   Maximum Altitude:       99.0689
Minimum Depth:          30.0578   Maximum Depth:         107.1302
Minimum Amplitude:    -100.0000   Maximum Amplitude:       9.0300
Minimum Sidescan:      -85.5000   Maximum Sidescan:        9.7333

Now try to apply a time offset

rm *.mb261*
mbpreprocess --verbose -I datalist.mb-1 --time-latency-apply-survey --time-latency-constant=3600

----8<-----snip------8<--------------------
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:40.132676 | ping_number:15583
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:40.632704 | ping_number:15584
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:41.132669 | ping_number:15585
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:41.632561 | ping_number:15586
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:42.132630 | ping_number:15587
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:42.632633 | ping_number:15588
Timestamp changed in function mbsys_kmbes_preprocess: 2022/01/31 18:09:43.132661 | ping_number:15589
Pass 2: Records read from input file 0: 0005_20220131_1717_sentry.kmall
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records
Pass 2: Records written to output file 0: 0005_20220131_1717_sentry.mb261
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records

Pass 2: Total records read from 1 input files
     6442 survey records
     0 comment records
     64412 nav records
     6314 nav1 records
     64412 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records
Pass 2: Total records written to 1 output files
     6442 survey records
     0 comment records
     32206 nav records
     3157 nav1 records
     32206 nav2 records
     0 nav3 records
     0 att records
     0 att1 records
     0 att2 records
     0 att3 records

mbinfo -I  0005_20220131_1717_sentry.mb261

Swath Data File:      0005_20220131_1717_sentry.mb261
MBIO Data Format ID:  261
Format name:          MBF_KEMKMALL
Informal Description: Kongsberg multibeam echosounder system kmall datagram format
Attributes:           Kongsberg fourth generation multibeam sonars (EM2040, EM712, 
                      EM304, EM124), bathymetry, amplitude, backscatter, variable beams, 
                      binary datagrams, Kongsberg.

Data Totals:
Number of Records:                        6442
Bathymetry Data (400 beams):
  Number of Beams:          2576800
  Number of Good Beams:      542480     21.05%
  Number of Zero Beams:     2034311     78.95%
  Number of Flagged Beams:        9      0.00%
Amplitude Data (400 beams):
  Number of Beams:          2576800
  Number of Good Beams:      542480     21.05%
  Number of Zero Beams:     2034311     78.95%
  Number of Flagged Beams:        9      0.00%
Sidescan Data (2048 pixels):
  Number of Pixels:        13193216
  Number of Good Pixels:    2496989     18.93%
  Number of Zero Pixels:          0      0.00%
  Number of Flagged Pixels:10696227     81.07%

Navigation Totals:
Total Time:             0.8946 hours
Total Track Length:     0.9503 km
Average Speed:          1.0622 km/hr ( 0.5742 knots)

Start of Data:
Time:  01 31 2022 18:16:02.632593  JD31 (2022-01-31T18:16:02.632593)
Lon:  -105.918931350     Lat:    -4.587855883     Depth:     0.4334 meters
Speed:  0.0000 km/hr ( 0.0000 knots)  Heading: 249.3385 degrees
Sonar Depth:    0.4334 m  Sonar Altitude:    0.0000 m

End of Data:
Time:  01 31 2022 19:09:43.132661  JD31 (2022-01-31T19:09:43.132661)
Lon:  -105.916698167     Lat:    -4.586998150     Depth:    68.9726 meters
Speed:  3.4259 km/hr ( 1.8518 knots)  Heading: 336.3500 degrees
Sonar Depth:    0.7335 m  Sonar Altitude:   68.9331 m

Limits:
Minimum Longitude:    -105.919778410   Maximum Longitude:    -105.915432616
Minimum Latitude:       -4.589228611   Maximum Latitude:       -4.584667649
Minimum Sonar Depth:    -3.9837   Maximum Sonar Depth:     6.7676
Minimum Altitude:        0.0000   Maximum Altitude:       99.0689
Minimum Depth:          30.0578   Maximum Depth:         107.1302
Minimum Amplitude:    -100.0000   Maximum Amplitude:       9.0300
Minimum Sidescan:      -85.5000   Maximum Sidescan:        9.7333

Same start and end time as without the time shift. Further processing shows that it's not just an issue with mbinfo, the data timestamps have indeed not moved. If I shift all the other data by flipping the sign of the desired shift and using --time-latency-apply-all-ancilliary I can get a properly navigated survey but all the timestamps are obviously wrong.

Provide information sufficient to reproduce the behavior:
Example kmall file: https://drive.google.com/drive/folders/1WDxXOpdVjjVVlVXDvwNJHDCGAj2G9Aee?usp=sharing

Expected behavior
Should see shifted times in "Start of Data" and "End of Data" from mbinfo

Computing context (please complete the following information):

  • OS: Fedora (silverblue) 35
  • MB-System version: 5.7.9beta27 (commit: fee4bdd)
  • GMT version: 6.1.1
@berkowski
Copy link
Author

Extracted 10 pings out of the original file with a small python script. Both script and smaller file are here:

https://drive.google.com/drive/folders/1WDxXOpdVjjVVlVXDvwNJHDCGAj2G9Aee?usp=sharing

@berkowski
Copy link
Author

berkowski commented Feb 4, 2022

Digging further it looks like this might be a combination of two issues with mbsys_kmbes_preprocess in mbsys_kmbes.c.

  1. The timestamps in the MRZ and XMT headers are not being adjusted at all
  2. No timing change information is provided to mbsys_kmbes_makess, so XMS headers can't be adjusted either
  3. None of of the other many datagrams ("#SVT", "SPO", etc) are shifted in this function. They don't seem to be shifted either, so not sure where that happens.

Fixing 1 seems easy enough, but I don't know enough about the internals here to deal with 2. Leaving 2 unpatched produces XMS datagrams with the original timestamps, which then propagates weirdness into other areas. In my example it makes mbinfo and mbedit think the very last ping has the original time stamp, while all the others are correctly adjusted.

For now, since I don't care about the sidescan packets at the moment, I've just removed that capability.

I don't know where to start with part 3. So for now I need to strip out every datagram that isn't MRZ first, then use the below patch. Doing that I can shift survey data as intended.

diff --git a/src/mbio/mbsys_kmbes.c b/src/mbio/mbsys_kmbes.c
index 8bc5471ee..d27de1adb 100644
--- a/src/mbio/mbsys_kmbes.c
+++ b/src/mbio/mbsys_kmbes.c
@@ -428,6 +428,7 @@ int mbsys_kmbes_preprocess(int verbose, void *mbio_ptr, void *store_ptr,
 
   int time_i[7];
   double time_d;
+  double time_delta;
   double navlon;
   double navlat;
   double sensordepth;
@@ -458,6 +459,7 @@ int mbsys_kmbes_preprocess(int verbose, void *mbio_ptr, void *store_ptr,
       mb_get_date(verbose, pars->time_d, time_i);
       for (int i = 0; i < 7; i++)
         store->time_i[i] = time_i[i];
+         time_delta = store->time_d - pars->time_d;
       store->time_d = pars->time_d;
       fprintf(stderr,
               "Timestamp changed in function %s: "
@@ -488,6 +490,11 @@ int mbsys_kmbes_preprocess(int verbose, void *mbio_ptr, void *store_ptr,
 
       // get time
       time_d = ((double)mrz->header.time_sec) + MBSYS_KMBES_NANO * mrz->header.time_nanosec;
+         if (pars->timestamp_changed) {
+                 time_d -= time_delta;
+                 mrz->header.time_sec = (unsigned int)(floor(time_d));
+                 mrz->header.time_nanosec = (unsigned int)((time_d - (double)mrz->header.time_sec) / MBSYS_KMBES_NANO);
+         }
 
       // construct xmt basics
       xmt->header = mrz->header;
@@ -769,6 +776,7 @@ int mbsys_kmbes_preprocess(int verbose, void *mbio_ptr, void *store_ptr,
       }
     }
 
+#if 0
     // generate pseudosidescan
     struct mbsys_kmbes_mrz *mrz = (struct mbsys_kmbes_mrz *)&store->mrz[0];
     if (xms->pingCnt != mrz->cmnPart.pingCnt) {
@@ -777,6 +785,7 @@ int mbsys_kmbes_preprocess(int verbose, void *mbio_ptr, void *store_ptr,
       status = mbsys_kmbes_makess(verbose, mbio_ptr, store_ptr, false,
                                   pixel_size, false, swath_width, 0, error);
     }
+#endif
   }
 
   if (verbose >= 2) {

Edit: I've updated the files on the gdrive share to include other datagrams besides MRZ for further testing

@dwcaress
Copy link
Owner

dwcaress commented Feb 4, 2022 via email

@berkowski
Copy link
Author

Hah, funny. At sea myself too.

We had an issue where the EM2040 clock never sync'd to the main stack. So all the ancillary data has the correct timestamp, but the actual ping data is about 1 hour ahead (eg. a timestamp of 17:00:00 in the file was really collected at 16:00:00).

I can use mbprerocess to shift all of the ancillary nav data to match the ping data but that's not the right solution here because the ping timestamp is wrong, not the nav data. And if MB-system never adjusts the primary sensor timestamp, what does --time-adjust-apply-survey do then?

@dwcaress
Copy link
Owner

dwcaress commented Feb 5, 2022 via email

@berkowski
Copy link
Author

Thanks, Dave.

We've been able to shift this dataset as needed using one-off hacks so there isn't a burning need to have this right-this-moment, but of course it'd be great to have it available in MB-System. I can help test your fix prior to merging if you'd like.

Zac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants