Skip to content

Commit

Permalink
Example: handle varying bathy_xyza lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
oysstu committed Jul 20, 2018
1 parent 6bc77a0 commit c00d8b5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/plot_sonar_bathy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
print('The following (supported) packets are present (XTFHeaderType:count): \n\t' +
str([key.name + ':{}'.format(len(v)) for key, v in p.items()]))

# Get multibeam (xyza) if present
# Get multibeam/bathy data (xyza) if present
if XTFHeaderType.bathy_xyza in p:
np_mb = [[y.fDepth for y in x.data] for x in p[XTFHeaderType.bathy_xyza]]
np_mb = np.vstack(np_mb)

# Allocate room (with padding in case of varying sizes)
mb_concat = np.full((len(np_mb), max([len(x) for x in np_mb])), dtype=np.float32, fill_value=np.nan)
for i, line in enumerate(np_mb):
mb_concat[i, :len(line)] = line

# Transpose if the longest axis is vertical
is_horizontal = np_mb.shape[0] < np_mb.shape[1]
np_mb = np_mb if is_horizontal else np_mb.T
is_horizontal = mb_concat.shape[0] < mb_concat.shape[1]
mb_concat = mb_concat if is_horizontal else mb_concat.T
plt.figure()
plt.imshow(np_mb, cmap='hot')
plt.imshow(mb_concat, cmap='hot')
plt.colorbar(orientation='horizontal')

# Get sonar if present
Expand Down

0 comments on commit c00d8b5

Please sign in to comment.