Skip to content

Commit

Permalink
Merge 0b38e5e into 323db78
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmlane committed Jul 21, 2020
2 parents 323db78 + 0b38e5e commit 851cc67
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/source/reference/bovycoords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ self-explanatory names:
custom_to_radec <coordscustomtoradec.rst>
cyl_to_rect <coordscyltorect.rst>
cyl_to_rect_vec <coordscyltorectvec.rst>
cyl_to_spher <coordscyltospher.rst>
cyl_to_spher_vec <coordscyltosphervec.rst>
dl_to_rphi_2d <coordsdltorphi2d.rst>
galcencyl_to_XYZ <coordsgalcencyltoxyz.rst>
galcencyl_to_vxvyvz <coordsgalcencyltovxvyvz.rst>
Expand All @@ -36,6 +38,8 @@ self-explanatory names:
Rz_to_coshucosv <coordsRztocoshucosv.rst>
Rz_to_uv <coordsRztouv.rst>
sphergal_to_rectgal <coordssphergaltorectgal.rst>
spher_to_cyl <coordssphertocyl.rst>
spher_to_cyl_vec <coordssphertocylvec.rst>
uv_to_Rz <coordsuvtoRz.rst>
vrpmllpmbb_to_vxvyvz <coordsvrpmllpmbbtovxvyvz.rst>
vRvz_to_pupv <coordsvRvztopupv.rst>
Expand Down
4 changes: 4 additions & 0 deletions doc/source/reference/coordscyltospher.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.util.bovy_coords.cyl_to_spher
====================================

.. autofunction:: galpy.util.bovy_coords.cyl_to_spher
4 changes: 4 additions & 0 deletions doc/source/reference/coordscyltosphervec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.util.bovy_coords.cyl_to_spher_vec
========================================

.. autofunction:: galpy.util.bovy_coords.cyl_to_spher_vec
4 changes: 4 additions & 0 deletions doc/source/reference/coordssphertocyl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.util.bovy_coords.spher_to_cyl
====================================

.. autofunction:: galpy.util.bovy_coords.spher_to_cyl
4 changes: 4 additions & 0 deletions doc/source/reference/coordssphertocylvec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.util.bovy_coords.spher_to_cyl_vec
========================================

.. autofunction:: galpy.util.bovy_coords.spher_to_cyl_vec
3 changes: 3 additions & 0 deletions doc/source/reference/orbit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Methods
rguiding <orbitrguiding.rst>
rperi <orbitrperi.rst>
SkyCoord <orbitskycoord.rst>
theta <orbittheta.rst>
time <orbittime.rst>
toLinear <orbittolinear.rst>
toPlanar <orbittoplanar.rst>
Expand All @@ -105,8 +106,10 @@ Methods
vll <orbitvll.rst>
vlos <orbitvlos.rst>
vphi <orbitvphi.rst>
vr <orbitsphvr.rst>
vR <orbitvr.rst>
vra <orbitvra.rst>
vtheta <orbitvtheta.rst>
vT <orbitvt.rst>
vx <orbitvx.rst>
vy <orbitvy.rst>
Expand Down
4 changes: 4 additions & 0 deletions doc/source/reference/orbitsphvr.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.orbit.Orbit.vr
=====================

.. automethod:: galpy.orbit.Orbit.vr
4 changes: 4 additions & 0 deletions doc/source/reference/orbittheta.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.orbit.Orbit.theta
========================

.. automethod:: galpy.orbit.Orbit.theta
4 changes: 4 additions & 0 deletions doc/source/reference/orbitvtheta.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
galpy.orbit.Orbit.vtheta
=========================

