Skip to content

Commit 5506e8f

Browse files
authored
Merge pull request #321 from alexlib/master
updated to 0.25.3 for openpiv_tk_gui
2 parents 52e58ba + 8294063 commit 5506e8f

File tree

5 files changed

+310
-342
lines changed

5 files changed

+310
-342
lines changed

openpiv/smoothn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from numpy import *
22
from pylab import *
33
import scipy.optimize.lbfgsb as lbfgsb
4-
import numpy.linalg
4+
import scipy
55
from scipy.fftpack import dct, idct
66
import numpy as np
77
import numpy.ma as ma
@@ -803,7 +803,8 @@ def sparseTest(n=1000):
803803
# https://stackoverflow.com/questions/17115030/want-to-smooth-a-contour-from-a-masked-array
804804

805805
def smooth(u, mask):
806-
r = u.filled(0.) # set all 'masked' points to 0. so they aren't used in the smoothing
806+
m = ~mask
807+
r = u*m # set all 'masked' points to 0. so they aren't used in the smoothing
807808
a = 4*r[1:-1,1:-1] + r[2:,1:-1] + r[:-2,1:-1] + r[1:-1,2:] + r[1:-1,:-2]
808809
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
809810
b[b==0] = 1. # for avoiding divide by 0 error (region is masked so value doesn't matter)

openpiv/validation.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy as np
2424
from scipy.ndimage import generic_filter
2525
import matplotlib.pyplot as plt
26+
from openpiv.windef import PIVSettings
2627

2728

2829

@@ -165,7 +166,13 @@ def sig2noise_val(
165166
return ind
166167

167168

168-
def local_median_val(u, v, u_threshold, v_threshold, size=1):
169+
def local_median_val(
170+
u: np.ndarray,
171+
v: np.ndarray,
172+
u_threshold: float,
173+
v_threshold: float,
174+
size: int=1
175+
)->np.ndarray:
169176
"""Eliminate spurious vectors with a local median threshold.
170177
171178
This validation method tests for the spatial consistency of the data.
@@ -201,16 +208,20 @@ def local_median_val(u, v, u_threshold, v_threshold, size=1):
201208
"""
202209

203210
# kernel footprint
204-
f = np.ones((2*size+1, 2*size+1))
205-
f[size,size] = 0
206-
207-
masked_u = np.where(~u.mask, u.data, np.nan)
208-
masked_v = np.where(~v.mask, v.data, np.nan)
211+
# f = np.ones((2*size+1, 2*size+1))
212+
# f[size,size] = 0
213+
214+
if np.ma.is_masked(u):
215+
masked_u = np.where(~u.mask, u.data, np.nan)
216+
masked_v = np.where(~v.mask, v.data, np.nan)
217+
else:
218+
masked_u = u
219+
masked_v = v
209220

210221
um = generic_filter(masked_u, np.nanmedian, mode='constant',
211-
cval=np.nan, footprint=f)
222+
cval=np.nan, size=(2*size+1, 2*size+1))
212223
vm = generic_filter(masked_v, np.nanmedian, mode='constant',
213-
cval=np.nan, footprint=f)
224+
cval=np.nan, size=(2*size+1, 2*size+1))
214225

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

0 commit comments

Comments
 (0)