Skip to content

Commit e4549c5

Browse files
author
Malcolm White
committed
DOC:: Update doc strings.
1 parent b30d943 commit e4549c5

File tree

1 file changed

+94
-10
lines changed

1 file changed

+94
-10
lines changed

pykonal/pykonal.pyx

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
# Specify Cython compiler flags.
12
# cython: boundscheck=False
23
# cython: cdivision=True
34
# cython: language_level=3
45
# distutils: language=c++
56

6-
# Python imports
7+
# Python imports.
78
import collections
89
import itertools
910
import numpy as np
1011

11-
# Cython imports
12+
# Cython imports.
1213
cimport numpy as np
1314
cimport libc.math
1415
from libcpp.vector cimport vector as cpp_vector
@@ -20,6 +21,7 @@ ctypedef np.uint16_t _UINT_t
2021
DTYPE_REAL = np.float64
2122
DTYPE_UINT = np.uint16
2223

24+
# Define a value to signal errors.
2325
DEF _ERROR_REAL = -999999999999.
2426
ERROR_REAL = DTYPE_REAL(_ERROR_REAL)
2527

@@ -34,54 +36,84 @@ class OutOfBoundsError(Exception):
3436

3537

3638
class EikonalSolver(object):
39+
'''
40+
A class to solver the Eikonal equation in 3D Cartesian or
41+
spherical coordinates.
42+
43+
Properties
44+
**********
45+
.. autoattribute:: close
46+
.. autoattribute:: iax_null
47+
.. autoattribute:: is_alive
48+
.. autoattribute:: is_far
49+
50+
Methods
51+
*******
52+
.. automethod:: trace_ray(self, end, step_size=None)
53+
'''
54+
3755
def __init__(self, coord_sys='cartesian'):
38-
'''
39-
Solves the Eikonal equation in 3D cartesian coordinates.
40-
'''
4156
self._ndim = 3
4257
self._class = str(self.__class__).strip('>\'').split('.')[-1]
4358
self._coord_sys = coord_sys
4459
self._vgrid = GridND(ndim=self._ndim, coord_sys=self.coord_sys)
4560

4661
@property
4762
def close(self):
63+
'''
64+
A list of node indices in the *Trial* region.
65+
'''
4866
if not hasattr(self, '_close'):
4967
self._close = Heap(self.uu)
5068
return (self._close)
5169

5270
@property
5371
def iax_null(self):
72+
'''
73+
'''
5474
return (self.pgrid.iax_null)
5575

5676
@property
5777
def is_alive(self):
78+
'''
79+
'''
5880
if not hasattr(self, '_is_alive'):
5981
self._is_alive = np.full(self.pgrid.npts, fill_value=False, dtype=np.bool)
6082
return (self._is_alive)
6183

6284
@property
6385
def is_far(self):
86+
'''
87+
'''
6488
if not hasattr(self, '_is_far'):
6589
self._is_far = np.full(self.pgrid.npts, fill_value=True, dtype=np.bool)
6690
return (self._is_far)
6791

6892
@property
6993
def coord_sys(self):
94+
'''
95+
'''
7096
return (self._coord_sys)
7197

7298
@coord_sys.setter
7399
def coord_sys(self, value):
100+
'''
101+
'''
74102
value = value.lower()
75103
if value not in ('cartesian', 'spherical'):
76104
raise (ValueError(f'Invalid coord_sys specification: {value}'))
77105
self._coord_sys = value
78106

79107
@property
80108
def ndim(self):
109+
'''
110+
'''
81111
return (self._ndim)
82112