.. automethod:: galpy.orbit.Orbit.vtheta
104 changes: 104 additions & 0 deletions galpy/orbit/Orbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,111 @@ def vphi(self,*args,**kwargs):
"""
thiso= self._call_internal(*args,**kwargs)
return (thiso[2]/thiso[0]).T

@physical_conversion('velocity')
@shapeDecorator
def vr(self,*args,**kwargs):
"""
NAME:
vr
PURPOSE:
return spherical radial velocity. For < 3 dimensions returns vR
INPUT:
t - (optional) time at which to get the radial velocity
vo= (Object-wide default) physical scale for velocities to use to convert
use_physical= use to override Object-wide default for using a physical scale for output
OUTPUT:
vr(t) [*input_shape,nt]
HISTORY:
2020-07-01 - Written - James (UofT)
"""
thiso = self._call_internal(*args,**kwargs)
if self.dim() == 3:
r = numpy.sqrt( numpy.square(thiso[0]) + numpy.square(thiso[3]) )
return ((thiso[0]*thiso[1]+thiso[3]*thiso[4])/r).T
else:
return thiso[1].T

@physical_conversion('velocity')
@shapeDecorator
def vtheta(self,*args,**kwargs):
"""
NAME:
vtheta
PURPOSE:
return spherical polar velocity
INPUT:
t - (optional) time at which to get the theta velocity
vo= (Object-wide default) physical scale for velocities to use to convert
use_physical= use to override Object-wide default for using a physical scale for output
OUTPUT:
vtheta(t) [*input_shape,nt]
HISTORY:
2020-07-01 - Written - James (UofT)
"""
thiso = self._call_internal(*args,**kwargs)
if not self.dim() == 3:
raise AttributeError("Orbit must be 3D to use vtheta()")
else:
r = numpy.sqrt(numpy.square(thiso[0])+numpy.square(thiso[3]))
return ((thiso[1]*thiso[3]-thiso[0]*thiso[4])/r).T

@physical_conversion('angle')
@shapeDecorator
def theta(self,*args,**kwargs):
"""
NAME:
theta
PURPOSE:
return spherical polar angle
INPUT:
t - (optional) time at which to get the angle
OUTPUT:
theta(t) [*input_shape,nt]
HISTORY:
2020-07-01 - Written - James (UofT)
"""
thiso = self._call_internal(*args,**kwargs)
if self.dim() != 3:
raise AttributeError("Orbit must be 3D to use theta()")
else:
return numpy.arctan2(thiso[0],thiso[3])


@physical_conversion('angle_deg')
@shapeDecorator
def ra(self,*args,**kwargs):
Expand Down
69 changes: 69 additions & 0 deletions galpy/util/bovy_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,75 @@ def galcencyl_to_vxvyvz(vR,vT,vZ,phi,vsun=[0.,1.,0.],Xsun=1.,Zsun=0.,
return galcenrect_to_vxvyvz(vXg,vYg,vZg,vsun=vsun,Xsun=Xsun,Zsun=Zsun,
_extra_rot=_extra_rot)

def cyl_to_spher_vec(vR,vT,vz,R,z):
"""
NAME:
cyl_to_spher_vec
PURPOSE:
transform vectors from cylindrical to spherical coordinates. vtheta is positive from pole towards equator.
INPUT:
vR - Galactocentric cylindrical radial velocity
vT - Galactocentric cylindrical tangential velocity
vz - Galactocentric cylindrical vertical velocity
R - Galactocentric cylindrical radius
z - Galactocentric cylindrical height
OUTPUT:
vr,vT,vtheta
HISTORY:
2020-07-01 - Written - James Lane (UofT)
"""
r = numpy.sqrt(numpy.square(R) + numpy.square(z))
vr = (R*vR + z*vz)/r
vtheta = (z*vR - R*vz)/r
return (vr,vT,vtheta)

def spher_to_cyl_vec(vr,vT,vtheta,theta):
"""
NAME:
spher_to_cyl_vec
PURPOSE:
transform vectors from spherical polar to cylindrical coordinates. vtheta is positive from pole towards equator, theta is 0 at pole
INPUT:
vr - Galactocentric spherical radial velocity
vT - Galactocentric spherical azimuthal velocity
vtheta - Galactocentric spherical polar velocity
theta - Galactocentric spherical polar angle
OUTPUT:
vR,vT,vz
HISTORY:
2020-07-01 - Written - James Lane (UofT)
"""
vR = vr*numpy.sin(theta) + vtheta*numpy.cos(theta)
vz = vr*numpy.cos(theta) - vtheta*numpy.sin(theta)
return (vR,vT,vz)

def rect_to_cyl_vec(vx,vy,vz,X,Y,Z,cyl=False):
"""
NAME:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,38 @@ def test_lbd_to_XYZ_jac():
assert numpy.fabs(jac[5,5]-numpy.sqrt(3.)/2.*d*4.740470463496208) < 10.**-10., 'lbd_to_XYZ_jac calculation did not work as expected'
return None

def test_cyl_to_spher_vec():
# Test 45 degrees, disk plane, & polar location
vr,vT,vtheta = bovy_coords.cyl_to_spher_vec(0.6,1.3,0.6,1.,1.)
assert numpy.fabs(vr-0.6*2**0.5) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vtheta-0) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vT-1.3) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
vr,vT,vtheta = bovy_coords.cyl_to_spher_vec(-1.2,-0.7,-0.8,1.,0.)
assert numpy.fabs(vr+1.2) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vtheta-0.8) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vT+0.7) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
vr,vT,vtheta = bovy_coords.cyl_to_spher_vec(-1.2,-0.7,-0.8,0.,1.)
assert numpy.fabs(vr+0.8) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vtheta+1.2) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
assert numpy.fabs(vT+0.7) < 10.**-8, 'cyl_to_spher_vec does not work as expected'
return None

def test_spher_to_cyl_vec():
# Test 45 degrees, disk plane, & polar location
vR,vT,vz = bovy_coords.spher_to_cyl_vec(0.7,1.4,0.7,numpy.pi/4.)
assert numpy.fabs(vR-0.7*2**0.5) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vT-1.4) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vz-0.) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
vR,vT,vz = bovy_coords.spher_to_cyl_vec(0.5,-1.3,0.7,0.)
assert numpy.fabs(vR-0.7) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vT+1.3) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vz-0.5) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
vR,vT,vz = bovy_coords.spher_to_cyl_vec(0.5,-1.3,0.7,numpy.pi/2.)
assert numpy.fabs(vR-0.5) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vT+1.3) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
assert numpy.fabs(vz+0.7) < 10.**-8, 'spher_to_cyl_vec does not work as expected'
return None

def test_cyl_to_spher():
# Just a few quick tests
r,t,p= bovy_coords.cyl_to_spher(1.2,3.2,1.)
Expand Down
Loading

0 comments on commit 851cc67

Please sign in to comment.