Skip to content

Commit

Permalink
Merge pull request #148 from jonnymaserati/bug/clearance-closest
Browse files Browse the repository at this point in the history
Fixed and refactored a little the clearance module.
  • Loading branch information
jonnymaserati authored Mar 28, 2023
2 parents a1e1861 + 59b8d7b commit 5ea42a3
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 174 deletions.
78 changes: 57 additions & 21 deletions tests/test_clearance_iscwsa.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from welleng.survey import Survey, make_survey_header
from welleng.clearance import Clearance, ISCWSA
from welleng.clearance import IscwsaClearance
import numpy as np
import json

"""
Test that the ISCWSA clearance model is working within a defined tolerance
(the default has been set to 0.5%), testing against the ISCWSA standard
set of wellpaths for evaluating clearance scenarios using the MWD Rev4
error model.
Test that the ISCWSA clearance model is working within a defined tolerance,
testing against the ISCWSA standard set of wellpaths for evaluating clearance
scenarios using the MWD Rev4 error model.
"""

# Set test tolerance as percentage
TOLERANCE = 0.5

# Read well and validation data
filename = (
"tests/test_data/clearance_iscwsa_well_data.json"
Expand Down Expand Up @@ -60,34 +56,74 @@ def generate_surveys(data):
return surveys


def test_clearance_iscwsa(data=data, tolerance=TOLERANCE):
def test_minimize_sf(data=data):
surveys = generate_surveys(data)
reference = surveys["Reference well"]
offset = surveys["09 - well"]

result = IscwsaClearance(reference, offset, minimize_sf=False)
result_min = IscwsaClearance(reference, offset, minimize_sf=True)

idx = np.where(result_min.ref.interpolated == False)

# Check that interpolated survey is not corrupted
for attr in [
'azi_grid_rad', 'azi_mag_rad', 'azi_true_rad', 'cov_hla', 'cov_nev',
'pos_nev', 'pos_xyz', 'md', 'radius'
]:
assert np.allclose(
getattr(result.ref, attr), getattr(result_min.ref, attr)[idx]
)

pass

for attr in [
'Rr', 'calc_hole', 'distance_cc', 'eou_boundary',
'eou_separation', 'hoz_bearing', 'idx', 'masd', 'off_cov_hla',
'off_cov_nev', 'off_delta_hlas', 'off_delta_nevs', 'off_pcr',
'ref_cov_hla', 'ref_cov_nev', 'ref_delta_hlas', 'ref_delta_nevs',
'ref_nevs', 'ref_pcr', 'sf', 'wellbore_separation'
]:
# `toolface_bearing` and `trav_cyl_azi_deg` are a bit unstable when
# well paths are parallel.

assert np.allclose(
getattr(result, attr), getattr(result_min, attr)[idx],
rtol=1e-01, atol=1e-02
)

pass


def test_clearance_iscwsa(data=data, rtol=1e-02, atol=1e-03):
surveys = generate_surveys(data)
reference = surveys["Reference well"]

# Perform clearance checks for each survey
for well in surveys:
if well != "09 - well":
continue
if well == "Reference well":
continue
else:
offset = surveys[well]
# skip well 10
if well == "10 - well":
if well in ["10 - well"]:
continue
else:
c = Clearance(reference, offset)

result = ISCWSA(c)
for b in [False, True]:
result = IscwsaClearance(reference, offset, minimize_sf=b)

normalized = np.absolute(
result.SF[
np.where(result.SF[:, 2] == 0)
][:, 1]
- np.array(data["wells"][well]["SF"])
) / np.array(data["wells"][well]["SF"]) * 100
assert np.allclose(
result.sf[np.where(result.ref.interpolated == False)],
np.array(data["wells"][well]["SF"]),
rtol=rtol, atol=atol
)

assert np.all(normalized < tolerance)
pass


# make above test runnanble separately
if __name__ == '__main__':
test_clearance_iscwsa(data=data, tolerance=TOLERANCE)
test_minimize_sf(data=data)
test_clearance_iscwsa(data=data)
Binary file modified tests/test_data/error_mwdrev5_iscwsa_validation_results.xlsx
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/test_survey_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def one_function_to_run_them_all():
and name != 'all')
]

[f() for f in test_functions]
for f in test_functions:
f()

pass


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 5ea42a3

Please sign in to comment.