From 2ed410d7ad733b8c5eb1d1b81075b96a7e857bed Mon Sep 17 00:00:00 2001 From: Malcolm White Date: Fri, 14 Aug 2020 11:30:46 -0400 Subject: [PATCH] Debug Issue #8 https://github.com/malcolmw/pykonal/issues/8 --- pykonal/__version__.py | 2 +- pykonal/fields.pyx | 9 ++++++++- pykonal/solver.pyx | 5 ++++- pykonal/transformations.py | 8 ++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pykonal/__version__.py b/pykonal/__version__.py index 6b077c4..4d2eafe 100644 --- a/pykonal/__version__.py +++ b/pykonal/__version__.py @@ -1,7 +1,7 @@ __major_version__ = 0 __minor_version__ = 3 __patch__ = 2 -__release__ = "b1" +__release__ = "b2" __version_tuple__ = ( __major_version__, __minor_version__, diff --git a/pykonal/fields.pyx b/pykonal/fields.pyx index bbcfaee..a4afbb4 100644 --- a/pykonal/fields.pyx +++ b/pykonal/fields.pyx @@ -296,7 +296,14 @@ cdef class Field3D(object): :rtype: numpy.ndarray(shape=(N0,N1,N2,3), dtype=numpy.float) """ if self.coord_sys == "spherical" and coord_sys.lower() == "spherical": - return (transformations.sph2sph(self.nodes, origin)) + force_phi_positive = self.min_coords[2] >= 0 + return ( + transformations.sph2sph( + self.nodes, + origin, + force_phi_positive=force_phi_positive + ) + ) elif self.coord_sys == "cartesian" and coord_sys.lower() == "spherical": return (transformations.xyz2sph(self.nodes, origin)) elif self.coord_sys == "spherical" and coord_sys.lower() == "cartesian": diff --git a/pykonal/solver.pyx b/pykonal/solver.pyx index fba1b9c..14cd785 100644 --- a/pykonal/solver.pyx +++ b/pykonal/solver.pyx @@ -634,7 +634,10 @@ class PointSourceSolver(EikonalSolver): origin = (r0, t0, p0) # Transform the coordinates of the near-field grid nodes to the # far-field coordinate system. - nodes = self.near_field.vv.transform_coordinates(self.coord_sys, origin) + nodes = self.near_field.vv.transform_coordinates( + self.coord_sys, + origin + ) # Find the indices of the near-field grid nodes that are inside # the far-field grid. bool_idx = True diff --git a/pykonal/transformations.py b/pykonal/transformations.py index 3e6a2c0..a87d596 100644 --- a/pykonal/transformations.py +++ b/pykonal/transformations.py @@ -26,7 +26,7 @@ def geo2sph(nodes): return (sph) -def sph2sph(nodes, origin=(0,0,0)): +def sph2sph(nodes, origin=(0,0,0), force_phi_positive=False): """ Transform spherical coordinates to new spherical coordinate system. @@ -55,11 +55,13 @@ def sph2sph(nodes, origin=(0,0,0)): tt = np.arccos(xyz[...,2] / rr) np.seterr(**old) pp = np.arctan2(xyz[...,1], xyz[...,0]) + if force_phi_positive: + pp = np.mod(pp, 2*np.pi) rtp = np.moveaxis(np.stack([rr, tt, pp]), 0, -1) return (rtp) -def xyz2sph(nodes, origin=(0,0,0)): +def xyz2sph(nodes, origin=(0,0,0), force_phi_positive=False): """ Transform Cartesian coordinates to new spherical coordinate system. @@ -78,6 +80,8 @@ def xyz2sph(nodes, origin=(0,0,0)): tt = np.arccos(xyz[...,2] / rr) np.seterr(**old) pp = np.arctan2(xyz[...,1], xyz[...,0]) + if force_phi_positive: + pp = np.mod(pp, 2*np.pi) rtp = np.moveaxis(np.stack([rr, tt, pp]), 0, -1) return (rtp)