forked from alexlib/pivpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_methods.py
125 lines (91 loc) · 3.24 KB
/
test_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# test_methods.py
from pivpy import io, pivpy
import numpy as np
import pkg_resources as pkg
import os
f1 = "Run000001.T000.D000.P000.H001.L.vec"
f2 = "Run000002.T000.D000.P000.H001.L.vec"
path = pkg.resource_filename("pivpy", "data/Insight")
_a = io.load_vec(os.path.join(path, f1))
_b = io.load_vec(os.path.join(path, f2))
def test_crop():
""" tests crop """
_c = _a.piv.crop([5, 15, -5, -15])
assert _c.u.shape == (32, 32, 1)
_c = io.create_sample_dataset()
_c = _c.sel(x=slice(35, 70), y=slice(30, 90))
assert _c.u.shape == (2, 2, 5) # note the last dimension is preserved
def test_pan():
""" test a shift by dx,dy using pan method """
_a = io.load_vec(os.path.join(path, f1))
_c = _a.piv.pan(1.0, -1.0) # note the use of .piv.
assert np.allclose(_c.coords["x"][0], 1.312480)
assert np.allclose(_c.coords["y"][0], -1.31248)
def test_mean():
data = io.create_sample_dataset(10)
assert np.allclose(data.piv.average.u.median(), 4.5)
def test_vec2scal():
data = io.create_sample_dataset()
data.piv.vec2scal()
data.piv.vec2scal(property="curl")
data.piv.vec2scal(property="ke")
assert len(data.attrs["variables"]) == 5
assert data.attrs["variables"][-1] == "ke"
def test_add():
data = io.create_sample_dataset()
tmp = data + data
assert tmp["u"][0, 0, 0] == 2.0
def test_subtract():
""" tests subtraction """
data = io.create_sample_dataset()
tmp = data - data
assert tmp["u"][0, 0, 0] == 0.0
def test_multiply():
""" tests subtraction """
data = io.create_sample_dataset()
tmp = data * 3.5
assert tmp["u"][0, 0, 0] == 3.5
def test_set_get_dt():
""" tests setting the new dt """
data = io.create_sample_dataset()
assert data.attrs["dt"] == 1.0
assert data.piv.dt == 1.0
data.piv.set_dt(2.0)
assert data.attrs["dt"] == 2.0
# def test_rotate():
# """ tests rotation """
# data = io.create_sample_dataset()
# data.piv.rotate(90) # rotate by 90 deg
# assert data['u'][0,0,0] == 2.1 # shall fail
def test_fluctuations():
data = io.create_sample_field()
data.piv.fluct()
assert np.allclose(data['u'], 0.0)
def test_reynolds_stress():
data = io.create_sample_field()
tmp = data.piv.reynolds_stress()
assert np.allclose(tmp['w'], 0.0)
def test_vorticity():
""" tests vorticity estimate """
data = io.create_sample_field()
data.piv.vorticity()
print(data['w'][0, 0])
assert np.allclose(data["w"][0, 0], -0.09266766)
def test_strain():
""" tests shear estimate """
data = io.create_sample_field()
data.piv.strain()
# this is homogeneous case in which the only derivative is
# vy so both shear and vorticity are equal
assert np.allclose(np.unique(data.w.values.flatten().round(decimals=6)),np.array([0.001998, 0.002063, 0.002211, 0.002629, 0.00268 ]))
def test_tke():
""" tests TKE """
data = io.create_sample_dataset()
data.piv.vec2scal(property="ke")
data.piv.vec2scal(property="tke") # now defined
assert data.attrs["variables"][-1] == "tke"
def test_curl():
""" tests curl that is also vorticity """
_a = io.load_vec(os.path.join(path, f1))
_a.piv.vec2scal(property="curl")
assert _a.attrs["variables"][-1] == "vorticity"