83113
@property
84114
def norm(self):
115+
'''
116+
'''
85117
if not hasattr(self, '_norm'):
86118
self._norm = np.tile(
87119
self.pgrid.node_intervals,
@@ -95,6 +127,8 @@ class EikonalSolver(object):
95127

96128
@property
97129
def pgrid(self):
130+
'''
131+
'''
98132
if not hasattr(self, '_pgrid'):
99133
self._pgrid = GridND(ndim=self._ndim, coord_sys=self.vgrid.coord_sys)
100134
for attr in ('min_coords', 'node_intervals', 'npts'):
@@ -103,10 +137,14 @@ class EikonalSolver(object):
103137

104138
@property
105139
def src_loc(self):
140+
'''
141+
'''
106142
return (self._src_loc)
107143

108144
@src_loc.setter
109145
def src_loc(self, value):
146+
'''
147+
'''
110148
if not isinstance(value, collections.Iterable):
111149
raise (TypeError(f'{self._class}.src_loc value must be <Iterable> type'))
112150
if len(value) != self._ndim:
@@ -118,6 +156,8 @@ class EikonalSolver(object):
118156

119157
@property
120158
def src_rtp(self):
159+
'''
160+
'''
121161
if self.coord_sys == 'spherical':
122162
return (self.src_loc)
123163
else:
@@ -128,6 +168,8 @@ class EikonalSolver(object):
128168

129169
@property
130170
def src_xyz(self):
171+
'''
172+
'''
131173
if self.coord_sys == 'cartesian':
132174
return (self.src_loc)
133175
else:
@@ -139,16 +181,22 @@ class EikonalSolver(object):
139181

140182
@property
141183
def uu(self):
184+
'''
185+
'''
142186
if not hasattr(self, '_uu'):
143187
self._uu = np.full(self.pgrid.npts, fill_value=np.inf, dtype=DTYPE_REAL)
144188
return (self._uu)
145189

146190
@property
147191
def vgrid(self):
192+
'''
193+
'''
148194
return (self._vgrid)
149195

150196
@property
151197
def vv(self):
198+
'''
199+
'''
152200
return (self._vv)
153201

154202
@vv.setter
@@ -159,6 +207,8 @@ class EikonalSolver(object):
159207

160208
@property
161209
def vvp(self):
210+
'''
211+
'''
162212
cdef Py_ssize_t i1, i2, i3
163213
cdef np.ndarray[_REAL_t, ndim=3] vvp
164214

@@ -186,10 +236,32 @@ class EikonalSolver(object):
186236

187237

188238
def solve(self):
239+
'''
240+
'''
189241
self._update()
190242

191243

192-
def trace_ray(self, start, step_size=None):
244+
def trace_ray(self, end, step_size=None):
245+
'''
246+
Trace the ray ending at *end*.
247+
248+
This method traces the ray that ends at *end* in reverse
249+
direction by taking small steps along the path of steepest
250+
travel-time descent. The resulting ray is reversed before being
251+
returned, so it is in the normal forward-time orientation.
252+
253+
:param end: Coordinates of the ray's end point.
254+
:type end: tuple, list, np.ndarray
255+
256+
:param step_size: The distance between points on the ray.
257+
The smaller this value is the more accurate the resulting
258+
ray will be. By default, this parameter is assigned the
259+
smallest node interval of the propagation grid.
260+
:type step_size: float, optional
261+
262+
:return: The ray path ending at *end*.
263+
:rtype: np.ndarray(Nx3)
264+
'''
193265
cdef cpp_vector[_REAL_t *] ray
194266
cdef _REAL_t g0, g1, g2, norm
195267
cdef _REAL_t *point_new
@@ -198,7 +270,7 @@ class EikonalSolver(object):
198270
cdef np.ndarray[_REAL_t, ndim=2] ray_np
199271

200272
point_new = <_REAL_t *> malloc(3 * sizeof(_REAL_t))
201-
point_new[0], point_new[1], point_new[2] = start
273+
point_new[0], point_new[1], point_new[2] = end
202274
ray.push_back(point_new)
203275
if step_size is None:
204276
step_size = self._get_step_size()
@@ -243,14 +315,26 @@ class EikonalSolver(object):
243315
ray_np[i, 1] = ray[i][1]
244316
ray_np[i, 2] = ray[i][2]
245317
free(ray[i])
246-
return (ray_np)
318+
return (np.flipud(ray_np))
247319

248320

249321
def transfer_travel_times_from(self, old, origin, rotate=False, set_alive=False):
250322
'''
251323
Transfer the velocity model from old EikonalSolver to self
252-
:param pykonal.EikonalSolver old: The old EikonalSolver to transfer from.
253-
:param tuple old_origin: The coordinates of the origin of old w.r.t. to the self frame of reference.
324+
325+
:param old: The old EikonalSolver to transfer from.
326+
:type old: pykonal.EikonalSolver
327+
328+
:param origin: The coordinates of the origin of old w.r.t. to
329+
the self frame of reference.
330+
:type origin: tuple, list, np.ndarray
331+
332+
:param rotate: Rotate the coordinates?
333+
:type rotate: bool
334+
335+
:return: None
336+
:rtype: NoneType
337+
254338
'''
255339

256340
pgrid_new = self.pgrid.map_to(old.coord_sys, origin, rotate=rotate)

0 commit comments

Comments
 (0)