Reputation: 25
I am still a newbie in python and I need to use PyAstronomy module for writing a code. I want to call this function as an Input for another code:
def phaseAngle(pos, los='-z'):
"""
Calculate the phase angle.
Parameters
----------
pos : array
Either a one-dimensional array with xyz coordinate or a
[3,N] array containing N xyz positions.
los : LineOfSight object
A `LineOfSight` object from the pyasl giving the line of
sight.
Returns
-------
Phase angle : The phase angle in degrees. Depending on the input,
it returns a single value or an array.
"""
from PyAstronomy.pyasl import LineOfSight
l = LineOfSight(los)
if pos.shape == (3,):
# It is a single value
return numpy.arccos(numpy.sum(-pos * (-l.los)) /
numpy.sqrt(numpy.sum(pos**2))) / numpy.pi * 180.
else:
# It is an array of positions
N = len(pos[::, 0])
result = numpy.zeros(N)
for i in smo.range(N):
print(i, numpy.sum((-pos[i, ::]) * (-l.los)), pos[i, ::])
result[i] = numpy.arccos(numpy.sum((-pos[i, ::]) * (-l.los)) /
numpy.sqrt(numpy.sum(pos[i, ::]**2)))
return result / numpy.pi * 180.
In the main code the inputs are entered this way by calling KeplerEllipse from pyasl:
...
from PyAstronomy import pyasl
...
ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0)
that works very well and gives the positions and velocities as the outputs. But I need to use this phase angle
as another input. But, I don't know how to inverse the output and input of def phaseAngle(pos, los='-z')
so that I use the phase angle
as an input and add it to
ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, ??? )
Upvotes: 0
Views: 146
Reputation: 25
If you have created:
def func():
pass
Then you will call it:
func()
Upvotes: 0
Reputation: 3281
If the missing argument you are looking for is the phase angle then invoke the PhaseAngle function. As Sven says in the comments, in Python you can inline and nest pretty much at will. So:
ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, phaseAngle(?, ?) )
You have to supply phase angle with pos argument, and los if you don't want the default. It'll spit out the phaseAngle, which will be inserted where you need the argument.
For debugging you can also pre-compute like so:
phase_angle = phaseAngle(?, ?) # Put in the pos and los arguments here
ke = pyasl.KeplerEllipse(1.3, 2., e=0.5, Omega=70., i=10.0, w=110.0, phase_angle)
I think this answers your questions? There is no inversion involved though. This is forward-direction function evaluation.
Upvotes: 1