Skip to content

Commit a4dd9a8

Browse files
authored
Merge pull request #193 from OpenPIV/add_testing_github_workflow
Create testing.yml
2 parents ffd7b81 + e56f7a0 commit a4dd9a8

8 files changed

Lines changed: 108 additions & 93 deletions

File tree

.github/workflows/testing.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.6, 3.7, 3.8]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install flake8 pytest
23+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
24+
- name: Lint with flake8
25+
run: |
26+
# stop the build if there are Python syntax errors or undefined names
27+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
28+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
29+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
30+
- name: Test with pytest
31+
run: |
32+
pytest

openpiv/filters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def gaussian_kernel(sigma, truncate=4.0):
6767

6868
def gaussian(u, v, half_width=1):
6969
"""Smooths the velocity field with a Gaussian kernel.
70-
70+
7171
Parameters
7272
----------
7373
u : 2d np.ndarray
@@ -86,7 +86,7 @@ def gaussian(u, v, half_width=1):
8686
the smoothed u velocity component field
8787
8888
vf : 2d np.ndarray
89-
the smoothed v velocity component field
89+
the smoothed v velocity component field
9090
9191
"""
9292
g = _gaussian_kernel(half_width=half_width)
@@ -150,17 +150,17 @@ def replace_outliers(u, v, w=None, method="localmean",
150150
151151
"""
152152
uf = replace_nans(
153-
u, method=method, max_iter=max_iter, tol=tol,
153+
u, method=method, max_iter=max_iter, tol=tol,
154154
kernel_size=kernel_size
155155
)
156156
vf = replace_nans(
157-
v, method=method, max_iter=max_iter, tol=tol,
157+
v, method=method, max_iter=max_iter, tol=tol,
158158
kernel_size=kernel_size
159159
)
160160

161161
if isinstance(w, np.ndarray):
162162
wf = replace_nans(
163-
w, method=method, max_iter=max_iter, tol=tol,
163+
w, method=method, max_iter=max_iter, tol=tol,
164164
kernel_size=kernel_size
165165
)
166166
return uf, vf, wf

openpiv/lib.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def replace_nans(array, max_iter, tol, kernel_size=2, method="disk"):
4444
4545
array : 2d or 3d np.ndarray
4646
an array containing NaN elements that have to be replaced
47-
if array is a masked array (numpy.ma.MaskedArray), then
47+
if array is a masked array (numpy.ma.MaskedArray), then
4848
the mask is reapplied after the replacement
4949
5050
max_iter : int
@@ -90,7 +90,9 @@ def replace_nans(array, max_iter, tol, kernel_size=2, method="disk"):
9090

9191
# list of kernel array indices
9292
# kernel_indices = np.indices(kernel.shape)
93-
# kernel_indices = np.reshape(kernel_indices, (n_dim, (2 * kernel_size + 1) ** n_dim), order="C").T
93+
# kernel_indices = np.reshape(kernel_indices,
94+
# (n_dim, (2 * kernel_size + 1) ** n_dim),
95+
# order="C").T
9496

9597
# indices where array is NaN
9698
nan_indices = np.array(np.nonzero(np.isnan(array))).T.astype(int)
@@ -104,7 +106,7 @@ def replace_nans(array, max_iter, tol, kernel_size=2, method="disk"):
104106

105107
# make several passes
106108
# until we reach convergence
107-
for it in range(max_iter):
109+
for _ in range(max_iter):
108110
# note: identifying new nan indices and looping other the new indices
109111
# would give slightly different result
110112

@@ -116,11 +118,10 @@ def replace_nans(array, max_iter, tol, kernel_size=2, method="disk"):
116118
# init to 0.0
117119
replaced_new[k] = 0.0
118120

119-
# generating a list of indices of the convolution window in the
121+
# generating a list of indices of the convolution window in the
120122
# array
121-
slice_indices = np.array(
122-
np.meshgrid(*[range(i - kernel_size, i + kernel_size + 1) for i in ind])
123-
)
123+
slice_indices = np.array(np.meshgrid(*[range(i - kernel_size,
124+
i + kernel_size + 1) for i in ind]))
124125

125126
# identifying all indices strictly inside the image edges:
126127
in_mask = np.array(

openpiv/piv.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ def simple_piv(im1, im2, plot=True):
4646
x, y = pyprocess.get_coordinates(image_size=im1.shape,
4747
search_area_size=32, overlap=16)
4848

49-
valid = s2n > np.percentile(s2n,5)
49+
valid = s2n > np.percentile(s2n, 5)
5050

5151
if plot:
5252
_, ax = plt.subplots(figsize=(6, 6))
5353
ax.imshow(im1, cmap=plt.get_cmap("gray"), alpha=0.5, origin="upper")
54-
ax.quiver(x[valid], y[valid], u[valid], -v[valid], scale=70, color='r',width=.005)
54+
ax.quiver(x[valid], y[valid], u[valid], -v[valid], scale=70,
55+
color='r', width=.005)
5556
plt.show()
5657

5758
return x, y, u, v
@@ -85,7 +86,7 @@ def piv_example():
8586
# each frame
8687
ims = []
8788
for i in range(2):
88-
im = ax.imshow(images[i % 2], animated=True, cmap=plt.cm.gray)
89+
im = ax.imshow(images[i % 2], animated=True, cmap="gray")
8990
ims.append([im])
9091

9192
_ = animation.ArtistAnimation(fig, ims, interval=500, blit=False,
@@ -105,7 +106,7 @@ def piv_example():
105106
fig, ax = plt.subplots(1, 2, figsize=(11, 8))
106107
ax[0].imshow(frame_a, cmap=plt.get_cmap("gray"), alpha=0.8)
107108
ax[0].quiver(x, y, vel[0], -vel[1], scale=50, color="r")
108-
ax[1].quiver(x, y[::-1,:], vel[0], -vel[1], scale=50, color="b")
109+
ax[1].quiver(x, y[::-1, :], vel[0], -1*vel[1], scale=50, color="b")
109110
ax[1].set_aspect(1)
110111
# ax[1].invert_yaxis()
111112
plt.show()

openpiv/pyprocess.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ def fft_correlate_images(image_a, image_b,
467467
"""
468468

469469
if normalized_correlation:
470-
# remove the effect of stronger laser or
470+
# remove the effect of stronger laser or
471471
# longer exposure for frame B
472-
# image_a = match_histograms(image_a, image_b)
472+
# image_a = match_histograms(image_a, image_b)
473473

474474
# remove mean background, normalize to 0..1 range
475475
image_a = normalize_intensity(image_a)
@@ -521,7 +521,8 @@ def normalize_intensity(window):
521521
window -= window.mean(axis=(-2, -1),
522522
keepdims=True, dtype=np.float32)
523523
tmp = window.std(axis=(-2, -1), keepdims=True)
524-
window = np.divide(window, tmp, out=np.zeros_like(window), where=(tmp != 0))
524+
window = np.divide(window, tmp, out=np.zeros_like(window),
525+
where=(tmp != 0))
525526
return np.clip(window, 0, window.max())
526527

527528

@@ -699,7 +700,7 @@ def extended_search_area_piv(
699700
the size of the interrogation window in the second frame,
700701
default is the same interrogation window size and it is a
701702
fallback to the simplest FFT based PIV
702-
703+
703704
normalized_correlation: bool
704705
if True, then the image intensity will be modified by removing
705706
the mean, dividing by the standard deviation and
@@ -828,10 +829,10 @@ def correlation_to_displacement(corr, n_rows, n_cols,
828829
subpixel_method=subpixel_method)) -\
829830
default_peak_position
830831

831-
# the horizontal shift from left to right is the u
832-
# the vertical displacement from top to bottom (increasing row) is v
833-
# x the vertical shift from top to bottom is row-wise shift is now
834-
# a negative vertical
832+
# the horizontal shift from left to right is the u
833+
# the vertical displacement from top to bottom (increasing row) is v
834+
# x the vertical shift from top to bottom is row-wise shift is now
835+
# a negative vertical
835836
u[k, m], v[k, m] = peak[1], peak[0]
836837

837838
return (u, v)

openpiv/scaling.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,25 @@
2020
"""
2121

2222

23-
import numpy as np
24-
25-
2623
def uniform(x, y, u, v, scaling_factor):
2724
"""
2825
Apply an uniform scaling
29-
26+
3027
Parameters
3128
----------
3229
x : 2d np.ndarray
33-
3430
y : 2d np.ndarray
35-
3631
u : 2d np.ndarray
37-
3832
v : 2d np.ndarray
39-
4033
scaling_factor : float
4134
the image scaling factor in pixels per meter
42-
35+
4336
Return
4437
----------
4538
x : 2d np.ndarray
46-
4739
y : 2d np.ndarray
48-
4940
u : 2d np.ndarray
50-
5141
v : 2d np.ndarray
52-
5342
"""
5443
return (
5544
x / scaling_factor,

0 commit comments

Comments
 (0)