Skip to content

Commit

Permalink
fixed missing imports and updated for the case of openpiv_tk_gui with…
Browse files Browse the repository at this point in the history
…out mask
  • Loading branch information
alexlib committed Apr 19, 2024
1 parent d1abec8 commit 5d14d89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions openpiv/smoothn.py
@@ -1,7 +1,7 @@
from numpy import *
from pylab import *
import scipy.optimize.lbfgsb as lbfgsb
import numpy.linalg
import scipy
from scipy.fftpack import dct, idct
import numpy as np
import numpy.ma as ma
Expand Down Expand Up @@ -803,7 +803,8 @@ def sparseTest(n=1000):
# https://stackoverflow.com/questions/17115030/want-to-smooth-a-contour-from-a-masked-array

def smooth(u, mask):
r = u.filled(0.) # set all 'masked' points to 0. so they aren't used in the smoothing
m = ~mask
r = u*m # set all 'masked' points to 0. so they aren't used in the smoothing
a = 4*r[1:-1,1:-1] + r[2:,1:-1] + r[:-2,1:-1] + r[1:-1,2:] + r[1:-1,:-2]
b = 4*m[1:-1,1:-1] + m[2:,1:-1] + m[:-2,1:-1] + m[1:-1,2:] + m[1:-1,:-2] # a divisor that accounts for masked points
b[b==0] = 1. # for avoiding divide by 0 error (region is masked so value doesn't matter)
Expand Down
18 changes: 11 additions & 7 deletions openpiv/validation.py
Expand Up @@ -208,16 +208,20 @@ def local_median_val(
"""

# kernel footprint
f = np.ones((2*size+1, 2*size+1))
f[size,size] = 0

masked_u = np.where(~u.mask, u.data, np.nan)
masked_v = np.where(~v.mask, v.data, np.nan)
# f = np.ones((2*size+1, 2*size+1))
# f[size,size] = 0

if np.ma.is_masked(u):
masked_u = np.where(~u.mask, u.data, np.nan)
masked_v = np.where(~v.mask, v.data, np.nan)
else:
masked_u = u
masked_v = v

um = generic_filter(masked_u, np.nanmedian, mode='constant',
cval=np.nan, footprint=f)
cval=np.nan, size=(2*size+1, 2*size+1))
vm = generic_filter(masked_v, np.nanmedian, mode='constant',
cval=np.nan, footprint=f)
cval=np.nan, size=(2*size+1, 2*size+1))

ind = (np.abs((u - um)) > u_threshold) | (np.abs((v - vm)) > v_threshold)

Expand Down

0 comments on commit 5d14d89

Please sign in to comment.