-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_calculations.py
258 lines (222 loc) · 11.6 KB
/
test_calculations.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import pytest
import numpy as np
import hypothesis
from ..tan import tan_method
from ..mincurve import minimum_curvature
from ..rad_curv import radius_curvature
from ..location import to_wellhead
from ..position_log import deviation, position_log as mc
# import test well data
well9 = np.loadtxt('./wellpathpy/test/fixtures/well9.csv', delimiter=",", skiprows=1)
well10 = np.loadtxt('./wellpathpy/test/fixtures/well10.csv', delimiter=",", skiprows=1)
straight_vert = np.loadtxt('./wellpathpy/test/fixtures/straight_vert_section.csv', delimiter=",", skiprows=1)
straight_deviated = np.loadtxt('./wellpathpy/test/fixtures/straight_dev_section.csv', delimiter=",", skiprows=1)
# get data series
well9_true_md_m = well9[:,0] * 0.3048 # converting feet to meters
well9_true_inc = well9[:,1]
well9_true_azi = well9[:,2]
well9_true_tvd_m = well9[:,3] * 0.3048 # converting feet to meters
well9_true_northing = well9[:,5]
well9_true_easting = well9[:,6]
well9_true_dls = well9[:,4]
well9_true_surface_northing = 39998.454
well9_true_surface_easting = 655701.278
well9_true_datum_elevation = 100 * 0.3048 # converting feet to meters
well10_true_md_m = well10[:,0] * 0.3048 # converting feet to meters
well10_true_inc = well10[:,1]
well10_true_azi = well10[:,2]
well10_true_tvd_m = well10[:,3] * 0.3048 # converting feet to meters
well10_true_northing = well10[:,5]
well10_true_easting = well10[:,6]
well10_true_dls = well10[:,4]
well10_true_surface_northing = 40004.564
well10_true_surface_easting = 655701.377
well10_true_datum_elevation = 100 * 0.3048 # converting feet to meters
# test methods
def test_high_tan():
tvd9, mN9, mE9 = tan_method(well9_true_md_m, well9_true_inc, well9_true_azi, choice='high')
tvd10, mN10, mE10 = tan_method(well10_true_md_m, well10_true_inc, well10_true_azi, choice='high')
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m, atol=12)
np.testing.assert_allclose(mE9, well9_true_easting, atol=12)
np.testing.assert_allclose(mN9, well9_true_northing, atol=12)
np.testing.assert_allclose(tvd10, well10_true_tvd_m, atol=12)
np.testing.assert_allclose(mE10, well10_true_easting, atol=15)
np.testing.assert_allclose(mN10, well10_true_northing, atol=12)
def test_low_tan():
tvd9, mN9, mE9 = tan_method(well9_true_md_m, well9_true_inc, well9_true_azi, choice='low')
tvd10, mN10, mE10 = tan_method(well10_true_md_m, well10_true_inc, well10_true_azi, choice='low')
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m, atol=12)
np.testing.assert_allclose(mE9, well9_true_easting, atol=12)
np.testing.assert_allclose(mN9, well9_true_northing, atol=12)
np.testing.assert_allclose(tvd10, well10_true_tvd_m, atol=12)
np.testing.assert_allclose(mE10, well10_true_easting, atol=15)
np.testing.assert_allclose(mN10, well10_true_northing, atol=12)
def test_avg_tan():
tvd9, mN9, mE9 = tan_method(well9_true_md_m, well9_true_inc, well9_true_azi, choice='avg')
tvd10, mN10, mE10 = tan_method(well10_true_md_m, well10_true_inc, well10_true_azi, choice='avg')
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m, atol=10)
np.testing.assert_allclose(mE9, well9_true_easting, atol=10)
np.testing.assert_allclose(mN9, well9_true_northing, atol=10)
np.testing.assert_allclose(tvd10, well10_true_tvd_m, atol=10)
np.testing.assert_allclose(mE10, well10_true_easting, atol=10)
np.testing.assert_allclose(mN10, well10_true_northing, atol=10)
def test_bal_tan():
tvd9, mN9, mE9 = tan_method(well9_true_md_m, well9_true_inc, well9_true_azi, choice='bal')
tvd10, mN10, mE10 = tan_method(well10_true_md_m, well10_true_inc, well10_true_azi, choice='bal')
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m, atol=10)
np.testing.assert_allclose(mE9, well9_true_easting, atol=10)
np.testing.assert_allclose(mN9, well9_true_northing, atol=10)
np.testing.assert_allclose(tvd10, well10_true_tvd_m, atol=10)
np.testing.assert_allclose(mE10, well10_true_easting, atol=10)
np.testing.assert_allclose(mN10, well10_true_northing, atol=10)
def test_min_curve():
tvd9, mN9, mE9, dls9 = minimum_curvature(well9_true_md_m, well9_true_inc, well9_true_azi)
tvd10, mN10, mE10, dls10 = minimum_curvature(well10_true_md_m, well10_true_inc, well10_true_azi)
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m)
np.testing.assert_allclose(mE9, well9_true_easting, atol=0.5)
np.testing.assert_allclose(mN9, well9_true_northing, atol=0.5)
np.testing.assert_allclose(dls9, well9_true_dls, atol=1)
np.testing.assert_allclose(tvd10, well10_true_tvd_m)
np.testing.assert_allclose(mE10, well10_true_easting, atol=0.5)
np.testing.assert_allclose(mN10, well10_true_northing, atol=0.5)
np.testing.assert_allclose(dls10, well10_true_dls, atol=1)
def test_min_curve_rf():
"""
This test was added as the code for mininum curvature initially read:
```
upper = np.sin(inc_upper) * np.cos(azi_upper)
lower = np.sin(inc_lower) * np.cos(azi_lower) * rf
northing = np.cumsum(md_diff / 2 * (upper + lower))
upper = np.sin(inc_upper) * np.sin(azi_upper)
lower = np.sin(inc_lower) * np.sin(azi_lower) * rf
easting = np.cumsum(md_diff / 2 * (upper + lower))
```
This was incorrect but not detected because the results were within noise because the angles are small,
so we use large angles here to force an error with that initial code.
With the correct code:
```
upper = np.sin(inc_upper) * np.cos(azi_upper)
lower = np.sin(inc_lower) * np.cos(azi_lower)
northing = np.cumsum((md_diff / 2) * (upper + lower) * rf)
upper = np.sin(inc_upper) * np.sin(azi_upper)
lower = np.sin(inc_lower) * np.sin(azi_lower)
easting = np.cumsum((md_diff / 2) * (upper + lower) * rf)
```
rf is multiplied to both upper and lower
the rf synthetic output is stored output from running the function and only serves as a regression test
"""
md = np.array([10, 20, 30, 40, 50])
inc = np.array([10, 35, 55, 75, 90])
azi = np.array([45, 45, 45, 45, 45])
tvd_ref = np.array([0, 9.16568053, 16.20090348, 20.4056626, 21.70720016])
mE_ref = np.array([0, 2.68456567, 7.65921952, 14.03529686, 21.02586714])
mN_ref = np.array([0, 2.68456567, 7.65921952, 14.03529686, 21.02586714])
dls_ref = np.array([0., 75., 60., 60., 45.])
tvd, mN, mE, dls = minimum_curvature(md, inc, azi)
np.testing.assert_allclose(tvd, tvd_ref)
np.testing.assert_allclose(mN, mN_ref)
np.testing.assert_allclose(mE, mE_ref)
np.testing.assert_allclose(dls, dls_ref)
def test_rad_curve():
tvd9, mN9, mE9 = radius_curvature(well9_true_md_m, well9_true_inc, well9_true_azi)
tvd10, mN10, mE10 = radius_curvature(well10_true_md_m, well10_true_inc, well10_true_azi)
tvd9, mN9, mE9 = to_wellhead(tvd9, mN9, mE9, 39998.454, 655701.278)
tvd10, mN10, mE10 = to_wellhead(tvd10, mN10, mE10, 40004.564, 655701.377)
np.testing.assert_allclose(tvd9, well9_true_tvd_m, atol=1)
np.testing.assert_allclose(mE9, well9_true_easting, atol=1)
np.testing.assert_allclose(mN9, well9_true_northing, atol=1)
np.testing.assert_allclose(tvd10, well10_true_tvd_m, atol=5)
np.testing.assert_allclose(mE10, well10_true_easting, atol=85)
np.testing.assert_allclose(mN10, well10_true_northing, atol=10)
np.testing.assert_allclose(mN10, well10_true_northing, atol=10)
def test_position_log_interface_mincurve():
"""
This pretty much only tests the mincurve, but packed in the
deviation+position_log interface
"""
md = well9_true_md_m
inc = well9_true_inc
azi = well9_true_azi
dev = deviation(md, inc, azi)
pos = dev.minimum_curvature()
pos = pos.resample(depths = md)
pos.to_wellhead(surface_northing = 39998.454, surface_easting = 655701.278, inplace = True)
np.testing.assert_allclose(pos.depth, well9_true_tvd_m, atol=1)
np.testing.assert_allclose(pos.northing, well9_true_northing, atol=1)
np.testing.assert_allclose(pos.easting, well9_true_easting, atol=1)
def test_roundtrip(atol = 0.01):
"""
This pretty much only tests the mincurve, but packed in the
deviation+position_log interface
"""
md = well9_true_md_m
inc = well9_true_inc
azi = well9_true_azi
dev = deviation(md, inc, azi)
pos = dev.minimum_curvature()
dev2 = pos.deviation()
np.testing.assert_allclose(dev.md, dev2.md, atol = atol)
np.testing.assert_allclose(dev.inc, dev2.inc, atol = atol)
np.testing.assert_allclose(dev.azi, dev2.azi, atol = atol)
pos.to_wellhead(surface_northing = 39998.454, surface_easting = 655701.278, inplace = True)
np.testing.assert_allclose(pos.depth, well9_true_tvd_m, atol=1)
np.testing.assert_allclose(pos.northing, well9_true_northing, atol=1)
np.testing.assert_allclose(pos.easting, well9_true_easting, atol=1)
def test_roundtrip_vertical_straight_hole(atol = 0.01):
"""
This pretty much only tests the mincurve, but packed in the
deviation+position_log interface
For a vertical straight hole, the inclination stays 0, but
azimuth can rotate freely.
"""
md_m = straight_vert[:, 0] * 0.3048 # converting feet to meters
inc = straight_vert[:, 1]
azi = straight_vert[:, 2]
tvd_m = straight_vert[:, 0] * 0.3048 # converting feet to meters
easting = [0, 0, 0, 0, 0, 0]
northing = [0, 0, 0, 0, 0, 0]
# the hole is vertical
assert np.all(inc) == 0
dev = deviation(md_m, inc, azi)
pos = dev.minimum_curvature()
dev2 = pos.deviation()
np.testing.assert_allclose(dev.md, dev2.md, atol = atol)
np.testing.assert_allclose(dev.inc, dev2.inc, atol = atol)
np.testing.assert_allclose(dev.azi, dev2.azi, atol = atol)
pos.to_wellhead(surface_northing = 0.0, surface_easting = 0.0, inplace = True)
np.testing.assert_allclose(pos.depth, tvd_m, atol=1)
np.testing.assert_allclose(pos.northing, northing, atol=1)
np.testing.assert_allclose(pos.easting, easting, atol=1)
def test_roundtrip_deviated_straight_hole(atol = 0.01):
"""
This pretty much only tests the mincurve, but packed in the
deviation+position_log interface
For a deviated straight hole, MD should increase, but inc
and azi must remain constant.
"""
md_m = straight_deviated[:, 0]
inc = straight_deviated[:, 1]
azi = straight_deviated[:, 2]
tvd_m = np.array([0., 50., 99.989847, 149.959388, 199.928929, 249.898471])
easting = [0, 0, 0, 0, 0, 0]
northing = np.array([0., 0., 0.872576, 2.617551, 4.362526, 6.107501])
dev = deviation(md_m, inc, azi)
pos = dev.minimum_curvature()
dev2 = pos.deviation()
np.testing.assert_allclose(dev.md, dev2.md, atol = atol)
np.testing.assert_allclose(dev.inc, dev2.inc, atol = atol)
np.testing.assert_allclose(dev.azi, dev2.azi, atol = atol)
pos.to_wellhead(surface_northing = 0.0, surface_easting = 0.0, inplace = True)
np.testing.assert_allclose(pos.depth, tvd_m, atol=1)
np.testing.assert_allclose(pos.northing, northing, atol=1)
np.testing.assert_allclose(pos.easting, easting, atol=1)