Skip to content

Commit

Permalink
Speedup wcp_src (#66) Thx @dbuscombe-usgs !!
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronBodine committed May 11, 2023
1 parent 3ef5553 commit 54ba723
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/class_sonObj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,15 +1570,18 @@ def _WCR_SRC(self, sonMeta, son=True):
#Iterate each ping
for j in range(self.sonDat.shape[1]):
depth = bedPick[j] # Get depth (in pixels) at nadir
dd = depth**2
# Create 1d array to store relocated bed pixels. Set to -9999 so we
## can later interpolate over gaps.
pingDat = (np.ones((self.sonDat.shape[0])).astype(np.float32)) * -9999
# pingDat = (np.ones((self.sonDat.shape[0])).astype(np.float32)) * -9999
pingDat = (np.ones((self.sonDat.shape[0])).astype(np.float32)) * np.nan
dataExtent = 0
#Iterate each sonar/ping return
for i in range(self.sonDat.shape[0]):
if i >= depth:
intensity = self.sonDat[i,j] # Get the intensity value
srcIndex = round(np.sqrt(i**2 - depth**2),0).astype(int) #Calculate horizontal range (in pixels) using pathagorean theorem
# srcIndex = round(np.sqrt(i**2 - depth**2),0).astype(int) #Calculate horizontal range (in pixels) using pathagorean theorem
srcIndex = int(round(math.sqrt(i**2 - dd),0)) #Calculate horizontal range (in pixels) using pathagorean theorem
pingDat[srcIndex] = intensity # Store intensity at appropriate horizontal range
dataExtent = srcIndex # Store range extent (max range) of ping
else:
Expand All @@ -1587,7 +1590,7 @@ def _WCR_SRC(self, sonMeta, son=True):

# Process of relocating bed pixels will introduce across track gaps
## in the array so we will interpolate over gaps to fill them.
pingDat[pingDat==-9999] = np.nan
# pingDat[pingDat==-9999] = np.nan
nans, x = np.isnan(pingDat), lambda z: z.nonzero()[0]
pingDat[nans] = np.interp(x(nans), x(~nans), pingDat[~nans])

Expand Down
1 change: 1 addition & 0 deletions src/funcs_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from numpy.lib.stride_tricks import as_strided as ast

import pandas as pd
import math

from collections import defaultdict
from copy import deepcopy
Expand Down

0 comments on commit 54ba723

Please sign in to comment.