Tutorial 5: Extract WCD in wedge view#
themachinethatgoesping tutorial series#
themachinethatgoesping concepts covered:
Get WCI
WCI data subselection
[1]:
%matplotlib widget
import numpy as np
import themachinethatgoesping as theping
from matplotlib import pyplot as plt
from tqdm.auto import tqdm
# data folder
folder = '../unittest_data'
# list raw data files
files = theping.echosounders.index_functions.find_files(folder,['.all','.wcd'])
files.sort()
# create the file handler
cache_files = theping.echosounders.index_functions.get_index_paths(files)
fileHandler = theping.echosounders.kongsbergall.KongsbergAllFileHandler(files,cache_files,init=True)
# get pings that contain WCD
pings = theping.pingprocessing.filter_pings.by_features(fileHandler.get_pings(),['watercolumn.amplitudes'])
# check data with the WCI Viewer
viewer = theping.widgets.WCIViewer(pings)
Found 18 files
indexing files ⢀ 98% [00m:00s<00m:00s] [Found: 729 datagrams in 18 files (10MB)]
Initializing ping interface ⢀ 90% [00m:00s<00m:00s] [Done]
WARNING: get_depth_sensor_offsets: Only DSH (Depth (pressure) sensor heave) == NI is supported yet, but DSH is IN
WARNING: get_depth_sensor_offsets: Only DSH (Depth (pressure) sensor heave) == NI is supported yet, but DSH is IN
Get WCI#
[2]:
# to get a wedge view for a ping, use the make_wci function
image, extent = theping.pingprocessing.watercolumn.image.make_wci(pings[0],512) # specify num steps in acrosstrack distance
# output is an across-track-distance x down-distance numpy array
print(f"num across-track-distance steps: {np.shape(image)[0]}, num down-distance steps: {np.shape(image)[1]}")
# display
fig1,ax1 = theping.pingprocessing.core.create_figure('wci1')
ax1.imshow(image.transpose(), extent=extent, aspect='auto') # we transpose the image for display purposes
ax1.set_xlabel('Across-track distance (m)')
ax1.set_ylabel('Down distance (m)')
ax1.set_title('first ping WCD, wedge view')
num across-track-distance steps: 512, num down-distance steps: 120
[2]:
Text(0.5, 1.0, 'first ping WCD, wedge view')
[3]:
# get down and across-track resolution from extent
down_res = (extent[3]-extent[2])/np.shape(image)[1]
across_res = (extent[1]-extent[0])/np.shape(image)[0]
print(f"Down resolution: {down_res} m, Across resolution: {across_res} m")
Down resolution: -0.9989458371815307 m, Across resolution: 1.006857099738373 m
WCI data subselection#
Example 1: Using ping sample selector (limit angles)#
[4]:
# We can specify the data we want, using a pingsampleselector
pss = theping.echosounders.pingtools.PingSampleSelector()
pss.select_beam_range_by_angles(-45,0,5) # min angle, max angle, stepsize in degrees. Other selection options are available
# apply the ping selector for wedge view
image_pss,extent_pss = theping.pingprocessing.watercolumn.image.make_wci(pings[0],512,ping_sample_selector=pss)
# display
fig2,ax2 = theping.pingprocessing.core.create_figure('wci2')
ax2.imshow(image_pss.transpose(), extent=extent_pss, aspect='auto') # we transpose the image for display purposes
ax2.set_xlabel('Across-track distance (m)')
ax2.set_ylabel('Down distance (m)')
ax2.set_title('first ping WCD, wedge view, selected beams')
[4]:
Text(0.5, 1.0, 'first ping WCD, wedge view, selected beams')
Example 2: Using ping sample selector (limit to minslant range)#
[5]:
# We can specify the data we want, using a pingsampleselector
pss = theping.echosounders.pingtools.PingSampleSelector()
pss.select_minslant_distance_percent(30, 98) # 30% -> 98% of the minimum slant range
# apply the ping selector for wedge view
image_pss,extent_pss = theping.pingprocessing.watercolumn.image.make_wci(pings[0],512,ping_sample_selector=pss)
# display
fig2,ax2 = theping.pingprocessing.core.create_figure('wci3')
ax2.imshow(image_pss.transpose(), extent=extent_pss, aspect='auto') # we transpose the image for display purposes
ax2.set_xlabel('Across-track distance (m)')
ax2.set_ylabel('Down distance (m)')
ax2.set_title('first ping WCD, wedge view, selected samples till 98% of the minimum slant range')
[5]:
Text(0.5, 1.0, 'first ping WCD, wedge view, selected samples till 98% of the minimum slant range')
Example 3: Specifying output min max#
[6]:
# besides the sample selector, we can also specify the y and z coordinates of the output wedge view
image_minmax,extent_minmax = theping.pingprocessing.watercolumn.image.make_wci(pings[0],512,hmin=0,hmax=30,vmin=30,vmax=50)
# first display full data
fig3,ax3 = theping.pingprocessing.core.create_figure('wci4')
ax3.imshow(image.transpose(), extent=extent, aspect='auto') # full data
xlim = ax3.get_xlim()
ylim = ax3.get_ylim()
# add image of selected ontop of the same plot
ax3.imshow(image_minmax.transpose(), extent=extent_minmax, aspect='auto', cmap='autumn') # selected data
ax3.set_xlim(xlim)
ax3.set_ylim(ylim)
ax3.set_xlabel('Across-track distance (m)')
ax3.set_ylabel('Down distance (m)')
ax3.set_title('first ping WCD, wedge view, selected beams (color), selected extent (autumn)')
[6]:
Text(0.5, 1.0, 'first ping WCD, wedge view, selected beams (color), selected extent (autumn)')
Example 4: Specifying YZ coordinates#
[7]:
# besides the sample selector, we can also specify the y and z coordinates of the output wedge view
image_yz,extent_yz = theping.pingprocessing.watercolumn.image.make_wci(pings[0],512,y_coordinates=np.linspace(0,30,100),z_coordinates=np.linspace(50,70,100))
# first display full data
fig4,ax4 = theping.pingprocessing.core.create_figure('wci5')
ax4.imshow(image.transpose(), extent=extent, aspect='auto') # full data
xlim = ax4.get_xlim()
ylim = ax4.get_ylim()
# add image2 ontop of the same plot
ax4.imshow(image_yz.transpose(), extent=extent_yz, aspect='auto', cmap='gray') # selected data
ax4.set_xlim(xlim)
ax4.set_ylim(ylim)
ax4.set_xlabel('Across-track distance (m)')
ax4.set_ylabel('Down distance (m)')
ax4.set_title('first ping WCD, wedge view, selected beams (color), selected extent (gray)')
[7]:
Text(0.5, 1.0, 'first ping WCD, wedge view, selected beams (color), selected extent (gray)')
Apply selection to WCIViewer widget#
You can also apply a ping sample selector to the WCIViewer widget E.g. only 30% of the minimum slant range -> 95% of the bottom detection range
[9]:
# create pingsampleselector
pss = theping.echosounders.pingtools.PingSampleSelector()
pss.select_minslant_distance_percent(70, None) # select only samples from 30% of the slant range
pss.select_bottom_distance_percent(None,95) # select only samples till 95% of the bottom deteciton range
pss.select_beam_range_by_angles(-40,40,2) # select only every 2nd beam with -40° -> 40°
# create viewer
viewer = theping.widgets.WCIViewer(pings,name = 'WCI (sub selected)')
# modify the viewer imagebuidler arguments
viewer.args_imagebuilder['ping_sample_selector'] = pss
viewer.update_data(1)
[ ]: