Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some suggestions #101

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.venv
.vscode

.devcontainer/

__pycache__

build
Expand All @@ -18,4 +20,6 @@ work

key.asc
.~*
VERSION*
VERSION*

test/test_data/*.xlsx
jonnymaserati marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@

# if someone wants to output a requirements file
# `python setup.py --list-all > requirements.txt`
if '--list-all' in sys.argv:
# will not include default requirements (numpy)
print('\n'.join(requirements_all))
if '--list-default' in sys.argv:
print('\n'.join(requirements_default))
exit()
elif '--list-all' in sys.argv:
requirements = requirements_all.union(requirements_default)
print('\n'.join(requirements))
exit()
elif '--list-easy' in sys.argv:
# again will not include numpy+setuptools
requirements = requirements_easy.union(requirements_default)
print('\n'.join(requirements_easy))
exit()

Expand Down
1,745 changes: 1,744 additions & 1 deletion tests/test_data/error_mwdrev4_1_iscwsa_data.json

Large diffs are not rendered by default.

Binary file not shown.
2,001 changes: 2,000 additions & 1 deletion tests/test_data/error_mwdrev5_1_iscwsa_data.json

Large diffs are not rendered by default.

Binary file not shown.
9 changes: 4 additions & 5 deletions welleng/errors/tool_errors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os

import numpy as np
from numpy import sin, cos, tan, pi, sqrt
from numpy.core.defchararray import index
import yaml
import os

from collections import OrderedDict
# import imp
from numpy import sin, cos, tan, pi, sqrt

# import welleng.error
Comment on lines +1 to -9
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Sorted the imports
  • Removed from numpy.core.defchararray import index since it wasn't used in the file.

from ..utils import NEV_to_HLA

# since this is running on different OS flavors
Expand Down
65 changes: 35 additions & 30 deletions welleng/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def __init__(
deg=True,
depth_unit='meters',
surface_unit='meters',
mag_defaults={
'b_total': 50_000.,
'dip': 70.,
'declination': 0.,
},
mag_defaults=None,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialization of function arguments to mutable objects is not recommended in python. Check "Using mutable objects as default argument values in python" of this page.

**kwargs
):
"""
Expand Down Expand Up @@ -142,7 +138,11 @@ def __init__(
self.G = G
self.azi_reference = azi_reference

self.mag_defaults = mag_defaults
self.mag_defaults = mag_defaults or {
'b_total': 50_000.,
'dip': 70.,
'declination': 0.,
}
self._get_mag_data(deg)

def _get_mag_data(self, deg):
Expand Down Expand Up @@ -234,8 +234,8 @@ def __init__(
cov_nev=None,
cov_hla=None,
error_model=None,
start_xyz=[0., 0., 0.],
start_nev=[0., 0., 0.],
start_xyz=None,
start_nev=None,
start_cov_nev=None,
deg=True,
unit="meters",
Expand Down Expand Up @@ -325,8 +325,10 @@ def __init__(
)
self.unit = unit
self.deg = deg
self.start_xyz = start_xyz
self.start_nev = start_nev

self.start_xyz = start_xyz or [0., 0., 0.]
self.start_nev = start_nev or [0., 0., 0.]

self.md = np.array(md).astype('float64')
self.start_cov_nev = start_cov_nev

Expand Down Expand Up @@ -384,6 +386,7 @@ def _process_azi_ref(self, inc, azi, deg):
self.azi_true_deg - math.degrees(self.header.declination)
)
self._get_azi_mag_and_true_rad()

elif self.header.azi_reference == 'true':
if deg:
self.azi_true_deg = np.array(azi).astype('float64')
Expand All @@ -400,6 +403,7 @@ def _process_azi_ref(self, inc, azi, deg):
self._get_azi_mag_and_true_deg()
azi_temp = self._get_azi_temp(deg)
self._make_angles(inc, azi_temp, deg)

else: # azi_reference is "magnetic"
if deg:
self.azi_mag_deg = np.array(azi).astype('float64')
Expand Down Expand Up @@ -444,8 +448,10 @@ def _get_azi_mag_and_true_deg(self):
def _get_radius(self, radius=None):
if radius is None:
self.radius = np.full_like(self.md.astype(float), 0.3048)

Copy link
Author

@mkamyab mkamyab Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is advisable to put an extra line after the if clause.

elif np.array([radius]).shape[-1] == 1:
self.radius = np.full_like(self.md.astype(float), radius)

else:
assert len(radius) == len(self.md), "Check radius"
self.radius = np.array(radius)
Expand All @@ -469,8 +475,10 @@ def _min_curve(self, vec):
if self.x is None:
# self.x, self.y, self.z = (mc.poss + self.start_xyz).T
self.x, self.y, self.z = (mc.poss).T

if self.n is None:
self._get_nev()

if vec is None:
self.vec_xyz = get_vec(self.inc_rad, self.azi_grid_rad, deg=False)
self.vec_nev = get_vec(
Expand Down Expand Up @@ -512,27 +520,29 @@ def get_error(self, error_model, return_error=False):

if return_error:
return self.err
else:
return self

return self

def _get_errors(self):
"""
Initiate a welleng.error.ErrorModel object and calculate the
covariance matrices with the specified error model.
"""
if self.error_model:
# if self.error_model == "iscwsa_mwd_rev4":
self.err = ErrorModel(
self,
error_model=self.error_model
)
self.cov_hla = self.err.errors.cov_HLAs.T
self.cov_nev = self.err.errors.cov_NEVs.T

else:
if self.cov_nev is not None and self.cov_hla is None:
self.cov_hla = NEV_to_HLA(self.survey_rad, self.cov_nev.T).T

elif self.cov_nev is None and self.cov_hla is not None:
self.cov_nev = HLA_to_NEV(self.survey_rad, self.cov_hla.T).T

else:
pass

Expand All @@ -547,10 +557,7 @@ def _curvature_to_rate(self, curvature):
with np.errstate(divide='ignore', invalid='ignore'):
radius = 1 / curvature
circumference = 2 * np.pi * radius
if self.unit == 'meters':
x = 30
else:
x = 100
x = 30 if self.unit == 'meters' else 100
rate = np.absolute(np.degrees(2 * np.pi / circumference) * x)

return rate
Expand All @@ -563,10 +570,7 @@ def _get_toolface_and_rates(self):
# split the survey
s = SplitSurvey(self)

if self.unit == 'meters':
x = 30
else:
x = 100
x = 30 if self.unit == 'meters' else 100

# this is lazy I know, but I'm using this mostly for flags
with np.errstate(divide='ignore', invalid='ignore'):
Expand Down Expand Up @@ -732,6 +736,7 @@ def project_to_bit(self, delta_md, dls=None, toolface=None):
"""
if dls is None:
dls = self.dls[-1]

if toolface is None:
toolface = self.toolface[-1]

Expand Down Expand Up @@ -817,10 +822,10 @@ def interpolate_md(survey, md):
x = md - survey.md[idx]
assert x >= 0

return _interpolate_survey(survey, x=x, index=idx)
return _interpolate_survey(survey, md=x, index=idx)


def _interpolate_survey(survey, x=0, index=0):
def _interpolate_survey(survey, md=0, index=0):
"""
Interpolates a point distance x between two survey stations
using minimum curvature.
Expand All @@ -829,7 +834,7 @@ def _interpolate_survey(survey, x=0, index=0):
----------
survey: welleng.Survey
A survey object with at least two survey stations.
x: float
md: float
Length along well path from indexed survey station to
perform the interpolate at. Must be less than length
to the next survey station.
Expand Down Expand Up @@ -861,7 +866,7 @@ def _interpolate_survey(survey, x=0, index=0):

total_dogleg = survey.dogleg[index + 1]

dogleg = x * (total_dogleg / survey.delta_md[index + 1])
dogleg = md * (total_dogleg / survey.delta_md[index + 1])

t = (
(math.sin(total_dogleg - dogleg) / math.sin(total_dogleg)) * t1
Expand All @@ -876,7 +881,7 @@ def _interpolate_survey(survey, x=0, index=0):
sh.azi_reference = 'grid'

s = Survey(
md=np.array([survey.md[index], survey.md[index] + x]),
md=np.array([survey.md[index], survey.md[index] + md]),
inc=np.array([survey.inc_rad[index], inc]),
azi=np.array([survey.azi_grid_rad[index], azi]),
start_xyz=np.array([survey.x, survey.y, survey.z]).T[index],
Expand All @@ -885,8 +890,8 @@ def _interpolate_survey(survey, x=0, index=0):
deg=False,
)
interpolated = False if any((
x == 0,
x == survey.md[index + 1] - survey.md[index]
md == 0,
md == survey.md[index + 1] - survey.md[index]
)) else True
s.interpolated = [False, interpolated]

Expand Down Expand Up @@ -932,7 +937,7 @@ def tidy_up_angle(d):
dogleg = s_temp.dogleg[-1]

if np.isnan(dogleg):
return _interpolate_survey(survey, x=0, index=idx)
return _interpolate_survey(survey, md=0, index=idx)

if dogleg == 0:
x = (
Expand Down Expand Up @@ -989,7 +994,7 @@ def tidy_up_angle(d):

assert x <= delta_md

interpolated_survey = _interpolate_survey(survey, x=x, index=idx)
interpolated_survey = _interpolate_survey(survey, md=x, index=idx)

interpolated = True if x > 0 else False
node = get_node(interpolated_survey, 1, interpolated=interpolated)
Expand Down
21 changes: 11 additions & 10 deletions welleng/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def get_vec(inc, azi, nev=False, r=1, deg=True):
else:
inc_rad = inc
azi_rad = azi

y = r * np.sin(inc_rad) * np.cos(azi_rad)
x = r * np.sin(inc_rad) * np.sin(azi_rad)
z = r * np.cos(inc_rad)
Expand All @@ -173,34 +174,35 @@ def get_vec(inc, azi, nev=False, r=1, deg=True):
return vec / np.linalg.norm(vec, axis=-1).reshape(-1, 1)


def get_nev(
pos, start_xyz=np.array([0., 0., 0.]), start_nev=np.array([0., 0., 0.])
):
def get_nev(pos, start_xyz=None, start_nev=None):
"""
Convert [x, y, z] coordinates to [n, e, tvd] coordinates.

Params:
pos: (n,3) array of floats
Array of [x, y, z] coordinates
start_xyz: (,3) array of floats
The datum of the [x, y, z] cooardinates
The datum of the [x, y, z] coordinates
start_nev: (,3) array of floats
The datum of the [n, e, tvd] coordinates

Returns:
An (n,3) array of [n, e, tvd] coordinates.
"""
# e, n, v = (
# np.array([pos]).reshape(-1,3) - np.array([start_xyz])
# ).T
start_xyz = start_xyz or np.array([0., 0., 0.])
start_nev = start_nev or np.array([0., 0., 0.])

e, n, v = (
np.array([pos]).reshape(-1, 3) - np.array([start_xyz])
).T

return (np.array([n, e, v]).T + np.array([start_nev]))


def get_xyz(pos, start_xyz=[0., 0., 0.], start_nev=[0., 0., 0.]):
def get_xyz(pos, start_xyz=None, start_nev=None):
start_xyz = start_xyz or [0., 0., 0.]
start_nev = start_nev or [0., 0., 0.]

y, x, z = (
np.array([pos]).reshape(-1, 3) - np.array([start_nev])
).T
Expand All @@ -215,7 +217,6 @@ def _get_angles(vec):

return np.stack((inc, azi), axis=1)


if NUMBA:
_get_angles = njit(_get_angles)

Expand Down Expand Up @@ -296,7 +297,7 @@ def NEV_to_HLA(survey, NEV, cov=True):
The NEV coordinates or covariance matrices.
cov: boolean
If cov is True then a (3,3,d) array of covariance matrices
is expecte, else a (d,3) array of coordinates.
is expected, else a (d,3) array of coordinates.

Returns:
Either a transformed (n,3) array of HLA coordinates or an
Expand Down