weigh_grid is the core Ocean Mapping Group bathymetric gridding program. It reads soundings from one or more OMG-HDCS .merged multibeam files (or MR1 sidescan bathy, or ASCII lon/lat/depth files), projects each unflagged beam into the coordinate system of a pre-initialized floating-point Digital Terrain Model (<dtmprefix>.r4), and computes a spatially weighted average depth for every grid cell using a Butterworth (default), reciprocal, or linear distance-weighting function.
Crucially, weigh_grid maintains three parallel floating-point array files on disk (initialized from <dtmprefix>.blank via the tor4 helper script):
<dtmprefix>.r4_weights β Cumulative sum of weights ($\sum w_i$) at every grid node.
<dtmprefix>.r4_weight_depth β Cumulative sum of weighted depths ($\sum w_i z_i$) at every grid node.
Because weigh_grid stores $\sum w_i$ and $\sum (w_i z_i)$ persistently, you can add new survey lines incrementally to an existing grid without re-gridding previous lines, or subtract (-subtract) a dirty line, edit it in swathed (which can also live-update .r4 grids directly via swathed -locate <dtmprefix>), and re-add it!
# Step 1: Create a floating-point .blank mapsheet from your .merged files
make_blank -float bay_2m -boundsof merged/JD100/*.merged
# (Enter 2.0 at the "input desired mpp :" prompt)# Step 2: Copy bay_2m.blank to bay_2m.r4, bay_2m.r4_weights, and bay_2m.r4_weight_depth
tor4 bay_2m.blank
# Step 3: Run weigh_grid with beam weighting to blend outer beams smoothly
weigh_grid -beam_weight bay_2m merged/JD100/*.merged
# Step 4: Convert .r4 to 8-bit and sun-illuminate for viewing in jview
r4to8bit bay_2m
addSUN -azi 315 -elev 45 -vert_exag 5 bay_2m.r4 bay_2m.sun_315
jview bay_2m.8bit -sun bay_2m.sun_315
Arguments
Core Input, Output & Incremental Gridding
Option
Description
Default
<dtmprefix>
Required. Base prefix of the .r4, .r4_weights, and .r4_weight_depth files (e.g., bay_2m or bay_2m.r4).
None
<omgfile(s)>
Required (unless -xyzlist is used). One or more .merged (or ASCII/MR1) files to grid (up to 100,000 files).
None
-xyzlist <listfile>
Read paths of .merged (or ASCII) files to grid from a text file (one filepath per line). Up to 5,000 list files can be passed.
Disabled
-fresh_start / -fs
Zero out .r4, .r4_weights, and .r4_weight_depth in memory before gridding, discarding any soundings previously accumulated in the grid. (Without -fs, weigh_gridadds to the existing grid!).
Incremental (adds to existing)
-subtract
Subtract the weighted depth contributions of the specified .merged file(s) from .r4_weights and .r4_weight_depth, then recompute .r4. Used to remove a line before or after re-cleaning.
Disabled
-nmap
Use POSIX mmap() memory-mapped file I/O (do_nmap()) instead of calloc() in-memory buffersβessential for very large regional grids.
Disabled
-no_regrid
Do not write the <dtmprefix>.regrid shell script upon completion.
Maximum interpolation search radius around each sounding (in grid pixel units).
2.0 * mpp (2 pixels)
-lambda <pixels>
Half-power (wavelength) radius $\lambda$ for the Butterworth filter (in grid pixel units).
0.5 * mpp (0.5 pixels)
-beam_weight
Apply a 60-point cross-swath beam weighting curve that down-weights noisy outer beams in overlap zones while preserving them where no inner-beam coverage exists.
Disabled
-qfactor_weight
Weight soundings by their Kongsberg / Ifremer quality factor.
Disabled
-cutoff_scaling
Dynamically expand the interpolation cutoff radius for outer beams (sec or sec^2 of incidence angle) to prevent gaps in equi-angular modes and smooth outer-swath artifacts.
Disabled
-custom_weight <file> / -cw <file>
Load a custom ASCII beam weight and beam mask table from <file>.
Disabled
-beamwidth <deg>
Acoustic beamwidth (degrees) used to scale the footprint radius with water depth.
3.3 deg
-along / -across / -asym
Footprint expansion geometry mode.
-along
-shoal_bias
Favor shoaler soundings within each grid cell (hydrographic safety mode).
Weighted mean
Vertical Datum, Tides, RTK & Heave Corrections
Option
Description
Default
-check_tide
Verify that profile.tide is non-zero before gridding; refuses to grid untided lines.
Disabled
-ignore_tide
Ignore profile.tide (grid raw observed depths relative to water surface).
Uses profile.tide (1)
-tide2
Use profile.Lowpass_RTK_at_RP as the vertical tide correction instead of profile.tide.
Disabled
-rawRTK
Use raw profile.RTK_at_RP and remove observed real-time heave.
Disabled
-blendRTK
Combine low-pass RTK elevation with high-pass inertial heave.
Disabled
-invert_heave_sign
Invert the sign of heave when applying RTK corrections.
Disabled
-add_dyn_draft_shift
Apply profile.longperiod_heaveCorrection (typically POS MV delayed heave minus real-time heave).
Disabled
-add_dyn_draft_shift2
Apply profile.dynamic_draftCorrection (typically heave difference between orientation sensor 1 and 2).
Disabled
-flip_dyn_draft
Invert the sign of the dynamic draft / long-period heave shift.
Disabled
-proc
Use beam.processedDepth (if populated) instead of beam.observedDepth.
observedDepth
-useallZ
Include flagged/rejected soundings (beam.status != 0) when gridding! Use only for diagnostic comparisons.
Unflagged only (0)
-coeffs
Apply interactive refraction tool coefficients (.ref_coeffs) during gridding.
Disabled
-xyz2
Use the updated 3D beam vector geolocator (OMG_get_rational_beams) instead of legacy offset approximation.
Disabled
Spatial, Angular, Depth & Temporal Filtering
Option
Description
Default
-try_anyway
Override the .merged.global_bounds / .100_ping_bounds bounding-box pre-check and test every ping in every file. Use this if you forgot to run getBounds or if bounds metadata is stale.
Uses getBounds index
-mindep <m> / -maxdep <m>
Only grid soundings between <mindep> and <maxdep> (note: OMG depths are negative downward, e.g., -maxdep -400 -mindep -50).
-15000.0 to +15000.0
-min_incidence <deg> / -max_incidence <deg>
Restrict gridding to beams with incidence angles between <min> and <max> degrees.
0.0 to 90.0
-leave_outer
Used with -max_incidence: retain outer beams beyond the incidence limit if needed.
Disabled
-etch <N_beams>
Exclude (etch away) the outermost <N_beams> on both port and starboard edges of every swath.
0
-port / -stbd / -both
Grid only port-side beams, starboard-side beams, or both.
-both
-port_2040D / -stbd_2040D
For Dual-Head EM2040D systems: grid only the port or starboard sonar head (rxFanIndex / serial number).
Both heads
-azirange <low_deg> <high_deg>
Only grid pings whose vessel heading falls between <low_deg> and <high_deg> (supports wrap-around, e.g., 330 30).
0 to 360
-time_start <yr> <jd> <hr> <min> <sec>
Only grid pings after the specified UTC time.
All times
-time_end <yr> <jd> <hr> <min> <sec>
Only grid pings before the specified UTC time.
All times
-time_around <unix_sec> <window_sec>
Only grid pings within $\pm \text{window_sec}$ of <unix_sec>.
Disabled
-select
Interactively prompt for the first and last ping number to grid for each input file.
Disabled
-skip <N>
Only grid every $N$-th ping along-track.
1
-beamskip <M>
Only grid every $M$-th beam across-track.
1
Backscatter, Spectral & ASCII Input Modes
Option
Description
Default
-use_beam_refl
Grid beam reflectivity values (-64 to +64 dB) instead of bathymetric depth!
<dtmprefix>.used β Text log listing all .merged files that contributed soundings to the grid.
<dtmprefix>.regrid β Auto-generated shell script containing the exact weigh_grid command line used, making it easy to re-run the grid from scratch with -fs.
Troubleshooting
Symptom / Error
Cause
Resolution
Could not open <dtmprefix>.r4_weights
weigh_grid was run on <dtmprefix> before tor4 <dtmprefix>.blank was executed.
Run make_blank -float <dtmprefix> ... followed by tor4 <dtmprefix>.blank first.