Picker¶
xopr_viewer.picker.GroundingLinePicker ¶
Bases: Parameterized
Interactive point picker for echogram annotation.
Click on the image to add points. Points are always stored in
canonical coordinates (slow_time, twtt) regardless of the
current display axis mode, and converted to/from display
coordinates at the boundary.
Parameters:
-
image(Image) –The echogram image to annotate.
-
ds(Dataset, default:None) –The echogram dataset (needed for coordinate conversion when axis modes other than the default are used).
-
x_mode(str, default:'gps_time') –X-axis display mode (default:
"gps_time"). -
y_mode(str, default:'twtt') –Y-axis display mode (default:
"twtt"). -
layers(dict, default:None) –Dictionary of layer name -> xr.Dataset for snap-to-layer.
-
snap_threshold(float, default:5.0) –Snap threshold in microseconds (default: 5.0).
visible_layers
property
writable
¶
Layer names to snap to, or None for all layers.
element ¶
Get the HoloViews element (image + points overlay).
panel ¶
Get a Panel layout with the picker and control buttons.
set_axis_modes ¶
Update current axis modes (called when sidebar dropdowns change).
Parameters:
-
_notify(bool, default:True) –If True (default), send on the points pipe to re-render points in the new coordinate system. Pass False when calling from inside a DynamicMap callback to avoid recursive overlay resolution.
xopr_viewer.picker.pick_echogram ¶
pick_echogram(
data: DataArray | Image,
x_dim: str = "trace",
y_dim: str = "twtt_us",
**opts,
) -> GroundingLinePicker
Convenience function to create a picker from xarray or holoviews data.
Parameters:
-
data(DataArray or Image) –The echogram data
-
x_dim(str, default:'trace') –X dimension name
-
y_dim(str, default:'twtt_us') –Y dimension name
-
**opts–Additional options passed to hv.Image.opts()
Returns:
-
GroundingLinePicker–The picker instance
xopr_viewer.picker.compute_layer_slope ¶
compute_layer_slope(twtt: DataArray, smoothing_window: int = 1) -> DataArray
Compute slope of a layer profile after smoothing.
Smoothing uses xr.DataArray.rolling with a centered uniform
(box-car) window followed by .mean(). Every output point is the
unweighted mean of the smoothing_window nearest input points.
The window is centered so the smoothed value at index i averages
indices i - window//2 … i + window//2.
Points within window // 2 of either edge have fewer neighbors,
so rolling().mean() returns NaN there. These NaN edges propagate
through the derivative and appear as gaps at the ends of the slope
curve.
The derivative is computed by xr.DataArray.differentiate, which
uses second-order central finite differences in the interior and
first-order one-sided differences at the boundaries. Because it
operates on coordinate values (not integer indices), the result is in
physical units: d(twtt) / d(coordinate). For datetime coordinates
like slow_time the denominator is in nanoseconds (NumPy's internal
representation), giving slope in seconds per nanosecond.
Developer notes — common customizations:
- Weighted smoothing — Replace
rolling().mean()with a Gaussian kernel (scipy.ndimage.gaussian_filter1d) or a Savitzky–Golay filter (scipy.signal.savgol_filter) to better preserve sharp features. Both require scipy. - Edge handling — Pass
min_periods=1torolling()to get biased shorter-window estimates near boundaries instead of NaN gaps. - Units — For datetime coordinates, multiply by
1e9to convert from seconds/nanosecond to dimensionless seconds/second, or convert the coordinate to elapsed seconds before calling this function.
Parameters:
-
twtt(DataArray) –Two-way travel time values in seconds, indexed by a single dimension.
-
smoothing_window(int, default:1) –Size of the rolling mean window for smoothing (1 = no smoothing).
Returns:
-
DataArray–Slope as d(twtt)/d(coordinate) along the first dimension.