Skip to content

Commit

Permalink
Merge pull request #321 from alexlib/master
Browse files Browse the repository at this point in the history
updated to 0.25.3 for openpiv_tk_gui
  • Loading branch information
alexlib authored Apr 19, 2024
2 parents 52e58ba + 8294063 commit 5506e8f
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 342 deletions.
5 changes: 3 additions & 2 deletions openpiv/smoothn.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 19 additions & 8 deletions openpiv/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import numpy as np
from scipy.ndimage import generic_filter
import matplotlib.pyplot as plt
from openpiv.windef import PIVSettings



Expand Down Expand Up @@ -165,7 +166,13 @@ def sig2noise_val(
return ind


def local_median_val(u, v, u_threshold, v_threshold, size=1):
def local_median_val(
u: np.ndarray,
v: np.ndarray,
u_threshold: float,
v_threshold: float,
size: int=1
)->np.ndarray:
"""Eliminate spurious vectors with a local median threshold.
This validation method tests for the spatial consistency of the data.
Expand Down Expand Up @@ -201,16 +208,20 @@ def local_median_val(u, v, u_threshold, v_threshold, size=1):
"""

# 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
Loading

0 comments on commit 5506e8f

Please sign in to comment.