Tutorial 2: Data access advanced concepts#

themachinethatgoesping tutorial series#

themachinethatgoesping concepts covered:

  • Advanced use of find_files()

  • Advanced use of File Handler

  • Advanced access of Pings

[1]:
%matplotlib widget

import numpy as np
import themachinethatgoesping as theping
from matplotlib import pyplot as plt
from tqdm.auto import tqdm

1. Advanced use of find_files()#

[2]:
# find_files() searches the input folder recursively (aka, including subfolders)
folder = '../unittest_data'
files = theping.echosounders.index_functions.find_files(folder, [".all","wcd"])
print(len(files))
Found 18 files
18
[3]:
# find_files() can use a list of folders as input
folders = []
folders.append('../unittest_data/kongsberg/simon/')
folders.append('../unittest_data/kongsberg/turbeams/')
files = theping.echosounders.index_functions.find_files(folders, [".all","wcd"])
print(len(files))
Found 6 files
6
[4]:
# pairs of files (e.g. .all and .wcd) don't have to be in the same folders.
# Remember they are only paired later, by a File Handler

2. Advanced use of File Handler#

[5]:
# Create a File Handler to access the raw data files
# TO DO - modify to talk about caching
folder = '../unittest_data'
files = theping.echosounders.index_functions.find_files(folder, [".all","wcd"])
fileHandler = theping.echosounders.kongsbergall.KongsbergAllFileHandler(files)
Found 18 files
indexing files ⠐ 100% [00m:00s<00m:00s] [..4033532462129271.wcd (1/18)]
indexing files ⠠ 100% [00m:00s<00m:00s] [..0211369500593285.wcd (18/18)]
indexing files ⢀ 100% [00m:00s<00m:00s] [Found: 1484 datagrams in 18 files (26MB)]
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

3. Advanced access of Pings#

[6]:
# pingcontainer are mostly for fast filtering of pings (eg on basis of sonar head, or location)
[7]:
# Access an individual ping in a Ping Container by indexing
pingContainer = fileHandler.get_pings()
ping42 = pingContainer[42]
type(ping42)
[7]:
themachinethatgoesping.echosounders_cppy.kongsbergall.filetypes.KongsbergAllPing
[8]:
#  This approach only works for a single ping. If you index a Ping Container for multiple pings, you will get a (smaller) Ping Container object
pings0To42 = pingContainer[0:42]
type(pings0To42)
[8]:
themachinethatgoesping.echosounders_cppy.kongsbergall.filedatacontainers.KongsbergAllPingContainer
[9]:
# If you want a list of Ping objects, you need to loop over each element of the Ping Container
pings0To42 = []
for i in range(42):
    pings0To42.append(pingContainer[i])
print(f"pings0To42 is now a {type(pings0To42)} where each element is a {type(pings0To42[0])}")
pings0To42 is now a <class 'list'> where each element is a <class 'themachinethatgoesping.echosounders_cppy.kongsbergall.filetypes.KongsbergAllPing'>
[10]:
# But you can also directly create lists of pings selected from a Ping Container by filtering for a specific critiera, for example pings containing watercolumn data
pingsWithWC = theping.pingprocessing.filter_pings.by_features(pingContainer,['watercolumn.amplitudes'])
print(f"pingsWithWC is a {type(pingsWithWC)} where each element is a {type(pingsWithWC[0])}")
pingsWithWC is a <class 'list'> where each element is a <class 'themachinethatgoesping.echosounders_cppy.kongsbergall.filetypes.KongsbergAllPing'>
[ ]: